1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 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 <net/checksum.h>
40 #include <net/ip6_checksum.h>
41 #include <linux/ethtool.h>
42 #include <linux/if_vlan.h>
43 #include <scsi/fc/fc_fcoe.h>
46 #include "ixgbe_common.h"
48 char ixgbe_driver_name
[] = "ixgbe";
49 static const char ixgbe_driver_string
[] =
50 "Intel(R) 10 Gigabit PCI Express Network Driver";
52 #define DRV_VERSION "2.0.37-k2"
53 const char ixgbe_driver_version
[] = DRV_VERSION
;
54 static char ixgbe_copyright
[] = "Copyright (c) 1999-2009 Intel Corporation.";
56 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
57 [board_82598
] = &ixgbe_82598_info
,
58 [board_82599
] = &ixgbe_82599_info
,
61 /* ixgbe_pci_tbl - PCI Device ID Table
63 * Wildcard entries (PCI_ANY_ID) should come last
64 * Last entry must be all 0s
66 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
67 * Class, Class Mask, private data (not used) }
69 static struct pci_device_id ixgbe_pci_tbl
[] = {
70 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
),
72 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
),
74 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
),
76 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
),
78 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
),
80 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
),
82 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
),
84 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
),
86 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
),
88 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
),
90 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
),
92 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
),
94 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
),
96 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
),
98 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
),
101 /* required last entry */
104 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
106 #ifdef CONFIG_IXGBE_DCA
107 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
109 static struct notifier_block dca_notifier
= {
110 .notifier_call
= ixgbe_notify_dca
,
116 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
117 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
118 MODULE_LICENSE("GPL");
119 MODULE_VERSION(DRV_VERSION
);
121 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
123 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
127 /* Let firmware take over control of h/w */
128 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
129 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
130 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
133 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
137 /* Let firmware know the driver has taken over */
138 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
139 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
140 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
144 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
145 * @adapter: pointer to adapter struct
146 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
147 * @queue: queue to map the corresponding interrupt to
148 * @msix_vector: the vector to map to the corresponding queue
151 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
152 u8 queue
, u8 msix_vector
)
155 struct ixgbe_hw
*hw
= &adapter
->hw
;
156 switch (hw
->mac
.type
) {
157 case ixgbe_mac_82598EB
:
158 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
161 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
162 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
163 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
164 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
165 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
167 case ixgbe_mac_82599EB
:
168 if (direction
== -1) {
170 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
171 index
= ((queue
& 1) * 8);
172 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
173 ivar
&= ~(0xFF << index
);
174 ivar
|= (msix_vector
<< index
);
175 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
178 /* tx or rx causes */
179 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
180 index
= ((16 * (queue
& 1)) + (8 * direction
));
181 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
182 ivar
&= ~(0xFF << index
);
183 ivar
|= (msix_vector
<< index
);
184 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
192 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
197 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
198 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
199 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
201 mask
= (qmask
& 0xFFFFFFFF);
202 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
203 mask
= (qmask
>> 32);
204 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
208 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter
*adapter
,
209 struct ixgbe_tx_buffer
212 tx_buffer_info
->dma
= 0;
213 if (tx_buffer_info
->skb
) {
214 skb_dma_unmap(&adapter
->pdev
->dev
, tx_buffer_info
->skb
,
216 dev_kfree_skb_any(tx_buffer_info
->skb
);
217 tx_buffer_info
->skb
= NULL
;
219 tx_buffer_info
->time_stamp
= 0;
220 /* tx_buffer_info must be completely set up in the transmit path */
223 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter
*adapter
,
224 struct ixgbe_ring
*tx_ring
,
227 struct ixgbe_hw
*hw
= &adapter
->hw
;
229 /* Detect a transmit hang in hardware, this serializes the
230 * check with the clearing of time_stamp and movement of eop */
231 adapter
->detect_tx_hung
= false;
232 if (tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
233 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
) &&
234 !(IXGBE_READ_REG(&adapter
->hw
, IXGBE_TFCS
) & IXGBE_TFCS_TXOFF
)) {
235 /* detected Tx unit hang */
236 union ixgbe_adv_tx_desc
*tx_desc
;
237 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
238 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
240 " TDH, TDT <%x>, <%x>\n"
241 " next_to_use <%x>\n"
242 " next_to_clean <%x>\n"
243 "tx_buffer_info[next_to_clean]\n"
244 " time_stamp <%lx>\n"
246 tx_ring
->queue_index
,
247 IXGBE_READ_REG(hw
, tx_ring
->head
),
248 IXGBE_READ_REG(hw
, tx_ring
->tail
),
249 tx_ring
->next_to_use
, eop
,
250 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
257 #define IXGBE_MAX_TXD_PWR 14
258 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
260 /* Tx Descriptors needed, worst case */
261 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
262 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
263 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
264 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
266 static void ixgbe_tx_timeout(struct net_device
*netdev
);
269 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
270 * @q_vector: structure containing interrupt and ring information
271 * @tx_ring: tx ring to clean
273 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
274 struct ixgbe_ring
*tx_ring
)
276 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
277 struct net_device
*netdev
= adapter
->netdev
;
278 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
279 struct ixgbe_tx_buffer
*tx_buffer_info
;
280 unsigned int i
, eop
, count
= 0;
281 unsigned int total_bytes
= 0, total_packets
= 0;
283 i
= tx_ring
->next_to_clean
;
284 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
285 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
287 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
288 (count
< tx_ring
->work_limit
)) {
289 bool cleaned
= false;
290 for ( ; !cleaned
; count
++) {
292 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
293 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
294 cleaned
= (i
== eop
);
295 skb
= tx_buffer_info
->skb
;
297 if (cleaned
&& skb
) {
298 unsigned int segs
, bytecount
;
299 unsigned int hlen
= skb_headlen(skb
);
301 /* gso_segs is currently only valid for tcp */
302 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
304 /* adjust for FCoE Sequence Offload */
305 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
306 && (skb
->protocol
== htons(ETH_P_FCOE
)) &&
308 hlen
= skb_transport_offset(skb
) +
309 sizeof(struct fc_frame_header
) +
310 sizeof(struct fcoe_crc_eof
);
311 segs
= DIV_ROUND_UP(skb
->len
- hlen
,
312 skb_shinfo(skb
)->gso_size
);
314 #endif /* IXGBE_FCOE */
315 /* multiply data chunks by size of headers */
316 bytecount
= ((segs
- 1) * hlen
) + skb
->len
;
317 total_packets
+= segs
;
318 total_bytes
+= bytecount
;
321 ixgbe_unmap_and_free_tx_resource(adapter
,
324 tx_desc
->wb
.status
= 0;
327 if (i
== tx_ring
->count
)
331 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
332 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
335 tx_ring
->next_to_clean
= i
;
337 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
338 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
339 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
340 /* Make sure that anybody stopping the queue after this
341 * sees the new next_to_clean.
344 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
345 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
346 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
347 ++adapter
->restart_queue
;
351 if (adapter
->detect_tx_hung
) {
352 if (ixgbe_check_tx_hang(adapter
, tx_ring
, i
)) {
353 /* schedule immediate reset if we believe we hung */
355 "tx hang %d detected, resetting adapter\n",
356 adapter
->tx_timeout_count
+ 1);
357 ixgbe_tx_timeout(adapter
->netdev
);
361 /* re-arm the interrupt */
362 if (count
>= tx_ring
->work_limit
)
363 ixgbe_irq_rearm_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
365 tx_ring
->total_bytes
+= total_bytes
;
366 tx_ring
->total_packets
+= total_packets
;
367 tx_ring
->stats
.packets
+= total_packets
;
368 tx_ring
->stats
.bytes
+= total_bytes
;
369 adapter
->net_stats
.tx_bytes
+= total_bytes
;
370 adapter
->net_stats
.tx_packets
+= total_packets
;
371 return (count
< tx_ring
->work_limit
);
374 #ifdef CONFIG_IXGBE_DCA
375 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
376 struct ixgbe_ring
*rx_ring
)
380 int q
= rx_ring
- adapter
->rx_ring
;
382 if (rx_ring
->cpu
!= cpu
) {
383 rxctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
));
384 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
385 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK
;
386 rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
387 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
388 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599
;
389 rxctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
390 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
);
392 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
393 rxctrl
|= IXGBE_DCA_RXCTRL_HEAD_DCA_EN
;
394 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN
);
395 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN
|
396 IXGBE_DCA_RXCTRL_DESC_HSRO_EN
);
397 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
), rxctrl
);
403 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
404 struct ixgbe_ring
*tx_ring
)
408 int q
= tx_ring
- adapter
->tx_ring
;
410 if (tx_ring
->cpu
!= cpu
) {
411 txctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_DCA_TXCTRL(q
));
412 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
413 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK
;
414 txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
415 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
416 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599
;
417 txctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
418 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
);
420 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
421 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_TXCTRL(q
), txctrl
);
427 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
431 if (!(adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
))
434 /* always use CB2 mode, difference is masked in the CB driver */
435 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 2);
437 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
438 adapter
->tx_ring
[i
].cpu
= -1;
439 ixgbe_update_tx_dca(adapter
, &adapter
->tx_ring
[i
]);
441 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
442 adapter
->rx_ring
[i
].cpu
= -1;
443 ixgbe_update_rx_dca(adapter
, &adapter
->rx_ring
[i
]);
447 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
449 struct net_device
*netdev
= dev_get_drvdata(dev
);
450 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
451 unsigned long event
= *(unsigned long *)data
;
454 case DCA_PROVIDER_ADD
:
455 /* if we're already enabled, don't do it again */
456 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
458 if (dca_add_requester(dev
) == 0) {
459 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
460 ixgbe_setup_dca(adapter
);
463 /* Fall Through since DCA is disabled. */
464 case DCA_PROVIDER_REMOVE
:
465 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
466 dca_remove_requester(dev
);
467 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
468 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
476 #endif /* CONFIG_IXGBE_DCA */
478 * ixgbe_receive_skb - Send a completed packet up the stack
479 * @adapter: board private structure
480 * @skb: packet to send up
481 * @status: hardware indication of status of receive
482 * @rx_ring: rx descriptor ring (for a specific queue) to setup
483 * @rx_desc: rx descriptor
485 static void ixgbe_receive_skb(struct ixgbe_q_vector
*q_vector
,
486 struct sk_buff
*skb
, u8 status
,
487 struct ixgbe_ring
*ring
,
488 union ixgbe_adv_rx_desc
*rx_desc
)
490 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
491 struct napi_struct
*napi
= &q_vector
->napi
;
492 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
493 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
495 skb_record_rx_queue(skb
, ring
->queue_index
);
496 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
497 if (adapter
->vlgrp
&& is_vlan
&& (tag
!= 0))
498 vlan_gro_receive(napi
, adapter
->vlgrp
, tag
, skb
);
500 napi_gro_receive(napi
, skb
);
502 if (adapter
->vlgrp
&& is_vlan
&& (tag
!= 0))
503 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
510 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
511 * @adapter: address of board private structure
512 * @status_err: hardware indication of status of receive
513 * @skb: skb currently being received and modified
515 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
516 u32 status_err
, struct sk_buff
*skb
)
518 skb
->ip_summed
= CHECKSUM_NONE
;
520 /* Rx csum disabled */
521 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
524 /* if IP and error */
525 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
526 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
527 adapter
->hw_csum_rx_error
++;
531 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
534 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
535 adapter
->hw_csum_rx_error
++;
539 /* It must be a TCP or UDP packet with a valid checksum */
540 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
541 adapter
->hw_csum_rx_good
++;
544 static inline void ixgbe_release_rx_desc(struct ixgbe_hw
*hw
,
545 struct ixgbe_ring
*rx_ring
, u32 val
)
548 * Force memory writes to complete before letting h/w
549 * know there are new descriptors to fetch. (Only
550 * applicable for weak-ordered memory model archs,
554 IXGBE_WRITE_REG(hw
, IXGBE_RDT(rx_ring
->reg_idx
), val
);
558 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
559 * @adapter: address of board private structure
561 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter
*adapter
,
562 struct ixgbe_ring
*rx_ring
,
565 struct pci_dev
*pdev
= adapter
->pdev
;
566 union ixgbe_adv_rx_desc
*rx_desc
;
567 struct ixgbe_rx_buffer
*bi
;
570 i
= rx_ring
->next_to_use
;
571 bi
= &rx_ring
->rx_buffer_info
[i
];
573 while (cleaned_count
--) {
574 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
577 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
579 bi
->page
= alloc_page(GFP_ATOMIC
);
581 adapter
->alloc_rx_page_failed
++;
586 /* use a half page if we're re-using */
587 bi
->page_offset
^= (PAGE_SIZE
/ 2);
590 bi
->page_dma
= pci_map_page(pdev
, bi
->page
,
598 skb
= netdev_alloc_skb(adapter
->netdev
,
599 (rx_ring
->rx_buf_len
+
603 adapter
->alloc_rx_buff_failed
++;
608 * Make buffer alignment 2 beyond a 16 byte boundary
609 * this will result in a 16 byte aligned IP header after
610 * the 14 byte MAC header is removed
612 skb_reserve(skb
, NET_IP_ALIGN
);
615 bi
->dma
= pci_map_single(pdev
, skb
->data
,
619 /* Refresh the desc even if buffer_addrs didn't change because
620 * each write-back erases this info. */
621 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
622 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
623 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
625 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
629 if (i
== rx_ring
->count
)
631 bi
= &rx_ring
->rx_buffer_info
[i
];
635 if (rx_ring
->next_to_use
!= i
) {
636 rx_ring
->next_to_use
= i
;
638 i
= (rx_ring
->count
- 1);
640 ixgbe_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
644 static inline u16
ixgbe_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
646 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
649 static inline u16
ixgbe_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
651 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
654 static inline u32
ixgbe_get_rsc_count(union ixgbe_adv_rx_desc
*rx_desc
)
656 return (le32_to_cpu(rx_desc
->wb
.lower
.lo_dword
.data
) &
657 IXGBE_RXDADV_RSCCNT_MASK
) >>
658 IXGBE_RXDADV_RSCCNT_SHIFT
;
662 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
663 * @skb: pointer to the last skb in the rsc queue
665 * This function changes a queue full of hw rsc buffers into a completed
666 * packet. It uses the ->prev pointers to find the first packet and then
667 * turns it into the frag list owner.
669 static inline struct sk_buff
*ixgbe_transform_rsc_queue(struct sk_buff
*skb
)
671 unsigned int frag_list_size
= 0;
674 struct sk_buff
*prev
= skb
->prev
;
675 frag_list_size
+= skb
->len
;
680 skb_shinfo(skb
)->frag_list
= skb
->next
;
682 skb
->len
+= frag_list_size
;
683 skb
->data_len
+= frag_list_size
;
684 skb
->truesize
+= frag_list_size
;
688 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
689 struct ixgbe_ring
*rx_ring
,
690 int *work_done
, int work_to_do
)
692 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
693 struct pci_dev
*pdev
= adapter
->pdev
;
694 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
695 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
697 unsigned int i
, rsc_count
= 0;
700 bool cleaned
= false;
701 int cleaned_count
= 0;
702 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
705 #endif /* IXGBE_FCOE */
707 i
= rx_ring
->next_to_clean
;
708 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
709 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
710 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
712 while (staterr
& IXGBE_RXD_STAT_DD
) {
714 if (*work_done
>= work_to_do
)
718 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
719 hdr_info
= le16_to_cpu(ixgbe_get_hdr_info(rx_desc
));
720 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
721 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
722 if (hdr_info
& IXGBE_RXDADV_SPH
)
723 adapter
->rx_hdr_split
++;
724 if (len
> IXGBE_RX_HDR_SIZE
)
725 len
= IXGBE_RX_HDR_SIZE
;
726 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
728 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
732 skb
= rx_buffer_info
->skb
;
733 prefetch(skb
->data
- NET_IP_ALIGN
);
734 rx_buffer_info
->skb
= NULL
;
736 if (rx_buffer_info
->dma
) {
737 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
740 rx_buffer_info
->dma
= 0;
745 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
746 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
747 rx_buffer_info
->page_dma
= 0;
748 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
749 rx_buffer_info
->page
,
750 rx_buffer_info
->page_offset
,
753 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
754 (page_count(rx_buffer_info
->page
) != 1))
755 rx_buffer_info
->page
= NULL
;
757 get_page(rx_buffer_info
->page
);
759 skb
->len
+= upper_len
;
760 skb
->data_len
+= upper_len
;
761 skb
->truesize
+= upper_len
;
765 if (i
== rx_ring
->count
)
768 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
772 if (adapter
->flags
& IXGBE_FLAG2_RSC_CAPABLE
)
773 rsc_count
= ixgbe_get_rsc_count(rx_desc
);
776 u32 nextp
= (staterr
& IXGBE_RXDADV_NEXTP_MASK
) >>
777 IXGBE_RXDADV_NEXTP_SHIFT
;
778 next_buffer
= &rx_ring
->rx_buffer_info
[nextp
];
779 rx_ring
->rsc_count
+= (rsc_count
- 1);
781 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
784 if (staterr
& IXGBE_RXD_STAT_EOP
) {
786 skb
= ixgbe_transform_rsc_queue(skb
);
787 rx_ring
->stats
.packets
++;
788 rx_ring
->stats
.bytes
+= skb
->len
;
790 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
791 rx_buffer_info
->skb
= next_buffer
->skb
;
792 rx_buffer_info
->dma
= next_buffer
->dma
;
793 next_buffer
->skb
= skb
;
794 next_buffer
->dma
= 0;
796 skb
->next
= next_buffer
->skb
;
797 skb
->next
->prev
= skb
;
799 adapter
->non_eop_descs
++;
803 if (staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) {
804 dev_kfree_skb_irq(skb
);
808 ixgbe_rx_checksum(adapter
, staterr
, skb
);
810 /* probably a little skewed due to removing CRC */
811 total_rx_bytes
+= skb
->len
;
814 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
816 /* if ddp, not passing to ULD unless for FCP_RSP or error */
817 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
818 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
822 #endif /* IXGBE_FCOE */
823 ixgbe_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
826 rx_desc
->wb
.upper
.status_error
= 0;
828 /* return some buffers to hardware, one at a time is too slow */
829 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
830 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
834 /* use prefetched values */
836 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
838 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
841 rx_ring
->next_to_clean
= i
;
842 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
845 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
848 /* include DDPed FCoE data */
852 mss
= adapter
->netdev
->mtu
- sizeof(struct fcoe_hdr
) -
853 sizeof(struct fc_frame_header
) -
854 sizeof(struct fcoe_crc_eof
);
857 total_rx_bytes
+= ddp_bytes
;
858 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
, mss
);
860 #endif /* IXGBE_FCOE */
862 rx_ring
->total_packets
+= total_rx_packets
;
863 rx_ring
->total_bytes
+= total_rx_bytes
;
864 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
865 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
870 static int ixgbe_clean_rxonly(struct napi_struct
*, int);
872 * ixgbe_configure_msix - Configure MSI-X hardware
873 * @adapter: board private structure
875 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
878 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
880 struct ixgbe_q_vector
*q_vector
;
881 int i
, j
, q_vectors
, v_idx
, r_idx
;
884 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
887 * Populate the IVAR table and set the ITR values to the
888 * corresponding register.
890 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
891 q_vector
= adapter
->q_vector
[v_idx
];
892 /* XXX for_each_bit(...) */
893 r_idx
= find_first_bit(q_vector
->rxr_idx
,
894 adapter
->num_rx_queues
);
896 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
897 j
= adapter
->rx_ring
[r_idx
].reg_idx
;
898 ixgbe_set_ivar(adapter
, 0, j
, v_idx
);
899 r_idx
= find_next_bit(q_vector
->rxr_idx
,
900 adapter
->num_rx_queues
,
903 r_idx
= find_first_bit(q_vector
->txr_idx
,
904 adapter
->num_tx_queues
);
906 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
907 j
= adapter
->tx_ring
[r_idx
].reg_idx
;
908 ixgbe_set_ivar(adapter
, 1, j
, v_idx
);
909 r_idx
= find_next_bit(q_vector
->txr_idx
,
910 adapter
->num_tx_queues
,
914 /* if this is a tx only vector halve the interrupt rate */
915 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
916 q_vector
->eitr
= (adapter
->eitr_param
>> 1);
917 else if (q_vector
->rxr_count
)
919 q_vector
->eitr
= adapter
->eitr_param
;
921 ixgbe_write_eitr(q_vector
);
924 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
925 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
927 else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
928 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
929 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
931 /* set up to autoclear timer, and the vectors */
932 mask
= IXGBE_EIMS_ENABLE_MASK
;
933 mask
&= ~(IXGBE_EIMS_OTHER
| IXGBE_EIMS_LSC
);
934 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
941 latency_invalid
= 255
945 * ixgbe_update_itr - update the dynamic ITR value based on statistics
946 * @adapter: pointer to adapter
947 * @eitr: eitr setting (ints per sec) to give last timeslice
948 * @itr_setting: current throttle rate in ints/second
949 * @packets: the number of packets during this measurement interval
950 * @bytes: the number of bytes during this measurement interval
952 * Stores a new ITR value based on packets and byte
953 * counts during the last interrupt. The advantage of per interrupt
954 * computation is faster updates and more accurate ITR for the current
955 * traffic pattern. Constants in this function were computed
956 * based on theoretical maximum wire speed and thresholds were set based
957 * on testing data as well as attempting to minimize response time
958 * while increasing bulk throughput.
959 * this functionality is controlled by the InterruptThrottleRate module
960 * parameter (see ixgbe_param.c)
962 static u8
ixgbe_update_itr(struct ixgbe_adapter
*adapter
,
963 u32 eitr
, u8 itr_setting
,
964 int packets
, int bytes
)
966 unsigned int retval
= itr_setting
;
971 goto update_itr_done
;
974 /* simple throttlerate management
975 * 0-20MB/s lowest (100000 ints/s)
976 * 20-100MB/s low (20000 ints/s)
977 * 100-1249MB/s bulk (8000 ints/s)
979 /* what was last interrupt timeslice? */
980 timepassed_us
= 1000000/eitr
;
981 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
983 switch (itr_setting
) {
985 if (bytes_perint
> adapter
->eitr_low
)
986 retval
= low_latency
;
989 if (bytes_perint
> adapter
->eitr_high
)
990 retval
= bulk_latency
;
991 else if (bytes_perint
<= adapter
->eitr_low
)
992 retval
= lowest_latency
;
995 if (bytes_perint
<= adapter
->eitr_high
)
996 retval
= low_latency
;
1005 * ixgbe_write_eitr - write EITR register in hardware specific way
1006 * @q_vector: structure containing interrupt and ring information
1008 * This function is made to be called by ethtool and by the driver
1009 * when it needs to update EITR registers at runtime. Hardware
1010 * specific quirks/differences are taken care of here.
1012 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
1014 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1015 struct ixgbe_hw
*hw
= &adapter
->hw
;
1016 int v_idx
= q_vector
->v_idx
;
1017 u32 itr_reg
= EITR_INTS_PER_SEC_TO_REG(q_vector
->eitr
);
1019 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1020 /* must write high and low 16 bits to reset counter */
1021 itr_reg
|= (itr_reg
<< 16);
1022 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1024 * set the WDIS bit to not clear the timer bits and cause an
1025 * immediate assertion of the interrupt
1027 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
1029 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
1032 static void ixgbe_set_itr_msix(struct ixgbe_q_vector
*q_vector
)
1034 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1036 u8 current_itr
, ret_itr
;
1038 struct ixgbe_ring
*rx_ring
, *tx_ring
;
1040 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1041 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1042 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1043 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1045 tx_ring
->total_packets
,
1046 tx_ring
->total_bytes
);
1047 /* if the result for this queue would decrease interrupt
1048 * rate for this vector then use that result */
1049 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
1050 q_vector
->tx_itr
- 1 : ret_itr
);
1051 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1055 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1056 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1057 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1058 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1060 rx_ring
->total_packets
,
1061 rx_ring
->total_bytes
);
1062 /* if the result for this queue would decrease interrupt
1063 * rate for this vector then use that result */
1064 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
1065 q_vector
->rx_itr
- 1 : ret_itr
);
1066 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1070 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1072 switch (current_itr
) {
1073 /* counts and packets in update_itr are dependent on these numbers */
1074 case lowest_latency
:
1078 new_itr
= 20000; /* aka hwitr = ~200 */
1086 if (new_itr
!= q_vector
->eitr
) {
1087 /* do an exponential smoothing */
1088 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1090 /* save the algorithm value here, not the smoothed one */
1091 q_vector
->eitr
= new_itr
;
1093 ixgbe_write_eitr(q_vector
);
1099 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
1101 struct ixgbe_hw
*hw
= &adapter
->hw
;
1103 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
1104 (eicr
& IXGBE_EICR_GPI_SDP1
)) {
1105 DPRINTK(PROBE
, CRIT
, "Fan has stopped, replace the adapter\n");
1106 /* write to clear the interrupt */
1107 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1111 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1113 struct ixgbe_hw
*hw
= &adapter
->hw
;
1115 if (eicr
& IXGBE_EICR_GPI_SDP1
) {
1116 /* Clear the interrupt */
1117 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1118 schedule_work(&adapter
->multispeed_fiber_task
);
1119 } else if (eicr
& IXGBE_EICR_GPI_SDP2
) {
1120 /* Clear the interrupt */
1121 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP2
);
1122 schedule_work(&adapter
->sfp_config_module_task
);
1124 /* Interrupt isn't for us... */
1129 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
1131 struct ixgbe_hw
*hw
= &adapter
->hw
;
1134 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1135 adapter
->link_check_timeout
= jiffies
;
1136 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1137 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
1138 schedule_work(&adapter
->watchdog_task
);
1142 static irqreturn_t
ixgbe_msix_lsc(int irq
, void *data
)
1144 struct net_device
*netdev
= data
;
1145 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1146 struct ixgbe_hw
*hw
= &adapter
->hw
;
1150 * Workaround for Silicon errata. Use clear-by-write instead
1151 * of clear-by-read. Reading with EICS will return the
1152 * interrupt causes without clearing, which later be done
1153 * with the write to EICR.
1155 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
1156 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
1158 if (eicr
& IXGBE_EICR_LSC
)
1159 ixgbe_check_lsc(adapter
);
1161 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
1162 ixgbe_check_fan_failure(adapter
, eicr
);
1164 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
1165 ixgbe_check_sfp_event(adapter
, eicr
);
1167 /* Handle Flow Director Full threshold interrupt */
1168 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
1170 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_FLOW_DIR
);
1171 /* Disable transmits before FDIR Re-initialization */
1172 netif_tx_stop_all_queues(netdev
);
1173 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1174 struct ixgbe_ring
*tx_ring
=
1175 &adapter
->tx_ring
[i
];
1176 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE
,
1177 &tx_ring
->reinit_state
))
1178 schedule_work(&adapter
->fdir_reinit_task
);
1182 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1183 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_OTHER
);
1188 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
1193 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1194 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1195 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1197 mask
= (qmask
& 0xFFFFFFFF);
1198 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(0), mask
);
1199 mask
= (qmask
>> 32);
1200 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(1), mask
);
1202 /* skip the flush */
1205 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
1210 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1211 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1212 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, mask
);
1214 mask
= (qmask
& 0xFFFFFFFF);
1215 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), mask
);
1216 mask
= (qmask
>> 32);
1217 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), mask
);
1219 /* skip the flush */
1222 static irqreturn_t
ixgbe_msix_clean_tx(int irq
, void *data
)
1224 struct ixgbe_q_vector
*q_vector
= data
;
1225 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1226 struct ixgbe_ring
*tx_ring
;
1229 if (!q_vector
->txr_count
)
1232 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1233 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1234 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1235 tx_ring
->total_bytes
= 0;
1236 tx_ring
->total_packets
= 0;
1237 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1241 /* disable interrupts on this vector only */
1242 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1243 napi_schedule(&q_vector
->napi
);
1249 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1251 * @data: pointer to our q_vector struct for this interrupt vector
1253 static irqreturn_t
ixgbe_msix_clean_rx(int irq
, void *data
)
1255 struct ixgbe_q_vector
*q_vector
= data
;
1256 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1257 struct ixgbe_ring
*rx_ring
;
1261 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1262 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1263 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1264 rx_ring
->total_bytes
= 0;
1265 rx_ring
->total_packets
= 0;
1266 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1270 if (!q_vector
->rxr_count
)
1273 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1274 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1275 /* disable interrupts on this vector only */
1276 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1277 napi_schedule(&q_vector
->napi
);
1282 static irqreturn_t
ixgbe_msix_clean_many(int irq
, void *data
)
1284 struct ixgbe_q_vector
*q_vector
= data
;
1285 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1286 struct ixgbe_ring
*ring
;
1290 if (!q_vector
->txr_count
&& !q_vector
->rxr_count
)
1293 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1294 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1295 ring
= &(adapter
->tx_ring
[r_idx
]);
1296 ring
->total_bytes
= 0;
1297 ring
->total_packets
= 0;
1298 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1302 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1303 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1304 ring
= &(adapter
->rx_ring
[r_idx
]);
1305 ring
->total_bytes
= 0;
1306 ring
->total_packets
= 0;
1307 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1311 /* disable interrupts on this vector only */
1312 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1313 napi_schedule(&q_vector
->napi
);
1319 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1320 * @napi: napi struct with our devices info in it
1321 * @budget: amount of work driver is allowed to do this pass, in packets
1323 * This function is optimized for cleaning one queue only on a single
1326 static int ixgbe_clean_rxonly(struct napi_struct
*napi
, int budget
)
1328 struct ixgbe_q_vector
*q_vector
=
1329 container_of(napi
, struct ixgbe_q_vector
, napi
);
1330 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1331 struct ixgbe_ring
*rx_ring
= NULL
;
1335 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1336 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1337 #ifdef CONFIG_IXGBE_DCA
1338 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1339 ixgbe_update_rx_dca(adapter
, rx_ring
);
1342 ixgbe_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
1344 /* If all Rx work done, exit the polling mode */
1345 if (work_done
< budget
) {
1346 napi_complete(napi
);
1347 if (adapter
->itr_setting
& 1)
1348 ixgbe_set_itr_msix(q_vector
);
1349 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1350 ixgbe_irq_enable_queues(adapter
,
1351 ((u64
)1 << q_vector
->v_idx
));
1358 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
1359 * @napi: napi struct with our devices info in it
1360 * @budget: amount of work driver is allowed to do this pass, in packets
1362 * This function will clean more than one rx queue associated with a
1365 static int ixgbe_clean_rxtx_many(struct napi_struct
*napi
, int budget
)
1367 struct ixgbe_q_vector
*q_vector
=
1368 container_of(napi
, struct ixgbe_q_vector
, napi
);
1369 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1370 struct ixgbe_ring
*ring
= NULL
;
1371 int work_done
= 0, i
;
1373 bool tx_clean_complete
= true;
1375 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1376 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1377 ring
= &(adapter
->tx_ring
[r_idx
]);
1378 #ifdef CONFIG_IXGBE_DCA
1379 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1380 ixgbe_update_tx_dca(adapter
, ring
);
1382 tx_clean_complete
&= ixgbe_clean_tx_irq(q_vector
, ring
);
1383 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1387 /* attempt to distribute budget to each queue fairly, but don't allow
1388 * the budget to go below 1 because we'll exit polling */
1389 budget
/= (q_vector
->rxr_count
?: 1);
1390 budget
= max(budget
, 1);
1391 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1392 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1393 ring
= &(adapter
->rx_ring
[r_idx
]);
1394 #ifdef CONFIG_IXGBE_DCA
1395 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1396 ixgbe_update_rx_dca(adapter
, ring
);
1398 ixgbe_clean_rx_irq(q_vector
, ring
, &work_done
, budget
);
1399 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1403 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1404 ring
= &(adapter
->rx_ring
[r_idx
]);
1405 /* If all Rx work done, exit the polling mode */
1406 if (work_done
< budget
) {
1407 napi_complete(napi
);
1408 if (adapter
->itr_setting
& 1)
1409 ixgbe_set_itr_msix(q_vector
);
1410 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1411 ixgbe_irq_enable_queues(adapter
,
1412 ((u64
)1 << q_vector
->v_idx
));
1420 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1421 * @napi: napi struct with our devices info in it
1422 * @budget: amount of work driver is allowed to do this pass, in packets
1424 * This function is optimized for cleaning one queue only on a single
1427 static int ixgbe_clean_txonly(struct napi_struct
*napi
, int budget
)
1429 struct ixgbe_q_vector
*q_vector
=
1430 container_of(napi
, struct ixgbe_q_vector
, napi
);
1431 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1432 struct ixgbe_ring
*tx_ring
= NULL
;
1436 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1437 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1438 #ifdef CONFIG_IXGBE_DCA
1439 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1440 ixgbe_update_tx_dca(adapter
, tx_ring
);
1443 if (!ixgbe_clean_tx_irq(q_vector
, tx_ring
))
1446 /* If all Rx work done, exit the polling mode */
1447 if (work_done
< budget
) {
1448 napi_complete(napi
);
1449 if (adapter
->itr_setting
& 1)
1450 ixgbe_set_itr_msix(q_vector
);
1451 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1452 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1458 static inline void map_vector_to_rxq(struct ixgbe_adapter
*a
, int v_idx
,
1461 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1463 set_bit(r_idx
, q_vector
->rxr_idx
);
1464 q_vector
->rxr_count
++;
1467 static inline void map_vector_to_txq(struct ixgbe_adapter
*a
, int v_idx
,
1470 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1472 set_bit(t_idx
, q_vector
->txr_idx
);
1473 q_vector
->txr_count
++;
1477 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1478 * @adapter: board private structure to initialize
1479 * @vectors: allotted vector count for descriptor rings
1481 * This function maps descriptor rings to the queue-specific vectors
1482 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1483 * one vector per ring/queue, but on a constrained vector budget, we
1484 * group the rings as "efficiently" as possible. You would add new
1485 * mapping configurations in here.
1487 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter
*adapter
,
1491 int rxr_idx
= 0, txr_idx
= 0;
1492 int rxr_remaining
= adapter
->num_rx_queues
;
1493 int txr_remaining
= adapter
->num_tx_queues
;
1498 /* No mapping required if MSI-X is disabled. */
1499 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
1503 * The ideal configuration...
1504 * We have enough vectors to map one per queue.
1506 if (vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1507 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1508 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1510 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1511 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1517 * If we don't have enough vectors for a 1-to-1
1518 * mapping, we'll have to group them so there are
1519 * multiple queues per vector.
1521 /* Re-adjusting *qpv takes care of the remainder. */
1522 for (i
= v_start
; i
< vectors
; i
++) {
1523 rqpv
= DIV_ROUND_UP(rxr_remaining
, vectors
- i
);
1524 for (j
= 0; j
< rqpv
; j
++) {
1525 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1530 for (i
= v_start
; i
< vectors
; i
++) {
1531 tqpv
= DIV_ROUND_UP(txr_remaining
, vectors
- i
);
1532 for (j
= 0; j
< tqpv
; j
++) {
1533 map_vector_to_txq(adapter
, i
, txr_idx
);
1544 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1545 * @adapter: board private structure
1547 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1548 * interrupts from the kernel.
1550 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
1552 struct net_device
*netdev
= adapter
->netdev
;
1553 irqreturn_t (*handler
)(int, void *);
1554 int i
, vector
, q_vectors
, err
;
1557 /* Decrement for Other and TCP Timer vectors */
1558 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1560 /* Map the Tx/Rx rings to the vectors we were allotted. */
1561 err
= ixgbe_map_rings_to_vectors(adapter
, q_vectors
);
1565 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1566 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1567 &ixgbe_msix_clean_many)
1568 for (vector
= 0; vector
< q_vectors
; vector
++) {
1569 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1571 if(handler
== &ixgbe_msix_clean_rx
) {
1572 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1573 netdev
->name
, "rx", ri
++);
1575 else if(handler
== &ixgbe_msix_clean_tx
) {
1576 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1577 netdev
->name
, "tx", ti
++);
1580 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1581 netdev
->name
, "TxRx", vector
);
1583 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1584 handler
, 0, adapter
->name
[vector
],
1585 adapter
->q_vector
[vector
]);
1588 "request_irq failed for MSIX interrupt "
1589 "Error: %d\n", err
);
1590 goto free_queue_irqs
;
1594 sprintf(adapter
->name
[vector
], "%s:lsc", netdev
->name
);
1595 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1596 &ixgbe_msix_lsc
, 0, adapter
->name
[vector
], netdev
);
1599 "request_irq for msix_lsc failed: %d\n", err
);
1600 goto free_queue_irqs
;
1606 for (i
= vector
- 1; i
>= 0; i
--)
1607 free_irq(adapter
->msix_entries
[--vector
].vector
,
1608 adapter
->q_vector
[i
]);
1609 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
1610 pci_disable_msix(adapter
->pdev
);
1611 kfree(adapter
->msix_entries
);
1612 adapter
->msix_entries
= NULL
;
1617 static void ixgbe_set_itr(struct ixgbe_adapter
*adapter
)
1619 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1621 u32 new_itr
= q_vector
->eitr
;
1622 struct ixgbe_ring
*rx_ring
= &adapter
->rx_ring
[0];
1623 struct ixgbe_ring
*tx_ring
= &adapter
->tx_ring
[0];
1625 q_vector
->tx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1627 tx_ring
->total_packets
,
1628 tx_ring
->total_bytes
);
1629 q_vector
->rx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1631 rx_ring
->total_packets
,
1632 rx_ring
->total_bytes
);
1634 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1636 switch (current_itr
) {
1637 /* counts and packets in update_itr are dependent on these numbers */
1638 case lowest_latency
:
1642 new_itr
= 20000; /* aka hwitr = ~200 */
1651 if (new_itr
!= q_vector
->eitr
) {
1652 /* do an exponential smoothing */
1653 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1655 /* save the algorithm value here, not the smoothed one */
1656 q_vector
->eitr
= new_itr
;
1658 ixgbe_write_eitr(q_vector
);
1665 * ixgbe_irq_enable - Enable default interrupt generation settings
1666 * @adapter: board private structure
1668 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
)
1672 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1673 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
1674 mask
|= IXGBE_EIMS_GPI_SDP1
;
1675 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1676 mask
|= IXGBE_EIMS_ECC
;
1677 mask
|= IXGBE_EIMS_GPI_SDP1
;
1678 mask
|= IXGBE_EIMS_GPI_SDP2
;
1680 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
1681 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
1682 mask
|= IXGBE_EIMS_FLOW_DIR
;
1684 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1685 ixgbe_irq_enable_queues(adapter
, ~0);
1686 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1690 * ixgbe_intr - legacy mode Interrupt Handler
1691 * @irq: interrupt number
1692 * @data: pointer to a network interface device structure
1694 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
1696 struct net_device
*netdev
= data
;
1697 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1698 struct ixgbe_hw
*hw
= &adapter
->hw
;
1699 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1703 * Workaround for silicon errata. Mask the interrupts
1704 * before the read of EICR.
1706 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
1708 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1709 * therefore no explict interrupt disable is necessary */
1710 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
1712 /* shared interrupt alert!
1713 * make sure interrupts are enabled because the read will
1714 * have disabled interrupts due to EIAM */
1715 ixgbe_irq_enable(adapter
);
1716 return IRQ_NONE
; /* Not our interrupt */
1719 if (eicr
& IXGBE_EICR_LSC
)
1720 ixgbe_check_lsc(adapter
);
1722 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
1723 ixgbe_check_sfp_event(adapter
, eicr
);
1725 ixgbe_check_fan_failure(adapter
, eicr
);
1727 if (napi_schedule_prep(&(q_vector
->napi
))) {
1728 adapter
->tx_ring
[0].total_packets
= 0;
1729 adapter
->tx_ring
[0].total_bytes
= 0;
1730 adapter
->rx_ring
[0].total_packets
= 0;
1731 adapter
->rx_ring
[0].total_bytes
= 0;
1732 /* would disable interrupts here but EIAM disabled it */
1733 __napi_schedule(&(q_vector
->napi
));
1739 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter
*adapter
)
1741 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1743 for (i
= 0; i
< q_vectors
; i
++) {
1744 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
1745 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1746 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1747 q_vector
->rxr_count
= 0;
1748 q_vector
->txr_count
= 0;
1753 * ixgbe_request_irq - initialize interrupts
1754 * @adapter: board private structure
1756 * Attempts to configure interrupts using the best available
1757 * capabilities of the hardware and kernel.
1759 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
1761 struct net_device
*netdev
= adapter
->netdev
;
1764 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1765 err
= ixgbe_request_msix_irqs(adapter
);
1766 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
1767 err
= request_irq(adapter
->pdev
->irq
, &ixgbe_intr
, 0,
1768 netdev
->name
, netdev
);
1770 err
= request_irq(adapter
->pdev
->irq
, &ixgbe_intr
, IRQF_SHARED
,
1771 netdev
->name
, netdev
);
1775 DPRINTK(PROBE
, ERR
, "request_irq failed, Error %d\n", err
);
1780 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
1782 struct net_device
*netdev
= adapter
->netdev
;
1784 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1787 q_vectors
= adapter
->num_msix_vectors
;
1790 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1793 for (; i
>= 0; i
--) {
1794 free_irq(adapter
->msix_entries
[i
].vector
,
1795 adapter
->q_vector
[i
]);
1798 ixgbe_reset_q_vectors(adapter
);
1800 free_irq(adapter
->pdev
->irq
, netdev
);
1805 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1806 * @adapter: board private structure
1808 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
1810 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1811 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
1813 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
1814 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
1815 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
1817 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1818 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1820 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1821 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1823 synchronize_irq(adapter
->pdev
->irq
);
1828 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1831 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
1833 struct ixgbe_hw
*hw
= &adapter
->hw
;
1835 IXGBE_WRITE_REG(hw
, IXGBE_EITR(0),
1836 EITR_INTS_PER_SEC_TO_REG(adapter
->eitr_param
));
1838 ixgbe_set_ivar(adapter
, 0, 0, 0);
1839 ixgbe_set_ivar(adapter
, 1, 0, 0);
1841 map_vector_to_rxq(adapter
, 0, 0);
1842 map_vector_to_txq(adapter
, 0, 0);
1844 DPRINTK(HW
, INFO
, "Legacy interrupt IVAR setup done\n");
1848 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1849 * @adapter: board private structure
1851 * Configure the Tx unit of the MAC after a reset.
1853 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
1856 struct ixgbe_hw
*hw
= &adapter
->hw
;
1857 u32 i
, j
, tdlen
, txctrl
;
1859 /* Setup the HW Tx Head and Tail descriptor pointers */
1860 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1861 struct ixgbe_ring
*ring
= &adapter
->tx_ring
[i
];
1864 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1865 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(j
),
1866 (tdba
& DMA_BIT_MASK(32)));
1867 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(j
), (tdba
>> 32));
1868 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(j
), tdlen
);
1869 IXGBE_WRITE_REG(hw
, IXGBE_TDH(j
), 0);
1870 IXGBE_WRITE_REG(hw
, IXGBE_TDT(j
), 0);
1871 adapter
->tx_ring
[i
].head
= IXGBE_TDH(j
);
1872 adapter
->tx_ring
[i
].tail
= IXGBE_TDT(j
);
1873 /* Disable Tx Head Writeback RO bit, since this hoses
1874 * bookkeeping if things aren't delivered in order.
1876 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(j
));
1877 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1878 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(j
), txctrl
);
1880 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
1881 /* We enable 8 traffic classes, DCB only */
1882 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
1883 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, (IXGBE_MTQC_RT_ENA
|
1884 IXGBE_MTQC_8TC_8TQ
));
1888 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1890 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
, int index
)
1892 struct ixgbe_ring
*rx_ring
;
1896 struct ixgbe_ring_feature
*feature
= adapter
->ring_feature
;
1898 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1899 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
1900 int dcb_i
= feature
[RING_F_DCB
].indices
;
1902 queue0
= index
>> 4;
1903 else if (dcb_i
== 4)
1904 queue0
= index
>> 5;
1906 dev_err(&adapter
->pdev
->dev
, "Invalid DCB "
1909 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
1910 struct ixgbe_ring_feature
*f
;
1912 rx_ring
= &adapter
->rx_ring
[queue0
];
1913 f
= &adapter
->ring_feature
[RING_F_FCOE
];
1914 if ((queue0
== 0) && (index
> rx_ring
->reg_idx
))
1915 queue0
= f
->mask
+ index
-
1916 rx_ring
->reg_idx
- 1;
1918 #endif /* IXGBE_FCOE */
1923 mask
= (unsigned long) feature
[RING_F_RSS
].mask
;
1924 queue0
= index
& mask
;
1925 index
= index
& mask
;
1928 rx_ring
= &adapter
->rx_ring
[queue0
];
1930 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(index
));
1932 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
1933 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
1935 srrctl
|= (IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1936 IXGBE_SRRCTL_BSIZEHDR_MASK
;
1938 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1939 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1940 srrctl
|= IXGBE_MAX_RXBUFFER
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1942 srrctl
|= (PAGE_SIZE
/ 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1944 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1946 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
1947 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1948 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1951 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(index
), srrctl
);
1954 static u32
ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
1959 if (!(adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
1962 mask
= adapter
->flags
& (IXGBE_FLAG_RSS_ENABLED
1963 #ifdef CONFIG_IXGBE_DCB
1964 | IXGBE_FLAG_DCB_ENABLED
1969 case (IXGBE_FLAG_RSS_ENABLED
):
1970 mrqc
= IXGBE_MRQC_RSSEN
;
1972 #ifdef CONFIG_IXGBE_DCB
1973 case (IXGBE_FLAG_DCB_ENABLED
):
1974 mrqc
= IXGBE_MRQC_RT8TCEN
;
1976 #endif /* CONFIG_IXGBE_DCB */
1985 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
1986 * @adapter: board private structure
1988 * Configure the Rx unit of the MAC after a reset.
1990 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
1993 struct ixgbe_hw
*hw
= &adapter
->hw
;
1994 struct net_device
*netdev
= adapter
->netdev
;
1995 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1997 u32 rdlen
, rxctrl
, rxcsum
;
1998 static const u32 seed
[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1999 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2000 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2002 u32 reta
= 0, mrqc
= 0;
2007 /* Decide whether to use packet split mode or not */
2008 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
2011 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
2012 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
2013 #endif /* IXGBE_FCOE */
2015 /* Set the RX buffer length according to the mode */
2016 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
2017 rx_buf_len
= IXGBE_RX_HDR_SIZE
;
2018 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2019 /* PSRTYPE must be initialized in 82599 */
2020 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
2021 IXGBE_PSRTYPE_UDPHDR
|
2022 IXGBE_PSRTYPE_IPV4HDR
|
2023 IXGBE_PSRTYPE_IPV6HDR
|
2024 IXGBE_PSRTYPE_L2HDR
;
2025 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(0), psrtype
);
2028 if (!(adapter
->flags
& IXGBE_FLAG2_RSC_ENABLED
) &&
2029 (netdev
->mtu
<= ETH_DATA_LEN
))
2030 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
2032 rx_buf_len
= ALIGN(max_frame
, 1024);
2035 fctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_FCTRL
);
2036 fctrl
|= IXGBE_FCTRL_BAM
;
2037 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
2038 fctrl
|= IXGBE_FCTRL_PMCF
;
2039 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_FCTRL
, fctrl
);
2041 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
2042 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2043 hlreg0
&= ~IXGBE_HLREG0_JUMBOEN
;
2045 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2047 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
2048 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2050 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
2052 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
2053 /* disable receives while setting up the descriptors */
2054 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2055 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
2058 * Setup the HW Rx Head and Tail Descriptor Pointers and
2059 * the Base and Length of the Rx Descriptor Ring
2061 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2062 rdba
= adapter
->rx_ring
[i
].dma
;
2063 j
= adapter
->rx_ring
[i
].reg_idx
;
2064 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(j
), (rdba
& DMA_BIT_MASK(32)));
2065 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(j
), (rdba
>> 32));
2066 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(j
), rdlen
);
2067 IXGBE_WRITE_REG(hw
, IXGBE_RDH(j
), 0);
2068 IXGBE_WRITE_REG(hw
, IXGBE_RDT(j
), 0);
2069 adapter
->rx_ring
[i
].head
= IXGBE_RDH(j
);
2070 adapter
->rx_ring
[i
].tail
= IXGBE_RDT(j
);
2071 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
2074 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
2075 struct ixgbe_ring_feature
*f
;
2076 f
= &adapter
->ring_feature
[RING_F_FCOE
];
2077 if ((rx_buf_len
< IXGBE_FCOE_JUMBO_FRAME_SIZE
) &&
2078 (i
>= f
->mask
) && (i
< f
->mask
+ f
->indices
))
2079 adapter
->rx_ring
[i
].rx_buf_len
=
2080 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2083 #endif /* IXGBE_FCOE */
2084 ixgbe_configure_srrctl(adapter
, j
);
2087 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2089 * For VMDq support of different descriptor types or
2090 * buffer sizes through the use of multiple SRRCTL
2091 * registers, RDRXCTL.MVMEN must be set to 1
2093 * also, the manual doesn't mention it clearly but DCA hints
2094 * will only use queue 0's tags unless this bit is set. Side
2095 * effects of setting this bit are only that SRRCTL must be
2096 * fully programmed [0..15]
2098 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2099 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
2100 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2103 /* Program MRQC for the distribution of queues */
2104 mrqc
= ixgbe_setup_mrqc(adapter
);
2106 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
2107 /* Fill out redirection table */
2108 for (i
= 0, j
= 0; i
< 128; i
++, j
++) {
2109 if (j
== adapter
->ring_feature
[RING_F_RSS
].indices
)
2111 /* reta = 4-byte sliding window of
2112 * 0x00..(indices-1)(indices-1)00..etc. */
2113 reta
= (reta
<< 8) | (j
* 0x11);
2115 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
2118 /* Fill out hash function seeds */
2119 for (i
= 0; i
< 10; i
++)
2120 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), seed
[i
]);
2122 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2123 mrqc
|= IXGBE_MRQC_RSSEN
;
2124 /* Perform hash on these packet types */
2125 mrqc
|= IXGBE_MRQC_RSS_FIELD_IPV4
2126 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2127 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2128 | IXGBE_MRQC_RSS_FIELD_IPV6
2129 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2130 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
2132 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
2134 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
2136 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
||
2137 adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
) {
2138 /* Disable indicating checksum in descriptor, enables
2140 rxcsum
|= IXGBE_RXCSUM_PCSD
;
2142 if (!(rxcsum
& IXGBE_RXCSUM_PCSD
)) {
2143 /* Enable IPv4 payload checksum for UDP fragments
2144 * if PCSD is not set */
2145 rxcsum
|= IXGBE_RXCSUM_IPPCSE
;
2148 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
2150 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2151 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2152 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
2153 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
2154 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2157 if (adapter
->flags
& IXGBE_FLAG2_RSC_ENABLED
) {
2158 /* Enable 82599 HW-RSC */
2159 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2160 j
= adapter
->rx_ring
[i
].reg_idx
;
2161 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(j
));
2162 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
2164 * we must limit the number of descriptors so that the
2165 * total size of max desc * buf_len is not greater
2168 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
2169 #if (MAX_SKB_FRAGS > 16)
2170 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2171 #elif (MAX_SKB_FRAGS > 8)
2172 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2173 #elif (MAX_SKB_FRAGS > 4)
2174 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2176 rscctrl
|= IXGBE_RSCCTL_MAXDESC_1
;
2179 if (rx_buf_len
< IXGBE_RXBUFFER_4096
)
2180 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2181 else if (rx_buf_len
< IXGBE_RXBUFFER_8192
)
2182 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2184 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2186 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(j
), rscctrl
);
2188 /* Disable RSC for ACK packets */
2189 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
2190 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
2194 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2196 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2197 struct ixgbe_hw
*hw
= &adapter
->hw
;
2199 /* add VID to filter table */
2200 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, 0, true);
2203 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2205 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2206 struct ixgbe_hw
*hw
= &adapter
->hw
;
2208 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2209 ixgbe_irq_disable(adapter
);
2211 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
2213 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2214 ixgbe_irq_enable(adapter
);
2216 /* remove VID from filter table */
2217 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, 0, false);
2220 static void ixgbe_vlan_rx_register(struct net_device
*netdev
,
2221 struct vlan_group
*grp
)
2223 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2227 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2228 ixgbe_irq_disable(adapter
);
2229 adapter
->vlgrp
= grp
;
2232 * For a DCB driver, always enable VLAN tag stripping so we can
2233 * still receive traffic from a DCB-enabled host even if we're
2236 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_VLNCTRL
);
2237 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
2238 ctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
2239 ctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2240 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VLNCTRL
, ctrl
);
2241 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
2242 ctrl
|= IXGBE_VLNCTRL_VFE
;
2243 /* enable VLAN tag insert/strip */
2244 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_VLNCTRL
);
2245 ctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2246 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VLNCTRL
, ctrl
);
2247 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2248 j
= adapter
->rx_ring
[i
].reg_idx
;
2249 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_RXDCTL(j
));
2250 ctrl
|= IXGBE_RXDCTL_VME
;
2251 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_RXDCTL(j
), ctrl
);
2254 ixgbe_vlan_rx_add_vid(netdev
, 0);
2256 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2257 ixgbe_irq_enable(adapter
);
2260 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
2262 ixgbe_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2264 if (adapter
->vlgrp
) {
2266 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2267 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
2269 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
2274 static u8
*ixgbe_addr_list_itr(struct ixgbe_hw
*hw
, u8
**mc_addr_ptr
, u32
*vmdq
)
2276 struct dev_mc_list
*mc_ptr
;
2277 u8
*addr
= *mc_addr_ptr
;
2280 mc_ptr
= container_of(addr
, struct dev_mc_list
, dmi_addr
[0]);
2282 *mc_addr_ptr
= mc_ptr
->next
->dmi_addr
;
2284 *mc_addr_ptr
= NULL
;
2290 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
2291 * @netdev: network interface device structure
2293 * The set_rx_method entry point is called whenever the unicast/multicast
2294 * address list or the network interface flags are updated. This routine is
2295 * responsible for configuring the hardware for proper unicast, multicast and
2298 static void ixgbe_set_rx_mode(struct net_device
*netdev
)
2300 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2301 struct ixgbe_hw
*hw
= &adapter
->hw
;
2303 u8
*addr_list
= NULL
;
2306 /* Check for Promiscuous and All Multicast modes */
2308 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
2309 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2311 if (netdev
->flags
& IFF_PROMISC
) {
2312 hw
->addr_ctrl
.user_set_promisc
= 1;
2313 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2314 vlnctrl
&= ~IXGBE_VLNCTRL_VFE
;
2316 if (netdev
->flags
& IFF_ALLMULTI
) {
2317 fctrl
|= IXGBE_FCTRL_MPE
;
2318 fctrl
&= ~IXGBE_FCTRL_UPE
;
2320 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2322 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
2323 hw
->addr_ctrl
.user_set_promisc
= 0;
2326 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
2327 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2329 /* reprogram secondary unicast list */
2330 hw
->mac
.ops
.update_uc_addr_list(hw
, &netdev
->uc
.list
);
2332 /* reprogram multicast list */
2333 addr_count
= netdev
->mc_count
;
2335 addr_list
= netdev
->mc_list
->dmi_addr
;
2336 hw
->mac
.ops
.update_mc_addr_list(hw
, addr_list
, addr_count
,
2337 ixgbe_addr_list_itr
);
2340 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
2343 struct ixgbe_q_vector
*q_vector
;
2344 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2346 /* legacy and MSI only use one vector */
2347 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2350 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2351 struct napi_struct
*napi
;
2352 q_vector
= adapter
->q_vector
[q_idx
];
2353 napi
= &q_vector
->napi
;
2354 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2355 if (!q_vector
->rxr_count
|| !q_vector
->txr_count
) {
2356 if (q_vector
->txr_count
== 1)
2357 napi
->poll
= &ixgbe_clean_txonly
;
2358 else if (q_vector
->rxr_count
== 1)
2359 napi
->poll
= &ixgbe_clean_rxonly
;
2367 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
2370 struct ixgbe_q_vector
*q_vector
;
2371 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2373 /* legacy and MSI only use one vector */
2374 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2377 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2378 q_vector
= adapter
->q_vector
[q_idx
];
2379 napi_disable(&q_vector
->napi
);
2383 #ifdef CONFIG_IXGBE_DCB
2385 * ixgbe_configure_dcb - Configure DCB hardware
2386 * @adapter: ixgbe adapter struct
2388 * This is called by the driver on open to configure the DCB hardware.
2389 * This is also called by the gennetlink interface when reconfiguring
2392 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
2394 struct ixgbe_hw
*hw
= &adapter
->hw
;
2395 u32 txdctl
, vlnctrl
;
2398 ixgbe_dcb_check_config(&adapter
->dcb_cfg
);
2399 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_TX_CONFIG
);
2400 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_RX_CONFIG
);
2402 /* reconfigure the hardware */
2403 ixgbe_dcb_hw_config(&adapter
->hw
, &adapter
->dcb_cfg
);
2405 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2406 j
= adapter
->tx_ring
[i
].reg_idx
;
2407 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2408 /* PThresh workaround for Tx hang with DFP enabled. */
2410 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2412 /* Enable VLAN tag insert/strip */
2413 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2414 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2415 vlnctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
2416 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2417 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2418 } else if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2419 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
2420 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2421 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2422 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2423 j
= adapter
->rx_ring
[i
].reg_idx
;
2424 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2425 vlnctrl
|= IXGBE_RXDCTL_VME
;
2426 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
2429 hw
->mac
.ops
.set_vfta(&adapter
->hw
, 0, 0, true);
2433 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
2435 struct net_device
*netdev
= adapter
->netdev
;
2436 struct ixgbe_hw
*hw
= &adapter
->hw
;
2439 ixgbe_set_rx_mode(netdev
);
2441 ixgbe_restore_vlan(adapter
);
2442 #ifdef CONFIG_IXGBE_DCB
2443 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
2444 netif_set_gso_max_size(netdev
, 32768);
2445 ixgbe_configure_dcb(adapter
);
2447 netif_set_gso_max_size(netdev
, 65536);
2450 netif_set_gso_max_size(netdev
, 65536);
2454 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
2455 ixgbe_configure_fcoe(adapter
);
2457 #endif /* IXGBE_FCOE */
2458 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2459 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2460 adapter
->tx_ring
[i
].atr_sample_rate
=
2461 adapter
->atr_sample_rate
;
2462 ixgbe_init_fdir_signature_82599(hw
, adapter
->fdir_pballoc
);
2463 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
2464 ixgbe_init_fdir_perfect_82599(hw
, adapter
->fdir_pballoc
);
2467 ixgbe_configure_tx(adapter
);
2468 ixgbe_configure_rx(adapter
);
2469 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2470 ixgbe_alloc_rx_buffers(adapter
, &adapter
->rx_ring
[i
],
2471 (adapter
->rx_ring
[i
].count
- 1));
2474 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2476 switch (hw
->phy
.type
) {
2477 case ixgbe_phy_sfp_avago
:
2478 case ixgbe_phy_sfp_ftl
:
2479 case ixgbe_phy_sfp_intel
:
2480 case ixgbe_phy_sfp_unknown
:
2481 case ixgbe_phy_tw_tyco
:
2482 case ixgbe_phy_tw_unknown
:
2490 * ixgbe_sfp_link_config - set up SFP+ link
2491 * @adapter: pointer to private adapter struct
2493 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
2495 struct ixgbe_hw
*hw
= &adapter
->hw
;
2497 if (hw
->phy
.multispeed_fiber
) {
2499 * In multispeed fiber setups, the device may not have
2500 * had a physical connection when the driver loaded.
2501 * If that's the case, the initial link configuration
2502 * couldn't get the MAC into 10G or 1G mode, so we'll
2503 * never have a link status change interrupt fire.
2504 * We need to try and force an autonegotiation
2505 * session, then bring up link.
2507 hw
->mac
.ops
.setup_sfp(hw
);
2508 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
2509 schedule_work(&adapter
->multispeed_fiber_task
);
2512 * Direct Attach Cu and non-multispeed fiber modules
2513 * still need to be configured properly prior to
2516 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_MOD_TASK
))
2517 schedule_work(&adapter
->sfp_config_module_task
);
2522 * ixgbe_non_sfp_link_config - set up non-SFP+ link
2523 * @hw: pointer to private hardware struct
2525 * Returns 0 on success, negative on failure
2527 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
2530 bool link_up
= false;
2531 u32 ret
= IXGBE_ERR_LINK_SETUP
;
2533 if (hw
->mac
.ops
.check_link
)
2534 ret
= hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
2539 if (hw
->mac
.ops
.get_link_capabilities
)
2540 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
,
2545 if (hw
->mac
.ops
.setup_link_speed
)
2546 ret
= hw
->mac
.ops
.setup_link_speed(hw
, autoneg
, true, link_up
);
2551 #define IXGBE_MAX_RX_DESC_POLL 10
2552 static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
2555 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
2558 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
2559 if (IXGBE_READ_REG(&adapter
->hw
,
2560 IXGBE_RXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
2565 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
2566 DPRINTK(DRV
, ERR
, "RXDCTL.ENABLE on Rx queue %d "
2567 "not set within the polling period\n", rxr
);
2569 ixgbe_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
2570 (adapter
->rx_ring
[rxr
].count
- 1));
2573 static int ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
2575 struct net_device
*netdev
= adapter
->netdev
;
2576 struct ixgbe_hw
*hw
= &adapter
->hw
;
2578 int num_rx_rings
= adapter
->num_rx_queues
;
2580 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2581 u32 txdctl
, rxdctl
, mhadd
;
2585 ixgbe_get_hw_control(adapter
);
2587 if ((adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) ||
2588 (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)) {
2589 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2590 gpie
= (IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_EIAME
|
2591 IXGBE_GPIE_PBA_SUPPORT
| IXGBE_GPIE_OCD
);
2596 /* XXX: to interrupt immediately for EICS writes, enable this */
2597 /* gpie |= IXGBE_GPIE_EIMEN; */
2598 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2601 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
2602 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2603 * specifically only auto mask tx and rx interrupts */
2604 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
2607 /* Enable fan failure interrupt if media type is copper */
2608 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
2609 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2610 gpie
|= IXGBE_SDP1_GPIEN
;
2611 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2614 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2615 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2616 gpie
|= IXGBE_SDP1_GPIEN
;
2617 gpie
|= IXGBE_SDP2_GPIEN
;
2618 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2622 /* adjust max frame to be able to do baby jumbo for FCoE */
2623 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
2624 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
2625 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2627 #endif /* IXGBE_FCOE */
2628 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
2629 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
2630 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
2631 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
2633 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
2636 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2637 j
= adapter
->tx_ring
[i
].reg_idx
;
2638 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2639 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2640 txdctl
|= (8 << 16);
2641 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2644 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2645 /* DMATXCTL.EN must be set after all Tx queue config is done */
2646 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
2647 dmatxctl
|= IXGBE_DMATXCTL_TE
;
2648 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
2650 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2651 j
= adapter
->tx_ring
[i
].reg_idx
;
2652 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2653 txdctl
|= IXGBE_TXDCTL_ENABLE
;
2654 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2657 for (i
= 0; i
< num_rx_rings
; i
++) {
2658 j
= adapter
->rx_ring
[i
].reg_idx
;
2659 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2660 /* enable PTHRESH=32 descriptors (half the internal cache)
2661 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2662 * this also removes a pesky rx_no_buffer_count increment */
2664 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
2665 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), rxdctl
);
2666 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2667 ixgbe_rx_desc_queue_enable(adapter
, i
);
2669 /* enable all receives */
2670 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2671 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2672 rxdctl
|= (IXGBE_RXCTRL_DMBYPS
| IXGBE_RXCTRL_RXEN
);
2674 rxdctl
|= IXGBE_RXCTRL_RXEN
;
2675 hw
->mac
.ops
.enable_rx_dma(hw
, rxdctl
);
2677 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
2678 ixgbe_configure_msix(adapter
);
2680 ixgbe_configure_msi_and_legacy(adapter
);
2682 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
2683 ixgbe_napi_enable_all(adapter
);
2685 /* clear any pending interrupts, may auto mask */
2686 IXGBE_READ_REG(hw
, IXGBE_EICR
);
2688 ixgbe_irq_enable(adapter
);
2691 * If this adapter has a fan, check to see if we had a failure
2692 * before we enabled the interrupt.
2694 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
2695 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2696 if (esdp
& IXGBE_ESDP_SDP1
)
2698 "Fan has stopped, replace the adapter\n");
2702 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2703 * arrived before interrupts were enabled but after probe. Such
2704 * devices wouldn't have their type identified yet. We need to
2705 * kick off the SFP+ module setup first, then try to bring up link.
2706 * If we're not hot-pluggable SFP+, we just need to configure link
2709 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
2710 err
= hw
->phy
.ops
.identify(hw
);
2711 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
2713 * Take the device down and schedule the sfp tasklet
2714 * which will unregister_netdev and log it.
2716 ixgbe_down(adapter
);
2717 schedule_work(&adapter
->sfp_config_module_task
);
2722 if (ixgbe_is_sfp(hw
)) {
2723 ixgbe_sfp_link_config(adapter
);
2725 err
= ixgbe_non_sfp_link_config(hw
);
2727 DPRINTK(PROBE
, ERR
, "link_config FAILED %d\n", err
);
2730 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2731 set_bit(__IXGBE_FDIR_INIT_DONE
,
2732 &(adapter
->tx_ring
[i
].reinit_state
));
2734 /* enable transmits */
2735 netif_tx_start_all_queues(netdev
);
2737 /* bring the link up in the watchdog, this could race with our first
2738 * link up interrupt but shouldn't be a problem */
2739 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
2740 adapter
->link_check_timeout
= jiffies
;
2741 mod_timer(&adapter
->watchdog_timer
, jiffies
);
2745 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
2747 WARN_ON(in_interrupt());
2748 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
2750 ixgbe_down(adapter
);
2752 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
2755 int ixgbe_up(struct ixgbe_adapter
*adapter
)
2757 /* hardware has been reset, we need to reload some things */
2758 ixgbe_configure(adapter
);
2760 return ixgbe_up_complete(adapter
);
2763 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
2765 struct ixgbe_hw
*hw
= &adapter
->hw
;
2768 err
= hw
->mac
.ops
.init_hw(hw
);
2771 case IXGBE_ERR_SFP_NOT_PRESENT
:
2773 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
2774 dev_err(&adapter
->pdev
->dev
, "master disable timed out\n");
2776 case IXGBE_ERR_EEPROM_VERSION
:
2777 /* We are running on a pre-production device, log a warning */
2778 dev_warn(&adapter
->pdev
->dev
, "This device is a pre-production "
2779 "adapter/LOM. Please be aware there may be issues "
2780 "associated with your hardware. If you are "
2781 "experiencing problems please contact your Intel or "
2782 "hardware representative who provided you with this "
2786 dev_err(&adapter
->pdev
->dev
, "Hardware Error: %d\n", err
);
2789 /* reprogram the RAR[0] in case user changed it. */
2790 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0, IXGBE_RAH_AV
);
2794 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2795 * @adapter: board private structure
2796 * @rx_ring: ring to free buffers from
2798 static void ixgbe_clean_rx_ring(struct ixgbe_adapter
*adapter
,
2799 struct ixgbe_ring
*rx_ring
)
2801 struct pci_dev
*pdev
= adapter
->pdev
;
2805 /* Free all the Rx ring sk_buffs */
2807 for (i
= 0; i
< rx_ring
->count
; i
++) {
2808 struct ixgbe_rx_buffer
*rx_buffer_info
;
2810 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
2811 if (rx_buffer_info
->dma
) {
2812 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
2813 rx_ring
->rx_buf_len
,
2814 PCI_DMA_FROMDEVICE
);
2815 rx_buffer_info
->dma
= 0;
2817 if (rx_buffer_info
->skb
) {
2818 struct sk_buff
*skb
= rx_buffer_info
->skb
;
2819 rx_buffer_info
->skb
= NULL
;
2821 struct sk_buff
*this = skb
;
2823 dev_kfree_skb(this);
2826 if (!rx_buffer_info
->page
)
2828 if (rx_buffer_info
->page_dma
) {
2829 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
2830 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
2831 rx_buffer_info
->page_dma
= 0;
2833 put_page(rx_buffer_info
->page
);
2834 rx_buffer_info
->page
= NULL
;
2835 rx_buffer_info
->page_offset
= 0;
2838 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
2839 memset(rx_ring
->rx_buffer_info
, 0, size
);
2841 /* Zero out the descriptor ring */
2842 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2844 rx_ring
->next_to_clean
= 0;
2845 rx_ring
->next_to_use
= 0;
2848 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
2850 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
2854 * ixgbe_clean_tx_ring - Free Tx Buffers
2855 * @adapter: board private structure
2856 * @tx_ring: ring to be cleaned
2858 static void ixgbe_clean_tx_ring(struct ixgbe_adapter
*adapter
,
2859 struct ixgbe_ring
*tx_ring
)
2861 struct ixgbe_tx_buffer
*tx_buffer_info
;
2865 /* Free all the Tx ring sk_buffs */
2867 for (i
= 0; i
< tx_ring
->count
; i
++) {
2868 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2869 ixgbe_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
2872 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
2873 memset(tx_ring
->tx_buffer_info
, 0, size
);
2875 /* Zero out the descriptor ring */
2876 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2878 tx_ring
->next_to_use
= 0;
2879 tx_ring
->next_to_clean
= 0;
2882 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2884 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2888 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2889 * @adapter: board private structure
2891 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
2895 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2896 ixgbe_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2900 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2901 * @adapter: board private structure
2903 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
2907 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2908 ixgbe_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2911 void ixgbe_down(struct ixgbe_adapter
*adapter
)
2913 struct net_device
*netdev
= adapter
->netdev
;
2914 struct ixgbe_hw
*hw
= &adapter
->hw
;
2919 /* signal that we are down to the interrupt handler */
2920 set_bit(__IXGBE_DOWN
, &adapter
->state
);
2922 /* disable receives */
2923 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2924 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
2926 netif_tx_disable(netdev
);
2928 IXGBE_WRITE_FLUSH(hw
);
2931 netif_tx_stop_all_queues(netdev
);
2933 ixgbe_irq_disable(adapter
);
2935 ixgbe_napi_disable_all(adapter
);
2937 del_timer_sync(&adapter
->watchdog_timer
);
2938 cancel_work_sync(&adapter
->watchdog_task
);
2940 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
2941 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
2942 cancel_work_sync(&adapter
->fdir_reinit_task
);
2944 /* disable transmits in the hardware now that interrupts are off */
2945 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2946 j
= adapter
->tx_ring
[i
].reg_idx
;
2947 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2948 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
),
2949 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
2951 /* Disable the Tx DMA engine on 82599 */
2952 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2953 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
2954 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
2955 ~IXGBE_DMATXCTL_TE
));
2957 netif_carrier_off(netdev
);
2959 if (!pci_channel_offline(adapter
->pdev
))
2960 ixgbe_reset(adapter
);
2961 ixgbe_clean_all_tx_rings(adapter
);
2962 ixgbe_clean_all_rx_rings(adapter
);
2964 #ifdef CONFIG_IXGBE_DCA
2965 /* since we reset the hardware DCA settings were cleared */
2966 ixgbe_setup_dca(adapter
);
2971 * ixgbe_poll - NAPI Rx polling callback
2972 * @napi: structure for representing this polling device
2973 * @budget: how many packets driver is allowed to clean
2975 * This function is used for legacy and MSI, NAPI mode
2977 static int ixgbe_poll(struct napi_struct
*napi
, int budget
)
2979 struct ixgbe_q_vector
*q_vector
=
2980 container_of(napi
, struct ixgbe_q_vector
, napi
);
2981 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2982 int tx_clean_complete
, work_done
= 0;
2984 #ifdef CONFIG_IXGBE_DCA
2985 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
2986 ixgbe_update_tx_dca(adapter
, adapter
->tx_ring
);
2987 ixgbe_update_rx_dca(adapter
, adapter
->rx_ring
);
2991 tx_clean_complete
= ixgbe_clean_tx_irq(q_vector
, adapter
->tx_ring
);
2992 ixgbe_clean_rx_irq(q_vector
, adapter
->rx_ring
, &work_done
, budget
);
2994 if (!tx_clean_complete
)
2997 /* If budget not fully consumed, exit the polling mode */
2998 if (work_done
< budget
) {
2999 napi_complete(napi
);
3000 if (adapter
->itr_setting
& 1)
3001 ixgbe_set_itr(adapter
);
3002 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3003 ixgbe_irq_enable_queues(adapter
, IXGBE_EIMS_RTX_QUEUE
);
3009 * ixgbe_tx_timeout - Respond to a Tx Hang
3010 * @netdev: network interface device structure
3012 static void ixgbe_tx_timeout(struct net_device
*netdev
)
3014 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3016 /* Do the reset outside of interrupt context */
3017 schedule_work(&adapter
->reset_task
);
3020 static void ixgbe_reset_task(struct work_struct
*work
)
3022 struct ixgbe_adapter
*adapter
;
3023 adapter
= container_of(work
, struct ixgbe_adapter
, reset_task
);
3025 /* If we're already down or resetting, just bail */
3026 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
3027 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
3030 adapter
->tx_timeout_count
++;
3032 ixgbe_reinit_locked(adapter
);
3035 #ifdef CONFIG_IXGBE_DCB
3036 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter
*adapter
)
3039 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_DCB
];
3041 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
3045 adapter
->num_rx_queues
= f
->indices
;
3046 adapter
->num_tx_queues
= f
->indices
;
3054 * ixgbe_set_rss_queues: Allocate queues for RSS
3055 * @adapter: board private structure to initialize
3057 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3058 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3061 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter
*adapter
)
3064 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_RSS
];
3066 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3068 adapter
->num_rx_queues
= f
->indices
;
3069 adapter
->num_tx_queues
= f
->indices
;
3079 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3080 * @adapter: board private structure to initialize
3082 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3083 * to the original CPU that initiated the Tx session. This runs in addition
3084 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3085 * Rx load across CPUs using RSS.
3088 static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter
*adapter
)
3091 struct ixgbe_ring_feature
*f_fdir
= &adapter
->ring_feature
[RING_F_FDIR
];
3093 f_fdir
->indices
= min((int)num_online_cpus(), f_fdir
->indices
);
3096 /* Flow Director must have RSS enabled */
3097 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3098 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3099 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)))) {
3100 adapter
->num_tx_queues
= f_fdir
->indices
;
3101 adapter
->num_rx_queues
= f_fdir
->indices
;
3104 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3105 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3112 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3113 * @adapter: board private structure to initialize
3115 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3116 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3117 * rx queues out of the max number of rx queues, instead, it is used as the
3118 * index of the first rx queue used by FCoE.
3121 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter
*adapter
)
3124 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3126 f
->indices
= min((int)num_online_cpus(), f
->indices
);
3127 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3128 #ifdef CONFIG_IXGBE_DCB
3129 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3130 DPRINTK(PROBE
, INFO
, "FCOE enabled with DCB \n");
3131 ixgbe_set_dcb_queues(adapter
);
3134 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3135 DPRINTK(PROBE
, INFO
, "FCOE enabled with RSS \n");
3136 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3137 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3138 ixgbe_set_fdir_queues(adapter
);
3140 ixgbe_set_rss_queues(adapter
);
3142 /* adding FCoE rx rings to the end */
3143 f
->mask
= adapter
->num_rx_queues
;
3144 adapter
->num_rx_queues
+= f
->indices
;
3145 if (adapter
->num_tx_queues
== 0)
3146 adapter
->num_tx_queues
= f
->indices
;
3154 #endif /* IXGBE_FCOE */
3156 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3157 * @adapter: board private structure to initialize
3159 * This is the top level queue allocation routine. The order here is very
3160 * important, starting with the "most" number of features turned on at once,
3161 * and ending with the smallest set of features. This way large combinations
3162 * can be allocated if they're turned on, and smaller combinations are the
3163 * fallthrough conditions.
3166 static void ixgbe_set_num_queues(struct ixgbe_adapter
*adapter
)
3169 if (ixgbe_set_fcoe_queues(adapter
))
3172 #endif /* IXGBE_FCOE */
3173 #ifdef CONFIG_IXGBE_DCB
3174 if (ixgbe_set_dcb_queues(adapter
))
3178 if (ixgbe_set_fdir_queues(adapter
))
3181 if (ixgbe_set_rss_queues(adapter
))
3184 /* fallback to base case */
3185 adapter
->num_rx_queues
= 1;
3186 adapter
->num_tx_queues
= 1;
3189 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3190 adapter
->netdev
->real_num_tx_queues
= adapter
->num_tx_queues
;
3193 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter
*adapter
,
3196 int err
, vector_threshold
;
3198 /* We'll want at least 3 (vector_threshold):
3201 * 3) Other (Link Status Change, etc.)
3202 * 4) TCP Timer (optional)
3204 vector_threshold
= MIN_MSIX_COUNT
;
3206 /* The more we get, the more we will assign to Tx/Rx Cleanup
3207 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3208 * Right now, we simply care about how many we'll get; we'll
3209 * set them up later while requesting irq's.
3211 while (vectors
>= vector_threshold
) {
3212 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
3214 if (!err
) /* Success in acquiring all requested vectors. */
3217 vectors
= 0; /* Nasty failure, quit now */
3218 else /* err == number of vectors we should try again with */
3222 if (vectors
< vector_threshold
) {
3223 /* Can't allocate enough MSI-X interrupts? Oh well.
3224 * This just means we'll go with either a single MSI
3225 * vector or fall back to legacy interrupts.
3227 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI-X interrupts\n");
3228 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3229 kfree(adapter
->msix_entries
);
3230 adapter
->msix_entries
= NULL
;
3232 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
; /* Woot! */
3234 * Adjust for only the vectors we'll use, which is minimum
3235 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3236 * vectors we were allocated.
3238 adapter
->num_msix_vectors
= min(vectors
,
3239 adapter
->max_msix_q_vectors
+ NON_Q_VECTORS
);
3244 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
3245 * @adapter: board private structure to initialize
3247 * Cache the descriptor ring offsets for RSS to the assigned rings.
3250 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter
*adapter
)
3255 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3256 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3257 adapter
->rx_ring
[i
].reg_idx
= i
;
3258 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3259 adapter
->tx_ring
[i
].reg_idx
= i
;
3268 #ifdef CONFIG_IXGBE_DCB
3270 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3271 * @adapter: board private structure to initialize
3273 * Cache the descriptor ring offsets for DCB to the assigned rings.
3276 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter
*adapter
)
3280 int dcb_i
= adapter
->ring_feature
[RING_F_DCB
].indices
;
3282 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3283 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3284 /* the number of queues is assumed to be symmetric */
3285 for (i
= 0; i
< dcb_i
; i
++) {
3286 adapter
->rx_ring
[i
].reg_idx
= i
<< 3;
3287 adapter
->tx_ring
[i
].reg_idx
= i
<< 2;
3290 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
3293 * Tx TC0 starts at: descriptor queue 0
3294 * Tx TC1 starts at: descriptor queue 32
3295 * Tx TC2 starts at: descriptor queue 64
3296 * Tx TC3 starts at: descriptor queue 80
3297 * Tx TC4 starts at: descriptor queue 96
3298 * Tx TC5 starts at: descriptor queue 104
3299 * Tx TC6 starts at: descriptor queue 112
3300 * Tx TC7 starts at: descriptor queue 120
3302 * Rx TC0-TC7 are offset by 16 queues each
3304 for (i
= 0; i
< 3; i
++) {
3305 adapter
->tx_ring
[i
].reg_idx
= i
<< 5;
3306 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3308 for ( ; i
< 5; i
++) {
3309 adapter
->tx_ring
[i
].reg_idx
=
3311 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3313 for ( ; i
< dcb_i
; i
++) {
3314 adapter
->tx_ring
[i
].reg_idx
=
3316 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3320 } else if (dcb_i
== 4) {
3322 * Tx TC0 starts at: descriptor queue 0
3323 * Tx TC1 starts at: descriptor queue 64
3324 * Tx TC2 starts at: descriptor queue 96
3325 * Tx TC3 starts at: descriptor queue 112
3327 * Rx TC0-TC3 are offset by 32 queues each
3329 adapter
->tx_ring
[0].reg_idx
= 0;
3330 adapter
->tx_ring
[1].reg_idx
= 64;
3331 adapter
->tx_ring
[2].reg_idx
= 96;
3332 adapter
->tx_ring
[3].reg_idx
= 112;
3333 for (i
= 0 ; i
< dcb_i
; i
++)
3334 adapter
->rx_ring
[i
].reg_idx
= i
<< 5;
3352 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3353 * @adapter: board private structure to initialize
3355 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3358 static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter
*adapter
)
3363 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3364 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3365 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))) {
3366 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3367 adapter
->rx_ring
[i
].reg_idx
= i
;
3368 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3369 adapter
->tx_ring
[i
].reg_idx
= i
;
3378 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3379 * @adapter: board private structure to initialize
3381 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3384 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter
*adapter
)
3388 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3390 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3391 #ifdef CONFIG_IXGBE_DCB
3392 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3393 ixgbe_cache_ring_dcb(adapter
);
3394 fcoe_i
= adapter
->rx_ring
[0].reg_idx
+ 1;
3396 #endif /* CONFIG_IXGBE_DCB */
3397 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3398 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3399 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3400 ixgbe_cache_ring_fdir(adapter
);
3402 ixgbe_cache_ring_rss(adapter
);
3406 for (i
= 0; i
< f
->indices
; i
++, fcoe_i
++)
3407 adapter
->rx_ring
[f
->mask
+ i
].reg_idx
= fcoe_i
;
3413 #endif /* IXGBE_FCOE */
3415 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3416 * @adapter: board private structure to initialize
3418 * Once we know the feature-set enabled for the device, we'll cache
3419 * the register offset the descriptor ring is assigned to.
3421 * Note, the order the various feature calls is important. It must start with
3422 * the "most" features enabled at the same time, then trickle down to the
3423 * least amount of features turned on at once.
3425 static void ixgbe_cache_ring_register(struct ixgbe_adapter
*adapter
)
3427 /* start with default case */
3428 adapter
->rx_ring
[0].reg_idx
= 0;
3429 adapter
->tx_ring
[0].reg_idx
= 0;
3432 if (ixgbe_cache_ring_fcoe(adapter
))
3435 #endif /* IXGBE_FCOE */
3436 #ifdef CONFIG_IXGBE_DCB
3437 if (ixgbe_cache_ring_dcb(adapter
))
3441 if (ixgbe_cache_ring_fdir(adapter
))
3444 if (ixgbe_cache_ring_rss(adapter
))
3449 * ixgbe_alloc_queues - Allocate memory for all rings
3450 * @adapter: board private structure to initialize
3452 * We allocate one ring per queue at run-time since we don't know the
3453 * number of queues at compile-time. The polling_netdev array is
3454 * intended for Multiqueue, but should work fine with a single queue.
3456 static int ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
3460 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
3461 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3462 if (!adapter
->tx_ring
)
3463 goto err_tx_ring_allocation
;
3465 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
3466 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3467 if (!adapter
->rx_ring
)
3468 goto err_rx_ring_allocation
;
3470 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3471 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
3472 adapter
->tx_ring
[i
].queue_index
= i
;
3475 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3476 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
3477 adapter
->rx_ring
[i
].queue_index
= i
;
3480 ixgbe_cache_ring_register(adapter
);
3484 err_rx_ring_allocation
:
3485 kfree(adapter
->tx_ring
);
3486 err_tx_ring_allocation
:
3491 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3492 * @adapter: board private structure to initialize
3494 * Attempt to configure the interrupts using the best available
3495 * capabilities of the hardware and the kernel.
3497 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter
*adapter
)
3499 struct ixgbe_hw
*hw
= &adapter
->hw
;
3501 int vector
, v_budget
;
3504 * It's easy to be greedy for MSI-X vectors, but it really
3505 * doesn't do us much good if we have a lot more vectors
3506 * than CPU's. So let's be conservative and only ask for
3507 * (roughly) twice the number of vectors as there are CPU's.
3509 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
3510 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
3513 * At the same time, hardware can only support a maximum of
3514 * hw.mac->max_msix_vectors vectors. With features
3515 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3516 * descriptor queues supported by our device. Thus, we cap it off in
3517 * those rare cases where the cpu count also exceeds our vector limit.
3519 v_budget
= min(v_budget
, (int)hw
->mac
.max_msix_vectors
);
3521 /* A failure in MSI-X entry allocation isn't fatal, but it does
3522 * mean we disable MSI-X capabilities of the adapter. */
3523 adapter
->msix_entries
= kcalloc(v_budget
,
3524 sizeof(struct msix_entry
), GFP_KERNEL
);
3525 if (adapter
->msix_entries
) {
3526 for (vector
= 0; vector
< v_budget
; vector
++)
3527 adapter
->msix_entries
[vector
].entry
= vector
;
3529 ixgbe_acquire_msix_vectors(adapter
, v_budget
);
3531 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3535 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
3536 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
3537 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3538 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3539 adapter
->atr_sample_rate
= 0;
3540 ixgbe_set_num_queues(adapter
);
3542 err
= pci_enable_msi(adapter
->pdev
);
3544 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
3546 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI interrupt, "
3547 "falling back to legacy. Error: %d\n", err
);
3557 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3558 * @adapter: board private structure to initialize
3560 * We allocate one q_vector per queue interrupt. If allocation fails we
3563 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter
*adapter
)
3565 int q_idx
, num_q_vectors
;
3566 struct ixgbe_q_vector
*q_vector
;
3568 int (*poll
)(struct napi_struct
*, int);
3570 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3571 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3572 napi_vectors
= adapter
->num_rx_queues
;
3573 poll
= &ixgbe_clean_rxtx_many
;
3580 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
3581 q_vector
= kzalloc(sizeof(struct ixgbe_q_vector
), GFP_KERNEL
);
3584 q_vector
->adapter
= adapter
;
3585 q_vector
->eitr
= adapter
->eitr_param
;
3586 q_vector
->v_idx
= q_idx
;
3587 netif_napi_add(adapter
->netdev
, &q_vector
->napi
, (*poll
), 64);
3588 adapter
->q_vector
[q_idx
] = q_vector
;
3596 q_vector
= adapter
->q_vector
[q_idx
];
3597 netif_napi_del(&q_vector
->napi
);
3599 adapter
->q_vector
[q_idx
] = NULL
;
3605 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3606 * @adapter: board private structure to initialize
3608 * This function frees the memory allocated to the q_vectors. In addition if
3609 * NAPI is enabled it will delete any references to the NAPI struct prior
3610 * to freeing the q_vector.
3612 static void ixgbe_free_q_vectors(struct ixgbe_adapter
*adapter
)
3614 int q_idx
, num_q_vectors
;
3616 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3617 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3621 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
3622 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
3623 adapter
->q_vector
[q_idx
] = NULL
;
3624 netif_napi_del(&q_vector
->napi
);
3629 void ixgbe_reset_interrupt_capability(struct ixgbe_adapter
*adapter
)
3631 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3632 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3633 pci_disable_msix(adapter
->pdev
);
3634 kfree(adapter
->msix_entries
);
3635 adapter
->msix_entries
= NULL
;
3636 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
3637 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
3638 pci_disable_msi(adapter
->pdev
);
3644 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3645 * @adapter: board private structure to initialize
3647 * We determine which interrupt scheme to use based on...
3648 * - Kernel support (MSI, MSI-X)
3649 * - which can be user-defined (via MODULE_PARAM)
3650 * - Hardware queue count (num_*_queues)
3651 * - defined by miscellaneous hardware support/features (RSS, etc.)
3653 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter
*adapter
)
3657 /* Number of supported queues */
3658 ixgbe_set_num_queues(adapter
);
3660 err
= ixgbe_set_interrupt_capability(adapter
);
3662 DPRINTK(PROBE
, ERR
, "Unable to setup interrupt capabilities\n");
3663 goto err_set_interrupt
;
3666 err
= ixgbe_alloc_q_vectors(adapter
);
3668 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queue "
3670 goto err_alloc_q_vectors
;
3673 err
= ixgbe_alloc_queues(adapter
);
3675 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
3676 goto err_alloc_queues
;
3679 DPRINTK(DRV
, INFO
, "Multiqueue %s: Rx Queue count = %u, "
3680 "Tx Queue count = %u\n",
3681 (adapter
->num_rx_queues
> 1) ? "Enabled" :
3682 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
3684 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3689 ixgbe_free_q_vectors(adapter
);
3690 err_alloc_q_vectors
:
3691 ixgbe_reset_interrupt_capability(adapter
);
3697 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3698 * @adapter: board private structure to clear interrupt scheme on
3700 * We go through and clear interrupt specific resources and reset the structure
3701 * to pre-load conditions
3703 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter
*adapter
)
3705 kfree(adapter
->tx_ring
);
3706 kfree(adapter
->rx_ring
);
3707 adapter
->tx_ring
= NULL
;
3708 adapter
->rx_ring
= NULL
;
3710 ixgbe_free_q_vectors(adapter
);
3711 ixgbe_reset_interrupt_capability(adapter
);
3715 * ixgbe_sfp_timer - worker thread to find a missing module
3716 * @data: pointer to our adapter struct
3718 static void ixgbe_sfp_timer(unsigned long data
)
3720 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
3723 * Do the sfp_timer outside of interrupt context due to the
3724 * delays that sfp+ detection requires
3726 schedule_work(&adapter
->sfp_task
);
3730 * ixgbe_sfp_task - worker thread to find a missing module
3731 * @work: pointer to work_struct containing our data
3733 static void ixgbe_sfp_task(struct work_struct
*work
)
3735 struct ixgbe_adapter
*adapter
= container_of(work
,
3736 struct ixgbe_adapter
,
3738 struct ixgbe_hw
*hw
= &adapter
->hw
;
3740 if ((hw
->phy
.type
== ixgbe_phy_nl
) &&
3741 (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)) {
3742 s32 ret
= hw
->phy
.ops
.identify_sfp(hw
);
3743 if (ret
== IXGBE_ERR_SFP_NOT_PRESENT
)
3745 ret
= hw
->phy
.ops
.reset(hw
);
3746 if (ret
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
3747 dev_err(&adapter
->pdev
->dev
, "failed to initialize "
3748 "because an unsupported SFP+ module type "
3750 "Reload the driver after installing a "
3751 "supported module.\n");
3752 unregister_netdev(adapter
->netdev
);
3754 DPRINTK(PROBE
, INFO
, "detected SFP+: %d\n",
3757 /* don't need this routine any more */
3758 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
3762 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
))
3763 mod_timer(&adapter
->sfp_timer
,
3764 round_jiffies(jiffies
+ (2 * HZ
)));
3768 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3769 * @adapter: board private structure to initialize
3771 * ixgbe_sw_init initializes the Adapter private data structure.
3772 * Fields are initialized based on PCI device information and
3773 * OS network device settings (MTU size).
3775 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
3777 struct ixgbe_hw
*hw
= &adapter
->hw
;
3778 struct pci_dev
*pdev
= adapter
->pdev
;
3780 #ifdef CONFIG_IXGBE_DCB
3782 struct tc_configuration
*tc
;
3785 /* PCI config space info */
3787 hw
->vendor_id
= pdev
->vendor
;
3788 hw
->device_id
= pdev
->device
;
3789 hw
->revision_id
= pdev
->revision
;
3790 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3791 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3793 /* Set capability flags */
3794 rss
= min(IXGBE_MAX_RSS_INDICES
, (int)num_online_cpus());
3795 adapter
->ring_feature
[RING_F_RSS
].indices
= rss
;
3796 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
3797 adapter
->ring_feature
[RING_F_DCB
].indices
= IXGBE_MAX_DCB_INDICES
;
3798 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3799 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
3800 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
3801 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82598
;
3802 } else if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
3803 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82599
;
3804 adapter
->flags
|= IXGBE_FLAG2_RSC_CAPABLE
;
3805 adapter
->flags
|= IXGBE_FLAG2_RSC_ENABLED
;
3806 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3807 adapter
->ring_feature
[RING_F_FDIR
].indices
=
3808 IXGBE_MAX_FDIR_INDICES
;
3809 adapter
->atr_sample_rate
= 20;
3810 adapter
->fdir_pballoc
= 0;
3812 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
3813 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
3814 adapter
->ring_feature
[RING_F_FCOE
].indices
= 0;
3815 #endif /* IXGBE_FCOE */
3818 #ifdef CONFIG_IXGBE_DCB
3819 /* Configure DCB traffic classes */
3820 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
3821 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
3822 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
3823 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
3824 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
3825 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
3826 tc
->dcb_pfc
= pfc_disabled
;
3828 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
3829 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
3830 adapter
->dcb_cfg
.rx_pba_cfg
= pba_equal
;
3831 adapter
->dcb_cfg
.pfc_mode_enable
= false;
3832 adapter
->dcb_cfg
.round_robin_enable
= false;
3833 adapter
->dcb_set_bitmap
= 0x00;
3834 ixgbe_copy_dcb_cfg(&adapter
->dcb_cfg
, &adapter
->temp_dcb_cfg
,
3835 adapter
->ring_feature
[RING_F_DCB
].indices
);
3839 /* default flow control settings */
3840 hw
->fc
.requested_mode
= ixgbe_fc_full
;
3841 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
3843 adapter
->last_lfc_mode
= hw
->fc
.current_mode
;
3845 hw
->fc
.high_water
= IXGBE_DEFAULT_FCRTH
;
3846 hw
->fc
.low_water
= IXGBE_DEFAULT_FCRTL
;
3847 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
3848 hw
->fc
.send_xon
= true;
3849 hw
->fc
.disable_fc_autoneg
= false;
3851 /* enable itr by default in dynamic mode */
3852 adapter
->itr_setting
= 1;
3853 adapter
->eitr_param
= 20000;
3855 /* set defaults for eitr in MegaBytes */
3856 adapter
->eitr_low
= 10;
3857 adapter
->eitr_high
= 20;
3859 /* set default ring sizes */
3860 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
3861 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
3863 /* initialize eeprom parameters */
3864 if (ixgbe_init_eeprom_params_generic(hw
)) {
3865 dev_err(&pdev
->dev
, "EEPROM initialization failed\n");
3869 /* enable rx csum by default */
3870 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
3872 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3878 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3879 * @adapter: board private structure
3880 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3882 * Return 0 on success, negative on failure
3884 int ixgbe_setup_tx_resources(struct ixgbe_adapter
*adapter
,
3885 struct ixgbe_ring
*tx_ring
)
3887 struct pci_dev
*pdev
= adapter
->pdev
;
3890 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
3891 tx_ring
->tx_buffer_info
= vmalloc(size
);
3892 if (!tx_ring
->tx_buffer_info
)
3894 memset(tx_ring
->tx_buffer_info
, 0, size
);
3896 /* round up to nearest 4K */
3897 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
3898 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
3900 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
3905 tx_ring
->next_to_use
= 0;
3906 tx_ring
->next_to_clean
= 0;
3907 tx_ring
->work_limit
= tx_ring
->count
;
3911 vfree(tx_ring
->tx_buffer_info
);
3912 tx_ring
->tx_buffer_info
= NULL
;
3913 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for the transmit "
3914 "descriptor ring\n");
3919 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3920 * @adapter: board private structure
3922 * If this function returns with an error, then it's possible one or
3923 * more of the rings is populated (while the rest are not). It is the
3924 * callers duty to clean those orphaned rings.
3926 * Return 0 on success, negative on failure
3928 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
3932 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3933 err
= ixgbe_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
3936 DPRINTK(PROBE
, ERR
, "Allocation for Tx Queue %u failed\n", i
);
3944 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3945 * @adapter: board private structure
3946 * @rx_ring: rx descriptor ring (for a specific queue) to setup
3948 * Returns 0 on success, negative on failure
3950 int ixgbe_setup_rx_resources(struct ixgbe_adapter
*adapter
,
3951 struct ixgbe_ring
*rx_ring
)
3953 struct pci_dev
*pdev
= adapter
->pdev
;
3956 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
3957 rx_ring
->rx_buffer_info
= vmalloc(size
);
3958 if (!rx_ring
->rx_buffer_info
) {
3960 "vmalloc allocation failed for the rx desc ring\n");
3963 memset(rx_ring
->rx_buffer_info
, 0, size
);
3965 /* Round up to nearest 4K */
3966 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
3967 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
3969 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
, &rx_ring
->dma
);
3971 if (!rx_ring
->desc
) {
3973 "Memory allocation failed for the rx desc ring\n");
3974 vfree(rx_ring
->rx_buffer_info
);
3978 rx_ring
->next_to_clean
= 0;
3979 rx_ring
->next_to_use
= 0;
3988 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3989 * @adapter: board private structure
3991 * If this function returns with an error, then it's possible one or
3992 * more of the rings is populated (while the rest are not). It is the
3993 * callers duty to clean those orphaned rings.
3995 * Return 0 on success, negative on failure
3998 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
4002 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4003 err
= ixgbe_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
4006 DPRINTK(PROBE
, ERR
, "Allocation for Rx Queue %u failed\n", i
);
4014 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4015 * @adapter: board private structure
4016 * @tx_ring: Tx descriptor ring for a specific queue
4018 * Free all transmit software resources
4020 void ixgbe_free_tx_resources(struct ixgbe_adapter
*adapter
,
4021 struct ixgbe_ring
*tx_ring
)
4023 struct pci_dev
*pdev
= adapter
->pdev
;
4025 ixgbe_clean_tx_ring(adapter
, tx_ring
);
4027 vfree(tx_ring
->tx_buffer_info
);
4028 tx_ring
->tx_buffer_info
= NULL
;
4030 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
4032 tx_ring
->desc
= NULL
;
4036 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4037 * @adapter: board private structure
4039 * Free all transmit software resources
4041 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
4045 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4046 if (adapter
->tx_ring
[i
].desc
)
4047 ixgbe_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
4051 * ixgbe_free_rx_resources - Free Rx Resources
4052 * @adapter: board private structure
4053 * @rx_ring: ring to clean the resources from
4055 * Free all receive software resources
4057 void ixgbe_free_rx_resources(struct ixgbe_adapter
*adapter
,
4058 struct ixgbe_ring
*rx_ring
)
4060 struct pci_dev
*pdev
= adapter
->pdev
;
4062 ixgbe_clean_rx_ring(adapter
, rx_ring
);
4064 vfree(rx_ring
->rx_buffer_info
);
4065 rx_ring
->rx_buffer_info
= NULL
;
4067 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
4069 rx_ring
->desc
= NULL
;
4073 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4074 * @adapter: board private structure
4076 * Free all receive software resources
4078 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
4082 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4083 if (adapter
->rx_ring
[i
].desc
)
4084 ixgbe_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
4088 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4089 * @netdev: network interface device structure
4090 * @new_mtu: new value for maximum frame size
4092 * Returns 0 on success, negative on failure
4094 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
4096 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4097 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4099 /* MTU < 68 is an error and causes problems on some kernels */
4100 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
4103 DPRINTK(PROBE
, INFO
, "changing MTU from %d to %d\n",
4104 netdev
->mtu
, new_mtu
);
4105 /* must set new MTU before calling down or up */
4106 netdev
->mtu
= new_mtu
;
4108 if (netif_running(netdev
))
4109 ixgbe_reinit_locked(adapter
);
4115 * ixgbe_open - Called when a network interface is made active
4116 * @netdev: network interface device structure
4118 * Returns 0 on success, negative value on failure
4120 * The open entry point is called when a network interface is made
4121 * active by the system (IFF_UP). At this point all resources needed
4122 * for transmit and receive operations are allocated, the interrupt
4123 * handler is registered with the OS, the watchdog timer is started,
4124 * and the stack is notified that the interface is ready.
4126 static int ixgbe_open(struct net_device
*netdev
)
4128 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4131 /* disallow open during test */
4132 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
4135 netif_carrier_off(netdev
);
4137 /* allocate transmit descriptors */
4138 err
= ixgbe_setup_all_tx_resources(adapter
);
4142 /* allocate receive descriptors */
4143 err
= ixgbe_setup_all_rx_resources(adapter
);
4147 ixgbe_configure(adapter
);
4149 err
= ixgbe_request_irq(adapter
);
4153 err
= ixgbe_up_complete(adapter
);
4157 netif_tx_start_all_queues(netdev
);
4162 ixgbe_release_hw_control(adapter
);
4163 ixgbe_free_irq(adapter
);
4166 ixgbe_free_all_rx_resources(adapter
);
4168 ixgbe_free_all_tx_resources(adapter
);
4169 ixgbe_reset(adapter
);
4175 * ixgbe_close - Disables a network interface
4176 * @netdev: network interface device structure
4178 * Returns 0, this is not allowed to fail
4180 * The close entry point is called when an interface is de-activated
4181 * by the OS. The hardware is still under the drivers control, but
4182 * needs to be disabled. A global MAC reset is issued to stop the
4183 * hardware, and all transmit and receive resources are freed.
4185 static int ixgbe_close(struct net_device
*netdev
)
4187 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4189 ixgbe_down(adapter
);
4190 ixgbe_free_irq(adapter
);
4192 ixgbe_free_all_tx_resources(adapter
);
4193 ixgbe_free_all_rx_resources(adapter
);
4195 ixgbe_release_hw_control(adapter
);
4201 static int ixgbe_resume(struct pci_dev
*pdev
)
4203 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4204 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4207 pci_set_power_state(pdev
, PCI_D0
);
4208 pci_restore_state(pdev
);
4210 err
= pci_enable_device_mem(pdev
);
4212 printk(KERN_ERR
"ixgbe: Cannot enable PCI device from "
4216 pci_set_master(pdev
);
4218 pci_wake_from_d3(pdev
, false);
4220 err
= ixgbe_init_interrupt_scheme(adapter
);
4222 printk(KERN_ERR
"ixgbe: Cannot initialize interrupts for "
4227 ixgbe_reset(adapter
);
4229 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
4231 if (netif_running(netdev
)) {
4232 err
= ixgbe_open(adapter
->netdev
);
4237 netif_device_attach(netdev
);
4241 #endif /* CONFIG_PM */
4243 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4245 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4246 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4247 struct ixgbe_hw
*hw
= &adapter
->hw
;
4249 u32 wufc
= adapter
->wol
;
4254 netif_device_detach(netdev
);
4256 if (netif_running(netdev
)) {
4257 ixgbe_down(adapter
);
4258 ixgbe_free_irq(adapter
);
4259 ixgbe_free_all_tx_resources(adapter
);
4260 ixgbe_free_all_rx_resources(adapter
);
4262 ixgbe_clear_interrupt_scheme(adapter
);
4265 retval
= pci_save_state(pdev
);
4271 ixgbe_set_rx_mode(netdev
);
4273 /* turn on all-multi mode if wake on multicast is enabled */
4274 if (wufc
& IXGBE_WUFC_MC
) {
4275 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4276 fctrl
|= IXGBE_FCTRL_MPE
;
4277 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4280 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
4281 ctrl
|= IXGBE_CTRL_GIO_DIS
;
4282 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
4284 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
4286 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
4287 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
4290 if (wufc
&& hw
->mac
.type
== ixgbe_mac_82599EB
)
4291 pci_wake_from_d3(pdev
, true);
4293 pci_wake_from_d3(pdev
, false);
4295 *enable_wake
= !!wufc
;
4297 ixgbe_release_hw_control(adapter
);
4299 pci_disable_device(pdev
);
4305 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4310 retval
= __ixgbe_shutdown(pdev
, &wake
);
4315 pci_prepare_to_sleep(pdev
);
4317 pci_wake_from_d3(pdev
, false);
4318 pci_set_power_state(pdev
, PCI_D3hot
);
4323 #endif /* CONFIG_PM */
4325 static void ixgbe_shutdown(struct pci_dev
*pdev
)
4329 __ixgbe_shutdown(pdev
, &wake
);
4331 if (system_state
== SYSTEM_POWER_OFF
) {
4332 pci_wake_from_d3(pdev
, wake
);
4333 pci_set_power_state(pdev
, PCI_D3hot
);
4338 * ixgbe_update_stats - Update the board statistics counters.
4339 * @adapter: board private structure
4341 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
4343 struct ixgbe_hw
*hw
= &adapter
->hw
;
4345 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
4347 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4349 for (i
= 0; i
< 16; i
++)
4350 adapter
->hw_rx_no_dma_resources
+=
4351 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4352 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4353 rsc_count
+= adapter
->rx_ring
[i
].rsc_count
;
4354 adapter
->rsc_count
= rsc_count
;
4357 adapter
->stats
.crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
4358 for (i
= 0; i
< 8; i
++) {
4359 /* for packet buffers not used, the register should read 0 */
4360 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
4362 adapter
->stats
.mpc
[i
] += mpc
;
4363 total_mpc
+= adapter
->stats
.mpc
[i
];
4364 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4365 adapter
->stats
.rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
4366 adapter
->stats
.qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
4367 adapter
->stats
.qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
4368 adapter
->stats
.qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
4369 adapter
->stats
.qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
4370 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4371 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4372 IXGBE_PXONRXCNT(i
));
4373 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4374 IXGBE_PXOFFRXCNT(i
));
4375 adapter
->stats
.qprdc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4377 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4379 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4382 adapter
->stats
.pxontxc
[i
] += IXGBE_READ_REG(hw
,
4384 adapter
->stats
.pxofftxc
[i
] += IXGBE_READ_REG(hw
,
4387 adapter
->stats
.gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
4388 /* work around hardware counting issue */
4389 adapter
->stats
.gprc
-= missed_rx
;
4391 /* 82598 hardware only has a 32 bit counter in the high register */
4392 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4393 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
4394 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
4395 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
4396 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
4397 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
4398 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
4399 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
4400 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
4401 adapter
->stats
.fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
4402 adapter
->stats
.fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
4404 adapter
->stats
.fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
4405 adapter
->stats
.fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
4406 adapter
->stats
.fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
4407 adapter
->stats
.fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
4408 adapter
->stats
.fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
4409 adapter
->stats
.fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
4410 #endif /* IXGBE_FCOE */
4412 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
4413 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
4414 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
4415 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
4416 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
4418 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
4419 adapter
->stats
.bprc
+= bprc
;
4420 adapter
->stats
.mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
4421 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4422 adapter
->stats
.mprc
-= bprc
;
4423 adapter
->stats
.roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
4424 adapter
->stats
.prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
4425 adapter
->stats
.prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
4426 adapter
->stats
.prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
4427 adapter
->stats
.prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
4428 adapter
->stats
.prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
4429 adapter
->stats
.prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
4430 adapter
->stats
.rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
4431 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
4432 adapter
->stats
.lxontxc
+= lxon
;
4433 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
4434 adapter
->stats
.lxofftxc
+= lxoff
;
4435 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4436 adapter
->stats
.gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
4437 adapter
->stats
.mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
4439 * 82598 errata - tx of flow control packets is included in tx counters
4441 xon_off_tot
= lxon
+ lxoff
;
4442 adapter
->stats
.gptc
-= xon_off_tot
;
4443 adapter
->stats
.mptc
-= xon_off_tot
;
4444 adapter
->stats
.gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
4445 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4446 adapter
->stats
.rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
4447 adapter
->stats
.rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
4448 adapter
->stats
.tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
4449 adapter
->stats
.ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
4450 adapter
->stats
.ptc64
-= xon_off_tot
;
4451 adapter
->stats
.ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
4452 adapter
->stats
.ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
4453 adapter
->stats
.ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
4454 adapter
->stats
.ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
4455 adapter
->stats
.ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
4456 adapter
->stats
.bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
4458 /* Fill out the OS statistics structure */
4459 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
4462 adapter
->net_stats
.rx_errors
= adapter
->stats
.crcerrs
+
4463 adapter
->stats
.rlec
;
4464 adapter
->net_stats
.rx_dropped
= 0;
4465 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
4466 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
4467 adapter
->net_stats
.rx_missed_errors
= total_mpc
;
4471 * ixgbe_watchdog - Timer Call-back
4472 * @data: pointer to adapter cast into an unsigned long
4474 static void ixgbe_watchdog(unsigned long data
)
4476 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
4477 struct ixgbe_hw
*hw
= &adapter
->hw
;
4482 * Do the watchdog outside of interrupt context due to the lovely
4483 * delays that some of the newer hardware requires
4486 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
4487 goto watchdog_short_circuit
;
4489 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
4491 * for legacy and MSI interrupts don't set any bits
4492 * that are enabled for EIAM, because this operation
4493 * would set *both* EIMS and EICS for any bit in EIAM
4495 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
4496 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
4497 goto watchdog_reschedule
;
4500 /* get one bit for every active tx/rx interrupt vector */
4501 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
4502 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
4503 if (qv
->rxr_count
|| qv
->txr_count
)
4504 eics
|= ((u64
)1 << i
);
4507 /* Cause software interrupt to ensure rx rings are cleaned */
4508 ixgbe_irq_rearm_queues(adapter
, eics
);
4510 watchdog_reschedule
:
4511 /* Reset the timer */
4512 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
4514 watchdog_short_circuit
:
4515 schedule_work(&adapter
->watchdog_task
);
4519 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4520 * @work: pointer to work_struct containing our data
4522 static void ixgbe_multispeed_fiber_task(struct work_struct
*work
)
4524 struct ixgbe_adapter
*adapter
= container_of(work
,
4525 struct ixgbe_adapter
,
4526 multispeed_fiber_task
);
4527 struct ixgbe_hw
*hw
= &adapter
->hw
;
4530 adapter
->flags
|= IXGBE_FLAG_IN_SFP_LINK_TASK
;
4531 autoneg
= hw
->phy
.autoneg_advertised
;
4532 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
4533 hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
,
4535 if (hw
->mac
.ops
.setup_link_speed
)
4536 hw
->mac
.ops
.setup_link_speed(hw
, autoneg
, true, true);
4537 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
4538 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_LINK_TASK
;
4542 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4543 * @work: pointer to work_struct containing our data
4545 static void ixgbe_sfp_config_module_task(struct work_struct
*work
)
4547 struct ixgbe_adapter
*adapter
= container_of(work
,
4548 struct ixgbe_adapter
,
4549 sfp_config_module_task
);
4550 struct ixgbe_hw
*hw
= &adapter
->hw
;
4553 adapter
->flags
|= IXGBE_FLAG_IN_SFP_MOD_TASK
;
4555 /* Time for electrical oscillations to settle down */
4557 err
= hw
->phy
.ops
.identify_sfp(hw
);
4559 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
4560 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
4561 "an unsupported SFP+ module type was detected.\n"
4562 "Reload the driver after installing a supported "
4564 unregister_netdev(adapter
->netdev
);
4567 hw
->mac
.ops
.setup_sfp(hw
);
4569 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
4570 /* This will also work for DA Twinax connections */
4571 schedule_work(&adapter
->multispeed_fiber_task
);
4572 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_MOD_TASK
;
4576 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4577 * @work: pointer to work_struct containing our data
4579 static void ixgbe_fdir_reinit_task(struct work_struct
*work
)
4581 struct ixgbe_adapter
*adapter
= container_of(work
,
4582 struct ixgbe_adapter
,
4584 struct ixgbe_hw
*hw
= &adapter
->hw
;
4587 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
4588 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4589 set_bit(__IXGBE_FDIR_INIT_DONE
,
4590 &(adapter
->tx_ring
[i
].reinit_state
));
4592 DPRINTK(PROBE
, ERR
, "failed to finish FDIR re-initialization, "
4593 "ignored adding FDIR ATR filters \n");
4595 /* Done FDIR Re-initialization, enable transmits */
4596 netif_tx_start_all_queues(adapter
->netdev
);
4600 * ixgbe_watchdog_task - worker thread to bring link up
4601 * @work: pointer to work_struct containing our data
4603 static void ixgbe_watchdog_task(struct work_struct
*work
)
4605 struct ixgbe_adapter
*adapter
= container_of(work
,
4606 struct ixgbe_adapter
,
4608 struct net_device
*netdev
= adapter
->netdev
;
4609 struct ixgbe_hw
*hw
= &adapter
->hw
;
4610 u32 link_speed
= adapter
->link_speed
;
4611 bool link_up
= adapter
->link_up
;
4613 struct ixgbe_ring
*tx_ring
;
4614 int some_tx_pending
= 0;
4616 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
4618 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
) {
4619 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
4622 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
4623 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++)
4624 hw
->mac
.ops
.fc_enable(hw
, i
);
4626 hw
->mac
.ops
.fc_enable(hw
, 0);
4629 hw
->mac
.ops
.fc_enable(hw
, 0);
4634 time_after(jiffies
, (adapter
->link_check_timeout
+
4635 IXGBE_TRY_LINK_TIMEOUT
))) {
4636 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
4637 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
4639 adapter
->link_up
= link_up
;
4640 adapter
->link_speed
= link_speed
;
4644 if (!netif_carrier_ok(netdev
)) {
4645 bool flow_rx
, flow_tx
;
4647 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4648 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
4649 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
4650 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
4651 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
4653 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4654 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
4655 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
4656 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
4659 printk(KERN_INFO
"ixgbe: %s NIC Link is Up %s, "
4660 "Flow Control: %s\n",
4662 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
4664 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
4665 "1 Gbps" : "unknown speed")),
4666 ((flow_rx
&& flow_tx
) ? "RX/TX" :
4668 (flow_tx
? "TX" : "None"))));
4670 netif_carrier_on(netdev
);
4672 /* Force detection of hung controller */
4673 adapter
->detect_tx_hung
= true;
4676 adapter
->link_up
= false;
4677 adapter
->link_speed
= 0;
4678 if (netif_carrier_ok(netdev
)) {
4679 printk(KERN_INFO
"ixgbe: %s NIC Link is Down\n",
4681 netif_carrier_off(netdev
);
4685 if (!netif_carrier_ok(netdev
)) {
4686 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4687 tx_ring
= &adapter
->tx_ring
[i
];
4688 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
) {
4689 some_tx_pending
= 1;
4694 if (some_tx_pending
) {
4695 /* We've lost link, so the controller stops DMA,
4696 * but we've got queued Tx work that's never going
4697 * to get done, so reset controller to flush Tx.
4698 * (Do the reset outside of interrupt context).
4700 schedule_work(&adapter
->reset_task
);
4704 ixgbe_update_stats(adapter
);
4705 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
4708 static int ixgbe_tso(struct ixgbe_adapter
*adapter
,
4709 struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
4710 u32 tx_flags
, u8
*hdr_len
)
4712 struct ixgbe_adv_tx_context_desc
*context_desc
;
4715 struct ixgbe_tx_buffer
*tx_buffer_info
;
4716 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
4717 u32 mss_l4len_idx
, l4len
;
4719 if (skb_is_gso(skb
)) {
4720 if (skb_header_cloned(skb
)) {
4721 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
4725 l4len
= tcp_hdrlen(skb
);
4728 if (skb
->protocol
== htons(ETH_P_IP
)) {
4729 struct iphdr
*iph
= ip_hdr(skb
);
4732 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
4736 adapter
->hw_tso_ctxt
++;
4737 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
4738 ipv6_hdr(skb
)->payload_len
= 0;
4739 tcp_hdr(skb
)->check
=
4740 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
4741 &ipv6_hdr(skb
)->daddr
,
4743 adapter
->hw_tso6_ctxt
++;
4746 i
= tx_ring
->next_to_use
;
4748 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4749 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
4751 /* VLAN MACLEN IPLEN */
4752 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
4754 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
4755 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
4756 IXGBE_ADVTXD_MACLEN_SHIFT
);
4757 *hdr_len
+= skb_network_offset(skb
);
4759 (skb_transport_header(skb
) - skb_network_header(skb
));
4761 (skb_transport_header(skb
) - skb_network_header(skb
));
4762 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
4763 context_desc
->seqnum_seed
= 0;
4765 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
4766 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
4767 IXGBE_ADVTXD_DTYP_CTXT
);
4769 if (skb
->protocol
== htons(ETH_P_IP
))
4770 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
4771 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4772 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
4776 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
4777 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
4778 /* use index 1 for TSO */
4779 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
4780 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
4782 tx_buffer_info
->time_stamp
= jiffies
;
4783 tx_buffer_info
->next_to_watch
= i
;
4786 if (i
== tx_ring
->count
)
4788 tx_ring
->next_to_use
= i
;
4795 static bool ixgbe_tx_csum(struct ixgbe_adapter
*adapter
,
4796 struct ixgbe_ring
*tx_ring
,
4797 struct sk_buff
*skb
, u32 tx_flags
)
4799 struct ixgbe_adv_tx_context_desc
*context_desc
;
4801 struct ixgbe_tx_buffer
*tx_buffer_info
;
4802 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
4804 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
4805 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
4806 i
= tx_ring
->next_to_use
;
4807 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4808 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
4810 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
4812 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
4813 vlan_macip_lens
|= (skb_network_offset(skb
) <<
4814 IXGBE_ADVTXD_MACLEN_SHIFT
);
4815 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
4816 vlan_macip_lens
|= (skb_transport_header(skb
) -
4817 skb_network_header(skb
));
4819 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
4820 context_desc
->seqnum_seed
= 0;
4822 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
4823 IXGBE_ADVTXD_DTYP_CTXT
);
4825 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
4826 switch (skb
->protocol
) {
4827 case cpu_to_be16(ETH_P_IP
):
4828 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
4829 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
4831 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4832 else if (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)
4834 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
4836 case cpu_to_be16(ETH_P_IPV6
):
4837 /* XXX what about other V6 headers?? */
4838 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
4840 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4841 else if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_SCTP
)
4843 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
4846 if (unlikely(net_ratelimit())) {
4847 DPRINTK(PROBE
, WARNING
,
4848 "partial checksum but proto=%x!\n",
4855 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
4856 /* use index zero for tx checksum offload */
4857 context_desc
->mss_l4len_idx
= 0;
4859 tx_buffer_info
->time_stamp
= jiffies
;
4860 tx_buffer_info
->next_to_watch
= i
;
4862 adapter
->hw_csum_tx_good
++;
4864 if (i
== tx_ring
->count
)
4866 tx_ring
->next_to_use
= i
;
4874 static int ixgbe_tx_map(struct ixgbe_adapter
*adapter
,
4875 struct ixgbe_ring
*tx_ring
,
4876 struct sk_buff
*skb
, u32 tx_flags
,
4879 struct ixgbe_tx_buffer
*tx_buffer_info
;
4881 unsigned int total
= skb
->len
;
4882 unsigned int offset
= 0, size
, count
= 0, i
;
4883 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
4887 i
= tx_ring
->next_to_use
;
4889 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
4890 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
4894 map
= skb_shinfo(skb
)->dma_maps
;
4896 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
)
4897 /* excluding fcoe_crc_eof for FCoE */
4898 total
-= sizeof(struct fcoe_crc_eof
);
4900 len
= min(skb_headlen(skb
), total
);
4902 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4903 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
4905 tx_buffer_info
->length
= size
;
4906 tx_buffer_info
->dma
= skb_shinfo(skb
)->dma_head
+ offset
;
4907 tx_buffer_info
->time_stamp
= jiffies
;
4908 tx_buffer_info
->next_to_watch
= i
;
4917 if (i
== tx_ring
->count
)
4922 for (f
= 0; f
< nr_frags
; f
++) {
4923 struct skb_frag_struct
*frag
;
4925 frag
= &skb_shinfo(skb
)->frags
[f
];
4926 len
= min((unsigned int)frag
->size
, total
);
4931 if (i
== tx_ring
->count
)
4934 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4935 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
4937 tx_buffer_info
->length
= size
;
4938 tx_buffer_info
->dma
= map
[f
] + offset
;
4939 tx_buffer_info
->time_stamp
= jiffies
;
4940 tx_buffer_info
->next_to_watch
= i
;
4951 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
4952 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
4957 static void ixgbe_tx_queue(struct ixgbe_adapter
*adapter
,
4958 struct ixgbe_ring
*tx_ring
,
4959 int tx_flags
, int count
, u32 paylen
, u8 hdr_len
)
4961 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
4962 struct ixgbe_tx_buffer
*tx_buffer_info
;
4963 u32 olinfo_status
= 0, cmd_type_len
= 0;
4965 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
4967 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
4969 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
4971 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
4972 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
4974 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
4975 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
4977 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
4978 IXGBE_ADVTXD_POPTS_SHIFT
;
4980 /* use index 1 context for tso */
4981 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
4982 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
4983 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
4984 IXGBE_ADVTXD_POPTS_SHIFT
;
4986 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
4987 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
4988 IXGBE_ADVTXD_POPTS_SHIFT
;
4990 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
4991 olinfo_status
|= IXGBE_ADVTXD_CC
;
4992 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
4993 if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
4994 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
4997 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
4999 i
= tx_ring
->next_to_use
;
5001 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5002 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
5003 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
5004 tx_desc
->read
.cmd_type_len
=
5005 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
5006 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
5008 if (i
== tx_ring
->count
)
5012 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
5015 * Force memory writes to complete before letting h/w
5016 * know there are new descriptors to fetch. (Only
5017 * applicable for weak-ordered memory model archs,
5022 tx_ring
->next_to_use
= i
;
5023 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
5026 static void ixgbe_atr(struct ixgbe_adapter
*adapter
, struct sk_buff
*skb
,
5027 int queue
, u32 tx_flags
)
5029 /* Right now, we support IPv4 only */
5030 struct ixgbe_atr_input atr_input
;
5033 struct iphdr
*iph
= ip_hdr(skb
);
5034 struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
5035 u16 vlan_id
, src_port
, dst_port
, flex_bytes
;
5036 u32 src_ipv4_addr
, dst_ipv4_addr
;
5039 /* check if we're UDP or TCP */
5040 if (iph
->protocol
== IPPROTO_TCP
) {
5042 src_port
= th
->source
;
5043 dst_port
= th
->dest
;
5044 l4type
|= IXGBE_ATR_L4TYPE_TCP
;
5045 /* l4type IPv4 type is 0, no need to assign */
5046 } else if(iph
->protocol
== IPPROTO_UDP
) {
5048 src_port
= uh
->source
;
5049 dst_port
= uh
->dest
;
5050 l4type
|= IXGBE_ATR_L4TYPE_UDP
;
5051 /* l4type IPv4 type is 0, no need to assign */
5053 /* Unsupported L4 header, just bail here */
5057 memset(&atr_input
, 0, sizeof(struct ixgbe_atr_input
));
5059 vlan_id
= (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
) >>
5060 IXGBE_TX_FLAGS_VLAN_SHIFT
;
5061 src_ipv4_addr
= iph
->saddr
;
5062 dst_ipv4_addr
= iph
->daddr
;
5063 flex_bytes
= eth
->h_proto
;
5065 ixgbe_atr_set_vlan_id_82599(&atr_input
, vlan_id
);
5066 ixgbe_atr_set_src_port_82599(&atr_input
, dst_port
);
5067 ixgbe_atr_set_dst_port_82599(&atr_input
, src_port
);
5068 ixgbe_atr_set_flex_byte_82599(&atr_input
, flex_bytes
);
5069 ixgbe_atr_set_l4type_82599(&atr_input
, l4type
);
5070 /* src and dst are inverted, think how the receiver sees them */
5071 ixgbe_atr_set_src_ipv4_82599(&atr_input
, dst_ipv4_addr
);
5072 ixgbe_atr_set_dst_ipv4_82599(&atr_input
, src_ipv4_addr
);
5074 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5075 ixgbe_fdir_add_signature_filter_82599(&adapter
->hw
, &atr_input
, queue
);
5078 static int __ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5079 struct ixgbe_ring
*tx_ring
, int size
)
5081 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5083 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
5084 /* Herbert's original patch had:
5085 * smp_mb__after_netif_stop_queue();
5086 * but since that doesn't exist yet, just open code it. */
5089 /* We need to check again in a case another CPU has just
5090 * made room available. */
5091 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
5094 /* A reprieve! - use start_queue because it doesn't call schedule */
5095 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
5096 ++adapter
->restart_queue
;
5100 static int ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5101 struct ixgbe_ring
*tx_ring
, int size
)
5103 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
5105 return __ixgbe_maybe_stop_tx(netdev
, tx_ring
, size
);
5108 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
5110 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5112 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
5113 return smp_processor_id();
5115 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
5116 return 0; /* All traffic should default to class 0 */
5118 return skb_tx_hash(dev
, skb
);
5121 static int ixgbe_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
5123 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5124 struct ixgbe_ring
*tx_ring
;
5126 unsigned int tx_flags
= 0;
5132 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
5133 tx_flags
|= vlan_tx_tag_get(skb
);
5134 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5135 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
5136 tx_flags
|= (skb
->queue_mapping
<< 13);
5138 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5139 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5140 } else if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5141 if (skb
->priority
!= TC_PRIO_CONTROL
) {
5142 tx_flags
|= (skb
->queue_mapping
<< 13);
5143 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5144 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5146 skb
->queue_mapping
=
5147 adapter
->ring_feature
[RING_F_DCB
].indices
-1;
5151 r_idx
= skb
->queue_mapping
;
5152 tx_ring
= &adapter
->tx_ring
[r_idx
];
5154 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
5155 (skb
->protocol
== htons(ETH_P_FCOE
)))
5156 tx_flags
|= IXGBE_TX_FLAGS_FCOE
;
5158 /* four things can cause us to need a context descriptor */
5159 if (skb_is_gso(skb
) ||
5160 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
5161 (tx_flags
& IXGBE_TX_FLAGS_VLAN
) ||
5162 (tx_flags
& IXGBE_TX_FLAGS_FCOE
))
5165 count
+= TXD_USE_COUNT(skb_headlen(skb
));
5166 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
5167 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
5169 if (ixgbe_maybe_stop_tx(netdev
, tx_ring
, count
)) {
5171 return NETDEV_TX_BUSY
;
5174 first
= tx_ring
->next_to_use
;
5175 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
5177 /* setup tx offload for FCoE */
5178 tso
= ixgbe_fso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5180 dev_kfree_skb_any(skb
);
5181 return NETDEV_TX_OK
;
5184 tx_flags
|= IXGBE_TX_FLAGS_FSO
;
5185 #endif /* IXGBE_FCOE */
5187 if (skb
->protocol
== htons(ETH_P_IP
))
5188 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
5189 tso
= ixgbe_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5191 dev_kfree_skb_any(skb
);
5192 return NETDEV_TX_OK
;
5196 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
5197 else if (ixgbe_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
5198 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
5199 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
5202 count
= ixgbe_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
);
5204 /* add the ATR filter if ATR is on */
5205 if (tx_ring
->atr_sample_rate
) {
5206 ++tx_ring
->atr_count
;
5207 if ((tx_ring
->atr_count
>= tx_ring
->atr_sample_rate
) &&
5208 test_bit(__IXGBE_FDIR_INIT_DONE
,
5209 &tx_ring
->reinit_state
)) {
5210 ixgbe_atr(adapter
, skb
, tx_ring
->queue_index
,
5212 tx_ring
->atr_count
= 0;
5215 ixgbe_tx_queue(adapter
, tx_ring
, tx_flags
, count
, skb
->len
,
5217 ixgbe_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
5220 dev_kfree_skb_any(skb
);
5221 tx_ring
->tx_buffer_info
[first
].time_stamp
= 0;
5222 tx_ring
->next_to_use
= first
;
5225 return NETDEV_TX_OK
;
5229 * ixgbe_get_stats - Get System Network Statistics
5230 * @netdev: network interface device structure
5232 * Returns the address of the device statistics structure.
5233 * The statistics are actually updated from the timer callback.
5235 static struct net_device_stats
*ixgbe_get_stats(struct net_device
*netdev
)
5237 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5239 /* only return the current stats */
5240 return &adapter
->net_stats
;
5244 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5245 * @netdev: network interface device structure
5246 * @p: pointer to an address structure
5248 * Returns 0 on success, negative on failure
5250 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
5252 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5253 struct ixgbe_hw
*hw
= &adapter
->hw
;
5254 struct sockaddr
*addr
= p
;
5256 if (!is_valid_ether_addr(addr
->sa_data
))
5257 return -EADDRNOTAVAIL
;
5259 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
5260 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
5262 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0, IXGBE_RAH_AV
);
5268 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
5270 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5271 struct ixgbe_hw
*hw
= &adapter
->hw
;
5275 if (prtad
!= hw
->phy
.mdio
.prtad
)
5277 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
5283 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
5284 u16 addr
, u16 value
)
5286 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5287 struct ixgbe_hw
*hw
= &adapter
->hw
;
5289 if (prtad
!= hw
->phy
.mdio
.prtad
)
5291 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
5294 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
5296 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5298 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
5302 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5304 * @netdev: network interface device structure
5306 * Returns non-zero on failure
5308 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
5311 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5312 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5314 if (is_valid_ether_addr(mac
->san_addr
)) {
5316 err
= dev_addr_add(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5323 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5325 * @netdev: network interface device structure
5327 * Returns non-zero on failure
5329 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
5332 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5333 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5335 if (is_valid_ether_addr(mac
->san_addr
)) {
5337 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5343 #ifdef CONFIG_NET_POLL_CONTROLLER
5345 * Polling 'interrupt' - used by things like netconsole to send skbs
5346 * without having to re-enable interrupts. It's not called while
5347 * the interrupt routine is executing.
5349 static void ixgbe_netpoll(struct net_device
*netdev
)
5351 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5353 disable_irq(adapter
->pdev
->irq
);
5354 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
5355 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
5356 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
5357 enable_irq(adapter
->pdev
->irq
);
5361 static const struct net_device_ops ixgbe_netdev_ops
= {
5362 .ndo_open
= ixgbe_open
,
5363 .ndo_stop
= ixgbe_close
,
5364 .ndo_start_xmit
= ixgbe_xmit_frame
,
5365 .ndo_select_queue
= ixgbe_select_queue
,
5366 .ndo_get_stats
= ixgbe_get_stats
,
5367 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
5368 .ndo_set_multicast_list
= ixgbe_set_rx_mode
,
5369 .ndo_validate_addr
= eth_validate_addr
,
5370 .ndo_set_mac_address
= ixgbe_set_mac
,
5371 .ndo_change_mtu
= ixgbe_change_mtu
,
5372 .ndo_tx_timeout
= ixgbe_tx_timeout
,
5373 .ndo_vlan_rx_register
= ixgbe_vlan_rx_register
,
5374 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
5375 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
5376 .ndo_do_ioctl
= ixgbe_ioctl
,
5377 #ifdef CONFIG_NET_POLL_CONTROLLER
5378 .ndo_poll_controller
= ixgbe_netpoll
,
5381 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
5382 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
5383 #endif /* IXGBE_FCOE */
5387 * ixgbe_probe - Device Initialization Routine
5388 * @pdev: PCI device information struct
5389 * @ent: entry in ixgbe_pci_tbl
5391 * Returns 0 on success, negative on failure
5393 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5394 * The OS initialization, configuring of the adapter private structure,
5395 * and a hardware reset occur.
5397 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
5398 const struct pci_device_id
*ent
)
5400 struct net_device
*netdev
;
5401 struct ixgbe_adapter
*adapter
= NULL
;
5402 struct ixgbe_hw
*hw
;
5403 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
5404 static int cards_found
;
5405 int i
, err
, pci_using_dac
;
5411 err
= pci_enable_device_mem(pdev
);
5415 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
5416 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
5419 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
5421 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
5423 dev_err(&pdev
->dev
, "No usable DMA "
5424 "configuration, aborting\n");
5431 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
5432 IORESOURCE_MEM
), ixgbe_driver_name
);
5435 "pci_request_selected_regions failed 0x%x\n", err
);
5439 err
= pci_enable_pcie_error_reporting(pdev
);
5441 dev_err(&pdev
->dev
, "pci_enable_pcie_error_reporting failed "
5443 /* non-fatal, continue */
5446 pci_set_master(pdev
);
5447 pci_save_state(pdev
);
5449 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), MAX_TX_QUEUES
);
5452 goto err_alloc_etherdev
;
5455 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
5457 pci_set_drvdata(pdev
, netdev
);
5458 adapter
= netdev_priv(netdev
);
5460 adapter
->netdev
= netdev
;
5461 adapter
->pdev
= pdev
;
5464 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
5466 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
5467 pci_resource_len(pdev
, 0));
5473 for (i
= 1; i
<= 5; i
++) {
5474 if (pci_resource_len(pdev
, i
) == 0)
5478 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
5479 ixgbe_set_ethtool_ops(netdev
);
5480 netdev
->watchdog_timeo
= 5 * HZ
;
5481 strcpy(netdev
->name
, pci_name(pdev
));
5483 adapter
->bd_number
= cards_found
;
5486 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
5487 hw
->mac
.type
= ii
->mac
;
5490 memcpy(&hw
->eeprom
.ops
, ii
->eeprom_ops
, sizeof(hw
->eeprom
.ops
));
5491 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC
);
5492 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5493 if (!(eec
& (1 << 8)))
5494 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
5497 memcpy(&hw
->phy
.ops
, ii
->phy_ops
, sizeof(hw
->phy
.ops
));
5498 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
5499 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5500 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
5501 hw
->phy
.mdio
.mmds
= 0;
5502 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
5503 hw
->phy
.mdio
.dev
= netdev
;
5504 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
5505 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
5507 /* set up this timer and work struct before calling get_invariants
5508 * which might start the timer
5510 init_timer(&adapter
->sfp_timer
);
5511 adapter
->sfp_timer
.function
= &ixgbe_sfp_timer
;
5512 adapter
->sfp_timer
.data
= (unsigned long) adapter
;
5514 INIT_WORK(&adapter
->sfp_task
, ixgbe_sfp_task
);
5516 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5517 INIT_WORK(&adapter
->multispeed_fiber_task
, ixgbe_multispeed_fiber_task
);
5519 /* a new SFP+ module arrival, called from GPI SDP2 context */
5520 INIT_WORK(&adapter
->sfp_config_module_task
,
5521 ixgbe_sfp_config_module_task
);
5523 ii
->get_invariants(hw
);
5525 /* setup the private structure */
5526 err
= ixgbe_sw_init(adapter
);
5531 * If there is a fan on this device and it has failed log the
5534 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
5535 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
5536 if (esdp
& IXGBE_ESDP_SDP1
)
5537 DPRINTK(PROBE
, CRIT
,
5538 "Fan has stopped, replace the adapter\n");
5541 /* reset_hw fills in the perm_addr as well */
5542 err
= hw
->mac
.ops
.reset_hw(hw
);
5543 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
&&
5544 hw
->mac
.type
== ixgbe_mac_82598EB
) {
5546 * Start a kernel thread to watch for a module to arrive.
5547 * Only do this for 82598, since 82599 will generate
5548 * interrupts on module arrival.
5550 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5551 mod_timer(&adapter
->sfp_timer
,
5552 round_jiffies(jiffies
+ (2 * HZ
)));
5554 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
5555 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
5556 "an unsupported SFP+ module type was detected.\n"
5557 "Reload the driver after installing a supported "
5561 dev_err(&adapter
->pdev
->dev
, "HW Init failed: %d\n", err
);
5565 netdev
->features
= NETIF_F_SG
|
5567 NETIF_F_HW_VLAN_TX
|
5568 NETIF_F_HW_VLAN_RX
|
5569 NETIF_F_HW_VLAN_FILTER
;
5571 netdev
->features
|= NETIF_F_IPV6_CSUM
;
5572 netdev
->features
|= NETIF_F_TSO
;
5573 netdev
->features
|= NETIF_F_TSO6
;
5574 netdev
->features
|= NETIF_F_GRO
;
5576 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
5577 netdev
->features
|= NETIF_F_SCTP_CSUM
;
5579 netdev
->vlan_features
|= NETIF_F_TSO
;
5580 netdev
->vlan_features
|= NETIF_F_TSO6
;
5581 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
5582 netdev
->vlan_features
|= NETIF_F_SG
;
5584 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
5585 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
5587 #ifdef CONFIG_IXGBE_DCB
5588 netdev
->dcbnl_ops
= &dcbnl_ops
;
5592 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
5593 if (hw
->mac
.ops
.get_device_caps
) {
5594 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
5595 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
5596 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
5599 #endif /* IXGBE_FCOE */
5601 netdev
->features
|= NETIF_F_HIGHDMA
;
5603 if (adapter
->flags
& IXGBE_FLAG2_RSC_ENABLED
)
5604 netdev
->features
|= NETIF_F_LRO
;
5606 /* make sure the EEPROM is good */
5607 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
5608 dev_err(&pdev
->dev
, "The EEPROM Checksum Is Not Valid\n");
5613 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
5614 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
5616 if (ixgbe_validate_mac_addr(netdev
->perm_addr
)) {
5617 dev_err(&pdev
->dev
, "invalid MAC address\n");
5622 init_timer(&adapter
->watchdog_timer
);
5623 adapter
->watchdog_timer
.function
= &ixgbe_watchdog
;
5624 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
5626 INIT_WORK(&adapter
->reset_task
, ixgbe_reset_task
);
5627 INIT_WORK(&adapter
->watchdog_task
, ixgbe_watchdog_task
);
5629 err
= ixgbe_init_interrupt_scheme(adapter
);
5633 switch (pdev
->device
) {
5634 case IXGBE_DEV_ID_82599_KX4
:
5635 adapter
->wol
= (IXGBE_WUFC_MAG
| IXGBE_WUFC_EX
|
5636 IXGBE_WUFC_MC
| IXGBE_WUFC_BC
);
5637 /* Enable ACPI wakeup in GRC */
5638 IXGBE_WRITE_REG(hw
, IXGBE_GRC
,
5639 (IXGBE_READ_REG(hw
, IXGBE_GRC
) & ~IXGBE_GRC_APME
));
5645 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
5647 /* pick up the PCI bus settings for reporting later */
5648 hw
->mac
.ops
.get_bus_info(hw
);
5650 /* print bus type/speed/width info */
5651 dev_info(&pdev
->dev
, "(PCI Express:%s:%s) %pM\n",
5652 ((hw
->bus
.speed
== ixgbe_bus_speed_5000
) ? "5.0Gb/s":
5653 (hw
->bus
.speed
== ixgbe_bus_speed_2500
) ? "2.5Gb/s":"Unknown"),
5654 ((hw
->bus
.width
== ixgbe_bus_width_pcie_x8
) ? "Width x8" :
5655 (hw
->bus
.width
== ixgbe_bus_width_pcie_x4
) ? "Width x4" :
5656 (hw
->bus
.width
== ixgbe_bus_width_pcie_x1
) ? "Width x1" :
5659 ixgbe_read_pba_num_generic(hw
, &part_num
);
5660 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
5661 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5662 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
5663 (part_num
>> 8), (part_num
& 0xff));
5665 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5666 hw
->mac
.type
, hw
->phy
.type
,
5667 (part_num
>> 8), (part_num
& 0xff));
5669 if (hw
->bus
.width
<= ixgbe_bus_width_pcie_x4
) {
5670 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for "
5671 "this card is not sufficient for optimal "
5673 dev_warn(&pdev
->dev
, "For optimal performance a x8 "
5674 "PCI-Express slot is required.\n");
5677 /* save off EEPROM version number */
5678 hw
->eeprom
.ops
.read(hw
, 0x29, &adapter
->eeprom_version
);
5680 /* reset the hardware with the new settings */
5681 err
= hw
->mac
.ops
.start_hw(hw
);
5683 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
5684 /* We are running on a pre-production device, log a warning */
5685 dev_warn(&pdev
->dev
, "This device is a pre-production "
5686 "adapter/LOM. Please be aware there may be issues "
5687 "associated with your hardware. If you are "
5688 "experiencing problems please contact your Intel or "
5689 "hardware representative who provided you with this "
5692 strcpy(netdev
->name
, "eth%d");
5693 err
= register_netdev(netdev
);
5697 /* carrier off reporting is important to ethtool even BEFORE open */
5698 netif_carrier_off(netdev
);
5700 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
5701 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
5702 INIT_WORK(&adapter
->fdir_reinit_task
, ixgbe_fdir_reinit_task
);
5704 #ifdef CONFIG_IXGBE_DCA
5705 if (dca_add_requester(&pdev
->dev
) == 0) {
5706 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
5707 ixgbe_setup_dca(adapter
);
5710 /* add san mac addr to netdev */
5711 ixgbe_add_sanmac_netdev(netdev
);
5713 dev_info(&pdev
->dev
, "Intel(R) 10 Gigabit Network Connection\n");
5718 ixgbe_release_hw_control(adapter
);
5719 ixgbe_clear_interrupt_scheme(adapter
);
5722 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5723 del_timer_sync(&adapter
->sfp_timer
);
5724 cancel_work_sync(&adapter
->sfp_task
);
5725 cancel_work_sync(&adapter
->multispeed_fiber_task
);
5726 cancel_work_sync(&adapter
->sfp_config_module_task
);
5727 iounmap(hw
->hw_addr
);
5729 free_netdev(netdev
);
5731 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
5735 pci_disable_device(pdev
);
5740 * ixgbe_remove - Device Removal Routine
5741 * @pdev: PCI device information struct
5743 * ixgbe_remove is called by the PCI subsystem to alert the driver
5744 * that it should release a PCI device. The could be caused by a
5745 * Hot-Plug event, or because the driver is going to be removed from
5748 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
5750 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5751 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5754 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5755 /* clear the module not found bit to make sure the worker won't
5758 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5759 del_timer_sync(&adapter
->watchdog_timer
);
5761 del_timer_sync(&adapter
->sfp_timer
);
5762 cancel_work_sync(&adapter
->watchdog_task
);
5763 cancel_work_sync(&adapter
->sfp_task
);
5764 cancel_work_sync(&adapter
->multispeed_fiber_task
);
5765 cancel_work_sync(&adapter
->sfp_config_module_task
);
5766 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
5767 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
5768 cancel_work_sync(&adapter
->fdir_reinit_task
);
5769 flush_scheduled_work();
5771 #ifdef CONFIG_IXGBE_DCA
5772 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
5773 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
5774 dca_remove_requester(&pdev
->dev
);
5775 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
5780 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
5781 ixgbe_cleanup_fcoe(adapter
);
5783 #endif /* IXGBE_FCOE */
5785 /* remove the added san mac */
5786 ixgbe_del_sanmac_netdev(netdev
);
5788 if (netdev
->reg_state
== NETREG_REGISTERED
)
5789 unregister_netdev(netdev
);
5791 ixgbe_clear_interrupt_scheme(adapter
);
5793 ixgbe_release_hw_control(adapter
);
5795 iounmap(adapter
->hw
.hw_addr
);
5796 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
5799 DPRINTK(PROBE
, INFO
, "complete\n");
5801 free_netdev(netdev
);
5803 err
= pci_disable_pcie_error_reporting(pdev
);
5806 "pci_disable_pcie_error_reporting failed 0x%x\n", err
);
5808 pci_disable_device(pdev
);
5812 * ixgbe_io_error_detected - called when PCI error is detected
5813 * @pdev: Pointer to PCI device
5814 * @state: The current pci connection state
5816 * This function is called after a PCI bus error affecting
5817 * this device has been detected.
5819 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
5820 pci_channel_state_t state
)
5822 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5823 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5825 netif_device_detach(netdev
);
5827 if (state
== pci_channel_io_perm_failure
)
5828 return PCI_ERS_RESULT_DISCONNECT
;
5830 if (netif_running(netdev
))
5831 ixgbe_down(adapter
);
5832 pci_disable_device(pdev
);
5834 /* Request a slot reset. */
5835 return PCI_ERS_RESULT_NEED_RESET
;
5839 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5840 * @pdev: Pointer to PCI device
5842 * Restart the card from scratch, as if from a cold-boot.
5844 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
5846 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5847 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5848 pci_ers_result_t result
;
5851 if (pci_enable_device_mem(pdev
)) {
5853 "Cannot re-enable PCI device after reset.\n");
5854 result
= PCI_ERS_RESULT_DISCONNECT
;
5856 pci_set_master(pdev
);
5857 pci_restore_state(pdev
);
5859 pci_wake_from_d3(pdev
, false);
5861 ixgbe_reset(adapter
);
5862 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
5863 result
= PCI_ERS_RESULT_RECOVERED
;
5866 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
5869 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err
);
5870 /* non-fatal, continue */
5877 * ixgbe_io_resume - called when traffic can start flowing again.
5878 * @pdev: Pointer to PCI device
5880 * This callback is called when the error recovery driver tells us that
5881 * its OK to resume normal operation.
5883 static void ixgbe_io_resume(struct pci_dev
*pdev
)
5885 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5886 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5888 if (netif_running(netdev
)) {
5889 if (ixgbe_up(adapter
)) {
5890 DPRINTK(PROBE
, INFO
, "ixgbe_up failed after reset\n");
5895 netif_device_attach(netdev
);
5898 static struct pci_error_handlers ixgbe_err_handler
= {
5899 .error_detected
= ixgbe_io_error_detected
,
5900 .slot_reset
= ixgbe_io_slot_reset
,
5901 .resume
= ixgbe_io_resume
,
5904 static struct pci_driver ixgbe_driver
= {
5905 .name
= ixgbe_driver_name
,
5906 .id_table
= ixgbe_pci_tbl
,
5907 .probe
= ixgbe_probe
,
5908 .remove
= __devexit_p(ixgbe_remove
),
5910 .suspend
= ixgbe_suspend
,
5911 .resume
= ixgbe_resume
,
5913 .shutdown
= ixgbe_shutdown
,
5914 .err_handler
= &ixgbe_err_handler
5918 * ixgbe_init_module - Driver Registration Routine
5920 * ixgbe_init_module is the first routine called when the driver is
5921 * loaded. All it does is register with the PCI subsystem.
5923 static int __init
ixgbe_init_module(void)
5926 printk(KERN_INFO
"%s: %s - version %s\n", ixgbe_driver_name
,
5927 ixgbe_driver_string
, ixgbe_driver_version
);
5929 printk(KERN_INFO
"%s: %s\n", ixgbe_driver_name
, ixgbe_copyright
);
5931 #ifdef CONFIG_IXGBE_DCA
5932 dca_register_notify(&dca_notifier
);
5935 ret
= pci_register_driver(&ixgbe_driver
);
5939 module_init(ixgbe_init_module
);
5942 * ixgbe_exit_module - Driver Exit Cleanup Routine
5944 * ixgbe_exit_module is called just before the driver is removed
5947 static void __exit
ixgbe_exit_module(void)
5949 #ifdef CONFIG_IXGBE_DCA
5950 dca_unregister_notify(&dca_notifier
);
5952 pci_unregister_driver(&ixgbe_driver
);
5955 #ifdef CONFIG_IXGBE_DCA
5956 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
5961 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
5962 __ixgbe_notify_dca
);
5964 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
5967 #endif /* CONFIG_IXGBE_DCA */
5970 * ixgbe_get_hw_dev_name - return device name string
5971 * used by hardware layer to print debugging information
5973 char *ixgbe_get_hw_dev_name(struct ixgbe_hw
*hw
)
5975 struct ixgbe_adapter
*adapter
= hw
->back
;
5976 return adapter
->netdev
->name
;
5980 module_exit(ixgbe_exit_module
);