1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2010 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>
36 #include <linux/tcp.h>
37 #include <linux/pkt_sched.h>
38 #include <linux/ipv6.h>
39 #include <linux/slab.h>
40 #include <net/checksum.h>
41 #include <net/ip6_checksum.h>
42 #include <linux/ethtool.h>
43 #include <linux/if_vlan.h>
44 #include <scsi/fc/fc_fcoe.h>
47 #include "ixgbe_common.h"
48 #include "ixgbe_dcb_82599.h"
49 #include "ixgbe_sriov.h"
51 char ixgbe_driver_name
[] = "ixgbe";
52 static const char ixgbe_driver_string
[] =
53 "Intel(R) 10 Gigabit PCI Express Network Driver";
55 #define DRV_VERSION "2.0.62-k2"
56 const char ixgbe_driver_version
[] = DRV_VERSION
;
57 static char ixgbe_copyright
[] = "Copyright (c) 1999-2010 Intel Corporation.";
59 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
60 [board_82598
] = &ixgbe_82598_info
,
61 [board_82599
] = &ixgbe_82599_info
,
64 /* ixgbe_pci_tbl - PCI Device ID Table
66 * Wildcard entries (PCI_ANY_ID) should come last
67 * Last entry must be all 0s
69 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
70 * Class, Class Mask, private data (not used) }
72 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl
) = {
73 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
),
75 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
),
77 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
),
79 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
),
81 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
),
83 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
),
85 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
),
87 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
),
89 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
),
91 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
),
93 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
),
95 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
),
97 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
),
99 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
),
101 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KR
),
103 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
),
105 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_EM
),
107 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
),
109 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
),
111 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
),
114 /* required last entry */
117 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
119 #ifdef CONFIG_IXGBE_DCA
120 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
122 static struct notifier_block dca_notifier
= {
123 .notifier_call
= ixgbe_notify_dca
,
129 #ifdef CONFIG_PCI_IOV
130 static unsigned int max_vfs
;
131 module_param(max_vfs
, uint
, 0);
132 MODULE_PARM_DESC(max_vfs
, "Maximum number of virtual functions to allocate "
133 "per physical function");
134 #endif /* CONFIG_PCI_IOV */
136 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
137 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
138 MODULE_LICENSE("GPL");
139 MODULE_VERSION(DRV_VERSION
);
141 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
143 static inline void ixgbe_disable_sriov(struct ixgbe_adapter
*adapter
)
145 struct ixgbe_hw
*hw
= &adapter
->hw
;
150 #ifdef CONFIG_PCI_IOV
151 /* disable iov and allow time for transactions to clear */
152 pci_disable_sriov(adapter
->pdev
);
155 /* turn off device IOV mode */
156 gcr
= IXGBE_READ_REG(hw
, IXGBE_GCR_EXT
);
157 gcr
&= ~(IXGBE_GCR_EXT_SRIOV
);
158 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr
);
159 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
160 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
161 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
163 /* set default pool back to 0 */
164 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
165 vmdctl
&= ~IXGBE_VT_CTL_POOL_MASK
;
166 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
);
168 /* take a breather then clean up driver data */
171 kfree(adapter
->vfinfo
);
172 adapter
->vfinfo
= NULL
;
174 adapter
->num_vfs
= 0;
175 adapter
->flags
&= ~IXGBE_FLAG_SRIOV_ENABLED
;
178 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
182 /* Let firmware take over control of h/w */
183 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
184 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
185 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
188 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
192 /* Let firmware know the driver has taken over */
193 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
194 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
195 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
199 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
200 * @adapter: pointer to adapter struct
201 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
202 * @queue: queue to map the corresponding interrupt to
203 * @msix_vector: the vector to map to the corresponding queue
206 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
207 u8 queue
, u8 msix_vector
)
210 struct ixgbe_hw
*hw
= &adapter
->hw
;
211 switch (hw
->mac
.type
) {
212 case ixgbe_mac_82598EB
:
213 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
216 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
217 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
218 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
219 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
220 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
222 case ixgbe_mac_82599EB
:
223 if (direction
== -1) {
225 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
226 index
= ((queue
& 1) * 8);
227 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
228 ivar
&= ~(0xFF << index
);
229 ivar
|= (msix_vector
<< index
);
230 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
233 /* tx or rx causes */
234 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
235 index
= ((16 * (queue
& 1)) + (8 * direction
));
236 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
237 ivar
&= ~(0xFF << index
);
238 ivar
|= (msix_vector
<< index
);
239 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
247 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
252 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
253 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
254 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
256 mask
= (qmask
& 0xFFFFFFFF);
257 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
258 mask
= (qmask
>> 32);
259 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
263 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter
*adapter
,
264 struct ixgbe_tx_buffer
267 if (tx_buffer_info
->dma
) {
268 if (tx_buffer_info
->mapped_as_page
)
269 pci_unmap_page(adapter
->pdev
,
271 tx_buffer_info
->length
,
274 pci_unmap_single(adapter
->pdev
,
276 tx_buffer_info
->length
,
278 tx_buffer_info
->dma
= 0;
280 if (tx_buffer_info
->skb
) {
281 dev_kfree_skb_any(tx_buffer_info
->skb
);
282 tx_buffer_info
->skb
= NULL
;
284 tx_buffer_info
->time_stamp
= 0;
285 /* tx_buffer_info must be completely set up in the transmit path */
289 * ixgbe_tx_is_paused - check if the tx ring is paused
290 * @adapter: the ixgbe adapter
291 * @tx_ring: the corresponding tx_ring
293 * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
294 * corresponding TC of this tx_ring when checking TFCS.
296 * Returns : true if paused
298 static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter
*adapter
,
299 struct ixgbe_ring
*tx_ring
)
301 u32 txoff
= IXGBE_TFCS_TXOFF
;
303 #ifdef CONFIG_IXGBE_DCB
304 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
306 int reg_idx
= tx_ring
->reg_idx
;
307 int dcb_i
= adapter
->ring_feature
[RING_F_DCB
].indices
;
309 switch (adapter
->hw
.mac
.type
) {
310 case ixgbe_mac_82598EB
:
312 txoff
= IXGBE_TFCS_TXOFF0
;
314 case ixgbe_mac_82599EB
:
316 txoff
= IXGBE_TFCS_TXOFF
;
320 if (tc
== 2) /* TC2, TC3 */
321 tc
+= (reg_idx
- 64) >> 4;
322 else if (tc
== 3) /* TC4, TC5, TC6, TC7 */
323 tc
+= 1 + ((reg_idx
- 96) >> 3);
324 } else if (dcb_i
== 4) {
328 tc
+= (reg_idx
- 64) >> 5;
329 if (tc
== 2) /* TC2, TC3 */
330 tc
+= (reg_idx
- 96) >> 4;
340 return IXGBE_READ_REG(&adapter
->hw
, IXGBE_TFCS
) & txoff
;
343 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter
*adapter
,
344 struct ixgbe_ring
*tx_ring
,
347 struct ixgbe_hw
*hw
= &adapter
->hw
;
349 /* Detect a transmit hang in hardware, this serializes the
350 * check with the clearing of time_stamp and movement of eop */
351 adapter
->detect_tx_hung
= false;
352 if (tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
353 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
) &&
354 !ixgbe_tx_is_paused(adapter
, tx_ring
)) {
355 /* detected Tx unit hang */
356 union ixgbe_adv_tx_desc
*tx_desc
;
357 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
358 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
360 " TDH, TDT <%x>, <%x>\n"
361 " next_to_use <%x>\n"
362 " next_to_clean <%x>\n"
363 "tx_buffer_info[next_to_clean]\n"
364 " time_stamp <%lx>\n"
366 tx_ring
->queue_index
,
367 IXGBE_READ_REG(hw
, tx_ring
->head
),
368 IXGBE_READ_REG(hw
, tx_ring
->tail
),
369 tx_ring
->next_to_use
, eop
,
370 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
377 #define IXGBE_MAX_TXD_PWR 14
378 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
380 /* Tx Descriptors needed, worst case */
381 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
382 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
383 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
384 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
386 static void ixgbe_tx_timeout(struct net_device
*netdev
);
389 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
390 * @q_vector: structure containing interrupt and ring information
391 * @tx_ring: tx ring to clean
393 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
394 struct ixgbe_ring
*tx_ring
)
396 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
397 struct net_device
*netdev
= adapter
->netdev
;
398 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
399 struct ixgbe_tx_buffer
*tx_buffer_info
;
400 unsigned int i
, eop
, count
= 0;
401 unsigned int total_bytes
= 0, total_packets
= 0;
403 i
= tx_ring
->next_to_clean
;
404 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
405 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
407 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
408 (count
< tx_ring
->work_limit
)) {
409 bool cleaned
= false;
410 for ( ; !cleaned
; count
++) {
412 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
413 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
414 cleaned
= (i
== eop
);
415 skb
= tx_buffer_info
->skb
;
417 if (cleaned
&& skb
) {
418 unsigned int segs
, bytecount
;
419 unsigned int hlen
= skb_headlen(skb
);
421 /* gso_segs is currently only valid for tcp */
422 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
424 /* adjust for FCoE Sequence Offload */
425 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
426 && (skb
->protocol
== htons(ETH_P_FCOE
)) &&
428 hlen
= skb_transport_offset(skb
) +
429 sizeof(struct fc_frame_header
) +
430 sizeof(struct fcoe_crc_eof
);
431 segs
= DIV_ROUND_UP(skb
->len
- hlen
,
432 skb_shinfo(skb
)->gso_size
);
434 #endif /* IXGBE_FCOE */
435 /* multiply data chunks by size of headers */
436 bytecount
= ((segs
- 1) * hlen
) + skb
->len
;
437 total_packets
+= segs
;
438 total_bytes
+= bytecount
;
441 ixgbe_unmap_and_free_tx_resource(adapter
,
444 tx_desc
->wb
.status
= 0;
447 if (i
== tx_ring
->count
)
451 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
452 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
455 tx_ring
->next_to_clean
= i
;
457 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
458 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
459 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
460 /* Make sure that anybody stopping the queue after this
461 * sees the new next_to_clean.
464 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
465 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
466 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
467 ++tx_ring
->restart_queue
;
471 if (adapter
->detect_tx_hung
) {
472 if (ixgbe_check_tx_hang(adapter
, tx_ring
, i
)) {
473 /* schedule immediate reset if we believe we hung */
475 "tx hang %d detected, resetting adapter\n",
476 adapter
->tx_timeout_count
+ 1);
477 ixgbe_tx_timeout(adapter
->netdev
);
481 /* re-arm the interrupt */
482 if (count
>= tx_ring
->work_limit
)
483 ixgbe_irq_rearm_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
485 tx_ring
->total_bytes
+= total_bytes
;
486 tx_ring
->total_packets
+= total_packets
;
487 tx_ring
->stats
.packets
+= total_packets
;
488 tx_ring
->stats
.bytes
+= total_bytes
;
489 return (count
< tx_ring
->work_limit
);
492 #ifdef CONFIG_IXGBE_DCA
493 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
494 struct ixgbe_ring
*rx_ring
)
498 int q
= rx_ring
->reg_idx
;
500 if (rx_ring
->cpu
!= cpu
) {
501 rxctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
));
502 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
503 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK
;
504 rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
505 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
506 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599
;
507 rxctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
508 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
);
510 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
511 rxctrl
|= IXGBE_DCA_RXCTRL_HEAD_DCA_EN
;
512 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN
);
513 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN
|
514 IXGBE_DCA_RXCTRL_DESC_HSRO_EN
);
515 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
), rxctrl
);
521 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
522 struct ixgbe_ring
*tx_ring
)
526 int q
= tx_ring
->reg_idx
;
527 struct ixgbe_hw
*hw
= &adapter
->hw
;
529 if (tx_ring
->cpu
!= cpu
) {
530 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
531 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(q
));
532 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK
;
533 txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
534 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
535 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(q
), txctrl
);
536 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
537 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL_82599(q
));
538 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599
;
539 txctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
540 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
);
541 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
542 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL_82599(q
), txctrl
);
549 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
553 if (!(adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
))
556 /* always use CB2 mode, difference is masked in the CB driver */
557 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 2);
559 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
560 adapter
->tx_ring
[i
]->cpu
= -1;
561 ixgbe_update_tx_dca(adapter
, adapter
->tx_ring
[i
]);
563 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
564 adapter
->rx_ring
[i
]->cpu
= -1;
565 ixgbe_update_rx_dca(adapter
, adapter
->rx_ring
[i
]);
569 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
571 struct net_device
*netdev
= dev_get_drvdata(dev
);
572 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
573 unsigned long event
= *(unsigned long *)data
;
576 case DCA_PROVIDER_ADD
:
577 /* if we're already enabled, don't do it again */
578 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
580 if (dca_add_requester(dev
) == 0) {
581 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
582 ixgbe_setup_dca(adapter
);
585 /* Fall Through since DCA is disabled. */
586 case DCA_PROVIDER_REMOVE
:
587 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
588 dca_remove_requester(dev
);
589 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
590 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
598 #endif /* CONFIG_IXGBE_DCA */
600 * ixgbe_receive_skb - Send a completed packet up the stack
601 * @adapter: board private structure
602 * @skb: packet to send up
603 * @status: hardware indication of status of receive
604 * @rx_ring: rx descriptor ring (for a specific queue) to setup
605 * @rx_desc: rx descriptor
607 static void ixgbe_receive_skb(struct ixgbe_q_vector
*q_vector
,
608 struct sk_buff
*skb
, u8 status
,
609 struct ixgbe_ring
*ring
,
610 union ixgbe_adv_rx_desc
*rx_desc
)
612 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
613 struct napi_struct
*napi
= &q_vector
->napi
;
614 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
615 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
617 skb_record_rx_queue(skb
, ring
->queue_index
);
618 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
619 if (adapter
->vlgrp
&& is_vlan
&& (tag
& VLAN_VID_MASK
))
620 vlan_gro_receive(napi
, adapter
->vlgrp
, tag
, skb
);
622 napi_gro_receive(napi
, skb
);
624 if (adapter
->vlgrp
&& is_vlan
&& (tag
& VLAN_VID_MASK
))
625 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
632 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
633 * @adapter: address of board private structure
634 * @status_err: hardware indication of status of receive
635 * @skb: skb currently being received and modified
637 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
638 union ixgbe_adv_rx_desc
*rx_desc
,
641 u32 status_err
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
643 skb
->ip_summed
= CHECKSUM_NONE
;
645 /* Rx csum disabled */
646 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
649 /* if IP and error */
650 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
651 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
652 adapter
->hw_csum_rx_error
++;
656 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
659 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
660 u16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
663 * 82599 errata, UDP frames with a 0 checksum can be marked as
666 if ((pkt_info
& IXGBE_RXDADV_PKTTYPE_UDP
) &&
667 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
670 adapter
->hw_csum_rx_error
++;
674 /* It must be a TCP or UDP packet with a valid checksum */
675 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
678 static inline void ixgbe_release_rx_desc(struct ixgbe_hw
*hw
,
679 struct ixgbe_ring
*rx_ring
, u32 val
)
682 * Force memory writes to complete before letting h/w
683 * know there are new descriptors to fetch. (Only
684 * applicable for weak-ordered memory model archs,
688 IXGBE_WRITE_REG(hw
, IXGBE_RDT(rx_ring
->reg_idx
), val
);
692 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
693 * @adapter: address of board private structure
695 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter
*adapter
,
696 struct ixgbe_ring
*rx_ring
,
699 struct pci_dev
*pdev
= adapter
->pdev
;
700 union ixgbe_adv_rx_desc
*rx_desc
;
701 struct ixgbe_rx_buffer
*bi
;
704 i
= rx_ring
->next_to_use
;
705 bi
= &rx_ring
->rx_buffer_info
[i
];
707 while (cleaned_count
--) {
708 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
711 (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
)) {
713 bi
->page
= alloc_page(GFP_ATOMIC
);
715 adapter
->alloc_rx_page_failed
++;
720 /* use a half page if we're re-using */
721 bi
->page_offset
^= (PAGE_SIZE
/ 2);
724 bi
->page_dma
= pci_map_page(pdev
, bi
->page
,
732 /* netdev_alloc_skb reserves 32 bytes up front!! */
733 uint bufsz
= rx_ring
->rx_buf_len
+ SMP_CACHE_BYTES
;
734 skb
= netdev_alloc_skb(adapter
->netdev
, bufsz
);
737 adapter
->alloc_rx_buff_failed
++;
741 /* advance the data pointer to the next cache line */
742 skb_reserve(skb
, (PTR_ALIGN(skb
->data
, SMP_CACHE_BYTES
)
746 bi
->dma
= pci_map_single(pdev
, skb
->data
,
750 /* Refresh the desc even if buffer_addrs didn't change because
751 * each write-back erases this info. */
752 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
753 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
754 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
756 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
760 if (i
== rx_ring
->count
)
762 bi
= &rx_ring
->rx_buffer_info
[i
];
766 if (rx_ring
->next_to_use
!= i
) {
767 rx_ring
->next_to_use
= i
;
769 i
= (rx_ring
->count
- 1);
771 ixgbe_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
775 static inline u16
ixgbe_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
777 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
780 static inline u16
ixgbe_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
782 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
785 static inline u32
ixgbe_get_rsc_count(union ixgbe_adv_rx_desc
*rx_desc
)
787 return (le32_to_cpu(rx_desc
->wb
.lower
.lo_dword
.data
) &
788 IXGBE_RXDADV_RSCCNT_MASK
) >>
789 IXGBE_RXDADV_RSCCNT_SHIFT
;
793 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
794 * @skb: pointer to the last skb in the rsc queue
795 * @count: pointer to number of packets coalesced in this context
797 * This function changes a queue full of hw rsc buffers into a completed
798 * packet. It uses the ->prev pointers to find the first packet and then
799 * turns it into the frag list owner.
801 static inline struct sk_buff
*ixgbe_transform_rsc_queue(struct sk_buff
*skb
,
804 unsigned int frag_list_size
= 0;
807 struct sk_buff
*prev
= skb
->prev
;
808 frag_list_size
+= skb
->len
;
814 skb_shinfo(skb
)->frag_list
= skb
->next
;
816 skb
->len
+= frag_list_size
;
817 skb
->data_len
+= frag_list_size
;
818 skb
->truesize
+= frag_list_size
;
822 struct ixgbe_rsc_cb
{
826 #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
828 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
829 struct ixgbe_ring
*rx_ring
,
830 int *work_done
, int work_to_do
)
832 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
833 struct net_device
*netdev
= adapter
->netdev
;
834 struct pci_dev
*pdev
= adapter
->pdev
;
835 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
836 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
838 unsigned int i
, rsc_count
= 0;
841 bool cleaned
= false;
842 int cleaned_count
= 0;
843 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
846 #endif /* IXGBE_FCOE */
848 i
= rx_ring
->next_to_clean
;
849 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
850 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
851 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
853 while (staterr
& IXGBE_RXD_STAT_DD
) {
855 if (*work_done
>= work_to_do
)
859 rmb(); /* read descriptor and rx_buffer_info after status DD */
860 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
861 hdr_info
= le16_to_cpu(ixgbe_get_hdr_info(rx_desc
));
862 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
863 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
864 if (len
> IXGBE_RX_HDR_SIZE
)
865 len
= IXGBE_RX_HDR_SIZE
;
866 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
868 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
872 skb
= rx_buffer_info
->skb
;
874 rx_buffer_info
->skb
= NULL
;
876 if (rx_buffer_info
->dma
) {
877 if ((adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
878 (!(staterr
& IXGBE_RXD_STAT_EOP
)) &&
881 * When HWRSC is enabled, delay unmapping
882 * of the first packet. It carries the
883 * header information, HW may still
884 * access the header after the writeback.
885 * Only unmap it when EOP is reached
887 IXGBE_RSC_CB(skb
)->dma
= rx_buffer_info
->dma
;
889 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
892 rx_buffer_info
->dma
= 0;
897 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
898 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
899 rx_buffer_info
->page_dma
= 0;
900 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
901 rx_buffer_info
->page
,
902 rx_buffer_info
->page_offset
,
905 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
906 (page_count(rx_buffer_info
->page
) != 1))
907 rx_buffer_info
->page
= NULL
;
909 get_page(rx_buffer_info
->page
);
911 skb
->len
+= upper_len
;
912 skb
->data_len
+= upper_len
;
913 skb
->truesize
+= upper_len
;
917 if (i
== rx_ring
->count
)
920 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
924 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
925 rsc_count
= ixgbe_get_rsc_count(rx_desc
);
928 u32 nextp
= (staterr
& IXGBE_RXDADV_NEXTP_MASK
) >>
929 IXGBE_RXDADV_NEXTP_SHIFT
;
930 next_buffer
= &rx_ring
->rx_buffer_info
[nextp
];
932 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
935 if (staterr
& IXGBE_RXD_STAT_EOP
) {
937 skb
= ixgbe_transform_rsc_queue(skb
, &(rx_ring
->rsc_count
));
938 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
939 if (IXGBE_RSC_CB(skb
)->dma
) {
940 pci_unmap_single(pdev
, IXGBE_RSC_CB(skb
)->dma
,
943 IXGBE_RSC_CB(skb
)->dma
= 0;
945 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
)
946 rx_ring
->rsc_count
+= skb_shinfo(skb
)->nr_frags
;
948 rx_ring
->rsc_count
++;
949 rx_ring
->rsc_flush
++;
951 rx_ring
->stats
.packets
++;
952 rx_ring
->stats
.bytes
+= skb
->len
;
954 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
955 rx_buffer_info
->skb
= next_buffer
->skb
;
956 rx_buffer_info
->dma
= next_buffer
->dma
;
957 next_buffer
->skb
= skb
;
958 next_buffer
->dma
= 0;
960 skb
->next
= next_buffer
->skb
;
961 skb
->next
->prev
= skb
;
963 rx_ring
->non_eop_descs
++;
967 if (staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) {
968 dev_kfree_skb_irq(skb
);
972 ixgbe_rx_checksum(adapter
, rx_desc
, skb
);
974 /* probably a little skewed due to removing CRC */
975 total_rx_bytes
+= skb
->len
;
978 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
980 /* if ddp, not passing to ULD unless for FCP_RSP or error */
981 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
982 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
986 #endif /* IXGBE_FCOE */
987 ixgbe_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
990 rx_desc
->wb
.upper
.status_error
= 0;
992 /* return some buffers to hardware, one at a time is too slow */
993 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
994 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
998 /* use prefetched values */
1000 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1002 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1005 rx_ring
->next_to_clean
= i
;
1006 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
1009 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
1012 /* include DDPed FCoE data */
1013 if (ddp_bytes
> 0) {
1016 mss
= adapter
->netdev
->mtu
- sizeof(struct fcoe_hdr
) -
1017 sizeof(struct fc_frame_header
) -
1018 sizeof(struct fcoe_crc_eof
);
1021 total_rx_bytes
+= ddp_bytes
;
1022 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
, mss
);
1024 #endif /* IXGBE_FCOE */
1026 rx_ring
->total_packets
+= total_rx_packets
;
1027 rx_ring
->total_bytes
+= total_rx_bytes
;
1028 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
1029 netdev
->stats
.rx_packets
+= total_rx_packets
;
1034 static int ixgbe_clean_rxonly(struct napi_struct
*, int);
1036 * ixgbe_configure_msix - Configure MSI-X hardware
1037 * @adapter: board private structure
1039 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1042 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
1044 struct ixgbe_q_vector
*q_vector
;
1045 int i
, j
, q_vectors
, v_idx
, r_idx
;
1048 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1051 * Populate the IVAR table and set the ITR values to the
1052 * corresponding register.
1054 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
1055 q_vector
= adapter
->q_vector
[v_idx
];
1056 /* XXX for_each_set_bit(...) */
1057 r_idx
= find_first_bit(q_vector
->rxr_idx
,
1058 adapter
->num_rx_queues
);
1060 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1061 j
= adapter
->rx_ring
[r_idx
]->reg_idx
;
1062 ixgbe_set_ivar(adapter
, 0, j
, v_idx
);
1063 r_idx
= find_next_bit(q_vector
->rxr_idx
,
1064 adapter
->num_rx_queues
,
1067 r_idx
= find_first_bit(q_vector
->txr_idx
,
1068 adapter
->num_tx_queues
);
1070 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1071 j
= adapter
->tx_ring
[r_idx
]->reg_idx
;
1072 ixgbe_set_ivar(adapter
, 1, j
, v_idx
);
1073 r_idx
= find_next_bit(q_vector
->txr_idx
,
1074 adapter
->num_tx_queues
,
1078 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
1080 q_vector
->eitr
= adapter
->tx_eitr_param
;
1081 else if (q_vector
->rxr_count
)
1083 q_vector
->eitr
= adapter
->rx_eitr_param
;
1085 ixgbe_write_eitr(q_vector
);
1088 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
1089 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
1091 else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
1092 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
1093 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
1095 /* set up to autoclear timer, and the vectors */
1096 mask
= IXGBE_EIMS_ENABLE_MASK
;
1097 if (adapter
->num_vfs
)
1098 mask
&= ~(IXGBE_EIMS_OTHER
|
1099 IXGBE_EIMS_MAILBOX
|
1102 mask
&= ~(IXGBE_EIMS_OTHER
| IXGBE_EIMS_LSC
);
1103 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
1106 enum latency_range
{
1110 latency_invalid
= 255
1114 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1115 * @adapter: pointer to adapter
1116 * @eitr: eitr setting (ints per sec) to give last timeslice
1117 * @itr_setting: current throttle rate in ints/second
1118 * @packets: the number of packets during this measurement interval
1119 * @bytes: the number of bytes during this measurement interval
1121 * Stores a new ITR value based on packets and byte
1122 * counts during the last interrupt. The advantage of per interrupt
1123 * computation is faster updates and more accurate ITR for the current
1124 * traffic pattern. Constants in this function were computed
1125 * based on theoretical maximum wire speed and thresholds were set based
1126 * on testing data as well as attempting to minimize response time
1127 * while increasing bulk throughput.
1128 * this functionality is controlled by the InterruptThrottleRate module
1129 * parameter (see ixgbe_param.c)
1131 static u8
ixgbe_update_itr(struct ixgbe_adapter
*adapter
,
1132 u32 eitr
, u8 itr_setting
,
1133 int packets
, int bytes
)
1135 unsigned int retval
= itr_setting
;
1140 goto update_itr_done
;
1143 /* simple throttlerate management
1144 * 0-20MB/s lowest (100000 ints/s)
1145 * 20-100MB/s low (20000 ints/s)
1146 * 100-1249MB/s bulk (8000 ints/s)
1148 /* what was last interrupt timeslice? */
1149 timepassed_us
= 1000000/eitr
;
1150 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
1152 switch (itr_setting
) {
1153 case lowest_latency
:
1154 if (bytes_perint
> adapter
->eitr_low
)
1155 retval
= low_latency
;
1158 if (bytes_perint
> adapter
->eitr_high
)
1159 retval
= bulk_latency
;
1160 else if (bytes_perint
<= adapter
->eitr_low
)
1161 retval
= lowest_latency
;
1164 if (bytes_perint
<= adapter
->eitr_high
)
1165 retval
= low_latency
;
1174 * ixgbe_write_eitr - write EITR register in hardware specific way
1175 * @q_vector: structure containing interrupt and ring information
1177 * This function is made to be called by ethtool and by the driver
1178 * when it needs to update EITR registers at runtime. Hardware
1179 * specific quirks/differences are taken care of here.
1181 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
1183 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1184 struct ixgbe_hw
*hw
= &adapter
->hw
;
1185 int v_idx
= q_vector
->v_idx
;
1186 u32 itr_reg
= EITR_INTS_PER_SEC_TO_REG(q_vector
->eitr
);
1188 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1189 /* must write high and low 16 bits to reset counter */
1190 itr_reg
|= (itr_reg
<< 16);
1191 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1193 * set the WDIS bit to not clear the timer bits and cause an
1194 * immediate assertion of the interrupt
1196 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
1198 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
1201 static void ixgbe_set_itr_msix(struct ixgbe_q_vector
*q_vector
)
1203 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1205 u8 current_itr
, ret_itr
;
1207 struct ixgbe_ring
*rx_ring
, *tx_ring
;
1209 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1210 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1211 tx_ring
= adapter
->tx_ring
[r_idx
];
1212 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1214 tx_ring
->total_packets
,
1215 tx_ring
->total_bytes
);
1216 /* if the result for this queue would decrease interrupt
1217 * rate for this vector then use that result */
1218 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
1219 q_vector
->tx_itr
- 1 : ret_itr
);
1220 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1224 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1225 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1226 rx_ring
= adapter
->rx_ring
[r_idx
];
1227 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1229 rx_ring
->total_packets
,
1230 rx_ring
->total_bytes
);
1231 /* if the result for this queue would decrease interrupt
1232 * rate for this vector then use that result */
1233 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
1234 q_vector
->rx_itr
- 1 : ret_itr
);
1235 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1239 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1241 switch (current_itr
) {
1242 /* counts and packets in update_itr are dependent on these numbers */
1243 case lowest_latency
:
1247 new_itr
= 20000; /* aka hwitr = ~200 */
1255 if (new_itr
!= q_vector
->eitr
) {
1256 /* do an exponential smoothing */
1257 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1259 /* save the algorithm value here, not the smoothed one */
1260 q_vector
->eitr
= new_itr
;
1262 ixgbe_write_eitr(q_vector
);
1268 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
1270 struct ixgbe_hw
*hw
= &adapter
->hw
;
1272 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
1273 (eicr
& IXGBE_EICR_GPI_SDP1
)) {
1274 DPRINTK(PROBE
, CRIT
, "Fan has stopped, replace the adapter\n");
1275 /* write to clear the interrupt */
1276 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1280 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1282 struct ixgbe_hw
*hw
= &adapter
->hw
;
1284 if (eicr
& IXGBE_EICR_GPI_SDP1
) {
1285 /* Clear the interrupt */
1286 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1287 schedule_work(&adapter
->multispeed_fiber_task
);
1288 } else if (eicr
& IXGBE_EICR_GPI_SDP2
) {
1289 /* Clear the interrupt */
1290 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP2
);
1291 schedule_work(&adapter
->sfp_config_module_task
);
1293 /* Interrupt isn't for us... */
1298 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
1300 struct ixgbe_hw
*hw
= &adapter
->hw
;
1303 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1304 adapter
->link_check_timeout
= jiffies
;
1305 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1306 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
1307 IXGBE_WRITE_FLUSH(hw
);
1308 schedule_work(&adapter
->watchdog_task
);
1312 static irqreturn_t
ixgbe_msix_lsc(int irq
, void *data
)
1314 struct net_device
*netdev
= data
;
1315 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1316 struct ixgbe_hw
*hw
= &adapter
->hw
;
1320 * Workaround for Silicon errata. Use clear-by-write instead
1321 * of clear-by-read. Reading with EICS will return the
1322 * interrupt causes without clearing, which later be done
1323 * with the write to EICR.
1325 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
1326 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
1328 if (eicr
& IXGBE_EICR_LSC
)
1329 ixgbe_check_lsc(adapter
);
1331 if (eicr
& IXGBE_EICR_MAILBOX
)
1332 ixgbe_msg_task(adapter
);
1334 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
1335 ixgbe_check_fan_failure(adapter
, eicr
);
1337 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
1338 ixgbe_check_sfp_event(adapter
, eicr
);
1340 /* Handle Flow Director Full threshold interrupt */
1341 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
1343 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_FLOW_DIR
);
1344 /* Disable transmits before FDIR Re-initialization */
1345 netif_tx_stop_all_queues(netdev
);
1346 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1347 struct ixgbe_ring
*tx_ring
=
1348 adapter
->tx_ring
[i
];
1349 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE
,
1350 &tx_ring
->reinit_state
))
1351 schedule_work(&adapter
->fdir_reinit_task
);
1355 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1356 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_OTHER
);
1361 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
1366 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1367 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1368 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1370 mask
= (qmask
& 0xFFFFFFFF);
1371 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(0), mask
);
1372 mask
= (qmask
>> 32);
1373 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(1), mask
);
1375 /* skip the flush */
1378 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
1383 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1384 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1385 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, mask
);
1387 mask
= (qmask
& 0xFFFFFFFF);
1388 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), mask
);
1389 mask
= (qmask
>> 32);
1390 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), mask
);
1392 /* skip the flush */
1395 static irqreturn_t
ixgbe_msix_clean_tx(int irq
, void *data
)
1397 struct ixgbe_q_vector
*q_vector
= data
;
1398 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1399 struct ixgbe_ring
*tx_ring
;
1402 if (!q_vector
->txr_count
)
1405 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1406 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1407 tx_ring
= adapter
->tx_ring
[r_idx
];
1408 tx_ring
->total_bytes
= 0;
1409 tx_ring
->total_packets
= 0;
1410 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1414 /* EIAM disabled interrupts (on this vector) for us */
1415 napi_schedule(&q_vector
->napi
);
1421 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1423 * @data: pointer to our q_vector struct for this interrupt vector
1425 static irqreturn_t
ixgbe_msix_clean_rx(int irq
, void *data
)
1427 struct ixgbe_q_vector
*q_vector
= data
;
1428 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1429 struct ixgbe_ring
*rx_ring
;
1433 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1434 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1435 rx_ring
= adapter
->rx_ring
[r_idx
];
1436 rx_ring
->total_bytes
= 0;
1437 rx_ring
->total_packets
= 0;
1438 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1442 if (!q_vector
->rxr_count
)
1445 /* disable interrupts on this vector only */
1446 /* EIAM disabled interrupts (on this vector) for us */
1447 napi_schedule(&q_vector
->napi
);
1452 static irqreturn_t
ixgbe_msix_clean_many(int irq
, void *data
)
1454 struct ixgbe_q_vector
*q_vector
= data
;
1455 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1456 struct ixgbe_ring
*ring
;
1460 if (!q_vector
->txr_count
&& !q_vector
->rxr_count
)
1463 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1464 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1465 ring
= adapter
->tx_ring
[r_idx
];
1466 ring
->total_bytes
= 0;
1467 ring
->total_packets
= 0;
1468 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1472 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1473 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1474 ring
= adapter
->rx_ring
[r_idx
];
1475 ring
->total_bytes
= 0;
1476 ring
->total_packets
= 0;
1477 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1481 /* EIAM disabled interrupts (on this vector) for us */
1482 napi_schedule(&q_vector
->napi
);
1488 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1489 * @napi: napi struct with our devices info in it
1490 * @budget: amount of work driver is allowed to do this pass, in packets
1492 * This function is optimized for cleaning one queue only on a single
1495 static int ixgbe_clean_rxonly(struct napi_struct
*napi
, int budget
)
1497 struct ixgbe_q_vector
*q_vector
=
1498 container_of(napi
, struct ixgbe_q_vector
, napi
);
1499 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1500 struct ixgbe_ring
*rx_ring
= NULL
;
1504 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1505 rx_ring
= adapter
->rx_ring
[r_idx
];
1506 #ifdef CONFIG_IXGBE_DCA
1507 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1508 ixgbe_update_rx_dca(adapter
, rx_ring
);
1511 ixgbe_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
1513 /* If all Rx work done, exit the polling mode */
1514 if (work_done
< budget
) {
1515 napi_complete(napi
);
1516 if (adapter
->rx_itr_setting
& 1)
1517 ixgbe_set_itr_msix(q_vector
);
1518 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1519 ixgbe_irq_enable_queues(adapter
,
1520 ((u64
)1 << q_vector
->v_idx
));
1527 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
1528 * @napi: napi struct with our devices info in it
1529 * @budget: amount of work driver is allowed to do this pass, in packets
1531 * This function will clean more than one rx queue associated with a
1534 static int ixgbe_clean_rxtx_many(struct napi_struct
*napi
, int budget
)
1536 struct ixgbe_q_vector
*q_vector
=
1537 container_of(napi
, struct ixgbe_q_vector
, napi
);
1538 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1539 struct ixgbe_ring
*ring
= NULL
;
1540 int work_done
= 0, i
;
1542 bool tx_clean_complete
= true;
1544 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1545 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1546 ring
= adapter
->tx_ring
[r_idx
];
1547 #ifdef CONFIG_IXGBE_DCA
1548 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1549 ixgbe_update_tx_dca(adapter
, ring
);
1551 tx_clean_complete
&= ixgbe_clean_tx_irq(q_vector
, ring
);
1552 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1556 /* attempt to distribute budget to each queue fairly, but don't allow
1557 * the budget to go below 1 because we'll exit polling */
1558 budget
/= (q_vector
->rxr_count
?: 1);
1559 budget
= max(budget
, 1);
1560 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1561 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1562 ring
= adapter
->rx_ring
[r_idx
];
1563 #ifdef CONFIG_IXGBE_DCA
1564 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1565 ixgbe_update_rx_dca(adapter
, ring
);
1567 ixgbe_clean_rx_irq(q_vector
, ring
, &work_done
, budget
);
1568 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1572 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1573 ring
= adapter
->rx_ring
[r_idx
];
1574 /* If all Rx work done, exit the polling mode */
1575 if (work_done
< budget
) {
1576 napi_complete(napi
);
1577 if (adapter
->rx_itr_setting
& 1)
1578 ixgbe_set_itr_msix(q_vector
);
1579 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1580 ixgbe_irq_enable_queues(adapter
,
1581 ((u64
)1 << q_vector
->v_idx
));
1589 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1590 * @napi: napi struct with our devices info in it
1591 * @budget: amount of work driver is allowed to do this pass, in packets
1593 * This function is optimized for cleaning one queue only on a single
1596 static int ixgbe_clean_txonly(struct napi_struct
*napi
, int budget
)
1598 struct ixgbe_q_vector
*q_vector
=
1599 container_of(napi
, struct ixgbe_q_vector
, napi
);
1600 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1601 struct ixgbe_ring
*tx_ring
= NULL
;
1605 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1606 tx_ring
= adapter
->tx_ring
[r_idx
];
1607 #ifdef CONFIG_IXGBE_DCA
1608 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1609 ixgbe_update_tx_dca(adapter
, tx_ring
);
1612 if (!ixgbe_clean_tx_irq(q_vector
, tx_ring
))
1615 /* If all Tx work done, exit the polling mode */
1616 if (work_done
< budget
) {
1617 napi_complete(napi
);
1618 if (adapter
->tx_itr_setting
& 1)
1619 ixgbe_set_itr_msix(q_vector
);
1620 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1621 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1627 static inline void map_vector_to_rxq(struct ixgbe_adapter
*a
, int v_idx
,
1630 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1632 set_bit(r_idx
, q_vector
->rxr_idx
);
1633 q_vector
->rxr_count
++;
1636 static inline void map_vector_to_txq(struct ixgbe_adapter
*a
, int v_idx
,
1639 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1641 set_bit(t_idx
, q_vector
->txr_idx
);
1642 q_vector
->txr_count
++;
1646 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1647 * @adapter: board private structure to initialize
1648 * @vectors: allotted vector count for descriptor rings
1650 * This function maps descriptor rings to the queue-specific vectors
1651 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1652 * one vector per ring/queue, but on a constrained vector budget, we
1653 * group the rings as "efficiently" as possible. You would add new
1654 * mapping configurations in here.
1656 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter
*adapter
,
1660 int rxr_idx
= 0, txr_idx
= 0;
1661 int rxr_remaining
= adapter
->num_rx_queues
;
1662 int txr_remaining
= adapter
->num_tx_queues
;
1667 /* No mapping required if MSI-X is disabled. */
1668 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
1672 * The ideal configuration...
1673 * We have enough vectors to map one per queue.
1675 if (vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1676 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1677 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1679 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1680 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1686 * If we don't have enough vectors for a 1-to-1
1687 * mapping, we'll have to group them so there are
1688 * multiple queues per vector.
1690 /* Re-adjusting *qpv takes care of the remainder. */
1691 for (i
= v_start
; i
< vectors
; i
++) {
1692 rqpv
= DIV_ROUND_UP(rxr_remaining
, vectors
- i
);
1693 for (j
= 0; j
< rqpv
; j
++) {
1694 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1699 for (i
= v_start
; i
< vectors
; i
++) {
1700 tqpv
= DIV_ROUND_UP(txr_remaining
, vectors
- i
);
1701 for (j
= 0; j
< tqpv
; j
++) {
1702 map_vector_to_txq(adapter
, i
, txr_idx
);
1713 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1714 * @adapter: board private structure
1716 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1717 * interrupts from the kernel.
1719 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
1721 struct net_device
*netdev
= adapter
->netdev
;
1722 irqreturn_t (*handler
)(int, void *);
1723 int i
, vector
, q_vectors
, err
;
1726 /* Decrement for Other and TCP Timer vectors */
1727 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1729 /* Map the Tx/Rx rings to the vectors we were allotted. */
1730 err
= ixgbe_map_rings_to_vectors(adapter
, q_vectors
);
1734 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1735 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1736 &ixgbe_msix_clean_many)
1737 for (vector
= 0; vector
< q_vectors
; vector
++) {
1738 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1740 if(handler
== &ixgbe_msix_clean_rx
) {
1741 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1742 netdev
->name
, "rx", ri
++);
1744 else if(handler
== &ixgbe_msix_clean_tx
) {
1745 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1746 netdev
->name
, "tx", ti
++);
1749 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1750 netdev
->name
, "TxRx", vector
);
1752 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1753 handler
, 0, adapter
->name
[vector
],
1754 adapter
->q_vector
[vector
]);
1757 "request_irq failed for MSIX interrupt "
1758 "Error: %d\n", err
);
1759 goto free_queue_irqs
;
1763 sprintf(adapter
->name
[vector
], "%s:lsc", netdev
->name
);
1764 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1765 ixgbe_msix_lsc
, 0, adapter
->name
[vector
], netdev
);
1768 "request_irq for msix_lsc failed: %d\n", err
);
1769 goto free_queue_irqs
;
1775 for (i
= vector
- 1; i
>= 0; i
--)
1776 free_irq(adapter
->msix_entries
[--vector
].vector
,
1777 adapter
->q_vector
[i
]);
1778 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
1779 pci_disable_msix(adapter
->pdev
);
1780 kfree(adapter
->msix_entries
);
1781 adapter
->msix_entries
= NULL
;
1786 static void ixgbe_set_itr(struct ixgbe_adapter
*adapter
)
1788 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1790 u32 new_itr
= q_vector
->eitr
;
1791 struct ixgbe_ring
*rx_ring
= adapter
->rx_ring
[0];
1792 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[0];
1794 q_vector
->tx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1796 tx_ring
->total_packets
,
1797 tx_ring
->total_bytes
);
1798 q_vector
->rx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1800 rx_ring
->total_packets
,
1801 rx_ring
->total_bytes
);
1803 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1805 switch (current_itr
) {
1806 /* counts and packets in update_itr are dependent on these numbers */
1807 case lowest_latency
:
1811 new_itr
= 20000; /* aka hwitr = ~200 */
1820 if (new_itr
!= q_vector
->eitr
) {
1821 /* do an exponential smoothing */
1822 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1824 /* save the algorithm value here, not the smoothed one */
1825 q_vector
->eitr
= new_itr
;
1827 ixgbe_write_eitr(q_vector
);
1834 * ixgbe_irq_enable - Enable default interrupt generation settings
1835 * @adapter: board private structure
1837 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
)
1841 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1842 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
1843 mask
|= IXGBE_EIMS_GPI_SDP1
;
1844 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1845 mask
|= IXGBE_EIMS_ECC
;
1846 mask
|= IXGBE_EIMS_GPI_SDP1
;
1847 mask
|= IXGBE_EIMS_GPI_SDP2
;
1848 if (adapter
->num_vfs
)
1849 mask
|= IXGBE_EIMS_MAILBOX
;
1851 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
1852 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
1853 mask
|= IXGBE_EIMS_FLOW_DIR
;
1855 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1856 ixgbe_irq_enable_queues(adapter
, ~0);
1857 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1859 if (adapter
->num_vfs
> 32) {
1860 u32 eitrsel
= (1 << (adapter
->num_vfs
- 32)) - 1;
1861 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
1866 * ixgbe_intr - legacy mode Interrupt Handler
1867 * @irq: interrupt number
1868 * @data: pointer to a network interface device structure
1870 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
1872 struct net_device
*netdev
= data
;
1873 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1874 struct ixgbe_hw
*hw
= &adapter
->hw
;
1875 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1879 * Workaround for silicon errata. Mask the interrupts
1880 * before the read of EICR.
1882 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
1884 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1885 * therefore no explict interrupt disable is necessary */
1886 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
1888 /* shared interrupt alert!
1889 * make sure interrupts are enabled because the read will
1890 * have disabled interrupts due to EIAM */
1891 ixgbe_irq_enable(adapter
);
1892 return IRQ_NONE
; /* Not our interrupt */
1895 if (eicr
& IXGBE_EICR_LSC
)
1896 ixgbe_check_lsc(adapter
);
1898 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
1899 ixgbe_check_sfp_event(adapter
, eicr
);
1901 ixgbe_check_fan_failure(adapter
, eicr
);
1903 if (napi_schedule_prep(&(q_vector
->napi
))) {
1904 adapter
->tx_ring
[0]->total_packets
= 0;
1905 adapter
->tx_ring
[0]->total_bytes
= 0;
1906 adapter
->rx_ring
[0]->total_packets
= 0;
1907 adapter
->rx_ring
[0]->total_bytes
= 0;
1908 /* would disable interrupts here but EIAM disabled it */
1909 __napi_schedule(&(q_vector
->napi
));
1915 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter
*adapter
)
1917 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1919 for (i
= 0; i
< q_vectors
; i
++) {
1920 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
1921 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1922 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1923 q_vector
->rxr_count
= 0;
1924 q_vector
->txr_count
= 0;
1929 * ixgbe_request_irq - initialize interrupts
1930 * @adapter: board private structure
1932 * Attempts to configure interrupts using the best available
1933 * capabilities of the hardware and kernel.
1935 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
1937 struct net_device
*netdev
= adapter
->netdev
;
1940 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1941 err
= ixgbe_request_msix_irqs(adapter
);
1942 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
1943 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
1944 netdev
->name
, netdev
);
1946 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
1947 netdev
->name
, netdev
);
1951 DPRINTK(PROBE
, ERR
, "request_irq failed, Error %d\n", err
);
1956 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
1958 struct net_device
*netdev
= adapter
->netdev
;
1960 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1963 q_vectors
= adapter
->num_msix_vectors
;
1966 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1969 for (; i
>= 0; i
--) {
1970 free_irq(adapter
->msix_entries
[i
].vector
,
1971 adapter
->q_vector
[i
]);
1974 ixgbe_reset_q_vectors(adapter
);
1976 free_irq(adapter
->pdev
->irq
, netdev
);
1981 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1982 * @adapter: board private structure
1984 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
1986 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1987 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
1989 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
1990 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
1991 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
1992 if (adapter
->num_vfs
> 32)
1993 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
1995 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1996 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1998 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1999 synchronize_irq(adapter
->msix_entries
[i
].vector
);
2001 synchronize_irq(adapter
->pdev
->irq
);
2006 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2009 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
2011 struct ixgbe_hw
*hw
= &adapter
->hw
;
2013 IXGBE_WRITE_REG(hw
, IXGBE_EITR(0),
2014 EITR_INTS_PER_SEC_TO_REG(adapter
->rx_eitr_param
));
2016 ixgbe_set_ivar(adapter
, 0, 0, 0);
2017 ixgbe_set_ivar(adapter
, 1, 0, 0);
2019 map_vector_to_rxq(adapter
, 0, 0);
2020 map_vector_to_txq(adapter
, 0, 0);
2022 DPRINTK(HW
, INFO
, "Legacy interrupt IVAR setup done\n");
2026 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2027 * @adapter: board private structure
2029 * Configure the Tx unit of the MAC after a reset.
2031 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
2034 struct ixgbe_hw
*hw
= &adapter
->hw
;
2035 u32 i
, j
, tdlen
, txctrl
;
2037 /* Setup the HW Tx Head and Tail descriptor pointers */
2038 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2039 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
2042 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2043 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(j
),
2044 (tdba
& DMA_BIT_MASK(32)));
2045 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(j
), (tdba
>> 32));
2046 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(j
), tdlen
);
2047 IXGBE_WRITE_REG(hw
, IXGBE_TDH(j
), 0);
2048 IXGBE_WRITE_REG(hw
, IXGBE_TDT(j
), 0);
2049 adapter
->tx_ring
[i
]->head
= IXGBE_TDH(j
);
2050 adapter
->tx_ring
[i
]->tail
= IXGBE_TDT(j
);
2052 * Disable Tx Head Writeback RO bit, since this hoses
2053 * bookkeeping if things aren't delivered in order.
2055 switch (hw
->mac
.type
) {
2056 case ixgbe_mac_82598EB
:
2057 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(j
));
2059 case ixgbe_mac_82599EB
:
2061 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL_82599(j
));
2064 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
2065 switch (hw
->mac
.type
) {
2066 case ixgbe_mac_82598EB
:
2067 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(j
), txctrl
);
2069 case ixgbe_mac_82599EB
:
2071 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL_82599(j
), txctrl
);
2076 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2080 /* disable the arbiter while setting MTQC */
2081 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
2082 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
2083 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2085 /* set transmit pool layout */
2086 mask
= (IXGBE_FLAG_SRIOV_ENABLED
| IXGBE_FLAG_DCB_ENABLED
);
2087 switch (adapter
->flags
& mask
) {
2089 case (IXGBE_FLAG_SRIOV_ENABLED
):
2090 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
,
2091 (IXGBE_MTQC_VT_ENA
| IXGBE_MTQC_64VF
));
2094 case (IXGBE_FLAG_DCB_ENABLED
):
2095 /* We enable 8 traffic classes, DCB only */
2096 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
,
2097 (IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
));
2101 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, IXGBE_MTQC_64Q_1PB
);
2105 /* re-eable the arbiter */
2106 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
2107 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2111 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2113 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
2114 struct ixgbe_ring
*rx_ring
)
2118 struct ixgbe_ring_feature
*feature
= adapter
->ring_feature
;
2120 index
= rx_ring
->reg_idx
;
2121 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
2123 mask
= (unsigned long) feature
[RING_F_RSS
].mask
;
2124 index
= index
& mask
;
2126 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(index
));
2128 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
2129 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
2131 srrctl
|= (IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
2132 IXGBE_SRRCTL_BSIZEHDR_MASK
;
2134 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
2135 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2136 srrctl
|= IXGBE_MAX_RXBUFFER
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2138 srrctl
|= (PAGE_SIZE
/ 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2140 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
2142 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
2143 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2144 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
2147 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(index
), srrctl
);
2150 static u32
ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
2155 if (!(adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
2158 mask
= adapter
->flags
& (IXGBE_FLAG_RSS_ENABLED
2159 #ifdef CONFIG_IXGBE_DCB
2160 | IXGBE_FLAG_DCB_ENABLED
2162 | IXGBE_FLAG_SRIOV_ENABLED
2166 case (IXGBE_FLAG_RSS_ENABLED
):
2167 mrqc
= IXGBE_MRQC_RSSEN
;
2169 case (IXGBE_FLAG_SRIOV_ENABLED
):
2170 mrqc
= IXGBE_MRQC_VMDQEN
;
2172 #ifdef CONFIG_IXGBE_DCB
2173 case (IXGBE_FLAG_DCB_ENABLED
):
2174 mrqc
= IXGBE_MRQC_RT8TCEN
;
2176 #endif /* CONFIG_IXGBE_DCB */
2185 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2186 * @adapter: address of board private structure
2187 * @index: index of ring to set
2189 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
, int index
)
2191 struct ixgbe_ring
*rx_ring
;
2192 struct ixgbe_hw
*hw
= &adapter
->hw
;
2197 rx_ring
= adapter
->rx_ring
[index
];
2198 j
= rx_ring
->reg_idx
;
2199 rx_buf_len
= rx_ring
->rx_buf_len
;
2200 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(j
));
2201 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
2203 * we must limit the number of descriptors so that the
2204 * total size of max desc * buf_len is not greater
2207 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
2208 #if (MAX_SKB_FRAGS > 16)
2209 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2210 #elif (MAX_SKB_FRAGS > 8)
2211 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2212 #elif (MAX_SKB_FRAGS > 4)
2213 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2215 rscctrl
|= IXGBE_RSCCTL_MAXDESC_1
;
2218 if (rx_buf_len
< IXGBE_RXBUFFER_4096
)
2219 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2220 else if (rx_buf_len
< IXGBE_RXBUFFER_8192
)
2221 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2223 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2225 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(j
), rscctrl
);
2229 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
2230 * @adapter: board private structure
2232 * Configure the Rx unit of the MAC after a reset.
2234 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
2237 struct ixgbe_hw
*hw
= &adapter
->hw
;
2238 struct ixgbe_ring
*rx_ring
;
2239 struct net_device
*netdev
= adapter
->netdev
;
2240 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2242 u32 rdlen
, rxctrl
, rxcsum
;
2243 static const u32 seed
[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2244 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2245 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2247 u32 reta
= 0, mrqc
= 0;
2251 /* Decide whether to use packet split mode or not */
2252 /* Do not use packet split if we're in SR-IOV Mode */
2253 if (!adapter
->num_vfs
)
2254 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
2256 /* Set the RX buffer length according to the mode */
2257 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
2258 rx_buf_len
= IXGBE_RX_HDR_SIZE
;
2259 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2260 /* PSRTYPE must be initialized in 82599 */
2261 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
2262 IXGBE_PSRTYPE_UDPHDR
|
2263 IXGBE_PSRTYPE_IPV4HDR
|
2264 IXGBE_PSRTYPE_IPV6HDR
|
2265 IXGBE_PSRTYPE_L2HDR
;
2267 IXGBE_PSRTYPE(adapter
->num_vfs
),
2271 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
2272 (netdev
->mtu
<= ETH_DATA_LEN
))
2273 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
2275 rx_buf_len
= ALIGN(max_frame
, 1024);
2278 fctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_FCTRL
);
2279 fctrl
|= IXGBE_FCTRL_BAM
;
2280 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
2281 fctrl
|= IXGBE_FCTRL_PMCF
;
2282 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_FCTRL
, fctrl
);
2284 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
2285 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2286 hlreg0
&= ~IXGBE_HLREG0_JUMBOEN
;
2288 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2290 if (netdev
->features
& NETIF_F_FCOE_MTU
)
2291 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2293 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
2295 rdlen
= adapter
->rx_ring
[0]->count
* sizeof(union ixgbe_adv_rx_desc
);
2296 /* disable receives while setting up the descriptors */
2297 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2298 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
2301 * Setup the HW Rx Head and Tail Descriptor Pointers and
2302 * the Base and Length of the Rx Descriptor Ring
2304 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2305 rx_ring
= adapter
->rx_ring
[i
];
2306 rdba
= rx_ring
->dma
;
2307 j
= rx_ring
->reg_idx
;
2308 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(j
), (rdba
& DMA_BIT_MASK(32)));
2309 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(j
), (rdba
>> 32));
2310 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(j
), rdlen
);
2311 IXGBE_WRITE_REG(hw
, IXGBE_RDH(j
), 0);
2312 IXGBE_WRITE_REG(hw
, IXGBE_RDT(j
), 0);
2313 rx_ring
->head
= IXGBE_RDH(j
);
2314 rx_ring
->tail
= IXGBE_RDT(j
);
2315 rx_ring
->rx_buf_len
= rx_buf_len
;
2317 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)
2318 rx_ring
->flags
|= IXGBE_RING_RX_PS_ENABLED
;
2320 rx_ring
->flags
&= ~IXGBE_RING_RX_PS_ENABLED
;
2323 if (netdev
->features
& NETIF_F_FCOE_MTU
) {
2324 struct ixgbe_ring_feature
*f
;
2325 f
= &adapter
->ring_feature
[RING_F_FCOE
];
2326 if ((i
>= f
->mask
) && (i
< f
->mask
+ f
->indices
)) {
2327 rx_ring
->flags
&= ~IXGBE_RING_RX_PS_ENABLED
;
2328 if (rx_buf_len
< IXGBE_FCOE_JUMBO_FRAME_SIZE
)
2329 rx_ring
->rx_buf_len
=
2330 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2334 #endif /* IXGBE_FCOE */
2335 ixgbe_configure_srrctl(adapter
, rx_ring
);
2338 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2340 * For VMDq support of different descriptor types or
2341 * buffer sizes through the use of multiple SRRCTL
2342 * registers, RDRXCTL.MVMEN must be set to 1
2344 * also, the manual doesn't mention it clearly but DCA hints
2345 * will only use queue 0's tags unless this bit is set. Side
2346 * effects of setting this bit are only that SRRCTL must be
2347 * fully programmed [0..15]
2349 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2350 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
2351 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2354 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
2356 u32 reg_offset
, vf_shift
;
2357 u32 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
2358 vt_reg_bits
= IXGBE_VMD_CTL_VMDQ_EN
2359 | IXGBE_VT_CTL_REPLEN
;
2360 vt_reg_bits
|= (adapter
->num_vfs
<<
2361 IXGBE_VT_CTL_POOL_SHIFT
);
2362 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
| vt_reg_bits
);
2363 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, 0);
2365 vf_shift
= adapter
->num_vfs
% 32;
2366 reg_offset
= adapter
->num_vfs
/ 32;
2367 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(0), 0);
2368 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(1), 0);
2369 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(0), 0);
2370 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(1), 0);
2371 /* Enable only the PF's pool for Tx/Rx */
2372 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), (1 << vf_shift
));
2373 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), (1 << vf_shift
));
2374 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
2375 ixgbe_set_vmolr(hw
, adapter
->num_vfs
);
2378 /* Program MRQC for the distribution of queues */
2379 mrqc
= ixgbe_setup_mrqc(adapter
);
2381 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
2382 /* Fill out redirection table */
2383 for (i
= 0, j
= 0; i
< 128; i
++, j
++) {
2384 if (j
== adapter
->ring_feature
[RING_F_RSS
].indices
)
2386 /* reta = 4-byte sliding window of
2387 * 0x00..(indices-1)(indices-1)00..etc. */
2388 reta
= (reta
<< 8) | (j
* 0x11);
2390 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
2393 /* Fill out hash function seeds */
2394 for (i
= 0; i
< 10; i
++)
2395 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), seed
[i
]);
2397 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2398 mrqc
|= IXGBE_MRQC_RSSEN
;
2399 /* Perform hash on these packet types */
2400 mrqc
|= IXGBE_MRQC_RSS_FIELD_IPV4
2401 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2402 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2403 | IXGBE_MRQC_RSS_FIELD_IPV6
2404 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2405 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
2407 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
2409 if (adapter
->num_vfs
) {
2412 /* Map PF MAC address in RAR Entry 0 to first pool
2414 hw
->mac
.ops
.set_vmdq(hw
, 0, adapter
->num_vfs
);
2416 /* Set up VF register offsets for selected VT Mode, i.e.
2417 * 64 VFs for SR-IOV */
2418 reg
= IXGBE_READ_REG(hw
, IXGBE_GCR_EXT
);
2419 reg
|= IXGBE_GCR_EXT_SRIOV
;
2420 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, reg
);
2423 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
2425 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
||
2426 adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
) {
2427 /* Disable indicating checksum in descriptor, enables
2429 rxcsum
|= IXGBE_RXCSUM_PCSD
;
2431 if (!(rxcsum
& IXGBE_RXCSUM_PCSD
)) {
2432 /* Enable IPv4 payload checksum for UDP fragments
2433 * if PCSD is not set */
2434 rxcsum
|= IXGBE_RXCSUM_IPPCSE
;
2437 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
2439 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2440 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2441 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
2442 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
2443 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2446 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
2447 /* Enable 82599 HW-RSC */
2448 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2449 ixgbe_configure_rscctl(adapter
, i
);
2451 /* Disable RSC for ACK packets */
2452 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
2453 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
2457 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2459 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2460 struct ixgbe_hw
*hw
= &adapter
->hw
;
2461 int pool_ndx
= adapter
->num_vfs
;
2463 /* add VID to filter table */
2464 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, true);
2467 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2469 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2470 struct ixgbe_hw
*hw
= &adapter
->hw
;
2471 int pool_ndx
= adapter
->num_vfs
;
2473 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2474 ixgbe_irq_disable(adapter
);
2476 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
2478 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2479 ixgbe_irq_enable(adapter
);
2481 /* remove VID from filter table */
2482 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, false);
2486 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
2487 * @adapter: driver data
2489 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter
*adapter
)
2491 struct ixgbe_hw
*hw
= &adapter
->hw
;
2492 u32 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2495 switch (hw
->mac
.type
) {
2496 case ixgbe_mac_82598EB
:
2497 vlnctrl
&= ~(IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
);
2498 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2499 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2501 case ixgbe_mac_82599EB
:
2502 vlnctrl
&= ~IXGBE_VLNCTRL_VFE
;
2503 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2504 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2505 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2506 j
= adapter
->rx_ring
[i
]->reg_idx
;
2507 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2508 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
2509 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
2518 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
2519 * @adapter: driver data
2521 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter
*adapter
)
2523 struct ixgbe_hw
*hw
= &adapter
->hw
;
2524 u32 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2527 switch (hw
->mac
.type
) {
2528 case ixgbe_mac_82598EB
:
2529 vlnctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
2530 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2531 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2533 case ixgbe_mac_82599EB
:
2534 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
2535 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2536 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2537 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2538 j
= adapter
->rx_ring
[i
]->reg_idx
;
2539 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2540 vlnctrl
|= IXGBE_RXDCTL_VME
;
2541 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
2549 static void ixgbe_vlan_rx_register(struct net_device
*netdev
,
2550 struct vlan_group
*grp
)
2552 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2554 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2555 ixgbe_irq_disable(adapter
);
2556 adapter
->vlgrp
= grp
;
2559 * For a DCB driver, always enable VLAN tag stripping so we can
2560 * still receive traffic from a DCB-enabled host even if we're
2563 ixgbe_vlan_filter_enable(adapter
);
2565 ixgbe_vlan_rx_add_vid(netdev
, 0);
2567 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2568 ixgbe_irq_enable(adapter
);
2571 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
2573 ixgbe_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2575 if (adapter
->vlgrp
) {
2577 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2578 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
2580 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
2586 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
2587 * @netdev: network interface device structure
2589 * The set_rx_method entry point is called whenever the unicast/multicast
2590 * address list or the network interface flags are updated. This routine is
2591 * responsible for configuring the hardware for proper unicast, multicast and
2594 void ixgbe_set_rx_mode(struct net_device
*netdev
)
2596 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2597 struct ixgbe_hw
*hw
= &adapter
->hw
;
2600 /* Check for Promiscuous and All Multicast modes */
2602 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
2604 if (netdev
->flags
& IFF_PROMISC
) {
2605 hw
->addr_ctrl
.user_set_promisc
= 1;
2606 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2607 /* don't hardware filter vlans in promisc mode */
2608 ixgbe_vlan_filter_disable(adapter
);
2610 if (netdev
->flags
& IFF_ALLMULTI
) {
2611 fctrl
|= IXGBE_FCTRL_MPE
;
2612 fctrl
&= ~IXGBE_FCTRL_UPE
;
2614 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2616 ixgbe_vlan_filter_enable(adapter
);
2617 hw
->addr_ctrl
.user_set_promisc
= 0;
2620 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
2622 /* reprogram secondary unicast list */
2623 hw
->mac
.ops
.update_uc_addr_list(hw
, netdev
);
2625 /* reprogram multicast list */
2626 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
2628 if (adapter
->num_vfs
)
2629 ixgbe_restore_vf_multicasts(adapter
);
2632 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
2635 struct ixgbe_q_vector
*q_vector
;
2636 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2638 /* legacy and MSI only use one vector */
2639 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2642 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2643 struct napi_struct
*napi
;
2644 q_vector
= adapter
->q_vector
[q_idx
];
2645 napi
= &q_vector
->napi
;
2646 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2647 if (!q_vector
->rxr_count
|| !q_vector
->txr_count
) {
2648 if (q_vector
->txr_count
== 1)
2649 napi
->poll
= &ixgbe_clean_txonly
;
2650 else if (q_vector
->rxr_count
== 1)
2651 napi
->poll
= &ixgbe_clean_rxonly
;
2659 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
2662 struct ixgbe_q_vector
*q_vector
;
2663 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2665 /* legacy and MSI only use one vector */
2666 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2669 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2670 q_vector
= adapter
->q_vector
[q_idx
];
2671 napi_disable(&q_vector
->napi
);
2675 #ifdef CONFIG_IXGBE_DCB
2677 * ixgbe_configure_dcb - Configure DCB hardware
2678 * @adapter: ixgbe adapter struct
2680 * This is called by the driver on open to configure the DCB hardware.
2681 * This is also called by the gennetlink interface when reconfiguring
2684 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
2686 struct ixgbe_hw
*hw
= &adapter
->hw
;
2690 ixgbe_dcb_check_config(&adapter
->dcb_cfg
);
2691 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_TX_CONFIG
);
2692 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_RX_CONFIG
);
2694 /* reconfigure the hardware */
2695 ixgbe_dcb_hw_config(&adapter
->hw
, &adapter
->dcb_cfg
);
2697 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2698 j
= adapter
->tx_ring
[i
]->reg_idx
;
2699 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2700 /* PThresh workaround for Tx hang with DFP enabled. */
2702 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2704 /* Enable VLAN tag insert/strip */
2705 ixgbe_vlan_filter_enable(adapter
);
2707 hw
->mac
.ops
.set_vfta(&adapter
->hw
, 0, 0, true);
2711 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
2713 struct net_device
*netdev
= adapter
->netdev
;
2714 struct ixgbe_hw
*hw
= &adapter
->hw
;
2717 ixgbe_set_rx_mode(netdev
);
2719 ixgbe_restore_vlan(adapter
);
2720 #ifdef CONFIG_IXGBE_DCB
2721 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
2722 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2723 netif_set_gso_max_size(netdev
, 32768);
2725 netif_set_gso_max_size(netdev
, 65536);
2726 ixgbe_configure_dcb(adapter
);
2728 netif_set_gso_max_size(netdev
, 65536);
2731 netif_set_gso_max_size(netdev
, 65536);
2735 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
2736 ixgbe_configure_fcoe(adapter
);
2738 #endif /* IXGBE_FCOE */
2739 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2740 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2741 adapter
->tx_ring
[i
]->atr_sample_rate
=
2742 adapter
->atr_sample_rate
;
2743 ixgbe_init_fdir_signature_82599(hw
, adapter
->fdir_pballoc
);
2744 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
2745 ixgbe_init_fdir_perfect_82599(hw
, adapter
->fdir_pballoc
);
2748 ixgbe_configure_tx(adapter
);
2749 ixgbe_configure_rx(adapter
);
2750 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2751 ixgbe_alloc_rx_buffers(adapter
, adapter
->rx_ring
[i
],
2752 (adapter
->rx_ring
[i
]->count
- 1));
2755 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2757 switch (hw
->phy
.type
) {
2758 case ixgbe_phy_sfp_avago
:
2759 case ixgbe_phy_sfp_ftl
:
2760 case ixgbe_phy_sfp_intel
:
2761 case ixgbe_phy_sfp_unknown
:
2762 case ixgbe_phy_tw_tyco
:
2763 case ixgbe_phy_tw_unknown
:
2771 * ixgbe_sfp_link_config - set up SFP+ link
2772 * @adapter: pointer to private adapter struct
2774 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
2776 struct ixgbe_hw
*hw
= &adapter
->hw
;
2778 if (hw
->phy
.multispeed_fiber
) {
2780 * In multispeed fiber setups, the device may not have
2781 * had a physical connection when the driver loaded.
2782 * If that's the case, the initial link configuration
2783 * couldn't get the MAC into 10G or 1G mode, so we'll
2784 * never have a link status change interrupt fire.
2785 * We need to try and force an autonegotiation
2786 * session, then bring up link.
2788 hw
->mac
.ops
.setup_sfp(hw
);
2789 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
2790 schedule_work(&adapter
->multispeed_fiber_task
);
2793 * Direct Attach Cu and non-multispeed fiber modules
2794 * still need to be configured properly prior to
2797 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_MOD_TASK
))
2798 schedule_work(&adapter
->sfp_config_module_task
);
2803 * ixgbe_non_sfp_link_config - set up non-SFP+ link
2804 * @hw: pointer to private hardware struct
2806 * Returns 0 on success, negative on failure
2808 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
2811 bool negotiation
, link_up
= false;
2812 u32 ret
= IXGBE_ERR_LINK_SETUP
;
2814 if (hw
->mac
.ops
.check_link
)
2815 ret
= hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
2820 if (hw
->mac
.ops
.get_link_capabilities
)
2821 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
2825 if (hw
->mac
.ops
.setup_link
)
2826 ret
= hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, link_up
);
2831 #define IXGBE_MAX_RX_DESC_POLL 10
2832 static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
2835 int j
= adapter
->rx_ring
[rxr
]->reg_idx
;
2838 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
2839 if (IXGBE_READ_REG(&adapter
->hw
,
2840 IXGBE_RXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
2845 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
2846 DPRINTK(DRV
, ERR
, "RXDCTL.ENABLE on Rx queue %d "
2847 "not set within the polling period\n", rxr
);
2849 ixgbe_release_rx_desc(&adapter
->hw
, adapter
->rx_ring
[rxr
],
2850 (adapter
->rx_ring
[rxr
]->count
- 1));
2853 static int ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
2855 struct net_device
*netdev
= adapter
->netdev
;
2856 struct ixgbe_hw
*hw
= &adapter
->hw
;
2858 int num_rx_rings
= adapter
->num_rx_queues
;
2860 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2861 u32 txdctl
, rxdctl
, mhadd
;
2866 ixgbe_get_hw_control(adapter
);
2868 if ((adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) ||
2869 (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)) {
2870 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2871 gpie
= (IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_EIAME
|
2872 IXGBE_GPIE_PBA_SUPPORT
| IXGBE_GPIE_OCD
);
2877 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
2878 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
2879 gpie
|= IXGBE_GPIE_VTMODE_64
;
2881 /* XXX: to interrupt immediately for EICS writes, enable this */
2882 /* gpie |= IXGBE_GPIE_EIMEN; */
2883 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2886 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2888 * use EIAM to auto-mask when MSI-X interrupt is asserted
2889 * this saves a register write for every interrupt
2891 switch (hw
->mac
.type
) {
2892 case ixgbe_mac_82598EB
:
2893 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
2896 case ixgbe_mac_82599EB
:
2897 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
2898 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
2902 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2903 * specifically only auto mask tx and rx interrupts */
2904 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
2907 /* Enable fan failure interrupt if media type is copper */
2908 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
2909 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2910 gpie
|= IXGBE_SDP1_GPIEN
;
2911 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2914 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2915 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2916 gpie
|= IXGBE_SDP1_GPIEN
;
2917 gpie
|= IXGBE_SDP2_GPIEN
;
2918 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2922 /* adjust max frame to be able to do baby jumbo for FCoE */
2923 if ((netdev
->features
& NETIF_F_FCOE_MTU
) &&
2924 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
2925 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2927 #endif /* IXGBE_FCOE */
2928 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
2929 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
2930 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
2931 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
2933 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
2936 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2937 j
= adapter
->tx_ring
[i
]->reg_idx
;
2938 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2939 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2940 txdctl
|= (8 << 16);
2941 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2944 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2945 /* DMATXCTL.EN must be set after all Tx queue config is done */
2946 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
2947 dmatxctl
|= IXGBE_DMATXCTL_TE
;
2948 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
2950 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2951 j
= adapter
->tx_ring
[i
]->reg_idx
;
2952 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2953 txdctl
|= IXGBE_TXDCTL_ENABLE
;
2954 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2955 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2957 /* poll for Tx Enable ready */
2960 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2961 } while (--wait_loop
&&
2962 !(txdctl
& IXGBE_TXDCTL_ENABLE
));
2964 DPRINTK(DRV
, ERR
, "Could not enable "
2965 "Tx Queue %d\n", j
);
2969 for (i
= 0; i
< num_rx_rings
; i
++) {
2970 j
= adapter
->rx_ring
[i
]->reg_idx
;
2971 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2972 /* enable PTHRESH=32 descriptors (half the internal cache)
2973 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2974 * this also removes a pesky rx_no_buffer_count increment */
2976 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
2977 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), rxdctl
);
2978 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2979 ixgbe_rx_desc_queue_enable(adapter
, i
);
2981 /* enable all receives */
2982 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2983 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2984 rxdctl
|= (IXGBE_RXCTRL_DMBYPS
| IXGBE_RXCTRL_RXEN
);
2986 rxdctl
|= IXGBE_RXCTRL_RXEN
;
2987 hw
->mac
.ops
.enable_rx_dma(hw
, rxdctl
);
2989 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
2990 ixgbe_configure_msix(adapter
);
2992 ixgbe_configure_msi_and_legacy(adapter
);
2994 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
2995 ixgbe_napi_enable_all(adapter
);
2997 /* clear any pending interrupts, may auto mask */
2998 IXGBE_READ_REG(hw
, IXGBE_EICR
);
3000 ixgbe_irq_enable(adapter
);
3003 * If this adapter has a fan, check to see if we had a failure
3004 * before we enabled the interrupt.
3006 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
3007 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
3008 if (esdp
& IXGBE_ESDP_SDP1
)
3010 "Fan has stopped, replace the adapter\n");
3014 * For hot-pluggable SFP+ devices, a new SFP+ module may have
3015 * arrived before interrupts were enabled but after probe. Such
3016 * devices wouldn't have their type identified yet. We need to
3017 * kick off the SFP+ module setup first, then try to bring up link.
3018 * If we're not hot-pluggable SFP+, we just need to configure link
3021 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
3022 err
= hw
->phy
.ops
.identify(hw
);
3023 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
3025 * Take the device down and schedule the sfp tasklet
3026 * which will unregister_netdev and log it.
3028 ixgbe_down(adapter
);
3029 schedule_work(&adapter
->sfp_config_module_task
);
3034 if (ixgbe_is_sfp(hw
)) {
3035 ixgbe_sfp_link_config(adapter
);
3037 err
= ixgbe_non_sfp_link_config(hw
);
3039 DPRINTK(PROBE
, ERR
, "link_config FAILED %d\n", err
);
3042 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3043 set_bit(__IXGBE_FDIR_INIT_DONE
,
3044 &(adapter
->tx_ring
[i
]->reinit_state
));
3046 /* enable transmits */
3047 netif_tx_start_all_queues(netdev
);
3049 /* bring the link up in the watchdog, this could race with our first
3050 * link up interrupt but shouldn't be a problem */
3051 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
3052 adapter
->link_check_timeout
= jiffies
;
3053 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3055 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3056 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
3057 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
3058 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
3063 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
3065 WARN_ON(in_interrupt());
3066 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
3068 ixgbe_down(adapter
);
3070 * If SR-IOV enabled then wait a bit before bringing the adapter
3071 * back up to give the VFs time to respond to the reset. The
3072 * two second wait is based upon the watchdog timer cycle in
3075 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3078 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
3081 int ixgbe_up(struct ixgbe_adapter
*adapter
)
3083 /* hardware has been reset, we need to reload some things */
3084 ixgbe_configure(adapter
);
3086 return ixgbe_up_complete(adapter
);
3089 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
3091 struct ixgbe_hw
*hw
= &adapter
->hw
;
3094 err
= hw
->mac
.ops
.init_hw(hw
);
3097 case IXGBE_ERR_SFP_NOT_PRESENT
:
3099 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
3100 dev_err(&adapter
->pdev
->dev
, "master disable timed out\n");
3102 case IXGBE_ERR_EEPROM_VERSION
:
3103 /* We are running on a pre-production device, log a warning */
3104 dev_warn(&adapter
->pdev
->dev
, "This device is a pre-production "
3105 "adapter/LOM. Please be aware there may be issues "
3106 "associated with your hardware. If you are "
3107 "experiencing problems please contact your Intel or "
3108 "hardware representative who provided you with this "
3112 dev_err(&adapter
->pdev
->dev
, "Hardware Error: %d\n", err
);
3115 /* reprogram the RAR[0] in case user changed it. */
3116 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
3121 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3122 * @adapter: board private structure
3123 * @rx_ring: ring to free buffers from
3125 static void ixgbe_clean_rx_ring(struct ixgbe_adapter
*adapter
,
3126 struct ixgbe_ring
*rx_ring
)
3128 struct pci_dev
*pdev
= adapter
->pdev
;
3132 /* Free all the Rx ring sk_buffs */
3134 for (i
= 0; i
< rx_ring
->count
; i
++) {
3135 struct ixgbe_rx_buffer
*rx_buffer_info
;
3137 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
3138 if (rx_buffer_info
->dma
) {
3139 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
3140 rx_ring
->rx_buf_len
,
3141 PCI_DMA_FROMDEVICE
);
3142 rx_buffer_info
->dma
= 0;
3144 if (rx_buffer_info
->skb
) {
3145 struct sk_buff
*skb
= rx_buffer_info
->skb
;
3146 rx_buffer_info
->skb
= NULL
;
3148 struct sk_buff
*this = skb
;
3149 if (IXGBE_RSC_CB(this)->dma
) {
3150 pci_unmap_single(pdev
, IXGBE_RSC_CB(this)->dma
,
3151 rx_ring
->rx_buf_len
,
3152 PCI_DMA_FROMDEVICE
);
3153 IXGBE_RSC_CB(this)->dma
= 0;
3156 dev_kfree_skb(this);
3159 if (!rx_buffer_info
->page
)
3161 if (rx_buffer_info
->page_dma
) {
3162 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
3163 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
3164 rx_buffer_info
->page_dma
= 0;
3166 put_page(rx_buffer_info
->page
);
3167 rx_buffer_info
->page
= NULL
;
3168 rx_buffer_info
->page_offset
= 0;
3171 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
3172 memset(rx_ring
->rx_buffer_info
, 0, size
);
3174 /* Zero out the descriptor ring */
3175 memset(rx_ring
->desc
, 0, rx_ring
->size
);
3177 rx_ring
->next_to_clean
= 0;
3178 rx_ring
->next_to_use
= 0;
3181 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
3183 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
3187 * ixgbe_clean_tx_ring - Free Tx Buffers
3188 * @adapter: board private structure
3189 * @tx_ring: ring to be cleaned
3191 static void ixgbe_clean_tx_ring(struct ixgbe_adapter
*adapter
,
3192 struct ixgbe_ring
*tx_ring
)
3194 struct ixgbe_tx_buffer
*tx_buffer_info
;
3198 /* Free all the Tx ring sk_buffs */
3200 for (i
= 0; i
< tx_ring
->count
; i
++) {
3201 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3202 ixgbe_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
3205 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
3206 memset(tx_ring
->tx_buffer_info
, 0, size
);
3208 /* Zero out the descriptor ring */
3209 memset(tx_ring
->desc
, 0, tx_ring
->size
);
3211 tx_ring
->next_to_use
= 0;
3212 tx_ring
->next_to_clean
= 0;
3215 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
3217 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3221 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3222 * @adapter: board private structure
3224 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
3228 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3229 ixgbe_clean_rx_ring(adapter
, adapter
->rx_ring
[i
]);
3233 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3234 * @adapter: board private structure
3236 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
3240 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3241 ixgbe_clean_tx_ring(adapter
, adapter
->tx_ring
[i
]);
3244 void ixgbe_down(struct ixgbe_adapter
*adapter
)
3246 struct net_device
*netdev
= adapter
->netdev
;
3247 struct ixgbe_hw
*hw
= &adapter
->hw
;
3252 /* signal that we are down to the interrupt handler */
3253 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3255 /* disable receive for all VFs and wait one second */
3256 if (adapter
->num_vfs
) {
3257 /* ping all the active vfs to let them know we are going down */
3258 ixgbe_ping_all_vfs(adapter
);
3260 /* Disable all VFTE/VFRE TX/RX */
3261 ixgbe_disable_tx_rx(adapter
);
3263 /* Mark all the VFs as inactive */
3264 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
3265 adapter
->vfinfo
[i
].clear_to_send
= 0;
3268 /* disable receives */
3269 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3270 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
3272 netif_tx_disable(netdev
);
3274 IXGBE_WRITE_FLUSH(hw
);
3277 netif_tx_stop_all_queues(netdev
);
3279 ixgbe_irq_disable(adapter
);
3281 ixgbe_napi_disable_all(adapter
);
3283 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
3284 del_timer_sync(&adapter
->sfp_timer
);
3285 del_timer_sync(&adapter
->watchdog_timer
);
3286 cancel_work_sync(&adapter
->watchdog_task
);
3288 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3289 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
3290 cancel_work_sync(&adapter
->fdir_reinit_task
);
3292 /* disable transmits in the hardware now that interrupts are off */
3293 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3294 j
= adapter
->tx_ring
[i
]->reg_idx
;
3295 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
3296 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
),
3297 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
3299 /* Disable the Tx DMA engine on 82599 */
3300 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
3301 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
3302 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
3303 ~IXGBE_DMATXCTL_TE
));
3305 netif_carrier_off(netdev
);
3307 /* clear n-tuple filters that are cached */
3308 ethtool_ntuple_flush(netdev
);
3310 if (!pci_channel_offline(adapter
->pdev
))
3311 ixgbe_reset(adapter
);
3312 ixgbe_clean_all_tx_rings(adapter
);
3313 ixgbe_clean_all_rx_rings(adapter
);
3315 #ifdef CONFIG_IXGBE_DCA
3316 /* since we reset the hardware DCA settings were cleared */
3317 ixgbe_setup_dca(adapter
);
3322 * ixgbe_poll - NAPI Rx polling callback
3323 * @napi: structure for representing this polling device
3324 * @budget: how many packets driver is allowed to clean
3326 * This function is used for legacy and MSI, NAPI mode
3328 static int ixgbe_poll(struct napi_struct
*napi
, int budget
)
3330 struct ixgbe_q_vector
*q_vector
=
3331 container_of(napi
, struct ixgbe_q_vector
, napi
);
3332 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
3333 int tx_clean_complete
, work_done
= 0;
3335 #ifdef CONFIG_IXGBE_DCA
3336 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
3337 ixgbe_update_tx_dca(adapter
, adapter
->tx_ring
[0]);
3338 ixgbe_update_rx_dca(adapter
, adapter
->rx_ring
[0]);
3342 tx_clean_complete
= ixgbe_clean_tx_irq(q_vector
, adapter
->tx_ring
[0]);
3343 ixgbe_clean_rx_irq(q_vector
, adapter
->rx_ring
[0], &work_done
, budget
);
3345 if (!tx_clean_complete
)
3348 /* If budget not fully consumed, exit the polling mode */
3349 if (work_done
< budget
) {
3350 napi_complete(napi
);
3351 if (adapter
->rx_itr_setting
& 1)
3352 ixgbe_set_itr(adapter
);
3353 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3354 ixgbe_irq_enable_queues(adapter
, IXGBE_EIMS_RTX_QUEUE
);
3360 * ixgbe_tx_timeout - Respond to a Tx Hang
3361 * @netdev: network interface device structure
3363 static void ixgbe_tx_timeout(struct net_device
*netdev
)
3365 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3367 /* Do the reset outside of interrupt context */
3368 schedule_work(&adapter
->reset_task
);
3371 static void ixgbe_reset_task(struct work_struct
*work
)
3373 struct ixgbe_adapter
*adapter
;
3374 adapter
= container_of(work
, struct ixgbe_adapter
, reset_task
);
3376 /* If we're already down or resetting, just bail */
3377 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
3378 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
3381 adapter
->tx_timeout_count
++;
3383 ixgbe_reinit_locked(adapter
);
3386 #ifdef CONFIG_IXGBE_DCB
3387 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter
*adapter
)
3390 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_DCB
];
3392 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
3396 adapter
->num_rx_queues
= f
->indices
;
3397 adapter
->num_tx_queues
= f
->indices
;
3405 * ixgbe_set_rss_queues: Allocate queues for RSS
3406 * @adapter: board private structure to initialize
3408 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3409 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3412 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter
*adapter
)
3415 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_RSS
];
3417 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3419 adapter
->num_rx_queues
= f
->indices
;
3420 adapter
->num_tx_queues
= f
->indices
;
3430 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3431 * @adapter: board private structure to initialize
3433 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3434 * to the original CPU that initiated the Tx session. This runs in addition
3435 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3436 * Rx load across CPUs using RSS.
3439 static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter
*adapter
)
3442 struct ixgbe_ring_feature
*f_fdir
= &adapter
->ring_feature
[RING_F_FDIR
];
3444 f_fdir
->indices
= min((int)num_online_cpus(), f_fdir
->indices
);
3447 /* Flow Director must have RSS enabled */
3448 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3449 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3450 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)))) {
3451 adapter
->num_tx_queues
= f_fdir
->indices
;
3452 adapter
->num_rx_queues
= f_fdir
->indices
;
3455 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3456 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3463 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3464 * @adapter: board private structure to initialize
3466 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3467 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3468 * rx queues out of the max number of rx queues, instead, it is used as the
3469 * index of the first rx queue used by FCoE.
3472 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter
*adapter
)
3475 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3477 f
->indices
= min((int)num_online_cpus(), f
->indices
);
3478 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3479 adapter
->num_rx_queues
= 1;
3480 adapter
->num_tx_queues
= 1;
3481 #ifdef CONFIG_IXGBE_DCB
3482 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3483 DPRINTK(PROBE
, INFO
, "FCoE enabled with DCB\n");
3484 ixgbe_set_dcb_queues(adapter
);
3487 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3488 DPRINTK(PROBE
, INFO
, "FCoE enabled with RSS\n");
3489 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3490 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3491 ixgbe_set_fdir_queues(adapter
);
3493 ixgbe_set_rss_queues(adapter
);
3495 /* adding FCoE rx rings to the end */
3496 f
->mask
= adapter
->num_rx_queues
;
3497 adapter
->num_rx_queues
+= f
->indices
;
3498 adapter
->num_tx_queues
+= f
->indices
;
3506 #endif /* IXGBE_FCOE */
3508 * ixgbe_set_sriov_queues: Allocate queues for IOV use
3509 * @adapter: board private structure to initialize
3511 * IOV doesn't actually use anything, so just NAK the
3512 * request for now and let the other queue routines
3513 * figure out what to do.
3515 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter
*adapter
)
3521 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3522 * @adapter: board private structure to initialize
3524 * This is the top level queue allocation routine. The order here is very
3525 * important, starting with the "most" number of features turned on at once,
3526 * and ending with the smallest set of features. This way large combinations
3527 * can be allocated if they're turned on, and smaller combinations are the
3528 * fallthrough conditions.
3531 static void ixgbe_set_num_queues(struct ixgbe_adapter
*adapter
)
3533 /* Start with base case */
3534 adapter
->num_rx_queues
= 1;
3535 adapter
->num_tx_queues
= 1;
3536 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
3537 adapter
->num_rx_queues_per_pool
= 1;
3539 if (ixgbe_set_sriov_queues(adapter
))
3543 if (ixgbe_set_fcoe_queues(adapter
))
3546 #endif /* IXGBE_FCOE */
3547 #ifdef CONFIG_IXGBE_DCB
3548 if (ixgbe_set_dcb_queues(adapter
))
3552 if (ixgbe_set_fdir_queues(adapter
))
3555 if (ixgbe_set_rss_queues(adapter
))
3558 /* fallback to base case */
3559 adapter
->num_rx_queues
= 1;
3560 adapter
->num_tx_queues
= 1;
3563 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3564 adapter
->netdev
->real_num_tx_queues
= adapter
->num_tx_queues
;
3567 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter
*adapter
,
3570 int err
, vector_threshold
;
3572 /* We'll want at least 3 (vector_threshold):
3575 * 3) Other (Link Status Change, etc.)
3576 * 4) TCP Timer (optional)
3578 vector_threshold
= MIN_MSIX_COUNT
;
3580 /* The more we get, the more we will assign to Tx/Rx Cleanup
3581 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3582 * Right now, we simply care about how many we'll get; we'll
3583 * set them up later while requesting irq's.
3585 while (vectors
>= vector_threshold
) {
3586 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
3588 if (!err
) /* Success in acquiring all requested vectors. */
3591 vectors
= 0; /* Nasty failure, quit now */
3592 else /* err == number of vectors we should try again with */
3596 if (vectors
< vector_threshold
) {
3597 /* Can't allocate enough MSI-X interrupts? Oh well.
3598 * This just means we'll go with either a single MSI
3599 * vector or fall back to legacy interrupts.
3601 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI-X interrupts\n");
3602 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3603 kfree(adapter
->msix_entries
);
3604 adapter
->msix_entries
= NULL
;
3606 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
; /* Woot! */
3608 * Adjust for only the vectors we'll use, which is minimum
3609 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3610 * vectors we were allocated.
3612 adapter
->num_msix_vectors
= min(vectors
,
3613 adapter
->max_msix_q_vectors
+ NON_Q_VECTORS
);
3618 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
3619 * @adapter: board private structure to initialize
3621 * Cache the descriptor ring offsets for RSS to the assigned rings.
3624 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter
*adapter
)
3629 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3630 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3631 adapter
->rx_ring
[i
]->reg_idx
= i
;
3632 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3633 adapter
->tx_ring
[i
]->reg_idx
= i
;
3642 #ifdef CONFIG_IXGBE_DCB
3644 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3645 * @adapter: board private structure to initialize
3647 * Cache the descriptor ring offsets for DCB to the assigned rings.
3650 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter
*adapter
)
3654 int dcb_i
= adapter
->ring_feature
[RING_F_DCB
].indices
;
3656 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3657 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3658 /* the number of queues is assumed to be symmetric */
3659 for (i
= 0; i
< dcb_i
; i
++) {
3660 adapter
->rx_ring
[i
]->reg_idx
= i
<< 3;
3661 adapter
->tx_ring
[i
]->reg_idx
= i
<< 2;
3664 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
3667 * Tx TC0 starts at: descriptor queue 0
3668 * Tx TC1 starts at: descriptor queue 32
3669 * Tx TC2 starts at: descriptor queue 64
3670 * Tx TC3 starts at: descriptor queue 80
3671 * Tx TC4 starts at: descriptor queue 96
3672 * Tx TC5 starts at: descriptor queue 104
3673 * Tx TC6 starts at: descriptor queue 112
3674 * Tx TC7 starts at: descriptor queue 120
3676 * Rx TC0-TC7 are offset by 16 queues each
3678 for (i
= 0; i
< 3; i
++) {
3679 adapter
->tx_ring
[i
]->reg_idx
= i
<< 5;
3680 adapter
->rx_ring
[i
]->reg_idx
= i
<< 4;
3682 for ( ; i
< 5; i
++) {
3683 adapter
->tx_ring
[i
]->reg_idx
=
3685 adapter
->rx_ring
[i
]->reg_idx
= i
<< 4;
3687 for ( ; i
< dcb_i
; i
++) {
3688 adapter
->tx_ring
[i
]->reg_idx
=
3690 adapter
->rx_ring
[i
]->reg_idx
= i
<< 4;
3694 } else if (dcb_i
== 4) {
3696 * Tx TC0 starts at: descriptor queue 0
3697 * Tx TC1 starts at: descriptor queue 64
3698 * Tx TC2 starts at: descriptor queue 96
3699 * Tx TC3 starts at: descriptor queue 112
3701 * Rx TC0-TC3 are offset by 32 queues each
3703 adapter
->tx_ring
[0]->reg_idx
= 0;
3704 adapter
->tx_ring
[1]->reg_idx
= 64;
3705 adapter
->tx_ring
[2]->reg_idx
= 96;
3706 adapter
->tx_ring
[3]->reg_idx
= 112;
3707 for (i
= 0 ; i
< dcb_i
; i
++)
3708 adapter
->rx_ring
[i
]->reg_idx
= i
<< 5;
3726 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3727 * @adapter: board private structure to initialize
3729 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3732 static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter
*adapter
)
3737 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3738 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3739 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))) {
3740 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3741 adapter
->rx_ring
[i
]->reg_idx
= i
;
3742 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3743 adapter
->tx_ring
[i
]->reg_idx
= i
;
3752 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3753 * @adapter: board private structure to initialize
3755 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3758 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter
*adapter
)
3760 int i
, fcoe_rx_i
= 0, fcoe_tx_i
= 0;
3762 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3764 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3765 #ifdef CONFIG_IXGBE_DCB
3766 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3767 struct ixgbe_fcoe
*fcoe
= &adapter
->fcoe
;
3769 ixgbe_cache_ring_dcb(adapter
);
3770 /* find out queues in TC for FCoE */
3771 fcoe_rx_i
= adapter
->rx_ring
[fcoe
->tc
]->reg_idx
+ 1;
3772 fcoe_tx_i
= adapter
->tx_ring
[fcoe
->tc
]->reg_idx
+ 1;
3774 * In 82599, the number of Tx queues for each traffic
3775 * class for both 8-TC and 4-TC modes are:
3776 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3777 * 8 TCs: 32 32 16 16 8 8 8 8
3778 * 4 TCs: 64 64 32 32
3779 * We have max 8 queues for FCoE, where 8 the is
3780 * FCoE redirection table size. If TC for FCoE is
3781 * less than or equal to TC3, we have enough queues
3782 * to add max of 8 queues for FCoE, so we start FCoE
3783 * tx descriptor from the next one, i.e., reg_idx + 1.
3784 * If TC for FCoE is above TC3, implying 8 TC mode,
3785 * and we need 8 for FCoE, we have to take all queues
3786 * in that traffic class for FCoE.
3788 if ((f
->indices
== IXGBE_FCRETA_SIZE
) && (fcoe
->tc
> 3))
3791 #endif /* CONFIG_IXGBE_DCB */
3792 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3793 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3794 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3795 ixgbe_cache_ring_fdir(adapter
);
3797 ixgbe_cache_ring_rss(adapter
);
3799 fcoe_rx_i
= f
->mask
;
3800 fcoe_tx_i
= f
->mask
;
3802 for (i
= 0; i
< f
->indices
; i
++, fcoe_rx_i
++, fcoe_tx_i
++) {
3803 adapter
->rx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_rx_i
;
3804 adapter
->tx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_tx_i
;
3811 #endif /* IXGBE_FCOE */
3813 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
3814 * @adapter: board private structure to initialize
3816 * SR-IOV doesn't use any descriptor rings but changes the default if
3817 * no other mapping is used.
3820 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter
*adapter
)
3822 adapter
->rx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
3823 adapter
->tx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
3824 if (adapter
->num_vfs
)
3831 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3832 * @adapter: board private structure to initialize
3834 * Once we know the feature-set enabled for the device, we'll cache
3835 * the register offset the descriptor ring is assigned to.
3837 * Note, the order the various feature calls is important. It must start with
3838 * the "most" features enabled at the same time, then trickle down to the
3839 * least amount of features turned on at once.
3841 static void ixgbe_cache_ring_register(struct ixgbe_adapter
*adapter
)
3843 /* start with default case */
3844 adapter
->rx_ring
[0]->reg_idx
= 0;
3845 adapter
->tx_ring
[0]->reg_idx
= 0;
3847 if (ixgbe_cache_ring_sriov(adapter
))
3851 if (ixgbe_cache_ring_fcoe(adapter
))
3854 #endif /* IXGBE_FCOE */
3855 #ifdef CONFIG_IXGBE_DCB
3856 if (ixgbe_cache_ring_dcb(adapter
))
3860 if (ixgbe_cache_ring_fdir(adapter
))
3863 if (ixgbe_cache_ring_rss(adapter
))
3868 * ixgbe_alloc_queues - Allocate memory for all rings
3869 * @adapter: board private structure to initialize
3871 * We allocate one ring per queue at run-time since we don't know the
3872 * number of queues at compile-time. The polling_netdev array is
3873 * intended for Multiqueue, but should work fine with a single queue.
3875 static int ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
3878 int orig_node
= adapter
->node
;
3880 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3881 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
3882 if (orig_node
== -1) {
3883 int cur_node
= next_online_node(adapter
->node
);
3884 if (cur_node
== MAX_NUMNODES
)
3885 cur_node
= first_online_node
;
3886 adapter
->node
= cur_node
;
3888 ring
= kzalloc_node(sizeof(struct ixgbe_ring
), GFP_KERNEL
,
3891 ring
= kzalloc(sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3893 goto err_tx_ring_allocation
;
3894 ring
->count
= adapter
->tx_ring_count
;
3895 ring
->queue_index
= i
;
3896 ring
->numa_node
= adapter
->node
;
3898 adapter
->tx_ring
[i
] = ring
;
3901 /* Restore the adapter's original node */
3902 adapter
->node
= orig_node
;
3904 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3905 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
3906 if (orig_node
== -1) {
3907 int cur_node
= next_online_node(adapter
->node
);
3908 if (cur_node
== MAX_NUMNODES
)
3909 cur_node
= first_online_node
;
3910 adapter
->node
= cur_node
;
3912 ring
= kzalloc_node(sizeof(struct ixgbe_ring
), GFP_KERNEL
,
3915 ring
= kzalloc(sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3917 goto err_rx_ring_allocation
;
3918 ring
->count
= adapter
->rx_ring_count
;
3919 ring
->queue_index
= i
;
3920 ring
->numa_node
= adapter
->node
;
3922 adapter
->rx_ring
[i
] = ring
;
3925 /* Restore the adapter's original node */
3926 adapter
->node
= orig_node
;
3928 ixgbe_cache_ring_register(adapter
);
3932 err_rx_ring_allocation
:
3933 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3934 kfree(adapter
->tx_ring
[i
]);
3935 err_tx_ring_allocation
:
3940 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3941 * @adapter: board private structure to initialize
3943 * Attempt to configure the interrupts using the best available
3944 * capabilities of the hardware and the kernel.
3946 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter
*adapter
)
3948 struct ixgbe_hw
*hw
= &adapter
->hw
;
3950 int vector
, v_budget
;
3953 * It's easy to be greedy for MSI-X vectors, but it really
3954 * doesn't do us much good if we have a lot more vectors
3955 * than CPU's. So let's be conservative and only ask for
3956 * (roughly) the same number of vectors as there are CPU's.
3958 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
3959 (int)num_online_cpus()) + NON_Q_VECTORS
;
3962 * At the same time, hardware can only support a maximum of
3963 * hw.mac->max_msix_vectors vectors. With features
3964 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3965 * descriptor queues supported by our device. Thus, we cap it off in
3966 * those rare cases where the cpu count also exceeds our vector limit.
3968 v_budget
= min(v_budget
, (int)hw
->mac
.max_msix_vectors
);
3970 /* A failure in MSI-X entry allocation isn't fatal, but it does
3971 * mean we disable MSI-X capabilities of the adapter. */
3972 adapter
->msix_entries
= kcalloc(v_budget
,
3973 sizeof(struct msix_entry
), GFP_KERNEL
);
3974 if (adapter
->msix_entries
) {
3975 for (vector
= 0; vector
< v_budget
; vector
++)
3976 adapter
->msix_entries
[vector
].entry
= vector
;
3978 ixgbe_acquire_msix_vectors(adapter
, v_budget
);
3980 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3984 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
3985 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
3986 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3987 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3988 adapter
->atr_sample_rate
= 0;
3989 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3990 ixgbe_disable_sriov(adapter
);
3992 ixgbe_set_num_queues(adapter
);
3994 err
= pci_enable_msi(adapter
->pdev
);
3996 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
3998 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI interrupt, "
3999 "falling back to legacy. Error: %d\n", err
);
4009 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4010 * @adapter: board private structure to initialize
4012 * We allocate one q_vector per queue interrupt. If allocation fails we
4015 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter
*adapter
)
4017 int q_idx
, num_q_vectors
;
4018 struct ixgbe_q_vector
*q_vector
;
4020 int (*poll
)(struct napi_struct
*, int);
4022 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
4023 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4024 napi_vectors
= adapter
->num_rx_queues
;
4025 poll
= &ixgbe_clean_rxtx_many
;
4032 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
4033 q_vector
= kzalloc_node(sizeof(struct ixgbe_q_vector
),
4034 GFP_KERNEL
, adapter
->node
);
4036 q_vector
= kzalloc(sizeof(struct ixgbe_q_vector
),
4040 q_vector
->adapter
= adapter
;
4041 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
4042 q_vector
->eitr
= adapter
->tx_eitr_param
;
4044 q_vector
->eitr
= adapter
->rx_eitr_param
;
4045 q_vector
->v_idx
= q_idx
;
4046 netif_napi_add(adapter
->netdev
, &q_vector
->napi
, (*poll
), 64);
4047 adapter
->q_vector
[q_idx
] = q_vector
;
4055 q_vector
= adapter
->q_vector
[q_idx
];
4056 netif_napi_del(&q_vector
->napi
);
4058 adapter
->q_vector
[q_idx
] = NULL
;
4064 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4065 * @adapter: board private structure to initialize
4067 * This function frees the memory allocated to the q_vectors. In addition if
4068 * NAPI is enabled it will delete any references to the NAPI struct prior
4069 * to freeing the q_vector.
4071 static void ixgbe_free_q_vectors(struct ixgbe_adapter
*adapter
)
4073 int q_idx
, num_q_vectors
;
4075 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4076 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4080 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
4081 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
4082 adapter
->q_vector
[q_idx
] = NULL
;
4083 netif_napi_del(&q_vector
->napi
);
4088 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter
*adapter
)
4090 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
4091 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
4092 pci_disable_msix(adapter
->pdev
);
4093 kfree(adapter
->msix_entries
);
4094 adapter
->msix_entries
= NULL
;
4095 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
4096 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
4097 pci_disable_msi(adapter
->pdev
);
4103 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4104 * @adapter: board private structure to initialize
4106 * We determine which interrupt scheme to use based on...
4107 * - Kernel support (MSI, MSI-X)
4108 * - which can be user-defined (via MODULE_PARAM)
4109 * - Hardware queue count (num_*_queues)
4110 * - defined by miscellaneous hardware support/features (RSS, etc.)
4112 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter
*adapter
)
4116 /* Number of supported queues */
4117 ixgbe_set_num_queues(adapter
);
4119 err
= ixgbe_set_interrupt_capability(adapter
);
4121 DPRINTK(PROBE
, ERR
, "Unable to setup interrupt capabilities\n");
4122 goto err_set_interrupt
;
4125 err
= ixgbe_alloc_q_vectors(adapter
);
4127 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queue "
4129 goto err_alloc_q_vectors
;
4132 err
= ixgbe_alloc_queues(adapter
);
4134 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
4135 goto err_alloc_queues
;
4138 DPRINTK(DRV
, INFO
, "Multiqueue %s: Rx Queue count = %u, "
4139 "Tx Queue count = %u\n",
4140 (adapter
->num_rx_queues
> 1) ? "Enabled" :
4141 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
4143 set_bit(__IXGBE_DOWN
, &adapter
->state
);
4148 ixgbe_free_q_vectors(adapter
);
4149 err_alloc_q_vectors
:
4150 ixgbe_reset_interrupt_capability(adapter
);
4156 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
4157 * @adapter: board private structure to clear interrupt scheme on
4159 * We go through and clear interrupt specific resources and reset the structure
4160 * to pre-load conditions
4162 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter
*adapter
)
4166 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4167 kfree(adapter
->tx_ring
[i
]);
4168 adapter
->tx_ring
[i
] = NULL
;
4170 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4171 kfree(adapter
->rx_ring
[i
]);
4172 adapter
->rx_ring
[i
] = NULL
;
4175 ixgbe_free_q_vectors(adapter
);
4176 ixgbe_reset_interrupt_capability(adapter
);
4180 * ixgbe_sfp_timer - worker thread to find a missing module
4181 * @data: pointer to our adapter struct
4183 static void ixgbe_sfp_timer(unsigned long data
)
4185 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
4188 * Do the sfp_timer outside of interrupt context due to the
4189 * delays that sfp+ detection requires
4191 schedule_work(&adapter
->sfp_task
);
4195 * ixgbe_sfp_task - worker thread to find a missing module
4196 * @work: pointer to work_struct containing our data
4198 static void ixgbe_sfp_task(struct work_struct
*work
)
4200 struct ixgbe_adapter
*adapter
= container_of(work
,
4201 struct ixgbe_adapter
,
4203 struct ixgbe_hw
*hw
= &adapter
->hw
;
4205 if ((hw
->phy
.type
== ixgbe_phy_nl
) &&
4206 (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)) {
4207 s32 ret
= hw
->phy
.ops
.identify_sfp(hw
);
4208 if (ret
== IXGBE_ERR_SFP_NOT_PRESENT
)
4210 ret
= hw
->phy
.ops
.reset(hw
);
4211 if (ret
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
4212 dev_err(&adapter
->pdev
->dev
, "failed to initialize "
4213 "because an unsupported SFP+ module type "
4215 "Reload the driver after installing a "
4216 "supported module.\n");
4217 unregister_netdev(adapter
->netdev
);
4219 DPRINTK(PROBE
, INFO
, "detected SFP+: %d\n",
4222 /* don't need this routine any more */
4223 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
4227 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
))
4228 mod_timer(&adapter
->sfp_timer
,
4229 round_jiffies(jiffies
+ (2 * HZ
)));
4233 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4234 * @adapter: board private structure to initialize
4236 * ixgbe_sw_init initializes the Adapter private data structure.
4237 * Fields are initialized based on PCI device information and
4238 * OS network device settings (MTU size).
4240 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
4242 struct ixgbe_hw
*hw
= &adapter
->hw
;
4243 struct pci_dev
*pdev
= adapter
->pdev
;
4244 struct net_device
*dev
= adapter
->netdev
;
4246 #ifdef CONFIG_IXGBE_DCB
4248 struct tc_configuration
*tc
;
4251 /* PCI config space info */
4253 hw
->vendor_id
= pdev
->vendor
;
4254 hw
->device_id
= pdev
->device
;
4255 hw
->revision_id
= pdev
->revision
;
4256 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
4257 hw
->subsystem_device_id
= pdev
->subsystem_device
;
4259 /* Set capability flags */
4260 rss
= min(IXGBE_MAX_RSS_INDICES
, (int)num_online_cpus());
4261 adapter
->ring_feature
[RING_F_RSS
].indices
= rss
;
4262 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
4263 adapter
->ring_feature
[RING_F_DCB
].indices
= IXGBE_MAX_DCB_INDICES
;
4264 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
4265 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
4266 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
4267 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82598
;
4268 } else if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4269 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82599
;
4270 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
4271 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
4272 if (dev
->features
& NETIF_F_NTUPLE
) {
4273 /* Flow Director perfect filter enabled */
4274 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
4275 adapter
->atr_sample_rate
= 0;
4276 spin_lock_init(&adapter
->fdir_perfect_lock
);
4278 /* Flow Director hash filters enabled */
4279 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4280 adapter
->atr_sample_rate
= 20;
4282 adapter
->ring_feature
[RING_F_FDIR
].indices
=
4283 IXGBE_MAX_FDIR_INDICES
;
4284 adapter
->fdir_pballoc
= 0;
4286 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
4287 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
4288 adapter
->ring_feature
[RING_F_FCOE
].indices
= 0;
4289 #ifdef CONFIG_IXGBE_DCB
4290 /* Default traffic class to use for FCoE */
4291 adapter
->fcoe
.tc
= IXGBE_FCOE_DEFTC
;
4293 #endif /* IXGBE_FCOE */
4296 #ifdef CONFIG_IXGBE_DCB
4297 /* Configure DCB traffic classes */
4298 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
4299 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
4300 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
4301 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
4302 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
4303 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
4304 tc
->dcb_pfc
= pfc_disabled
;
4306 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
4307 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
4308 adapter
->dcb_cfg
.rx_pba_cfg
= pba_equal
;
4309 adapter
->dcb_cfg
.pfc_mode_enable
= false;
4310 adapter
->dcb_cfg
.round_robin_enable
= false;
4311 adapter
->dcb_set_bitmap
= 0x00;
4312 ixgbe_copy_dcb_cfg(&adapter
->dcb_cfg
, &adapter
->temp_dcb_cfg
,
4313 adapter
->ring_feature
[RING_F_DCB
].indices
);
4317 /* default flow control settings */
4318 hw
->fc
.requested_mode
= ixgbe_fc_full
;
4319 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
4321 adapter
->last_lfc_mode
= hw
->fc
.current_mode
;
4323 hw
->fc
.high_water
= IXGBE_DEFAULT_FCRTH
;
4324 hw
->fc
.low_water
= IXGBE_DEFAULT_FCRTL
;
4325 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
4326 hw
->fc
.send_xon
= true;
4327 hw
->fc
.disable_fc_autoneg
= false;
4329 /* enable itr by default in dynamic mode */
4330 adapter
->rx_itr_setting
= 1;
4331 adapter
->rx_eitr_param
= 20000;
4332 adapter
->tx_itr_setting
= 1;
4333 adapter
->tx_eitr_param
= 10000;
4335 /* set defaults for eitr in MegaBytes */
4336 adapter
->eitr_low
= 10;
4337 adapter
->eitr_high
= 20;
4339 /* set default ring sizes */
4340 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
4341 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
4343 /* initialize eeprom parameters */
4344 if (ixgbe_init_eeprom_params_generic(hw
)) {
4345 dev_err(&pdev
->dev
, "EEPROM initialization failed\n");
4349 /* enable rx csum by default */
4350 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
4352 /* get assigned NUMA node */
4353 adapter
->node
= dev_to_node(&pdev
->dev
);
4355 set_bit(__IXGBE_DOWN
, &adapter
->state
);
4361 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4362 * @adapter: board private structure
4363 * @tx_ring: tx descriptor ring (for a specific queue) to setup
4365 * Return 0 on success, negative on failure
4367 int ixgbe_setup_tx_resources(struct ixgbe_adapter
*adapter
,
4368 struct ixgbe_ring
*tx_ring
)
4370 struct pci_dev
*pdev
= adapter
->pdev
;
4373 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
4374 tx_ring
->tx_buffer_info
= vmalloc_node(size
, tx_ring
->numa_node
);
4375 if (!tx_ring
->tx_buffer_info
)
4376 tx_ring
->tx_buffer_info
= vmalloc(size
);
4377 if (!tx_ring
->tx_buffer_info
)
4379 memset(tx_ring
->tx_buffer_info
, 0, size
);
4381 /* round up to nearest 4K */
4382 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
4383 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
4385 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
4390 tx_ring
->next_to_use
= 0;
4391 tx_ring
->next_to_clean
= 0;
4392 tx_ring
->work_limit
= tx_ring
->count
;
4396 vfree(tx_ring
->tx_buffer_info
);
4397 tx_ring
->tx_buffer_info
= NULL
;
4398 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for the transmit "
4399 "descriptor ring\n");
4404 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4405 * @adapter: board private structure
4407 * If this function returns with an error, then it's possible one or
4408 * more of the rings is populated (while the rest are not). It is the
4409 * callers duty to clean those orphaned rings.
4411 * Return 0 on success, negative on failure
4413 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
4417 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4418 err
= ixgbe_setup_tx_resources(adapter
, adapter
->tx_ring
[i
]);
4421 DPRINTK(PROBE
, ERR
, "Allocation for Tx Queue %u failed\n", i
);
4429 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4430 * @adapter: board private structure
4431 * @rx_ring: rx descriptor ring (for a specific queue) to setup
4433 * Returns 0 on success, negative on failure
4435 int ixgbe_setup_rx_resources(struct ixgbe_adapter
*adapter
,
4436 struct ixgbe_ring
*rx_ring
)
4438 struct pci_dev
*pdev
= adapter
->pdev
;
4441 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
4442 rx_ring
->rx_buffer_info
= vmalloc_node(size
, adapter
->node
);
4443 if (!rx_ring
->rx_buffer_info
)
4444 rx_ring
->rx_buffer_info
= vmalloc(size
);
4445 if (!rx_ring
->rx_buffer_info
) {
4447 "vmalloc allocation failed for the rx desc ring\n");
4450 memset(rx_ring
->rx_buffer_info
, 0, size
);
4452 /* Round up to nearest 4K */
4453 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
4454 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
4456 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
, &rx_ring
->dma
);
4458 if (!rx_ring
->desc
) {
4460 "Memory allocation failed for the rx desc ring\n");
4461 vfree(rx_ring
->rx_buffer_info
);
4465 rx_ring
->next_to_clean
= 0;
4466 rx_ring
->next_to_use
= 0;
4475 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4476 * @adapter: board private structure
4478 * If this function returns with an error, then it's possible one or
4479 * more of the rings is populated (while the rest are not). It is the
4480 * callers duty to clean those orphaned rings.
4482 * Return 0 on success, negative on failure
4485 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
4489 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4490 err
= ixgbe_setup_rx_resources(adapter
, adapter
->rx_ring
[i
]);
4493 DPRINTK(PROBE
, ERR
, "Allocation for Rx Queue %u failed\n", i
);
4501 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4502 * @adapter: board private structure
4503 * @tx_ring: Tx descriptor ring for a specific queue
4505 * Free all transmit software resources
4507 void ixgbe_free_tx_resources(struct ixgbe_adapter
*adapter
,
4508 struct ixgbe_ring
*tx_ring
)
4510 struct pci_dev
*pdev
= adapter
->pdev
;
4512 ixgbe_clean_tx_ring(adapter
, tx_ring
);
4514 vfree(tx_ring
->tx_buffer_info
);
4515 tx_ring
->tx_buffer_info
= NULL
;
4517 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
4519 tx_ring
->desc
= NULL
;
4523 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4524 * @adapter: board private structure
4526 * Free all transmit software resources
4528 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
4532 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4533 if (adapter
->tx_ring
[i
]->desc
)
4534 ixgbe_free_tx_resources(adapter
, adapter
->tx_ring
[i
]);
4538 * ixgbe_free_rx_resources - Free Rx Resources
4539 * @adapter: board private structure
4540 * @rx_ring: ring to clean the resources from
4542 * Free all receive software resources
4544 void ixgbe_free_rx_resources(struct ixgbe_adapter
*adapter
,
4545 struct ixgbe_ring
*rx_ring
)
4547 struct pci_dev
*pdev
= adapter
->pdev
;
4549 ixgbe_clean_rx_ring(adapter
, rx_ring
);
4551 vfree(rx_ring
->rx_buffer_info
);
4552 rx_ring
->rx_buffer_info
= NULL
;
4554 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
4556 rx_ring
->desc
= NULL
;
4560 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4561 * @adapter: board private structure
4563 * Free all receive software resources
4565 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
4569 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4570 if (adapter
->rx_ring
[i
]->desc
)
4571 ixgbe_free_rx_resources(adapter
, adapter
->rx_ring
[i
]);
4575 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4576 * @netdev: network interface device structure
4577 * @new_mtu: new value for maximum frame size
4579 * Returns 0 on success, negative on failure
4581 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
4583 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4584 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4586 /* MTU < 68 is an error and causes problems on some kernels */
4587 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
4590 DPRINTK(PROBE
, INFO
, "changing MTU from %d to %d\n",
4591 netdev
->mtu
, new_mtu
);
4592 /* must set new MTU before calling down or up */
4593 netdev
->mtu
= new_mtu
;
4595 if (netif_running(netdev
))
4596 ixgbe_reinit_locked(adapter
);
4602 * ixgbe_open - Called when a network interface is made active
4603 * @netdev: network interface device structure
4605 * Returns 0 on success, negative value on failure
4607 * The open entry point is called when a network interface is made
4608 * active by the system (IFF_UP). At this point all resources needed
4609 * for transmit and receive operations are allocated, the interrupt
4610 * handler is registered with the OS, the watchdog timer is started,
4611 * and the stack is notified that the interface is ready.
4613 static int ixgbe_open(struct net_device
*netdev
)
4615 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4618 /* disallow open during test */
4619 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
4622 netif_carrier_off(netdev
);
4624 /* allocate transmit descriptors */
4625 err
= ixgbe_setup_all_tx_resources(adapter
);
4629 /* allocate receive descriptors */
4630 err
= ixgbe_setup_all_rx_resources(adapter
);
4634 ixgbe_configure(adapter
);
4636 err
= ixgbe_request_irq(adapter
);
4640 err
= ixgbe_up_complete(adapter
);
4644 netif_tx_start_all_queues(netdev
);
4649 ixgbe_release_hw_control(adapter
);
4650 ixgbe_free_irq(adapter
);
4653 ixgbe_free_all_rx_resources(adapter
);
4655 ixgbe_free_all_tx_resources(adapter
);
4656 ixgbe_reset(adapter
);
4662 * ixgbe_close - Disables a network interface
4663 * @netdev: network interface device structure
4665 * Returns 0, this is not allowed to fail
4667 * The close entry point is called when an interface is de-activated
4668 * by the OS. The hardware is still under the drivers control, but
4669 * needs to be disabled. A global MAC reset is issued to stop the
4670 * hardware, and all transmit and receive resources are freed.
4672 static int ixgbe_close(struct net_device
*netdev
)
4674 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4676 ixgbe_down(adapter
);
4677 ixgbe_free_irq(adapter
);
4679 ixgbe_free_all_tx_resources(adapter
);
4680 ixgbe_free_all_rx_resources(adapter
);
4682 ixgbe_release_hw_control(adapter
);
4688 static int ixgbe_resume(struct pci_dev
*pdev
)
4690 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4691 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4694 pci_set_power_state(pdev
, PCI_D0
);
4695 pci_restore_state(pdev
);
4697 * pci_restore_state clears dev->state_saved so call
4698 * pci_save_state to restore it.
4700 pci_save_state(pdev
);
4702 err
= pci_enable_device_mem(pdev
);
4704 printk(KERN_ERR
"ixgbe: Cannot enable PCI device from "
4708 pci_set_master(pdev
);
4710 pci_wake_from_d3(pdev
, false);
4712 err
= ixgbe_init_interrupt_scheme(adapter
);
4714 printk(KERN_ERR
"ixgbe: Cannot initialize interrupts for "
4719 ixgbe_reset(adapter
);
4721 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
4723 if (netif_running(netdev
)) {
4724 err
= ixgbe_open(adapter
->netdev
);
4729 netif_device_attach(netdev
);
4733 #endif /* CONFIG_PM */
4735 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4737 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4738 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4739 struct ixgbe_hw
*hw
= &adapter
->hw
;
4741 u32 wufc
= adapter
->wol
;
4746 netif_device_detach(netdev
);
4748 if (netif_running(netdev
)) {
4749 ixgbe_down(adapter
);
4750 ixgbe_free_irq(adapter
);
4751 ixgbe_free_all_tx_resources(adapter
);
4752 ixgbe_free_all_rx_resources(adapter
);
4754 ixgbe_clear_interrupt_scheme(adapter
);
4757 retval
= pci_save_state(pdev
);
4763 ixgbe_set_rx_mode(netdev
);
4765 /* turn on all-multi mode if wake on multicast is enabled */
4766 if (wufc
& IXGBE_WUFC_MC
) {
4767 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4768 fctrl
|= IXGBE_FCTRL_MPE
;
4769 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4772 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
4773 ctrl
|= IXGBE_CTRL_GIO_DIS
;
4774 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
4776 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
4778 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
4779 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
4782 if (wufc
&& hw
->mac
.type
== ixgbe_mac_82599EB
)
4783 pci_wake_from_d3(pdev
, true);
4785 pci_wake_from_d3(pdev
, false);
4787 *enable_wake
= !!wufc
;
4789 ixgbe_release_hw_control(adapter
);
4791 pci_disable_device(pdev
);
4797 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4802 retval
= __ixgbe_shutdown(pdev
, &wake
);
4807 pci_prepare_to_sleep(pdev
);
4809 pci_wake_from_d3(pdev
, false);
4810 pci_set_power_state(pdev
, PCI_D3hot
);
4815 #endif /* CONFIG_PM */
4817 static void ixgbe_shutdown(struct pci_dev
*pdev
)
4821 __ixgbe_shutdown(pdev
, &wake
);
4823 if (system_state
== SYSTEM_POWER_OFF
) {
4824 pci_wake_from_d3(pdev
, wake
);
4825 pci_set_power_state(pdev
, PCI_D3hot
);
4830 * ixgbe_update_stats - Update the board statistics counters.
4831 * @adapter: board private structure
4833 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
4835 struct net_device
*netdev
= adapter
->netdev
;
4836 struct ixgbe_hw
*hw
= &adapter
->hw
;
4838 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
4839 u64 non_eop_descs
= 0, restart_queue
= 0;
4841 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
4844 for (i
= 0; i
< 16; i
++)
4845 adapter
->hw_rx_no_dma_resources
+=
4846 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4847 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4848 rsc_count
+= adapter
->rx_ring
[i
]->rsc_count
;
4849 rsc_flush
+= adapter
->rx_ring
[i
]->rsc_flush
;
4851 adapter
->rsc_total_count
= rsc_count
;
4852 adapter
->rsc_total_flush
= rsc_flush
;
4855 /* gather some stats to the adapter struct that are per queue */
4856 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4857 restart_queue
+= adapter
->tx_ring
[i
]->restart_queue
;
4858 adapter
->restart_queue
= restart_queue
;
4860 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4861 non_eop_descs
+= adapter
->rx_ring
[i
]->non_eop_descs
;
4862 adapter
->non_eop_descs
= non_eop_descs
;
4864 adapter
->stats
.crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
4865 for (i
= 0; i
< 8; i
++) {
4866 /* for packet buffers not used, the register should read 0 */
4867 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
4869 adapter
->stats
.mpc
[i
] += mpc
;
4870 total_mpc
+= adapter
->stats
.mpc
[i
];
4871 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4872 adapter
->stats
.rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
4873 adapter
->stats
.qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
4874 adapter
->stats
.qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
4875 adapter
->stats
.qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
4876 adapter
->stats
.qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
4877 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4878 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4879 IXGBE_PXONRXCNT(i
));
4880 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4881 IXGBE_PXOFFRXCNT(i
));
4882 adapter
->stats
.qprdc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4884 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4886 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4889 adapter
->stats
.pxontxc
[i
] += IXGBE_READ_REG(hw
,
4891 adapter
->stats
.pxofftxc
[i
] += IXGBE_READ_REG(hw
,
4894 adapter
->stats
.gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
4895 /* work around hardware counting issue */
4896 adapter
->stats
.gprc
-= missed_rx
;
4898 /* 82598 hardware only has a 32 bit counter in the high register */
4899 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4901 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
4902 tmp
= IXGBE_READ_REG(hw
, IXGBE_GORCH
) & 0xF; /* 4 high bits of GORC */
4903 adapter
->stats
.gorc
+= (tmp
<< 32);
4904 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
4905 tmp
= IXGBE_READ_REG(hw
, IXGBE_GOTCH
) & 0xF; /* 4 high bits of GOTC */
4906 adapter
->stats
.gotc
+= (tmp
<< 32);
4907 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
4908 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
4909 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
4910 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
4911 adapter
->stats
.fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
4912 adapter
->stats
.fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
4914 adapter
->stats
.fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
4915 adapter
->stats
.fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
4916 adapter
->stats
.fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
4917 adapter
->stats
.fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
4918 adapter
->stats
.fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
4919 adapter
->stats
.fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
4920 #endif /* IXGBE_FCOE */
4922 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
4923 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
4924 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
4925 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
4926 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
4928 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
4929 adapter
->stats
.bprc
+= bprc
;
4930 adapter
->stats
.mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
4931 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4932 adapter
->stats
.mprc
-= bprc
;
4933 adapter
->stats
.roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
4934 adapter
->stats
.prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
4935 adapter
->stats
.prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
4936 adapter
->stats
.prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
4937 adapter
->stats
.prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
4938 adapter
->stats
.prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
4939 adapter
->stats
.prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
4940 adapter
->stats
.rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
4941 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
4942 adapter
->stats
.lxontxc
+= lxon
;
4943 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
4944 adapter
->stats
.lxofftxc
+= lxoff
;
4945 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4946 adapter
->stats
.gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
4947 adapter
->stats
.mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
4949 * 82598 errata - tx of flow control packets is included in tx counters
4951 xon_off_tot
= lxon
+ lxoff
;
4952 adapter
->stats
.gptc
-= xon_off_tot
;
4953 adapter
->stats
.mptc
-= xon_off_tot
;
4954 adapter
->stats
.gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
4955 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4956 adapter
->stats
.rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
4957 adapter
->stats
.rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
4958 adapter
->stats
.tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
4959 adapter
->stats
.ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
4960 adapter
->stats
.ptc64
-= xon_off_tot
;
4961 adapter
->stats
.ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
4962 adapter
->stats
.ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
4963 adapter
->stats
.ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
4964 adapter
->stats
.ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
4965 adapter
->stats
.ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
4966 adapter
->stats
.bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
4968 /* Fill out the OS statistics structure */
4969 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
4972 netdev
->stats
.rx_errors
= adapter
->stats
.crcerrs
+
4973 adapter
->stats
.rlec
;
4974 netdev
->stats
.rx_dropped
= 0;
4975 netdev
->stats
.rx_length_errors
= adapter
->stats
.rlec
;
4976 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
4977 netdev
->stats
.rx_missed_errors
= total_mpc
;
4981 * ixgbe_watchdog - Timer Call-back
4982 * @data: pointer to adapter cast into an unsigned long
4984 static void ixgbe_watchdog(unsigned long data
)
4986 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
4987 struct ixgbe_hw
*hw
= &adapter
->hw
;
4992 * Do the watchdog outside of interrupt context due to the lovely
4993 * delays that some of the newer hardware requires
4996 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
4997 goto watchdog_short_circuit
;
4999 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
5001 * for legacy and MSI interrupts don't set any bits
5002 * that are enabled for EIAM, because this operation
5003 * would set *both* EIMS and EICS for any bit in EIAM
5005 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
5006 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
5007 goto watchdog_reschedule
;
5010 /* get one bit for every active tx/rx interrupt vector */
5011 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
5012 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
5013 if (qv
->rxr_count
|| qv
->txr_count
)
5014 eics
|= ((u64
)1 << i
);
5017 /* Cause software interrupt to ensure rx rings are cleaned */
5018 ixgbe_irq_rearm_queues(adapter
, eics
);
5020 watchdog_reschedule
:
5021 /* Reset the timer */
5022 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
5024 watchdog_short_circuit
:
5025 schedule_work(&adapter
->watchdog_task
);
5029 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
5030 * @work: pointer to work_struct containing our data
5032 static void ixgbe_multispeed_fiber_task(struct work_struct
*work
)
5034 struct ixgbe_adapter
*adapter
= container_of(work
,
5035 struct ixgbe_adapter
,
5036 multispeed_fiber_task
);
5037 struct ixgbe_hw
*hw
= &adapter
->hw
;
5041 adapter
->flags
|= IXGBE_FLAG_IN_SFP_LINK_TASK
;
5042 autoneg
= hw
->phy
.autoneg_advertised
;
5043 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
5044 hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
5045 hw
->mac
.autotry_restart
= false;
5046 if (hw
->mac
.ops
.setup_link
)
5047 hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, true);
5048 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
5049 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_LINK_TASK
;
5053 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
5054 * @work: pointer to work_struct containing our data
5056 static void ixgbe_sfp_config_module_task(struct work_struct
*work
)
5058 struct ixgbe_adapter
*adapter
= container_of(work
,
5059 struct ixgbe_adapter
,
5060 sfp_config_module_task
);
5061 struct ixgbe_hw
*hw
= &adapter
->hw
;
5064 adapter
->flags
|= IXGBE_FLAG_IN_SFP_MOD_TASK
;
5066 /* Time for electrical oscillations to settle down */
5068 err
= hw
->phy
.ops
.identify_sfp(hw
);
5070 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
5071 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
5072 "an unsupported SFP+ module type was detected.\n"
5073 "Reload the driver after installing a supported "
5075 unregister_netdev(adapter
->netdev
);
5078 hw
->mac
.ops
.setup_sfp(hw
);
5080 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
5081 /* This will also work for DA Twinax connections */
5082 schedule_work(&adapter
->multispeed_fiber_task
);
5083 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_MOD_TASK
;
5087 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
5088 * @work: pointer to work_struct containing our data
5090 static void ixgbe_fdir_reinit_task(struct work_struct
*work
)
5092 struct ixgbe_adapter
*adapter
= container_of(work
,
5093 struct ixgbe_adapter
,
5095 struct ixgbe_hw
*hw
= &adapter
->hw
;
5098 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
5099 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5100 set_bit(__IXGBE_FDIR_INIT_DONE
,
5101 &(adapter
->tx_ring
[i
]->reinit_state
));
5103 DPRINTK(PROBE
, ERR
, "failed to finish FDIR re-initialization, "
5104 "ignored adding FDIR ATR filters\n");
5106 /* Done FDIR Re-initialization, enable transmits */
5107 netif_tx_start_all_queues(adapter
->netdev
);
5110 static DEFINE_MUTEX(ixgbe_watchdog_lock
);
5113 * ixgbe_watchdog_task - worker thread to bring link up
5114 * @work: pointer to work_struct containing our data
5116 static void ixgbe_watchdog_task(struct work_struct
*work
)
5118 struct ixgbe_adapter
*adapter
= container_of(work
,
5119 struct ixgbe_adapter
,
5121 struct net_device
*netdev
= adapter
->netdev
;
5122 struct ixgbe_hw
*hw
= &adapter
->hw
;
5126 struct ixgbe_ring
*tx_ring
;
5127 int some_tx_pending
= 0;
5129 mutex_lock(&ixgbe_watchdog_lock
);
5131 link_up
= adapter
->link_up
;
5132 link_speed
= adapter
->link_speed
;
5134 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
) {
5135 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
5138 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5139 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++)
5140 hw
->mac
.ops
.fc_enable(hw
, i
);
5142 hw
->mac
.ops
.fc_enable(hw
, 0);
5145 hw
->mac
.ops
.fc_enable(hw
, 0);
5150 time_after(jiffies
, (adapter
->link_check_timeout
+
5151 IXGBE_TRY_LINK_TIMEOUT
))) {
5152 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
5153 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
5155 adapter
->link_up
= link_up
;
5156 adapter
->link_speed
= link_speed
;
5160 if (!netif_carrier_ok(netdev
)) {
5161 bool flow_rx
, flow_tx
;
5163 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
5164 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
5165 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
5166 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
5167 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
5169 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
5170 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
5171 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
5172 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
5175 printk(KERN_INFO
"ixgbe: %s NIC Link is Up %s, "
5176 "Flow Control: %s\n",
5178 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
5180 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
5181 "1 Gbps" : "unknown speed")),
5182 ((flow_rx
&& flow_tx
) ? "RX/TX" :
5184 (flow_tx
? "TX" : "None"))));
5186 netif_carrier_on(netdev
);
5188 /* Force detection of hung controller */
5189 adapter
->detect_tx_hung
= true;
5192 adapter
->link_up
= false;
5193 adapter
->link_speed
= 0;
5194 if (netif_carrier_ok(netdev
)) {
5195 printk(KERN_INFO
"ixgbe: %s NIC Link is Down\n",
5197 netif_carrier_off(netdev
);
5201 if (!netif_carrier_ok(netdev
)) {
5202 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5203 tx_ring
= adapter
->tx_ring
[i
];
5204 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
) {
5205 some_tx_pending
= 1;
5210 if (some_tx_pending
) {
5211 /* We've lost link, so the controller stops DMA,
5212 * but we've got queued Tx work that's never going
5213 * to get done, so reset controller to flush Tx.
5214 * (Do the reset outside of interrupt context).
5216 schedule_work(&adapter
->reset_task
);
5220 ixgbe_update_stats(adapter
);
5221 mutex_unlock(&ixgbe_watchdog_lock
);
5224 static int ixgbe_tso(struct ixgbe_adapter
*adapter
,
5225 struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
5226 u32 tx_flags
, u8
*hdr_len
)
5228 struct ixgbe_adv_tx_context_desc
*context_desc
;
5231 struct ixgbe_tx_buffer
*tx_buffer_info
;
5232 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
5233 u32 mss_l4len_idx
, l4len
;
5235 if (skb_is_gso(skb
)) {
5236 if (skb_header_cloned(skb
)) {
5237 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
5241 l4len
= tcp_hdrlen(skb
);
5244 if (skb
->protocol
== htons(ETH_P_IP
)) {
5245 struct iphdr
*iph
= ip_hdr(skb
);
5248 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
5252 } else if (skb_is_gso_v6(skb
)) {
5253 ipv6_hdr(skb
)->payload_len
= 0;
5254 tcp_hdr(skb
)->check
=
5255 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
5256 &ipv6_hdr(skb
)->daddr
,
5260 i
= tx_ring
->next_to_use
;
5262 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5263 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
5265 /* VLAN MACLEN IPLEN */
5266 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
5268 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
5269 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
5270 IXGBE_ADVTXD_MACLEN_SHIFT
);
5271 *hdr_len
+= skb_network_offset(skb
);
5273 (skb_transport_header(skb
) - skb_network_header(skb
));
5275 (skb_transport_header(skb
) - skb_network_header(skb
));
5276 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
5277 context_desc
->seqnum_seed
= 0;
5279 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5280 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
5281 IXGBE_ADVTXD_DTYP_CTXT
);
5283 if (skb
->protocol
== htons(ETH_P_IP
))
5284 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
5285 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
5286 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
5290 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
5291 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
5292 /* use index 1 for TSO */
5293 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
5294 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
5296 tx_buffer_info
->time_stamp
= jiffies
;
5297 tx_buffer_info
->next_to_watch
= i
;
5300 if (i
== tx_ring
->count
)
5302 tx_ring
->next_to_use
= i
;
5309 static bool ixgbe_tx_csum(struct ixgbe_adapter
*adapter
,
5310 struct ixgbe_ring
*tx_ring
,
5311 struct sk_buff
*skb
, u32 tx_flags
)
5313 struct ixgbe_adv_tx_context_desc
*context_desc
;
5315 struct ixgbe_tx_buffer
*tx_buffer_info
;
5316 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
5318 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
5319 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
5320 i
= tx_ring
->next_to_use
;
5321 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5322 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
5324 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
5326 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
5327 vlan_macip_lens
|= (skb_network_offset(skb
) <<
5328 IXGBE_ADVTXD_MACLEN_SHIFT
);
5329 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
5330 vlan_macip_lens
|= (skb_transport_header(skb
) -
5331 skb_network_header(skb
));
5333 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
5334 context_desc
->seqnum_seed
= 0;
5336 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
5337 IXGBE_ADVTXD_DTYP_CTXT
);
5339 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
5342 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
)) {
5343 const struct vlan_ethhdr
*vhdr
=
5344 (const struct vlan_ethhdr
*)skb
->data
;
5346 protocol
= vhdr
->h_vlan_encapsulated_proto
;
5348 protocol
= skb
->protocol
;
5352 case cpu_to_be16(ETH_P_IP
):
5353 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
5354 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
5356 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
5357 else if (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)
5359 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
5361 case cpu_to_be16(ETH_P_IPV6
):
5362 /* XXX what about other V6 headers?? */
5363 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
5365 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
5366 else if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_SCTP
)
5368 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
5371 if (unlikely(net_ratelimit())) {
5372 DPRINTK(PROBE
, WARNING
,
5373 "partial checksum but proto=%x!\n",
5380 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
5381 /* use index zero for tx checksum offload */
5382 context_desc
->mss_l4len_idx
= 0;
5384 tx_buffer_info
->time_stamp
= jiffies
;
5385 tx_buffer_info
->next_to_watch
= i
;
5388 if (i
== tx_ring
->count
)
5390 tx_ring
->next_to_use
= i
;
5398 static int ixgbe_tx_map(struct ixgbe_adapter
*adapter
,
5399 struct ixgbe_ring
*tx_ring
,
5400 struct sk_buff
*skb
, u32 tx_flags
,
5403 struct pci_dev
*pdev
= adapter
->pdev
;
5404 struct ixgbe_tx_buffer
*tx_buffer_info
;
5406 unsigned int total
= skb
->len
;
5407 unsigned int offset
= 0, size
, count
= 0, i
;
5408 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
5411 i
= tx_ring
->next_to_use
;
5413 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
)
5414 /* excluding fcoe_crc_eof for FCoE */
5415 total
-= sizeof(struct fcoe_crc_eof
);
5417 len
= min(skb_headlen(skb
), total
);
5419 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5420 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
5422 tx_buffer_info
->length
= size
;
5423 tx_buffer_info
->mapped_as_page
= false;
5424 tx_buffer_info
->dma
= pci_map_single(pdev
,
5426 size
, PCI_DMA_TODEVICE
);
5427 if (pci_dma_mapping_error(pdev
, tx_buffer_info
->dma
))
5429 tx_buffer_info
->time_stamp
= jiffies
;
5430 tx_buffer_info
->next_to_watch
= i
;
5439 if (i
== tx_ring
->count
)
5444 for (f
= 0; f
< nr_frags
; f
++) {
5445 struct skb_frag_struct
*frag
;
5447 frag
= &skb_shinfo(skb
)->frags
[f
];
5448 len
= min((unsigned int)frag
->size
, total
);
5449 offset
= frag
->page_offset
;
5453 if (i
== tx_ring
->count
)
5456 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5457 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
5459 tx_buffer_info
->length
= size
;
5460 tx_buffer_info
->dma
= pci_map_page(adapter
->pdev
,
5464 tx_buffer_info
->mapped_as_page
= true;
5465 if (pci_dma_mapping_error(pdev
, tx_buffer_info
->dma
))
5467 tx_buffer_info
->time_stamp
= jiffies
;
5468 tx_buffer_info
->next_to_watch
= i
;
5479 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
5480 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
5485 dev_err(&pdev
->dev
, "TX DMA map failed\n");
5487 /* clear timestamp and dma mappings for failed tx_buffer_info map */
5488 tx_buffer_info
->dma
= 0;
5489 tx_buffer_info
->time_stamp
= 0;
5490 tx_buffer_info
->next_to_watch
= 0;
5494 /* clear timestamp and dma mappings for remaining portion of packet */
5497 i
+= tx_ring
->count
;
5499 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5500 ixgbe_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
5506 static void ixgbe_tx_queue(struct ixgbe_adapter
*adapter
,
5507 struct ixgbe_ring
*tx_ring
,
5508 int tx_flags
, int count
, u32 paylen
, u8 hdr_len
)
5510 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
5511 struct ixgbe_tx_buffer
*tx_buffer_info
;
5512 u32 olinfo_status
= 0, cmd_type_len
= 0;
5514 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
5516 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
5518 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
5520 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
5521 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
5523 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
5524 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
5526 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
5527 IXGBE_ADVTXD_POPTS_SHIFT
;
5529 /* use index 1 context for tso */
5530 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
5531 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
5532 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
5533 IXGBE_ADVTXD_POPTS_SHIFT
;
5535 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
5536 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
5537 IXGBE_ADVTXD_POPTS_SHIFT
;
5539 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
5540 olinfo_status
|= IXGBE_ADVTXD_CC
;
5541 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
5542 if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
5543 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
5546 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
5548 i
= tx_ring
->next_to_use
;
5550 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5551 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
5552 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
5553 tx_desc
->read
.cmd_type_len
=
5554 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
5555 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
5557 if (i
== tx_ring
->count
)
5561 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
5564 * Force memory writes to complete before letting h/w
5565 * know there are new descriptors to fetch. (Only
5566 * applicable for weak-ordered memory model archs,
5571 tx_ring
->next_to_use
= i
;
5572 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
5575 static void ixgbe_atr(struct ixgbe_adapter
*adapter
, struct sk_buff
*skb
,
5576 int queue
, u32 tx_flags
)
5578 /* Right now, we support IPv4 only */
5579 struct ixgbe_atr_input atr_input
;
5581 struct iphdr
*iph
= ip_hdr(skb
);
5582 struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
5583 u16 vlan_id
, src_port
, dst_port
, flex_bytes
;
5584 u32 src_ipv4_addr
, dst_ipv4_addr
;
5587 /* check if we're UDP or TCP */
5588 if (iph
->protocol
== IPPROTO_TCP
) {
5590 src_port
= th
->source
;
5591 dst_port
= th
->dest
;
5592 l4type
|= IXGBE_ATR_L4TYPE_TCP
;
5593 /* l4type IPv4 type is 0, no need to assign */
5595 /* Unsupported L4 header, just bail here */
5599 memset(&atr_input
, 0, sizeof(struct ixgbe_atr_input
));
5601 vlan_id
= (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
) >>
5602 IXGBE_TX_FLAGS_VLAN_SHIFT
;
5603 src_ipv4_addr
= iph
->saddr
;
5604 dst_ipv4_addr
= iph
->daddr
;
5605 flex_bytes
= eth
->h_proto
;
5607 ixgbe_atr_set_vlan_id_82599(&atr_input
, vlan_id
);
5608 ixgbe_atr_set_src_port_82599(&atr_input
, dst_port
);
5609 ixgbe_atr_set_dst_port_82599(&atr_input
, src_port
);
5610 ixgbe_atr_set_flex_byte_82599(&atr_input
, flex_bytes
);
5611 ixgbe_atr_set_l4type_82599(&atr_input
, l4type
);
5612 /* src and dst are inverted, think how the receiver sees them */
5613 ixgbe_atr_set_src_ipv4_82599(&atr_input
, dst_ipv4_addr
);
5614 ixgbe_atr_set_dst_ipv4_82599(&atr_input
, src_ipv4_addr
);
5616 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5617 ixgbe_fdir_add_signature_filter_82599(&adapter
->hw
, &atr_input
, queue
);
5620 static int __ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5621 struct ixgbe_ring
*tx_ring
, int size
)
5623 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
5624 /* Herbert's original patch had:
5625 * smp_mb__after_netif_stop_queue();
5626 * but since that doesn't exist yet, just open code it. */
5629 /* We need to check again in a case another CPU has just
5630 * made room available. */
5631 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
5634 /* A reprieve! - use start_queue because it doesn't call schedule */
5635 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
5636 ++tx_ring
->restart_queue
;
5640 static int ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5641 struct ixgbe_ring
*tx_ring
, int size
)
5643 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
5645 return __ixgbe_maybe_stop_tx(netdev
, tx_ring
, size
);
5648 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
5650 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5651 int txq
= smp_processor_id();
5653 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
5654 while (unlikely(txq
>= dev
->real_num_tx_queues
))
5655 txq
-= dev
->real_num_tx_queues
;
5660 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
5661 ((skb
->protocol
== htons(ETH_P_FCOE
)) ||
5662 (skb
->protocol
== htons(ETH_P_FIP
)))) {
5663 txq
&= (adapter
->ring_feature
[RING_F_FCOE
].indices
- 1);
5664 txq
+= adapter
->ring_feature
[RING_F_FCOE
].mask
;
5668 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5669 if (skb
->priority
== TC_PRIO_CONTROL
)
5670 txq
= adapter
->ring_feature
[RING_F_DCB
].indices
-1;
5672 txq
= (skb
->vlan_tci
& IXGBE_TX_FLAGS_VLAN_PRIO_MASK
)
5677 return skb_tx_hash(dev
, skb
);
5680 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
,
5681 struct net_device
*netdev
)
5683 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5684 struct ixgbe_ring
*tx_ring
;
5685 struct netdev_queue
*txq
;
5687 unsigned int tx_flags
= 0;
5693 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
5694 tx_flags
|= vlan_tx_tag_get(skb
);
5695 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5696 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
5697 tx_flags
|= ((skb
->queue_mapping
& 0x7) << 13);
5699 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5700 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5701 } else if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5702 tx_flags
|= ((skb
->queue_mapping
& 0x7) << 13);
5703 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5704 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5707 tx_ring
= adapter
->tx_ring
[skb
->queue_mapping
];
5710 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
5711 #ifdef CONFIG_IXGBE_DCB
5712 /* for FCoE with DCB, we force the priority to what
5713 * was specified by the switch */
5714 if ((skb
->protocol
== htons(ETH_P_FCOE
)) ||
5715 (skb
->protocol
== htons(ETH_P_FIP
))) {
5716 tx_flags
&= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
5717 << IXGBE_TX_FLAGS_VLAN_SHIFT
);
5718 tx_flags
|= ((adapter
->fcoe
.up
<< 13)
5719 << IXGBE_TX_FLAGS_VLAN_SHIFT
);
5722 /* flag for FCoE offloads */
5723 if (skb
->protocol
== htons(ETH_P_FCOE
))
5724 tx_flags
|= IXGBE_TX_FLAGS_FCOE
;
5728 /* four things can cause us to need a context descriptor */
5729 if (skb_is_gso(skb
) ||
5730 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
5731 (tx_flags
& IXGBE_TX_FLAGS_VLAN
) ||
5732 (tx_flags
& IXGBE_TX_FLAGS_FCOE
))
5735 count
+= TXD_USE_COUNT(skb_headlen(skb
));
5736 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
5737 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
5739 if (ixgbe_maybe_stop_tx(netdev
, tx_ring
, count
)) {
5741 return NETDEV_TX_BUSY
;
5744 first
= tx_ring
->next_to_use
;
5745 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
5747 /* setup tx offload for FCoE */
5748 tso
= ixgbe_fso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5750 dev_kfree_skb_any(skb
);
5751 return NETDEV_TX_OK
;
5754 tx_flags
|= IXGBE_TX_FLAGS_FSO
;
5755 #endif /* IXGBE_FCOE */
5757 if (skb
->protocol
== htons(ETH_P_IP
))
5758 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
5759 tso
= ixgbe_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5761 dev_kfree_skb_any(skb
);
5762 return NETDEV_TX_OK
;
5766 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
5767 else if (ixgbe_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
5768 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
5769 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
5772 count
= ixgbe_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
);
5774 /* add the ATR filter if ATR is on */
5775 if (tx_ring
->atr_sample_rate
) {
5776 ++tx_ring
->atr_count
;
5777 if ((tx_ring
->atr_count
>= tx_ring
->atr_sample_rate
) &&
5778 test_bit(__IXGBE_FDIR_INIT_DONE
,
5779 &tx_ring
->reinit_state
)) {
5780 ixgbe_atr(adapter
, skb
, tx_ring
->queue_index
,
5782 tx_ring
->atr_count
= 0;
5785 txq
= netdev_get_tx_queue(netdev
, tx_ring
->queue_index
);
5786 txq
->tx_bytes
+= skb
->len
;
5788 ixgbe_tx_queue(adapter
, tx_ring
, tx_flags
, count
, skb
->len
,
5790 ixgbe_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
5793 dev_kfree_skb_any(skb
);
5794 tx_ring
->tx_buffer_info
[first
].time_stamp
= 0;
5795 tx_ring
->next_to_use
= first
;
5798 return NETDEV_TX_OK
;
5802 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5803 * @netdev: network interface device structure
5804 * @p: pointer to an address structure
5806 * Returns 0 on success, negative on failure
5808 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
5810 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5811 struct ixgbe_hw
*hw
= &adapter
->hw
;
5812 struct sockaddr
*addr
= p
;
5814 if (!is_valid_ether_addr(addr
->sa_data
))
5815 return -EADDRNOTAVAIL
;
5817 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
5818 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
5820 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
5827 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
5829 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5830 struct ixgbe_hw
*hw
= &adapter
->hw
;
5834 if (prtad
!= hw
->phy
.mdio
.prtad
)
5836 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
5842 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
5843 u16 addr
, u16 value
)
5845 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5846 struct ixgbe_hw
*hw
= &adapter
->hw
;
5848 if (prtad
!= hw
->phy
.mdio
.prtad
)
5850 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
5853 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
5855 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5857 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
5861 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5863 * @netdev: network interface device structure
5865 * Returns non-zero on failure
5867 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
5870 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5871 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5873 if (is_valid_ether_addr(mac
->san_addr
)) {
5875 err
= dev_addr_add(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5882 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5884 * @netdev: network interface device structure
5886 * Returns non-zero on failure
5888 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
5891 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5892 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5894 if (is_valid_ether_addr(mac
->san_addr
)) {
5896 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5902 #ifdef CONFIG_NET_POLL_CONTROLLER
5904 * Polling 'interrupt' - used by things like netconsole to send skbs
5905 * without having to re-enable interrupts. It's not called while
5906 * the interrupt routine is executing.
5908 static void ixgbe_netpoll(struct net_device
*netdev
)
5910 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5913 /* if interface is down do nothing */
5914 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
5917 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
5918 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
5919 int num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
5920 for (i
= 0; i
< num_q_vectors
; i
++) {
5921 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
5922 ixgbe_msix_clean_many(0, q_vector
);
5925 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
5927 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
5931 static const struct net_device_ops ixgbe_netdev_ops
= {
5932 .ndo_open
= ixgbe_open
,
5933 .ndo_stop
= ixgbe_close
,
5934 .ndo_start_xmit
= ixgbe_xmit_frame
,
5935 .ndo_select_queue
= ixgbe_select_queue
,
5936 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
5937 .ndo_set_multicast_list
= ixgbe_set_rx_mode
,
5938 .ndo_validate_addr
= eth_validate_addr
,
5939 .ndo_set_mac_address
= ixgbe_set_mac
,
5940 .ndo_change_mtu
= ixgbe_change_mtu
,
5941 .ndo_tx_timeout
= ixgbe_tx_timeout
,
5942 .ndo_vlan_rx_register
= ixgbe_vlan_rx_register
,
5943 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
5944 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
5945 .ndo_do_ioctl
= ixgbe_ioctl
,
5946 #ifdef CONFIG_NET_POLL_CONTROLLER
5947 .ndo_poll_controller
= ixgbe_netpoll
,
5950 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
5951 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
5952 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
5953 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
5954 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
5955 #endif /* IXGBE_FCOE */
5958 static void __devinit
ixgbe_probe_vf(struct ixgbe_adapter
*adapter
,
5959 const struct ixgbe_info
*ii
)
5961 #ifdef CONFIG_PCI_IOV
5962 struct ixgbe_hw
*hw
= &adapter
->hw
;
5965 if (hw
->mac
.type
!= ixgbe_mac_82599EB
|| !max_vfs
)
5968 /* The 82599 supports up to 64 VFs per physical function
5969 * but this implementation limits allocation to 63 so that
5970 * basic networking resources are still available to the
5973 adapter
->num_vfs
= (max_vfs
> 63) ? 63 : max_vfs
;
5974 adapter
->flags
|= IXGBE_FLAG_SRIOV_ENABLED
;
5975 err
= pci_enable_sriov(adapter
->pdev
, adapter
->num_vfs
);
5978 "Failed to enable PCI sriov: %d\n", err
);
5981 /* If call to enable VFs succeeded then allocate memory
5982 * for per VF control structures.
5985 kcalloc(adapter
->num_vfs
,
5986 sizeof(struct vf_data_storage
), GFP_KERNEL
);
5987 if (adapter
->vfinfo
) {
5988 /* Now that we're sure SR-IOV is enabled
5989 * and memory allocated set up the mailbox parameters
5991 ixgbe_init_mbx_params_pf(hw
);
5992 memcpy(&hw
->mbx
.ops
, ii
->mbx_ops
,
5993 sizeof(hw
->mbx
.ops
));
5995 /* Disable RSC when in SR-IOV mode */
5996 adapter
->flags2
&= ~(IXGBE_FLAG2_RSC_CAPABLE
|
5997 IXGBE_FLAG2_RSC_ENABLED
);
6003 "Unable to allocate memory for VF "
6004 "Data Storage - SRIOV disabled\n");
6005 pci_disable_sriov(adapter
->pdev
);
6008 adapter
->flags
&= ~IXGBE_FLAG_SRIOV_ENABLED
;
6009 adapter
->num_vfs
= 0;
6010 #endif /* CONFIG_PCI_IOV */
6014 * ixgbe_probe - Device Initialization Routine
6015 * @pdev: PCI device information struct
6016 * @ent: entry in ixgbe_pci_tbl
6018 * Returns 0 on success, negative on failure
6020 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
6021 * The OS initialization, configuring of the adapter private structure,
6022 * and a hardware reset occur.
6024 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
6025 const struct pci_device_id
*ent
)
6027 struct net_device
*netdev
;
6028 struct ixgbe_adapter
*adapter
= NULL
;
6029 struct ixgbe_hw
*hw
;
6030 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
6031 static int cards_found
;
6032 int i
, err
, pci_using_dac
;
6033 unsigned int indices
= num_possible_cpus();
6039 err
= pci_enable_device_mem(pdev
);
6043 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
6044 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
6047 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
6049 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
6051 dev_err(&pdev
->dev
, "No usable DMA "
6052 "configuration, aborting\n");
6059 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
6060 IORESOURCE_MEM
), ixgbe_driver_name
);
6063 "pci_request_selected_regions failed 0x%x\n", err
);
6067 pci_enable_pcie_error_reporting(pdev
);
6069 pci_set_master(pdev
);
6070 pci_save_state(pdev
);
6072 if (ii
->mac
== ixgbe_mac_82598EB
)
6073 indices
= min_t(unsigned int, indices
, IXGBE_MAX_RSS_INDICES
);
6075 indices
= min_t(unsigned int, indices
, IXGBE_MAX_FDIR_INDICES
);
6077 indices
= max_t(unsigned int, indices
, IXGBE_MAX_DCB_INDICES
);
6079 indices
+= min_t(unsigned int, num_possible_cpus(),
6080 IXGBE_MAX_FCOE_INDICES
);
6082 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
6085 goto err_alloc_etherdev
;
6088 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
6090 pci_set_drvdata(pdev
, netdev
);
6091 adapter
= netdev_priv(netdev
);
6093 adapter
->netdev
= netdev
;
6094 adapter
->pdev
= pdev
;
6097 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
6099 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
6100 pci_resource_len(pdev
, 0));
6106 for (i
= 1; i
<= 5; i
++) {
6107 if (pci_resource_len(pdev
, i
) == 0)
6111 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
6112 ixgbe_set_ethtool_ops(netdev
);
6113 netdev
->watchdog_timeo
= 5 * HZ
;
6114 strcpy(netdev
->name
, pci_name(pdev
));
6116 adapter
->bd_number
= cards_found
;
6119 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
6120 hw
->mac
.type
= ii
->mac
;
6123 memcpy(&hw
->eeprom
.ops
, ii
->eeprom_ops
, sizeof(hw
->eeprom
.ops
));
6124 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC
);
6125 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
6126 if (!(eec
& (1 << 8)))
6127 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
6130 memcpy(&hw
->phy
.ops
, ii
->phy_ops
, sizeof(hw
->phy
.ops
));
6131 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
6132 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
6133 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
6134 hw
->phy
.mdio
.mmds
= 0;
6135 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
6136 hw
->phy
.mdio
.dev
= netdev
;
6137 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
6138 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
6140 /* set up this timer and work struct before calling get_invariants
6141 * which might start the timer
6143 init_timer(&adapter
->sfp_timer
);
6144 adapter
->sfp_timer
.function
= &ixgbe_sfp_timer
;
6145 adapter
->sfp_timer
.data
= (unsigned long) adapter
;
6147 INIT_WORK(&adapter
->sfp_task
, ixgbe_sfp_task
);
6149 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
6150 INIT_WORK(&adapter
->multispeed_fiber_task
, ixgbe_multispeed_fiber_task
);
6152 /* a new SFP+ module arrival, called from GPI SDP2 context */
6153 INIT_WORK(&adapter
->sfp_config_module_task
,
6154 ixgbe_sfp_config_module_task
);
6156 ii
->get_invariants(hw
);
6158 /* setup the private structure */
6159 err
= ixgbe_sw_init(adapter
);
6163 /* Make it possible the adapter to be woken up via WOL */
6164 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
6165 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
6168 * If there is a fan on this device and it has failed log the
6171 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
6172 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
6173 if (esdp
& IXGBE_ESDP_SDP1
)
6174 DPRINTK(PROBE
, CRIT
,
6175 "Fan has stopped, replace the adapter\n");
6178 /* reset_hw fills in the perm_addr as well */
6179 err
= hw
->mac
.ops
.reset_hw(hw
);
6180 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
&&
6181 hw
->mac
.type
== ixgbe_mac_82598EB
) {
6183 * Start a kernel thread to watch for a module to arrive.
6184 * Only do this for 82598, since 82599 will generate
6185 * interrupts on module arrival.
6187 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
6188 mod_timer(&adapter
->sfp_timer
,
6189 round_jiffies(jiffies
+ (2 * HZ
)));
6191 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
6192 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
6193 "an unsupported SFP+ module type was detected.\n"
6194 "Reload the driver after installing a supported "
6198 dev_err(&adapter
->pdev
->dev
, "HW Init failed: %d\n", err
);
6202 ixgbe_probe_vf(adapter
, ii
);
6204 netdev
->features
= NETIF_F_SG
|
6206 NETIF_F_HW_VLAN_TX
|
6207 NETIF_F_HW_VLAN_RX
|
6208 NETIF_F_HW_VLAN_FILTER
;
6210 netdev
->features
|= NETIF_F_IPV6_CSUM
;
6211 netdev
->features
|= NETIF_F_TSO
;
6212 netdev
->features
|= NETIF_F_TSO6
;
6213 netdev
->features
|= NETIF_F_GRO
;
6215 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
6216 netdev
->features
|= NETIF_F_SCTP_CSUM
;
6218 netdev
->vlan_features
|= NETIF_F_TSO
;
6219 netdev
->vlan_features
|= NETIF_F_TSO6
;
6220 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
6221 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
6222 netdev
->vlan_features
|= NETIF_F_SG
;
6224 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
6225 adapter
->flags
&= ~(IXGBE_FLAG_RSS_ENABLED
|
6226 IXGBE_FLAG_DCB_ENABLED
);
6227 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
6228 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
6230 #ifdef CONFIG_IXGBE_DCB
6231 netdev
->dcbnl_ops
= &dcbnl_ops
;
6235 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
6236 if (hw
->mac
.ops
.get_device_caps
) {
6237 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
6238 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
6239 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
6242 #endif /* IXGBE_FCOE */
6244 netdev
->features
|= NETIF_F_HIGHDMA
;
6246 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
6247 netdev
->features
|= NETIF_F_LRO
;
6249 /* make sure the EEPROM is good */
6250 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
6251 dev_err(&pdev
->dev
, "The EEPROM Checksum Is Not Valid\n");
6256 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
6257 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
6259 if (ixgbe_validate_mac_addr(netdev
->perm_addr
)) {
6260 dev_err(&pdev
->dev
, "invalid MAC address\n");
6265 init_timer(&adapter
->watchdog_timer
);
6266 adapter
->watchdog_timer
.function
= &ixgbe_watchdog
;
6267 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
6269 INIT_WORK(&adapter
->reset_task
, ixgbe_reset_task
);
6270 INIT_WORK(&adapter
->watchdog_task
, ixgbe_watchdog_task
);
6272 err
= ixgbe_init_interrupt_scheme(adapter
);
6276 switch (pdev
->device
) {
6277 case IXGBE_DEV_ID_82599_KX4
:
6278 adapter
->wol
= (IXGBE_WUFC_MAG
| IXGBE_WUFC_EX
|
6279 IXGBE_WUFC_MC
| IXGBE_WUFC_BC
);
6285 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
6287 /* pick up the PCI bus settings for reporting later */
6288 hw
->mac
.ops
.get_bus_info(hw
);
6290 /* print bus type/speed/width info */
6291 dev_info(&pdev
->dev
, "(PCI Express:%s:%s) %pM\n",
6292 ((hw
->bus
.speed
== ixgbe_bus_speed_5000
) ? "5.0Gb/s":
6293 (hw
->bus
.speed
== ixgbe_bus_speed_2500
) ? "2.5Gb/s":"Unknown"),
6294 ((hw
->bus
.width
== ixgbe_bus_width_pcie_x8
) ? "Width x8" :
6295 (hw
->bus
.width
== ixgbe_bus_width_pcie_x4
) ? "Width x4" :
6296 (hw
->bus
.width
== ixgbe_bus_width_pcie_x1
) ? "Width x1" :
6299 ixgbe_read_pba_num_generic(hw
, &part_num
);
6300 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
6301 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
6302 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
6303 (part_num
>> 8), (part_num
& 0xff));
6305 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
6306 hw
->mac
.type
, hw
->phy
.type
,
6307 (part_num
>> 8), (part_num
& 0xff));
6309 if (hw
->bus
.width
<= ixgbe_bus_width_pcie_x4
) {
6310 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for "
6311 "this card is not sufficient for optimal "
6313 dev_warn(&pdev
->dev
, "For optimal performance a x8 "
6314 "PCI-Express slot is required.\n");
6317 /* save off EEPROM version number */
6318 hw
->eeprom
.ops
.read(hw
, 0x29, &adapter
->eeprom_version
);
6320 /* reset the hardware with the new settings */
6321 err
= hw
->mac
.ops
.start_hw(hw
);
6323 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
6324 /* We are running on a pre-production device, log a warning */
6325 dev_warn(&pdev
->dev
, "This device is a pre-production "
6326 "adapter/LOM. Please be aware there may be issues "
6327 "associated with your hardware. If you are "
6328 "experiencing problems please contact your Intel or "
6329 "hardware representative who provided you with this "
6332 strcpy(netdev
->name
, "eth%d");
6333 err
= register_netdev(netdev
);
6337 /* carrier off reporting is important to ethtool even BEFORE open */
6338 netif_carrier_off(netdev
);
6340 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
6341 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
6342 INIT_WORK(&adapter
->fdir_reinit_task
, ixgbe_fdir_reinit_task
);
6344 #ifdef CONFIG_IXGBE_DCA
6345 if (dca_add_requester(&pdev
->dev
) == 0) {
6346 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
6347 ixgbe_setup_dca(adapter
);
6350 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
6351 DPRINTK(PROBE
, INFO
, "IOV is enabled with %d VFs\n",
6353 for (i
= 0; i
< adapter
->num_vfs
; i
++)
6354 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
6357 /* add san mac addr to netdev */
6358 ixgbe_add_sanmac_netdev(netdev
);
6360 dev_info(&pdev
->dev
, "Intel(R) 10 Gigabit Network Connection\n");
6365 ixgbe_release_hw_control(adapter
);
6366 ixgbe_clear_interrupt_scheme(adapter
);
6369 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
6370 ixgbe_disable_sriov(adapter
);
6371 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
6372 del_timer_sync(&adapter
->sfp_timer
);
6373 cancel_work_sync(&adapter
->sfp_task
);
6374 cancel_work_sync(&adapter
->multispeed_fiber_task
);
6375 cancel_work_sync(&adapter
->sfp_config_module_task
);
6376 iounmap(hw
->hw_addr
);
6378 free_netdev(netdev
);
6380 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
6384 pci_disable_device(pdev
);
6389 * ixgbe_remove - Device Removal Routine
6390 * @pdev: PCI device information struct
6392 * ixgbe_remove is called by the PCI subsystem to alert the driver
6393 * that it should release a PCI device. The could be caused by a
6394 * Hot-Plug event, or because the driver is going to be removed from
6397 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
6399 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6400 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6402 set_bit(__IXGBE_DOWN
, &adapter
->state
);
6403 /* clear the module not found bit to make sure the worker won't
6406 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
6407 del_timer_sync(&adapter
->watchdog_timer
);
6409 del_timer_sync(&adapter
->sfp_timer
);
6410 cancel_work_sync(&adapter
->watchdog_task
);
6411 cancel_work_sync(&adapter
->sfp_task
);
6412 if (adapter
->hw
.phy
.multispeed_fiber
) {
6413 struct ixgbe_hw
*hw
= &adapter
->hw
;
6415 * Restart clause 37 autoneg, disable and re-enable
6416 * the tx laser, to clear & alert the link partner
6417 * that it needs to restart autotry
6419 hw
->mac
.autotry_restart
= true;
6420 hw
->mac
.ops
.flap_tx_laser(hw
);
6422 cancel_work_sync(&adapter
->multispeed_fiber_task
);
6423 cancel_work_sync(&adapter
->sfp_config_module_task
);
6424 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
6425 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
6426 cancel_work_sync(&adapter
->fdir_reinit_task
);
6427 flush_scheduled_work();
6429 #ifdef CONFIG_IXGBE_DCA
6430 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
6431 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
6432 dca_remove_requester(&pdev
->dev
);
6433 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
6438 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
6439 ixgbe_cleanup_fcoe(adapter
);
6441 #endif /* IXGBE_FCOE */
6443 /* remove the added san mac */
6444 ixgbe_del_sanmac_netdev(netdev
);
6446 if (netdev
->reg_state
== NETREG_REGISTERED
)
6447 unregister_netdev(netdev
);
6449 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
6450 ixgbe_disable_sriov(adapter
);
6452 ixgbe_clear_interrupt_scheme(adapter
);
6454 ixgbe_release_hw_control(adapter
);
6456 iounmap(adapter
->hw
.hw_addr
);
6457 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
6460 DPRINTK(PROBE
, INFO
, "complete\n");
6462 free_netdev(netdev
);
6464 pci_disable_pcie_error_reporting(pdev
);
6466 pci_disable_device(pdev
);
6470 * ixgbe_io_error_detected - called when PCI error is detected
6471 * @pdev: Pointer to PCI device
6472 * @state: The current pci connection state
6474 * This function is called after a PCI bus error affecting
6475 * this device has been detected.
6477 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
6478 pci_channel_state_t state
)
6480 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6481 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6483 netif_device_detach(netdev
);
6485 if (state
== pci_channel_io_perm_failure
)
6486 return PCI_ERS_RESULT_DISCONNECT
;
6488 if (netif_running(netdev
))
6489 ixgbe_down(adapter
);
6490 pci_disable_device(pdev
);
6492 /* Request a slot reset. */
6493 return PCI_ERS_RESULT_NEED_RESET
;
6497 * ixgbe_io_slot_reset - called after the pci bus has been reset.
6498 * @pdev: Pointer to PCI device
6500 * Restart the card from scratch, as if from a cold-boot.
6502 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
6504 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6505 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6506 pci_ers_result_t result
;
6509 if (pci_enable_device_mem(pdev
)) {
6511 "Cannot re-enable PCI device after reset.\n");
6512 result
= PCI_ERS_RESULT_DISCONNECT
;
6514 pci_set_master(pdev
);
6515 pci_restore_state(pdev
);
6516 pci_save_state(pdev
);
6518 pci_wake_from_d3(pdev
, false);
6520 ixgbe_reset(adapter
);
6521 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
6522 result
= PCI_ERS_RESULT_RECOVERED
;
6525 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
6528 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err
);
6529 /* non-fatal, continue */
6536 * ixgbe_io_resume - called when traffic can start flowing again.
6537 * @pdev: Pointer to PCI device
6539 * This callback is called when the error recovery driver tells us that
6540 * its OK to resume normal operation.
6542 static void ixgbe_io_resume(struct pci_dev
*pdev
)
6544 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6545 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6547 if (netif_running(netdev
)) {
6548 if (ixgbe_up(adapter
)) {
6549 DPRINTK(PROBE
, INFO
, "ixgbe_up failed after reset\n");
6554 netif_device_attach(netdev
);
6557 static struct pci_error_handlers ixgbe_err_handler
= {
6558 .error_detected
= ixgbe_io_error_detected
,
6559 .slot_reset
= ixgbe_io_slot_reset
,
6560 .resume
= ixgbe_io_resume
,
6563 static struct pci_driver ixgbe_driver
= {
6564 .name
= ixgbe_driver_name
,
6565 .id_table
= ixgbe_pci_tbl
,
6566 .probe
= ixgbe_probe
,
6567 .remove
= __devexit_p(ixgbe_remove
),
6569 .suspend
= ixgbe_suspend
,
6570 .resume
= ixgbe_resume
,
6572 .shutdown
= ixgbe_shutdown
,
6573 .err_handler
= &ixgbe_err_handler
6577 * ixgbe_init_module - Driver Registration Routine
6579 * ixgbe_init_module is the first routine called when the driver is
6580 * loaded. All it does is register with the PCI subsystem.
6582 static int __init
ixgbe_init_module(void)
6585 printk(KERN_INFO
"%s: %s - version %s\n", ixgbe_driver_name
,
6586 ixgbe_driver_string
, ixgbe_driver_version
);
6588 printk(KERN_INFO
"%s: %s\n", ixgbe_driver_name
, ixgbe_copyright
);
6590 #ifdef CONFIG_IXGBE_DCA
6591 dca_register_notify(&dca_notifier
);
6594 ret
= pci_register_driver(&ixgbe_driver
);
6598 module_init(ixgbe_init_module
);
6601 * ixgbe_exit_module - Driver Exit Cleanup Routine
6603 * ixgbe_exit_module is called just before the driver is removed
6606 static void __exit
ixgbe_exit_module(void)
6608 #ifdef CONFIG_IXGBE_DCA
6609 dca_unregister_notify(&dca_notifier
);
6611 pci_unregister_driver(&ixgbe_driver
);
6614 #ifdef CONFIG_IXGBE_DCA
6615 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
6620 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
6621 __ixgbe_notify_dca
);
6623 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
6626 #endif /* CONFIG_IXGBE_DCA */
6629 * ixgbe_get_hw_dev_name - return device name string
6630 * used by hardware layer to print debugging information
6632 char *ixgbe_get_hw_dev_name(struct ixgbe_hw
*hw
)
6634 struct ixgbe_adapter
*adapter
= hw
->back
;
6635 return adapter
->netdev
->name
;
6639 module_exit(ixgbe_exit_module
);