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.44-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
),
100 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
),
102 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
),
104 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
),
107 /* required last entry */
110 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
112 #ifdef CONFIG_IXGBE_DCA
113 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
115 static struct notifier_block dca_notifier
= {
116 .notifier_call
= ixgbe_notify_dca
,
122 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
123 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
124 MODULE_LICENSE("GPL");
125 MODULE_VERSION(DRV_VERSION
);
127 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
129 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
133 /* Let firmware take over control of h/w */
134 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
135 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
136 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
139 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
143 /* Let firmware know the driver has taken over */
144 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
145 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
146 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
150 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
151 * @adapter: pointer to adapter struct
152 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
153 * @queue: queue to map the corresponding interrupt to
154 * @msix_vector: the vector to map to the corresponding queue
157 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
158 u8 queue
, u8 msix_vector
)
161 struct ixgbe_hw
*hw
= &adapter
->hw
;
162 switch (hw
->mac
.type
) {
163 case ixgbe_mac_82598EB
:
164 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
167 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
168 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
169 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
170 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
171 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
173 case ixgbe_mac_82599EB
:
174 if (direction
== -1) {
176 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
177 index
= ((queue
& 1) * 8);
178 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
179 ivar
&= ~(0xFF << index
);
180 ivar
|= (msix_vector
<< index
);
181 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
184 /* tx or rx causes */
185 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
186 index
= ((16 * (queue
& 1)) + (8 * direction
));
187 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
188 ivar
&= ~(0xFF << index
);
189 ivar
|= (msix_vector
<< index
);
190 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
198 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
203 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
204 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
205 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
207 mask
= (qmask
& 0xFFFFFFFF);
208 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
209 mask
= (qmask
>> 32);
210 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
214 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter
*adapter
,
215 struct ixgbe_tx_buffer
218 tx_buffer_info
->dma
= 0;
219 if (tx_buffer_info
->skb
) {
220 skb_dma_unmap(&adapter
->pdev
->dev
, tx_buffer_info
->skb
,
222 dev_kfree_skb_any(tx_buffer_info
->skb
);
223 tx_buffer_info
->skb
= NULL
;
225 tx_buffer_info
->time_stamp
= 0;
226 /* tx_buffer_info must be completely set up in the transmit path */
229 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter
*adapter
,
230 struct ixgbe_ring
*tx_ring
,
233 struct ixgbe_hw
*hw
= &adapter
->hw
;
235 /* Detect a transmit hang in hardware, this serializes the
236 * check with the clearing of time_stamp and movement of eop */
237 adapter
->detect_tx_hung
= false;
238 if (tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
239 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
) &&
240 !(IXGBE_READ_REG(&adapter
->hw
, IXGBE_TFCS
) & IXGBE_TFCS_TXOFF
)) {
241 /* detected Tx unit hang */
242 union ixgbe_adv_tx_desc
*tx_desc
;
243 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
244 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
246 " TDH, TDT <%x>, <%x>\n"
247 " next_to_use <%x>\n"
248 " next_to_clean <%x>\n"
249 "tx_buffer_info[next_to_clean]\n"
250 " time_stamp <%lx>\n"
252 tx_ring
->queue_index
,
253 IXGBE_READ_REG(hw
, tx_ring
->head
),
254 IXGBE_READ_REG(hw
, tx_ring
->tail
),
255 tx_ring
->next_to_use
, eop
,
256 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
263 #define IXGBE_MAX_TXD_PWR 14
264 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
266 /* Tx Descriptors needed, worst case */
267 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
268 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
269 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
270 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
272 static void ixgbe_tx_timeout(struct net_device
*netdev
);
275 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
276 * @q_vector: structure containing interrupt and ring information
277 * @tx_ring: tx ring to clean
279 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
280 struct ixgbe_ring
*tx_ring
)
282 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
283 struct net_device
*netdev
= adapter
->netdev
;
284 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
285 struct ixgbe_tx_buffer
*tx_buffer_info
;
286 unsigned int i
, eop
, count
= 0;
287 unsigned int total_bytes
= 0, total_packets
= 0;
289 i
= tx_ring
->next_to_clean
;
290 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
291 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
293 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
294 (count
< tx_ring
->work_limit
)) {
295 bool cleaned
= false;
296 for ( ; !cleaned
; count
++) {
298 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
299 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
300 cleaned
= (i
== eop
);
301 skb
= tx_buffer_info
->skb
;
303 if (cleaned
&& skb
) {
304 unsigned int segs
, bytecount
;
305 unsigned int hlen
= skb_headlen(skb
);
307 /* gso_segs is currently only valid for tcp */
308 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
310 /* adjust for FCoE Sequence Offload */
311 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
312 && (skb
->protocol
== htons(ETH_P_FCOE
)) &&
314 hlen
= skb_transport_offset(skb
) +
315 sizeof(struct fc_frame_header
) +
316 sizeof(struct fcoe_crc_eof
);
317 segs
= DIV_ROUND_UP(skb
->len
- hlen
,
318 skb_shinfo(skb
)->gso_size
);
320 #endif /* IXGBE_FCOE */
321 /* multiply data chunks by size of headers */
322 bytecount
= ((segs
- 1) * hlen
) + skb
->len
;
323 total_packets
+= segs
;
324 total_bytes
+= bytecount
;
327 ixgbe_unmap_and_free_tx_resource(adapter
,
330 tx_desc
->wb
.status
= 0;
333 if (i
== tx_ring
->count
)
337 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
338 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
341 tx_ring
->next_to_clean
= i
;
343 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
344 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
345 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
346 /* Make sure that anybody stopping the queue after this
347 * sees the new next_to_clean.
350 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
351 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
352 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
353 ++adapter
->restart_queue
;
357 if (adapter
->detect_tx_hung
) {
358 if (ixgbe_check_tx_hang(adapter
, tx_ring
, i
)) {
359 /* schedule immediate reset if we believe we hung */
361 "tx hang %d detected, resetting adapter\n",
362 adapter
->tx_timeout_count
+ 1);
363 ixgbe_tx_timeout(adapter
->netdev
);
367 /* re-arm the interrupt */
368 if (count
>= tx_ring
->work_limit
)
369 ixgbe_irq_rearm_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
371 tx_ring
->total_bytes
+= total_bytes
;
372 tx_ring
->total_packets
+= total_packets
;
373 tx_ring
->stats
.packets
+= total_packets
;
374 tx_ring
->stats
.bytes
+= total_bytes
;
375 adapter
->net_stats
.tx_bytes
+= total_bytes
;
376 adapter
->net_stats
.tx_packets
+= total_packets
;
377 return (count
< tx_ring
->work_limit
);
380 #ifdef CONFIG_IXGBE_DCA
381 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
382 struct ixgbe_ring
*rx_ring
)
386 int q
= rx_ring
- adapter
->rx_ring
;
388 if (rx_ring
->cpu
!= cpu
) {
389 rxctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
));
390 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
391 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK
;
392 rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
393 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
394 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599
;
395 rxctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
396 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
);
398 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
399 rxctrl
|= IXGBE_DCA_RXCTRL_HEAD_DCA_EN
;
400 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN
);
401 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN
|
402 IXGBE_DCA_RXCTRL_DESC_HSRO_EN
);
403 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_RXCTRL(q
), rxctrl
);
409 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
410 struct ixgbe_ring
*tx_ring
)
414 int q
= tx_ring
- adapter
->tx_ring
;
416 if (tx_ring
->cpu
!= cpu
) {
417 txctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_DCA_TXCTRL(q
));
418 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
419 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK
;
420 txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
421 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
422 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599
;
423 txctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
424 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
);
426 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
427 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_TXCTRL(q
), txctrl
);
433 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
437 if (!(adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
))
440 /* always use CB2 mode, difference is masked in the CB driver */
441 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 2);
443 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
444 adapter
->tx_ring
[i
].cpu
= -1;
445 ixgbe_update_tx_dca(adapter
, &adapter
->tx_ring
[i
]);
447 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
448 adapter
->rx_ring
[i
].cpu
= -1;
449 ixgbe_update_rx_dca(adapter
, &adapter
->rx_ring
[i
]);
453 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
455 struct net_device
*netdev
= dev_get_drvdata(dev
);
456 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
457 unsigned long event
= *(unsigned long *)data
;
460 case DCA_PROVIDER_ADD
:
461 /* if we're already enabled, don't do it again */
462 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
464 if (dca_add_requester(dev
) == 0) {
465 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
466 ixgbe_setup_dca(adapter
);
469 /* Fall Through since DCA is disabled. */
470 case DCA_PROVIDER_REMOVE
:
471 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
472 dca_remove_requester(dev
);
473 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
474 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
482 #endif /* CONFIG_IXGBE_DCA */
484 * ixgbe_receive_skb - Send a completed packet up the stack
485 * @adapter: board private structure
486 * @skb: packet to send up
487 * @status: hardware indication of status of receive
488 * @rx_ring: rx descriptor ring (for a specific queue) to setup
489 * @rx_desc: rx descriptor
491 static void ixgbe_receive_skb(struct ixgbe_q_vector
*q_vector
,
492 struct sk_buff
*skb
, u8 status
,
493 struct ixgbe_ring
*ring
,
494 union ixgbe_adv_rx_desc
*rx_desc
)
496 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
497 struct napi_struct
*napi
= &q_vector
->napi
;
498 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
499 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
501 skb_record_rx_queue(skb
, ring
->queue_index
);
502 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
503 if (adapter
->vlgrp
&& is_vlan
&& (tag
& VLAN_VID_MASK
))
504 vlan_gro_receive(napi
, adapter
->vlgrp
, tag
, skb
);
506 napi_gro_receive(napi
, skb
);
508 if (adapter
->vlgrp
&& is_vlan
&& (tag
& VLAN_VID_MASK
))
509 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
516 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
517 * @adapter: address of board private structure
518 * @status_err: hardware indication of status of receive
519 * @skb: skb currently being received and modified
521 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
522 union ixgbe_adv_rx_desc
*rx_desc
,
525 u32 status_err
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
527 skb
->ip_summed
= CHECKSUM_NONE
;
529 /* Rx csum disabled */
530 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
533 /* if IP and error */
534 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
535 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
536 adapter
->hw_csum_rx_error
++;
540 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
543 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
544 u16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
547 * 82599 errata, UDP frames with a 0 checksum can be marked as
550 if ((pkt_info
& IXGBE_RXDADV_PKTTYPE_UDP
) &&
551 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
554 adapter
->hw_csum_rx_error
++;
558 /* It must be a TCP or UDP packet with a valid checksum */
559 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
560 adapter
->hw_csum_rx_good
++;
563 static inline void ixgbe_release_rx_desc(struct ixgbe_hw
*hw
,
564 struct ixgbe_ring
*rx_ring
, u32 val
)
567 * Force memory writes to complete before letting h/w
568 * know there are new descriptors to fetch. (Only
569 * applicable for weak-ordered memory model archs,
573 IXGBE_WRITE_REG(hw
, IXGBE_RDT(rx_ring
->reg_idx
), val
);
577 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
578 * @adapter: address of board private structure
580 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter
*adapter
,
581 struct ixgbe_ring
*rx_ring
,
584 struct pci_dev
*pdev
= adapter
->pdev
;
585 union ixgbe_adv_rx_desc
*rx_desc
;
586 struct ixgbe_rx_buffer
*bi
;
589 i
= rx_ring
->next_to_use
;
590 bi
= &rx_ring
->rx_buffer_info
[i
];
592 while (cleaned_count
--) {
593 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
596 (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
)) {
598 bi
->page
= alloc_page(GFP_ATOMIC
);
600 adapter
->alloc_rx_page_failed
++;
605 /* use a half page if we're re-using */
606 bi
->page_offset
^= (PAGE_SIZE
/ 2);
609 bi
->page_dma
= pci_map_page(pdev
, bi
->page
,
617 skb
= netdev_alloc_skb(adapter
->netdev
,
618 (rx_ring
->rx_buf_len
+
622 adapter
->alloc_rx_buff_failed
++;
627 * Make buffer alignment 2 beyond a 16 byte boundary
628 * this will result in a 16 byte aligned IP header after
629 * the 14 byte MAC header is removed
631 skb_reserve(skb
, NET_IP_ALIGN
);
634 bi
->dma
= pci_map_single(pdev
, skb
->data
,
638 /* Refresh the desc even if buffer_addrs didn't change because
639 * each write-back erases this info. */
640 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
641 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
642 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
644 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
648 if (i
== rx_ring
->count
)
650 bi
= &rx_ring
->rx_buffer_info
[i
];
654 if (rx_ring
->next_to_use
!= i
) {
655 rx_ring
->next_to_use
= i
;
657 i
= (rx_ring
->count
- 1);
659 ixgbe_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
663 static inline u16
ixgbe_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
665 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
668 static inline u16
ixgbe_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
670 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
673 static inline u32
ixgbe_get_rsc_count(union ixgbe_adv_rx_desc
*rx_desc
)
675 return (le32_to_cpu(rx_desc
->wb
.lower
.lo_dword
.data
) &
676 IXGBE_RXDADV_RSCCNT_MASK
) >>
677 IXGBE_RXDADV_RSCCNT_SHIFT
;
681 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
682 * @skb: pointer to the last skb in the rsc queue
684 * This function changes a queue full of hw rsc buffers into a completed
685 * packet. It uses the ->prev pointers to find the first packet and then
686 * turns it into the frag list owner.
688 static inline struct sk_buff
*ixgbe_transform_rsc_queue(struct sk_buff
*skb
)
690 unsigned int frag_list_size
= 0;
693 struct sk_buff
*prev
= skb
->prev
;
694 frag_list_size
+= skb
->len
;
699 skb_shinfo(skb
)->frag_list
= skb
->next
;
701 skb
->len
+= frag_list_size
;
702 skb
->data_len
+= frag_list_size
;
703 skb
->truesize
+= frag_list_size
;
707 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
708 struct ixgbe_ring
*rx_ring
,
709 int *work_done
, int work_to_do
)
711 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
712 struct pci_dev
*pdev
= adapter
->pdev
;
713 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
714 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
716 unsigned int i
, rsc_count
= 0;
719 bool cleaned
= false;
720 int cleaned_count
= 0;
721 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
724 #endif /* IXGBE_FCOE */
726 i
= rx_ring
->next_to_clean
;
727 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
728 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
729 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
731 while (staterr
& IXGBE_RXD_STAT_DD
) {
733 if (*work_done
>= work_to_do
)
737 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
738 hdr_info
= le16_to_cpu(ixgbe_get_hdr_info(rx_desc
));
739 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
740 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
741 if (hdr_info
& IXGBE_RXDADV_SPH
)
742 adapter
->rx_hdr_split
++;
743 if (len
> IXGBE_RX_HDR_SIZE
)
744 len
= IXGBE_RX_HDR_SIZE
;
745 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
747 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
751 skb
= rx_buffer_info
->skb
;
752 prefetch(skb
->data
- NET_IP_ALIGN
);
753 rx_buffer_info
->skb
= NULL
;
755 if (rx_buffer_info
->dma
) {
756 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
759 rx_buffer_info
->dma
= 0;
764 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
765 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
766 rx_buffer_info
->page_dma
= 0;
767 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
768 rx_buffer_info
->page
,
769 rx_buffer_info
->page_offset
,
772 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
773 (page_count(rx_buffer_info
->page
) != 1))
774 rx_buffer_info
->page
= NULL
;
776 get_page(rx_buffer_info
->page
);
778 skb
->len
+= upper_len
;
779 skb
->data_len
+= upper_len
;
780 skb
->truesize
+= upper_len
;
784 if (i
== rx_ring
->count
)
787 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
791 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
792 rsc_count
= ixgbe_get_rsc_count(rx_desc
);
795 u32 nextp
= (staterr
& IXGBE_RXDADV_NEXTP_MASK
) >>
796 IXGBE_RXDADV_NEXTP_SHIFT
;
797 next_buffer
= &rx_ring
->rx_buffer_info
[nextp
];
798 rx_ring
->rsc_count
+= (rsc_count
- 1);
800 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
803 if (staterr
& IXGBE_RXD_STAT_EOP
) {
805 skb
= ixgbe_transform_rsc_queue(skb
);
806 rx_ring
->stats
.packets
++;
807 rx_ring
->stats
.bytes
+= skb
->len
;
809 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
810 rx_buffer_info
->skb
= next_buffer
->skb
;
811 rx_buffer_info
->dma
= next_buffer
->dma
;
812 next_buffer
->skb
= skb
;
813 next_buffer
->dma
= 0;
815 skb
->next
= next_buffer
->skb
;
816 skb
->next
->prev
= skb
;
818 adapter
->non_eop_descs
++;
822 if (staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) {
823 dev_kfree_skb_irq(skb
);
827 ixgbe_rx_checksum(adapter
, rx_desc
, skb
);
829 /* probably a little skewed due to removing CRC */
830 total_rx_bytes
+= skb
->len
;
833 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
835 /* if ddp, not passing to ULD unless for FCP_RSP or error */
836 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
837 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
841 #endif /* IXGBE_FCOE */
842 ixgbe_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
845 rx_desc
->wb
.upper
.status_error
= 0;
847 /* return some buffers to hardware, one at a time is too slow */
848 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
849 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
853 /* use prefetched values */
855 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
857 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
860 rx_ring
->next_to_clean
= i
;
861 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
864 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
867 /* include DDPed FCoE data */
871 mss
= adapter
->netdev
->mtu
- sizeof(struct fcoe_hdr
) -
872 sizeof(struct fc_frame_header
) -
873 sizeof(struct fcoe_crc_eof
);
876 total_rx_bytes
+= ddp_bytes
;
877 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
, mss
);
879 #endif /* IXGBE_FCOE */
881 rx_ring
->total_packets
+= total_rx_packets
;
882 rx_ring
->total_bytes
+= total_rx_bytes
;
883 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
884 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
889 static int ixgbe_clean_rxonly(struct napi_struct
*, int);
891 * ixgbe_configure_msix - Configure MSI-X hardware
892 * @adapter: board private structure
894 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
897 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
899 struct ixgbe_q_vector
*q_vector
;
900 int i
, j
, q_vectors
, v_idx
, r_idx
;
903 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
906 * Populate the IVAR table and set the ITR values to the
907 * corresponding register.
909 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
910 q_vector
= adapter
->q_vector
[v_idx
];
911 /* XXX for_each_bit(...) */
912 r_idx
= find_first_bit(q_vector
->rxr_idx
,
913 adapter
->num_rx_queues
);
915 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
916 j
= adapter
->rx_ring
[r_idx
].reg_idx
;
917 ixgbe_set_ivar(adapter
, 0, j
, v_idx
);
918 r_idx
= find_next_bit(q_vector
->rxr_idx
,
919 adapter
->num_rx_queues
,
922 r_idx
= find_first_bit(q_vector
->txr_idx
,
923 adapter
->num_tx_queues
);
925 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
926 j
= adapter
->tx_ring
[r_idx
].reg_idx
;
927 ixgbe_set_ivar(adapter
, 1, j
, v_idx
);
928 r_idx
= find_next_bit(q_vector
->txr_idx
,
929 adapter
->num_tx_queues
,
933 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
935 q_vector
->eitr
= adapter
->tx_eitr_param
;
936 else if (q_vector
->rxr_count
)
938 q_vector
->eitr
= adapter
->rx_eitr_param
;
940 ixgbe_write_eitr(q_vector
);
943 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
944 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
946 else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
947 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
948 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
950 /* set up to autoclear timer, and the vectors */
951 mask
= IXGBE_EIMS_ENABLE_MASK
;
952 mask
&= ~(IXGBE_EIMS_OTHER
| IXGBE_EIMS_LSC
);
953 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
960 latency_invalid
= 255
964 * ixgbe_update_itr - update the dynamic ITR value based on statistics
965 * @adapter: pointer to adapter
966 * @eitr: eitr setting (ints per sec) to give last timeslice
967 * @itr_setting: current throttle rate in ints/second
968 * @packets: the number of packets during this measurement interval
969 * @bytes: the number of bytes during this measurement interval
971 * Stores a new ITR value based on packets and byte
972 * counts during the last interrupt. The advantage of per interrupt
973 * computation is faster updates and more accurate ITR for the current
974 * traffic pattern. Constants in this function were computed
975 * based on theoretical maximum wire speed and thresholds were set based
976 * on testing data as well as attempting to minimize response time
977 * while increasing bulk throughput.
978 * this functionality is controlled by the InterruptThrottleRate module
979 * parameter (see ixgbe_param.c)
981 static u8
ixgbe_update_itr(struct ixgbe_adapter
*adapter
,
982 u32 eitr
, u8 itr_setting
,
983 int packets
, int bytes
)
985 unsigned int retval
= itr_setting
;
990 goto update_itr_done
;
993 /* simple throttlerate management
994 * 0-20MB/s lowest (100000 ints/s)
995 * 20-100MB/s low (20000 ints/s)
996 * 100-1249MB/s bulk (8000 ints/s)
998 /* what was last interrupt timeslice? */
999 timepassed_us
= 1000000/eitr
;
1000 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
1002 switch (itr_setting
) {
1003 case lowest_latency
:
1004 if (bytes_perint
> adapter
->eitr_low
)
1005 retval
= low_latency
;
1008 if (bytes_perint
> adapter
->eitr_high
)
1009 retval
= bulk_latency
;
1010 else if (bytes_perint
<= adapter
->eitr_low
)
1011 retval
= lowest_latency
;
1014 if (bytes_perint
<= adapter
->eitr_high
)
1015 retval
= low_latency
;
1024 * ixgbe_write_eitr - write EITR register in hardware specific way
1025 * @q_vector: structure containing interrupt and ring information
1027 * This function is made to be called by ethtool and by the driver
1028 * when it needs to update EITR registers at runtime. Hardware
1029 * specific quirks/differences are taken care of here.
1031 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
1033 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1034 struct ixgbe_hw
*hw
= &adapter
->hw
;
1035 int v_idx
= q_vector
->v_idx
;
1036 u32 itr_reg
= EITR_INTS_PER_SEC_TO_REG(q_vector
->eitr
);
1038 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1039 /* must write high and low 16 bits to reset counter */
1040 itr_reg
|= (itr_reg
<< 16);
1041 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1043 * set the WDIS bit to not clear the timer bits and cause an
1044 * immediate assertion of the interrupt
1046 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
1048 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
1051 static void ixgbe_set_itr_msix(struct ixgbe_q_vector
*q_vector
)
1053 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1055 u8 current_itr
, ret_itr
;
1057 struct ixgbe_ring
*rx_ring
, *tx_ring
;
1059 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1060 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1061 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1062 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1064 tx_ring
->total_packets
,
1065 tx_ring
->total_bytes
);
1066 /* if the result for this queue would decrease interrupt
1067 * rate for this vector then use that result */
1068 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
1069 q_vector
->tx_itr
- 1 : ret_itr
);
1070 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1074 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1075 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1076 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1077 ret_itr
= ixgbe_update_itr(adapter
, q_vector
->eitr
,
1079 rx_ring
->total_packets
,
1080 rx_ring
->total_bytes
);
1081 /* if the result for this queue would decrease interrupt
1082 * rate for this vector then use that result */
1083 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
1084 q_vector
->rx_itr
- 1 : ret_itr
);
1085 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1089 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1091 switch (current_itr
) {
1092 /* counts and packets in update_itr are dependent on these numbers */
1093 case lowest_latency
:
1097 new_itr
= 20000; /* aka hwitr = ~200 */
1105 if (new_itr
!= q_vector
->eitr
) {
1106 /* do an exponential smoothing */
1107 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1109 /* save the algorithm value here, not the smoothed one */
1110 q_vector
->eitr
= new_itr
;
1112 ixgbe_write_eitr(q_vector
);
1118 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
1120 struct ixgbe_hw
*hw
= &adapter
->hw
;
1122 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
1123 (eicr
& IXGBE_EICR_GPI_SDP1
)) {
1124 DPRINTK(PROBE
, CRIT
, "Fan has stopped, replace the adapter\n");
1125 /* write to clear the interrupt */
1126 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1130 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1132 struct ixgbe_hw
*hw
= &adapter
->hw
;
1134 if (eicr
& IXGBE_EICR_GPI_SDP1
) {
1135 /* Clear the interrupt */
1136 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1137 schedule_work(&adapter
->multispeed_fiber_task
);
1138 } else if (eicr
& IXGBE_EICR_GPI_SDP2
) {
1139 /* Clear the interrupt */
1140 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP2
);
1141 schedule_work(&adapter
->sfp_config_module_task
);
1143 /* Interrupt isn't for us... */
1148 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
1150 struct ixgbe_hw
*hw
= &adapter
->hw
;
1153 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1154 adapter
->link_check_timeout
= jiffies
;
1155 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1156 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
1157 schedule_work(&adapter
->watchdog_task
);
1161 static irqreturn_t
ixgbe_msix_lsc(int irq
, void *data
)
1163 struct net_device
*netdev
= data
;
1164 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1165 struct ixgbe_hw
*hw
= &adapter
->hw
;
1169 * Workaround for Silicon errata. Use clear-by-write instead
1170 * of clear-by-read. Reading with EICS will return the
1171 * interrupt causes without clearing, which later be done
1172 * with the write to EICR.
1174 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
1175 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
1177 if (eicr
& IXGBE_EICR_LSC
)
1178 ixgbe_check_lsc(adapter
);
1180 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
1181 ixgbe_check_fan_failure(adapter
, eicr
);
1183 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
1184 ixgbe_check_sfp_event(adapter
, eicr
);
1186 /* Handle Flow Director Full threshold interrupt */
1187 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
1189 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_FLOW_DIR
);
1190 /* Disable transmits before FDIR Re-initialization */
1191 netif_tx_stop_all_queues(netdev
);
1192 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1193 struct ixgbe_ring
*tx_ring
=
1194 &adapter
->tx_ring
[i
];
1195 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE
,
1196 &tx_ring
->reinit_state
))
1197 schedule_work(&adapter
->fdir_reinit_task
);
1201 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1202 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_OTHER
);
1207 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
1212 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1213 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1214 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1216 mask
= (qmask
& 0xFFFFFFFF);
1217 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(0), mask
);
1218 mask
= (qmask
>> 32);
1219 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS_EX(1), mask
);
1221 /* skip the flush */
1224 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
1229 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1230 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1231 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, mask
);
1233 mask
= (qmask
& 0xFFFFFFFF);
1234 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), mask
);
1235 mask
= (qmask
>> 32);
1236 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), mask
);
1238 /* skip the flush */
1241 static irqreturn_t
ixgbe_msix_clean_tx(int irq
, void *data
)
1243 struct ixgbe_q_vector
*q_vector
= data
;
1244 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1245 struct ixgbe_ring
*tx_ring
;
1248 if (!q_vector
->txr_count
)
1251 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1252 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1253 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1254 tx_ring
->total_bytes
= 0;
1255 tx_ring
->total_packets
= 0;
1256 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1260 /* disable interrupts on this vector only */
1261 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1262 napi_schedule(&q_vector
->napi
);
1268 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1270 * @data: pointer to our q_vector struct for this interrupt vector
1272 static irqreturn_t
ixgbe_msix_clean_rx(int irq
, void *data
)
1274 struct ixgbe_q_vector
*q_vector
= data
;
1275 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1276 struct ixgbe_ring
*rx_ring
;
1280 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1281 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1282 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1283 rx_ring
->total_bytes
= 0;
1284 rx_ring
->total_packets
= 0;
1285 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1289 if (!q_vector
->rxr_count
)
1292 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1293 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1294 /* disable interrupts on this vector only */
1295 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1296 napi_schedule(&q_vector
->napi
);
1301 static irqreturn_t
ixgbe_msix_clean_many(int irq
, void *data
)
1303 struct ixgbe_q_vector
*q_vector
= data
;
1304 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1305 struct ixgbe_ring
*ring
;
1309 if (!q_vector
->txr_count
&& !q_vector
->rxr_count
)
1312 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1313 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1314 ring
= &(adapter
->tx_ring
[r_idx
]);
1315 ring
->total_bytes
= 0;
1316 ring
->total_packets
= 0;
1317 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1321 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1322 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1323 ring
= &(adapter
->rx_ring
[r_idx
]);
1324 ring
->total_bytes
= 0;
1325 ring
->total_packets
= 0;
1326 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1330 /* disable interrupts on this vector only */
1331 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1332 napi_schedule(&q_vector
->napi
);
1338 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1339 * @napi: napi struct with our devices info in it
1340 * @budget: amount of work driver is allowed to do this pass, in packets
1342 * This function is optimized for cleaning one queue only on a single
1345 static int ixgbe_clean_rxonly(struct napi_struct
*napi
, int budget
)
1347 struct ixgbe_q_vector
*q_vector
=
1348 container_of(napi
, struct ixgbe_q_vector
, napi
);
1349 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1350 struct ixgbe_ring
*rx_ring
= NULL
;
1354 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1355 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1356 #ifdef CONFIG_IXGBE_DCA
1357 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1358 ixgbe_update_rx_dca(adapter
, rx_ring
);
1361 ixgbe_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
1363 /* If all Rx work done, exit the polling mode */
1364 if (work_done
< budget
) {
1365 napi_complete(napi
);
1366 if (adapter
->rx_itr_setting
& 1)
1367 ixgbe_set_itr_msix(q_vector
);
1368 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1369 ixgbe_irq_enable_queues(adapter
,
1370 ((u64
)1 << q_vector
->v_idx
));
1377 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
1378 * @napi: napi struct with our devices info in it
1379 * @budget: amount of work driver is allowed to do this pass, in packets
1381 * This function will clean more than one rx queue associated with a
1384 static int ixgbe_clean_rxtx_many(struct napi_struct
*napi
, int budget
)
1386 struct ixgbe_q_vector
*q_vector
=
1387 container_of(napi
, struct ixgbe_q_vector
, napi
);
1388 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1389 struct ixgbe_ring
*ring
= NULL
;
1390 int work_done
= 0, i
;
1392 bool tx_clean_complete
= true;
1394 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1395 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1396 ring
= &(adapter
->tx_ring
[r_idx
]);
1397 #ifdef CONFIG_IXGBE_DCA
1398 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1399 ixgbe_update_tx_dca(adapter
, ring
);
1401 tx_clean_complete
&= ixgbe_clean_tx_irq(q_vector
, ring
);
1402 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1406 /* attempt to distribute budget to each queue fairly, but don't allow
1407 * the budget to go below 1 because we'll exit polling */
1408 budget
/= (q_vector
->rxr_count
?: 1);
1409 budget
= max(budget
, 1);
1410 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1411 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1412 ring
= &(adapter
->rx_ring
[r_idx
]);
1413 #ifdef CONFIG_IXGBE_DCA
1414 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1415 ixgbe_update_rx_dca(adapter
, ring
);
1417 ixgbe_clean_rx_irq(q_vector
, ring
, &work_done
, budget
);
1418 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1422 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1423 ring
= &(adapter
->rx_ring
[r_idx
]);
1424 /* If all Rx work done, exit the polling mode */
1425 if (work_done
< budget
) {
1426 napi_complete(napi
);
1427 if (adapter
->rx_itr_setting
& 1)
1428 ixgbe_set_itr_msix(q_vector
);
1429 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1430 ixgbe_irq_enable_queues(adapter
,
1431 ((u64
)1 << q_vector
->v_idx
));
1439 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1440 * @napi: napi struct with our devices info in it
1441 * @budget: amount of work driver is allowed to do this pass, in packets
1443 * This function is optimized for cleaning one queue only on a single
1446 static int ixgbe_clean_txonly(struct napi_struct
*napi
, int budget
)
1448 struct ixgbe_q_vector
*q_vector
=
1449 container_of(napi
, struct ixgbe_q_vector
, napi
);
1450 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1451 struct ixgbe_ring
*tx_ring
= NULL
;
1455 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1456 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1457 #ifdef CONFIG_IXGBE_DCA
1458 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1459 ixgbe_update_tx_dca(adapter
, tx_ring
);
1462 if (!ixgbe_clean_tx_irq(q_vector
, tx_ring
))
1465 /* If all Tx work done, exit the polling mode */
1466 if (work_done
< budget
) {
1467 napi_complete(napi
);
1468 if (adapter
->tx_itr_setting
& 1)
1469 ixgbe_set_itr_msix(q_vector
);
1470 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1471 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
1477 static inline void map_vector_to_rxq(struct ixgbe_adapter
*a
, int v_idx
,
1480 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1482 set_bit(r_idx
, q_vector
->rxr_idx
);
1483 q_vector
->rxr_count
++;
1486 static inline void map_vector_to_txq(struct ixgbe_adapter
*a
, int v_idx
,
1489 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1491 set_bit(t_idx
, q_vector
->txr_idx
);
1492 q_vector
->txr_count
++;
1496 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1497 * @adapter: board private structure to initialize
1498 * @vectors: allotted vector count for descriptor rings
1500 * This function maps descriptor rings to the queue-specific vectors
1501 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1502 * one vector per ring/queue, but on a constrained vector budget, we
1503 * group the rings as "efficiently" as possible. You would add new
1504 * mapping configurations in here.
1506 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter
*adapter
,
1510 int rxr_idx
= 0, txr_idx
= 0;
1511 int rxr_remaining
= adapter
->num_rx_queues
;
1512 int txr_remaining
= adapter
->num_tx_queues
;
1517 /* No mapping required if MSI-X is disabled. */
1518 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
1522 * The ideal configuration...
1523 * We have enough vectors to map one per queue.
1525 if (vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1526 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1527 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1529 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1530 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1536 * If we don't have enough vectors for a 1-to-1
1537 * mapping, we'll have to group them so there are
1538 * multiple queues per vector.
1540 /* Re-adjusting *qpv takes care of the remainder. */
1541 for (i
= v_start
; i
< vectors
; i
++) {
1542 rqpv
= DIV_ROUND_UP(rxr_remaining
, vectors
- i
);
1543 for (j
= 0; j
< rqpv
; j
++) {
1544 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1549 for (i
= v_start
; i
< vectors
; i
++) {
1550 tqpv
= DIV_ROUND_UP(txr_remaining
, vectors
- i
);
1551 for (j
= 0; j
< tqpv
; j
++) {
1552 map_vector_to_txq(adapter
, i
, txr_idx
);
1563 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1564 * @adapter: board private structure
1566 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1567 * interrupts from the kernel.
1569 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
1571 struct net_device
*netdev
= adapter
->netdev
;
1572 irqreturn_t (*handler
)(int, void *);
1573 int i
, vector
, q_vectors
, err
;
1576 /* Decrement for Other and TCP Timer vectors */
1577 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1579 /* Map the Tx/Rx rings to the vectors we were allotted. */
1580 err
= ixgbe_map_rings_to_vectors(adapter
, q_vectors
);
1584 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1585 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1586 &ixgbe_msix_clean_many)
1587 for (vector
= 0; vector
< q_vectors
; vector
++) {
1588 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1590 if(handler
== &ixgbe_msix_clean_rx
) {
1591 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1592 netdev
->name
, "rx", ri
++);
1594 else if(handler
== &ixgbe_msix_clean_tx
) {
1595 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1596 netdev
->name
, "tx", ti
++);
1599 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1600 netdev
->name
, "TxRx", vector
);
1602 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1603 handler
, 0, adapter
->name
[vector
],
1604 adapter
->q_vector
[vector
]);
1607 "request_irq failed for MSIX interrupt "
1608 "Error: %d\n", err
);
1609 goto free_queue_irqs
;
1613 sprintf(adapter
->name
[vector
], "%s:lsc", netdev
->name
);
1614 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1615 &ixgbe_msix_lsc
, 0, adapter
->name
[vector
], netdev
);
1618 "request_irq for msix_lsc failed: %d\n", err
);
1619 goto free_queue_irqs
;
1625 for (i
= vector
- 1; i
>= 0; i
--)
1626 free_irq(adapter
->msix_entries
[--vector
].vector
,
1627 adapter
->q_vector
[i
]);
1628 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
1629 pci_disable_msix(adapter
->pdev
);
1630 kfree(adapter
->msix_entries
);
1631 adapter
->msix_entries
= NULL
;
1636 static void ixgbe_set_itr(struct ixgbe_adapter
*adapter
)
1638 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1640 u32 new_itr
= q_vector
->eitr
;
1641 struct ixgbe_ring
*rx_ring
= &adapter
->rx_ring
[0];
1642 struct ixgbe_ring
*tx_ring
= &adapter
->tx_ring
[0];
1644 q_vector
->tx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1646 tx_ring
->total_packets
,
1647 tx_ring
->total_bytes
);
1648 q_vector
->rx_itr
= ixgbe_update_itr(adapter
, new_itr
,
1650 rx_ring
->total_packets
,
1651 rx_ring
->total_bytes
);
1653 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
1655 switch (current_itr
) {
1656 /* counts and packets in update_itr are dependent on these numbers */
1657 case lowest_latency
:
1661 new_itr
= 20000; /* aka hwitr = ~200 */
1670 if (new_itr
!= q_vector
->eitr
) {
1671 /* do an exponential smoothing */
1672 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
1674 /* save the algorithm value here, not the smoothed one */
1675 q_vector
->eitr
= new_itr
;
1677 ixgbe_write_eitr(q_vector
);
1684 * ixgbe_irq_enable - Enable default interrupt generation settings
1685 * @adapter: board private structure
1687 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
)
1691 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1692 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
1693 mask
|= IXGBE_EIMS_GPI_SDP1
;
1694 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
1695 mask
|= IXGBE_EIMS_ECC
;
1696 mask
|= IXGBE_EIMS_GPI_SDP1
;
1697 mask
|= IXGBE_EIMS_GPI_SDP2
;
1699 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
1700 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
1701 mask
|= IXGBE_EIMS_FLOW_DIR
;
1703 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1704 ixgbe_irq_enable_queues(adapter
, ~0);
1705 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1709 * ixgbe_intr - legacy mode Interrupt Handler
1710 * @irq: interrupt number
1711 * @data: pointer to a network interface device structure
1713 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
1715 struct net_device
*netdev
= data
;
1716 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1717 struct ixgbe_hw
*hw
= &adapter
->hw
;
1718 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
1722 * Workaround for silicon errata. Mask the interrupts
1723 * before the read of EICR.
1725 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
1727 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1728 * therefore no explict interrupt disable is necessary */
1729 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
1731 /* shared interrupt alert!
1732 * make sure interrupts are enabled because the read will
1733 * have disabled interrupts due to EIAM */
1734 ixgbe_irq_enable(adapter
);
1735 return IRQ_NONE
; /* Not our interrupt */
1738 if (eicr
& IXGBE_EICR_LSC
)
1739 ixgbe_check_lsc(adapter
);
1741 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
1742 ixgbe_check_sfp_event(adapter
, eicr
);
1744 ixgbe_check_fan_failure(adapter
, eicr
);
1746 if (napi_schedule_prep(&(q_vector
->napi
))) {
1747 adapter
->tx_ring
[0].total_packets
= 0;
1748 adapter
->tx_ring
[0].total_bytes
= 0;
1749 adapter
->rx_ring
[0].total_packets
= 0;
1750 adapter
->rx_ring
[0].total_bytes
= 0;
1751 /* would disable interrupts here but EIAM disabled it */
1752 __napi_schedule(&(q_vector
->napi
));
1758 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter
*adapter
)
1760 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1762 for (i
= 0; i
< q_vectors
; i
++) {
1763 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
1764 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1765 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1766 q_vector
->rxr_count
= 0;
1767 q_vector
->txr_count
= 0;
1772 * ixgbe_request_irq - initialize interrupts
1773 * @adapter: board private structure
1775 * Attempts to configure interrupts using the best available
1776 * capabilities of the hardware and kernel.
1778 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
1780 struct net_device
*netdev
= adapter
->netdev
;
1783 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1784 err
= ixgbe_request_msix_irqs(adapter
);
1785 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
1786 err
= request_irq(adapter
->pdev
->irq
, &ixgbe_intr
, 0,
1787 netdev
->name
, netdev
);
1789 err
= request_irq(adapter
->pdev
->irq
, &ixgbe_intr
, IRQF_SHARED
,
1790 netdev
->name
, netdev
);
1794 DPRINTK(PROBE
, ERR
, "request_irq failed, Error %d\n", err
);
1799 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
1801 struct net_device
*netdev
= adapter
->netdev
;
1803 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1806 q_vectors
= adapter
->num_msix_vectors
;
1809 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1812 for (; i
>= 0; i
--) {
1813 free_irq(adapter
->msix_entries
[i
].vector
,
1814 adapter
->q_vector
[i
]);
1817 ixgbe_reset_q_vectors(adapter
);
1819 free_irq(adapter
->pdev
->irq
, netdev
);
1824 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1825 * @adapter: board private structure
1827 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
1829 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1830 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
1832 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
1833 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
1834 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
1836 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1837 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1839 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1840 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1842 synchronize_irq(adapter
->pdev
->irq
);
1847 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1850 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
1852 struct ixgbe_hw
*hw
= &adapter
->hw
;
1854 IXGBE_WRITE_REG(hw
, IXGBE_EITR(0),
1855 EITR_INTS_PER_SEC_TO_REG(adapter
->rx_eitr_param
));
1857 ixgbe_set_ivar(adapter
, 0, 0, 0);
1858 ixgbe_set_ivar(adapter
, 1, 0, 0);
1860 map_vector_to_rxq(adapter
, 0, 0);
1861 map_vector_to_txq(adapter
, 0, 0);
1863 DPRINTK(HW
, INFO
, "Legacy interrupt IVAR setup done\n");
1867 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1868 * @adapter: board private structure
1870 * Configure the Tx unit of the MAC after a reset.
1872 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
1875 struct ixgbe_hw
*hw
= &adapter
->hw
;
1876 u32 i
, j
, tdlen
, txctrl
;
1878 /* Setup the HW Tx Head and Tail descriptor pointers */
1879 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1880 struct ixgbe_ring
*ring
= &adapter
->tx_ring
[i
];
1883 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1884 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(j
),
1885 (tdba
& DMA_BIT_MASK(32)));
1886 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(j
), (tdba
>> 32));
1887 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(j
), tdlen
);
1888 IXGBE_WRITE_REG(hw
, IXGBE_TDH(j
), 0);
1889 IXGBE_WRITE_REG(hw
, IXGBE_TDT(j
), 0);
1890 adapter
->tx_ring
[i
].head
= IXGBE_TDH(j
);
1891 adapter
->tx_ring
[i
].tail
= IXGBE_TDT(j
);
1893 * Disable Tx Head Writeback RO bit, since this hoses
1894 * bookkeeping if things aren't delivered in order.
1896 switch (hw
->mac
.type
) {
1897 case ixgbe_mac_82598EB
:
1898 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(j
));
1900 case ixgbe_mac_82599EB
:
1902 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL_82599(j
));
1905 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1906 switch (hw
->mac
.type
) {
1907 case ixgbe_mac_82598EB
:
1908 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(j
), txctrl
);
1910 case ixgbe_mac_82599EB
:
1912 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL_82599(j
), txctrl
);
1916 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
1917 /* We enable 8 traffic classes, DCB only */
1918 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
1919 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, (IXGBE_MTQC_RT_ENA
|
1920 IXGBE_MTQC_8TC_8TQ
));
1924 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1926 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
1927 struct ixgbe_ring
*rx_ring
)
1931 struct ixgbe_ring_feature
*feature
= adapter
->ring_feature
;
1933 index
= rx_ring
->reg_idx
;
1934 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
1936 mask
= (unsigned long) feature
[RING_F_RSS
].mask
;
1937 index
= index
& mask
;
1939 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(index
));
1941 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
1942 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
1944 srrctl
|= (IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1945 IXGBE_SRRCTL_BSIZEHDR_MASK
;
1947 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
1948 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1949 srrctl
|= IXGBE_MAX_RXBUFFER
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1951 srrctl
|= (PAGE_SIZE
/ 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1953 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1955 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
1956 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1957 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1960 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(index
), srrctl
);
1963 static u32
ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
1968 if (!(adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
1971 mask
= adapter
->flags
& (IXGBE_FLAG_RSS_ENABLED
1972 #ifdef CONFIG_IXGBE_DCB
1973 | IXGBE_FLAG_DCB_ENABLED
1978 case (IXGBE_FLAG_RSS_ENABLED
):
1979 mrqc
= IXGBE_MRQC_RSSEN
;
1981 #ifdef CONFIG_IXGBE_DCB
1982 case (IXGBE_FLAG_DCB_ENABLED
):
1983 mrqc
= IXGBE_MRQC_RT8TCEN
;
1985 #endif /* CONFIG_IXGBE_DCB */
1994 * ixgbe_configure_rscctl - enable RSC for the indicated ring
1995 * @adapter: address of board private structure
1996 * @index: index of ring to set
1997 * @rx_buf_len: rx buffer length
1999 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
, int index
,
2002 struct ixgbe_ring
*rx_ring
;
2003 struct ixgbe_hw
*hw
= &adapter
->hw
;
2007 rx_ring
= &adapter
->rx_ring
[index
];
2008 j
= rx_ring
->reg_idx
;
2009 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(j
));
2010 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
2012 * we must limit the number of descriptors so that the
2013 * total size of max desc * buf_len is not greater
2016 if (rx_ring
->flags
& IXGBE_RING_RX_PS_ENABLED
) {
2017 #if (MAX_SKB_FRAGS > 16)
2018 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2019 #elif (MAX_SKB_FRAGS > 8)
2020 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2021 #elif (MAX_SKB_FRAGS > 4)
2022 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2024 rscctrl
|= IXGBE_RSCCTL_MAXDESC_1
;
2027 if (rx_buf_len
< IXGBE_RXBUFFER_4096
)
2028 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2029 else if (rx_buf_len
< IXGBE_RXBUFFER_8192
)
2030 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2032 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2034 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(j
), rscctrl
);
2038 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
2039 * @adapter: board private structure
2041 * Configure the Rx unit of the MAC after a reset.
2043 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
2046 struct ixgbe_hw
*hw
= &adapter
->hw
;
2047 struct ixgbe_ring
*rx_ring
;
2048 struct net_device
*netdev
= adapter
->netdev
;
2049 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2051 u32 rdlen
, rxctrl
, rxcsum
;
2052 static const u32 seed
[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2053 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2054 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2056 u32 reta
= 0, mrqc
= 0;
2060 /* Decide whether to use packet split mode or not */
2061 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
2063 /* Set the RX buffer length according to the mode */
2064 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
2065 rx_buf_len
= IXGBE_RX_HDR_SIZE
;
2066 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2067 /* PSRTYPE must be initialized in 82599 */
2068 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
2069 IXGBE_PSRTYPE_UDPHDR
|
2070 IXGBE_PSRTYPE_IPV4HDR
|
2071 IXGBE_PSRTYPE_IPV6HDR
|
2072 IXGBE_PSRTYPE_L2HDR
;
2073 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(0), psrtype
);
2076 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
2077 (netdev
->mtu
<= ETH_DATA_LEN
))
2078 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
2080 rx_buf_len
= ALIGN(max_frame
, 1024);
2083 fctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_FCTRL
);
2084 fctrl
|= IXGBE_FCTRL_BAM
;
2085 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
2086 fctrl
|= IXGBE_FCTRL_PMCF
;
2087 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_FCTRL
, fctrl
);
2089 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
2090 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
2091 hlreg0
&= ~IXGBE_HLREG0_JUMBOEN
;
2093 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2095 if (netdev
->features
& NETIF_F_FCOE_MTU
)
2096 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2098 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
2100 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
2101 /* disable receives while setting up the descriptors */
2102 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2103 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
2106 * Setup the HW Rx Head and Tail Descriptor Pointers and
2107 * the Base and Length of the Rx Descriptor Ring
2109 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2110 rx_ring
= &adapter
->rx_ring
[i
];
2111 rdba
= rx_ring
->dma
;
2112 j
= rx_ring
->reg_idx
;
2113 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(j
), (rdba
& DMA_BIT_MASK(32)));
2114 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(j
), (rdba
>> 32));
2115 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(j
), rdlen
);
2116 IXGBE_WRITE_REG(hw
, IXGBE_RDH(j
), 0);
2117 IXGBE_WRITE_REG(hw
, IXGBE_RDT(j
), 0);
2118 rx_ring
->head
= IXGBE_RDH(j
);
2119 rx_ring
->tail
= IXGBE_RDT(j
);
2120 rx_ring
->rx_buf_len
= rx_buf_len
;
2122 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)
2123 rx_ring
->flags
|= IXGBE_RING_RX_PS_ENABLED
;
2125 rx_ring
->flags
&= ~IXGBE_RING_RX_PS_ENABLED
;
2128 if (netdev
->features
& NETIF_F_FCOE_MTU
) {
2129 struct ixgbe_ring_feature
*f
;
2130 f
= &adapter
->ring_feature
[RING_F_FCOE
];
2131 if ((i
>= f
->mask
) && (i
< f
->mask
+ f
->indices
)) {
2132 rx_ring
->flags
&= ~IXGBE_RING_RX_PS_ENABLED
;
2133 if (rx_buf_len
< IXGBE_FCOE_JUMBO_FRAME_SIZE
)
2134 rx_ring
->rx_buf_len
=
2135 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2139 #endif /* IXGBE_FCOE */
2140 ixgbe_configure_srrctl(adapter
, rx_ring
);
2143 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2145 * For VMDq support of different descriptor types or
2146 * buffer sizes through the use of multiple SRRCTL
2147 * registers, RDRXCTL.MVMEN must be set to 1
2149 * also, the manual doesn't mention it clearly but DCA hints
2150 * will only use queue 0's tags unless this bit is set. Side
2151 * effects of setting this bit are only that SRRCTL must be
2152 * fully programmed [0..15]
2154 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2155 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
2156 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2159 /* Program MRQC for the distribution of queues */
2160 mrqc
= ixgbe_setup_mrqc(adapter
);
2162 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
2163 /* Fill out redirection table */
2164 for (i
= 0, j
= 0; i
< 128; i
++, j
++) {
2165 if (j
== adapter
->ring_feature
[RING_F_RSS
].indices
)
2167 /* reta = 4-byte sliding window of
2168 * 0x00..(indices-1)(indices-1)00..etc. */
2169 reta
= (reta
<< 8) | (j
* 0x11);
2171 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
2174 /* Fill out hash function seeds */
2175 for (i
= 0; i
< 10; i
++)
2176 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), seed
[i
]);
2178 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2179 mrqc
|= IXGBE_MRQC_RSSEN
;
2180 /* Perform hash on these packet types */
2181 mrqc
|= IXGBE_MRQC_RSS_FIELD_IPV4
2182 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2183 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2184 | IXGBE_MRQC_RSS_FIELD_IPV6
2185 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2186 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
2188 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
2190 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
2192 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
||
2193 adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
) {
2194 /* Disable indicating checksum in descriptor, enables
2196 rxcsum
|= IXGBE_RXCSUM_PCSD
;
2198 if (!(rxcsum
& IXGBE_RXCSUM_PCSD
)) {
2199 /* Enable IPv4 payload checksum for UDP fragments
2200 * if PCSD is not set */
2201 rxcsum
|= IXGBE_RXCSUM_IPPCSE
;
2204 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
2206 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2207 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2208 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
2209 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
2210 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2213 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
2214 /* Enable 82599 HW-RSC */
2215 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2216 ixgbe_configure_rscctl(adapter
, i
, rx_buf_len
);
2218 /* Disable RSC for ACK packets */
2219 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
2220 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
2224 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
2226 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2227 struct ixgbe_hw
*hw
= &adapter
->hw
;
2229 /* add VID to filter table */
2230 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, 0, true);
2233 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
2235 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2236 struct ixgbe_hw
*hw
= &adapter
->hw
;
2238 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2239 ixgbe_irq_disable(adapter
);
2241 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
2243 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2244 ixgbe_irq_enable(adapter
);
2246 /* remove VID from filter table */
2247 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, 0, false);
2250 static void ixgbe_vlan_rx_register(struct net_device
*netdev
,
2251 struct vlan_group
*grp
)
2253 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2257 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2258 ixgbe_irq_disable(adapter
);
2259 adapter
->vlgrp
= grp
;
2262 * For a DCB driver, always enable VLAN tag stripping so we can
2263 * still receive traffic from a DCB-enabled host even if we're
2266 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_VLNCTRL
);
2267 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
2268 ctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
2269 ctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2270 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VLNCTRL
, ctrl
);
2271 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
2272 ctrl
|= IXGBE_VLNCTRL_VFE
;
2273 /* enable VLAN tag insert/strip */
2274 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_VLNCTRL
);
2275 ctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2276 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VLNCTRL
, ctrl
);
2277 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2278 j
= adapter
->rx_ring
[i
].reg_idx
;
2279 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_RXDCTL(j
));
2280 ctrl
|= IXGBE_RXDCTL_VME
;
2281 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_RXDCTL(j
), ctrl
);
2284 ixgbe_vlan_rx_add_vid(netdev
, 0);
2286 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2287 ixgbe_irq_enable(adapter
);
2290 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
2292 ixgbe_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2294 if (adapter
->vlgrp
) {
2296 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2297 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
2299 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
2304 static u8
*ixgbe_addr_list_itr(struct ixgbe_hw
*hw
, u8
**mc_addr_ptr
, u32
*vmdq
)
2306 struct dev_mc_list
*mc_ptr
;
2307 u8
*addr
= *mc_addr_ptr
;
2310 mc_ptr
= container_of(addr
, struct dev_mc_list
, dmi_addr
[0]);
2312 *mc_addr_ptr
= mc_ptr
->next
->dmi_addr
;
2314 *mc_addr_ptr
= NULL
;
2320 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
2321 * @netdev: network interface device structure
2323 * The set_rx_method entry point is called whenever the unicast/multicast
2324 * address list or the network interface flags are updated. This routine is
2325 * responsible for configuring the hardware for proper unicast, multicast and
2328 static void ixgbe_set_rx_mode(struct net_device
*netdev
)
2330 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2331 struct ixgbe_hw
*hw
= &adapter
->hw
;
2333 u8
*addr_list
= NULL
;
2336 /* Check for Promiscuous and All Multicast modes */
2338 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
2339 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2341 if (netdev
->flags
& IFF_PROMISC
) {
2342 hw
->addr_ctrl
.user_set_promisc
= 1;
2343 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2344 vlnctrl
&= ~IXGBE_VLNCTRL_VFE
;
2346 if (netdev
->flags
& IFF_ALLMULTI
) {
2347 fctrl
|= IXGBE_FCTRL_MPE
;
2348 fctrl
&= ~IXGBE_FCTRL_UPE
;
2350 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
2352 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
2353 hw
->addr_ctrl
.user_set_promisc
= 0;
2356 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
2357 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2359 /* reprogram secondary unicast list */
2360 hw
->mac
.ops
.update_uc_addr_list(hw
, &netdev
->uc
.list
);
2362 /* reprogram multicast list */
2363 addr_count
= netdev
->mc_count
;
2365 addr_list
= netdev
->mc_list
->dmi_addr
;
2366 hw
->mac
.ops
.update_mc_addr_list(hw
, addr_list
, addr_count
,
2367 ixgbe_addr_list_itr
);
2370 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
2373 struct ixgbe_q_vector
*q_vector
;
2374 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2376 /* legacy and MSI only use one vector */
2377 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2380 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2381 struct napi_struct
*napi
;
2382 q_vector
= adapter
->q_vector
[q_idx
];
2383 napi
= &q_vector
->napi
;
2384 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2385 if (!q_vector
->rxr_count
|| !q_vector
->txr_count
) {
2386 if (q_vector
->txr_count
== 1)
2387 napi
->poll
= &ixgbe_clean_txonly
;
2388 else if (q_vector
->rxr_count
== 1)
2389 napi
->poll
= &ixgbe_clean_rxonly
;
2397 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
2400 struct ixgbe_q_vector
*q_vector
;
2401 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2403 /* legacy and MSI only use one vector */
2404 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2407 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
2408 q_vector
= adapter
->q_vector
[q_idx
];
2409 napi_disable(&q_vector
->napi
);
2413 #ifdef CONFIG_IXGBE_DCB
2415 * ixgbe_configure_dcb - Configure DCB hardware
2416 * @adapter: ixgbe adapter struct
2418 * This is called by the driver on open to configure the DCB hardware.
2419 * This is also called by the gennetlink interface when reconfiguring
2422 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
2424 struct ixgbe_hw
*hw
= &adapter
->hw
;
2425 u32 txdctl
, vlnctrl
;
2428 ixgbe_dcb_check_config(&adapter
->dcb_cfg
);
2429 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_TX_CONFIG
);
2430 ixgbe_dcb_calculate_tc_credits(&adapter
->dcb_cfg
, DCB_RX_CONFIG
);
2432 /* reconfigure the hardware */
2433 ixgbe_dcb_hw_config(&adapter
->hw
, &adapter
->dcb_cfg
);
2435 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2436 j
= adapter
->tx_ring
[i
].reg_idx
;
2437 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2438 /* PThresh workaround for Tx hang with DFP enabled. */
2440 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2442 /* Enable VLAN tag insert/strip */
2443 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
2444 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2445 vlnctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
2446 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2447 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2448 } else if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2449 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
2450 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
2451 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
2452 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2453 j
= adapter
->rx_ring
[i
].reg_idx
;
2454 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2455 vlnctrl
|= IXGBE_RXDCTL_VME
;
2456 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
2459 hw
->mac
.ops
.set_vfta(&adapter
->hw
, 0, 0, true);
2463 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
2465 struct net_device
*netdev
= adapter
->netdev
;
2466 struct ixgbe_hw
*hw
= &adapter
->hw
;
2469 ixgbe_set_rx_mode(netdev
);
2471 ixgbe_restore_vlan(adapter
);
2472 #ifdef CONFIG_IXGBE_DCB
2473 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
2474 netif_set_gso_max_size(netdev
, 32768);
2475 ixgbe_configure_dcb(adapter
);
2477 netif_set_gso_max_size(netdev
, 65536);
2480 netif_set_gso_max_size(netdev
, 65536);
2484 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
2485 ixgbe_configure_fcoe(adapter
);
2487 #endif /* IXGBE_FCOE */
2488 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2489 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2490 adapter
->tx_ring
[i
].atr_sample_rate
=
2491 adapter
->atr_sample_rate
;
2492 ixgbe_init_fdir_signature_82599(hw
, adapter
->fdir_pballoc
);
2493 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
2494 ixgbe_init_fdir_perfect_82599(hw
, adapter
->fdir_pballoc
);
2497 ixgbe_configure_tx(adapter
);
2498 ixgbe_configure_rx(adapter
);
2499 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2500 ixgbe_alloc_rx_buffers(adapter
, &adapter
->rx_ring
[i
],
2501 (adapter
->rx_ring
[i
].count
- 1));
2504 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2506 switch (hw
->phy
.type
) {
2507 case ixgbe_phy_sfp_avago
:
2508 case ixgbe_phy_sfp_ftl
:
2509 case ixgbe_phy_sfp_intel
:
2510 case ixgbe_phy_sfp_unknown
:
2511 case ixgbe_phy_tw_tyco
:
2512 case ixgbe_phy_tw_unknown
:
2520 * ixgbe_sfp_link_config - set up SFP+ link
2521 * @adapter: pointer to private adapter struct
2523 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
2525 struct ixgbe_hw
*hw
= &adapter
->hw
;
2527 if (hw
->phy
.multispeed_fiber
) {
2529 * In multispeed fiber setups, the device may not have
2530 * had a physical connection when the driver loaded.
2531 * If that's the case, the initial link configuration
2532 * couldn't get the MAC into 10G or 1G mode, so we'll
2533 * never have a link status change interrupt fire.
2534 * We need to try and force an autonegotiation
2535 * session, then bring up link.
2537 hw
->mac
.ops
.setup_sfp(hw
);
2538 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
2539 schedule_work(&adapter
->multispeed_fiber_task
);
2542 * Direct Attach Cu and non-multispeed fiber modules
2543 * still need to be configured properly prior to
2546 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_MOD_TASK
))
2547 schedule_work(&adapter
->sfp_config_module_task
);
2552 * ixgbe_non_sfp_link_config - set up non-SFP+ link
2553 * @hw: pointer to private hardware struct
2555 * Returns 0 on success, negative on failure
2557 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
2560 bool negotiation
, link_up
= false;
2561 u32 ret
= IXGBE_ERR_LINK_SETUP
;
2563 if (hw
->mac
.ops
.check_link
)
2564 ret
= hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
2569 if (hw
->mac
.ops
.get_link_capabilities
)
2570 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
2574 if (hw
->mac
.ops
.setup_link
)
2575 ret
= hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, link_up
);
2580 #define IXGBE_MAX_RX_DESC_POLL 10
2581 static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
2584 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
2587 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
2588 if (IXGBE_READ_REG(&adapter
->hw
,
2589 IXGBE_RXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
2594 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
2595 DPRINTK(DRV
, ERR
, "RXDCTL.ENABLE on Rx queue %d "
2596 "not set within the polling period\n", rxr
);
2598 ixgbe_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
2599 (adapter
->rx_ring
[rxr
].count
- 1));
2602 static int ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
2604 struct net_device
*netdev
= adapter
->netdev
;
2605 struct ixgbe_hw
*hw
= &adapter
->hw
;
2607 int num_rx_rings
= adapter
->num_rx_queues
;
2609 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2610 u32 txdctl
, rxdctl
, mhadd
;
2614 ixgbe_get_hw_control(adapter
);
2616 if ((adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) ||
2617 (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)) {
2618 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2619 gpie
= (IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_EIAME
|
2620 IXGBE_GPIE_PBA_SUPPORT
| IXGBE_GPIE_OCD
);
2625 /* XXX: to interrupt immediately for EICS writes, enable this */
2626 /* gpie |= IXGBE_GPIE_EIMEN; */
2627 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2630 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
2631 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2632 * specifically only auto mask tx and rx interrupts */
2633 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
2636 /* Enable fan failure interrupt if media type is copper */
2637 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
2638 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2639 gpie
|= IXGBE_SDP1_GPIEN
;
2640 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2643 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2644 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
2645 gpie
|= IXGBE_SDP1_GPIEN
;
2646 gpie
|= IXGBE_SDP2_GPIEN
;
2647 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
2651 /* adjust max frame to be able to do baby jumbo for FCoE */
2652 if ((netdev
->features
& NETIF_F_FCOE_MTU
) &&
2653 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
2654 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2656 #endif /* IXGBE_FCOE */
2657 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
2658 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
2659 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
2660 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
2662 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
2665 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2666 j
= adapter
->tx_ring
[i
].reg_idx
;
2667 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2668 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2669 txdctl
|= (8 << 16);
2670 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2673 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
2674 /* DMATXCTL.EN must be set after all Tx queue config is done */
2675 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
2676 dmatxctl
|= IXGBE_DMATXCTL_TE
;
2677 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
2679 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2680 j
= adapter
->tx_ring
[i
].reg_idx
;
2681 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2682 txdctl
|= IXGBE_TXDCTL_ENABLE
;
2683 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
), txdctl
);
2686 for (i
= 0; i
< num_rx_rings
; i
++) {
2687 j
= adapter
->rx_ring
[i
].reg_idx
;
2688 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
2689 /* enable PTHRESH=32 descriptors (half the internal cache)
2690 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2691 * this also removes a pesky rx_no_buffer_count increment */
2693 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
2694 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), rxdctl
);
2695 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2696 ixgbe_rx_desc_queue_enable(adapter
, i
);
2698 /* enable all receives */
2699 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2700 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2701 rxdctl
|= (IXGBE_RXCTRL_DMBYPS
| IXGBE_RXCTRL_RXEN
);
2703 rxdctl
|= IXGBE_RXCTRL_RXEN
;
2704 hw
->mac
.ops
.enable_rx_dma(hw
, rxdctl
);
2706 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
2707 ixgbe_configure_msix(adapter
);
2709 ixgbe_configure_msi_and_legacy(adapter
);
2711 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
2712 ixgbe_napi_enable_all(adapter
);
2714 /* clear any pending interrupts, may auto mask */
2715 IXGBE_READ_REG(hw
, IXGBE_EICR
);
2717 ixgbe_irq_enable(adapter
);
2720 * If this adapter has a fan, check to see if we had a failure
2721 * before we enabled the interrupt.
2723 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
2724 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2725 if (esdp
& IXGBE_ESDP_SDP1
)
2727 "Fan has stopped, replace the adapter\n");
2731 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2732 * arrived before interrupts were enabled but after probe. Such
2733 * devices wouldn't have their type identified yet. We need to
2734 * kick off the SFP+ module setup first, then try to bring up link.
2735 * If we're not hot-pluggable SFP+, we just need to configure link
2738 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
2739 err
= hw
->phy
.ops
.identify(hw
);
2740 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
2742 * Take the device down and schedule the sfp tasklet
2743 * which will unregister_netdev and log it.
2745 ixgbe_down(adapter
);
2746 schedule_work(&adapter
->sfp_config_module_task
);
2751 if (ixgbe_is_sfp(hw
)) {
2752 ixgbe_sfp_link_config(adapter
);
2754 err
= ixgbe_non_sfp_link_config(hw
);
2756 DPRINTK(PROBE
, ERR
, "link_config FAILED %d\n", err
);
2759 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2760 set_bit(__IXGBE_FDIR_INIT_DONE
,
2761 &(adapter
->tx_ring
[i
].reinit_state
));
2763 /* enable transmits */
2764 netif_tx_start_all_queues(netdev
);
2766 /* bring the link up in the watchdog, this could race with our first
2767 * link up interrupt but shouldn't be a problem */
2768 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
2769 adapter
->link_check_timeout
= jiffies
;
2770 mod_timer(&adapter
->watchdog_timer
, jiffies
);
2774 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
2776 WARN_ON(in_interrupt());
2777 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
2779 ixgbe_down(adapter
);
2781 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
2784 int ixgbe_up(struct ixgbe_adapter
*adapter
)
2786 /* hardware has been reset, we need to reload some things */
2787 ixgbe_configure(adapter
);
2789 return ixgbe_up_complete(adapter
);
2792 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
2794 struct ixgbe_hw
*hw
= &adapter
->hw
;
2797 err
= hw
->mac
.ops
.init_hw(hw
);
2800 case IXGBE_ERR_SFP_NOT_PRESENT
:
2802 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
2803 dev_err(&adapter
->pdev
->dev
, "master disable timed out\n");
2805 case IXGBE_ERR_EEPROM_VERSION
:
2806 /* We are running on a pre-production device, log a warning */
2807 dev_warn(&adapter
->pdev
->dev
, "This device is a pre-production "
2808 "adapter/LOM. Please be aware there may be issues "
2809 "associated with your hardware. If you are "
2810 "experiencing problems please contact your Intel or "
2811 "hardware representative who provided you with this "
2815 dev_err(&adapter
->pdev
->dev
, "Hardware Error: %d\n", err
);
2818 /* reprogram the RAR[0] in case user changed it. */
2819 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0, IXGBE_RAH_AV
);
2823 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2824 * @adapter: board private structure
2825 * @rx_ring: ring to free buffers from
2827 static void ixgbe_clean_rx_ring(struct ixgbe_adapter
*adapter
,
2828 struct ixgbe_ring
*rx_ring
)
2830 struct pci_dev
*pdev
= adapter
->pdev
;
2834 /* Free all the Rx ring sk_buffs */
2836 for (i
= 0; i
< rx_ring
->count
; i
++) {
2837 struct ixgbe_rx_buffer
*rx_buffer_info
;
2839 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
2840 if (rx_buffer_info
->dma
) {
2841 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
2842 rx_ring
->rx_buf_len
,
2843 PCI_DMA_FROMDEVICE
);
2844 rx_buffer_info
->dma
= 0;
2846 if (rx_buffer_info
->skb
) {
2847 struct sk_buff
*skb
= rx_buffer_info
->skb
;
2848 rx_buffer_info
->skb
= NULL
;
2850 struct sk_buff
*this = skb
;
2852 dev_kfree_skb(this);
2855 if (!rx_buffer_info
->page
)
2857 if (rx_buffer_info
->page_dma
) {
2858 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
2859 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
2860 rx_buffer_info
->page_dma
= 0;
2862 put_page(rx_buffer_info
->page
);
2863 rx_buffer_info
->page
= NULL
;
2864 rx_buffer_info
->page_offset
= 0;
2867 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
2868 memset(rx_ring
->rx_buffer_info
, 0, size
);
2870 /* Zero out the descriptor ring */
2871 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2873 rx_ring
->next_to_clean
= 0;
2874 rx_ring
->next_to_use
= 0;
2877 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
2879 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
2883 * ixgbe_clean_tx_ring - Free Tx Buffers
2884 * @adapter: board private structure
2885 * @tx_ring: ring to be cleaned
2887 static void ixgbe_clean_tx_ring(struct ixgbe_adapter
*adapter
,
2888 struct ixgbe_ring
*tx_ring
)
2890 struct ixgbe_tx_buffer
*tx_buffer_info
;
2894 /* Free all the Tx ring sk_buffs */
2896 for (i
= 0; i
< tx_ring
->count
; i
++) {
2897 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2898 ixgbe_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
2901 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
2902 memset(tx_ring
->tx_buffer_info
, 0, size
);
2904 /* Zero out the descriptor ring */
2905 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2907 tx_ring
->next_to_use
= 0;
2908 tx_ring
->next_to_clean
= 0;
2911 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2913 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2917 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2918 * @adapter: board private structure
2920 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
2924 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2925 ixgbe_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2929 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2930 * @adapter: board private structure
2932 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
2936 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2937 ixgbe_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2940 void ixgbe_down(struct ixgbe_adapter
*adapter
)
2942 struct net_device
*netdev
= adapter
->netdev
;
2943 struct ixgbe_hw
*hw
= &adapter
->hw
;
2948 /* signal that we are down to the interrupt handler */
2949 set_bit(__IXGBE_DOWN
, &adapter
->state
);
2951 /* disable receives */
2952 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
2953 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
2955 netif_tx_disable(netdev
);
2957 IXGBE_WRITE_FLUSH(hw
);
2960 netif_tx_stop_all_queues(netdev
);
2962 ixgbe_irq_disable(adapter
);
2964 ixgbe_napi_disable_all(adapter
);
2966 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
2967 del_timer_sync(&adapter
->sfp_timer
);
2968 del_timer_sync(&adapter
->watchdog_timer
);
2969 cancel_work_sync(&adapter
->watchdog_task
);
2971 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
2972 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
2973 cancel_work_sync(&adapter
->fdir_reinit_task
);
2975 /* disable transmits in the hardware now that interrupts are off */
2976 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2977 j
= adapter
->tx_ring
[i
].reg_idx
;
2978 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(j
));
2979 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(j
),
2980 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
2982 /* Disable the Tx DMA engine on 82599 */
2983 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2984 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
2985 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
2986 ~IXGBE_DMATXCTL_TE
));
2988 netif_carrier_off(netdev
);
2990 if (!pci_channel_offline(adapter
->pdev
))
2991 ixgbe_reset(adapter
);
2992 ixgbe_clean_all_tx_rings(adapter
);
2993 ixgbe_clean_all_rx_rings(adapter
);
2995 #ifdef CONFIG_IXGBE_DCA
2996 /* since we reset the hardware DCA settings were cleared */
2997 ixgbe_setup_dca(adapter
);
3002 * ixgbe_poll - NAPI Rx polling callback
3003 * @napi: structure for representing this polling device
3004 * @budget: how many packets driver is allowed to clean
3006 * This function is used for legacy and MSI, NAPI mode
3008 static int ixgbe_poll(struct napi_struct
*napi
, int budget
)
3010 struct ixgbe_q_vector
*q_vector
=
3011 container_of(napi
, struct ixgbe_q_vector
, napi
);
3012 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
3013 int tx_clean_complete
, work_done
= 0;
3015 #ifdef CONFIG_IXGBE_DCA
3016 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
3017 ixgbe_update_tx_dca(adapter
, adapter
->tx_ring
);
3018 ixgbe_update_rx_dca(adapter
, adapter
->rx_ring
);
3022 tx_clean_complete
= ixgbe_clean_tx_irq(q_vector
, adapter
->tx_ring
);
3023 ixgbe_clean_rx_irq(q_vector
, adapter
->rx_ring
, &work_done
, budget
);
3025 if (!tx_clean_complete
)
3028 /* If budget not fully consumed, exit the polling mode */
3029 if (work_done
< budget
) {
3030 napi_complete(napi
);
3031 if (adapter
->rx_itr_setting
& 1)
3032 ixgbe_set_itr(adapter
);
3033 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3034 ixgbe_irq_enable_queues(adapter
, IXGBE_EIMS_RTX_QUEUE
);
3040 * ixgbe_tx_timeout - Respond to a Tx Hang
3041 * @netdev: network interface device structure
3043 static void ixgbe_tx_timeout(struct net_device
*netdev
)
3045 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3047 /* Do the reset outside of interrupt context */
3048 schedule_work(&adapter
->reset_task
);
3051 static void ixgbe_reset_task(struct work_struct
*work
)
3053 struct ixgbe_adapter
*adapter
;
3054 adapter
= container_of(work
, struct ixgbe_adapter
, reset_task
);
3056 /* If we're already down or resetting, just bail */
3057 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
3058 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
3061 adapter
->tx_timeout_count
++;
3063 ixgbe_reinit_locked(adapter
);
3066 #ifdef CONFIG_IXGBE_DCB
3067 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter
*adapter
)
3070 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_DCB
];
3072 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
3076 adapter
->num_rx_queues
= f
->indices
;
3077 adapter
->num_tx_queues
= f
->indices
;
3085 * ixgbe_set_rss_queues: Allocate queues for RSS
3086 * @adapter: board private structure to initialize
3088 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3089 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3092 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter
*adapter
)
3095 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_RSS
];
3097 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3099 adapter
->num_rx_queues
= f
->indices
;
3100 adapter
->num_tx_queues
= f
->indices
;
3110 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3111 * @adapter: board private structure to initialize
3113 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3114 * to the original CPU that initiated the Tx session. This runs in addition
3115 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3116 * Rx load across CPUs using RSS.
3119 static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter
*adapter
)
3122 struct ixgbe_ring_feature
*f_fdir
= &adapter
->ring_feature
[RING_F_FDIR
];
3124 f_fdir
->indices
= min((int)num_online_cpus(), f_fdir
->indices
);
3127 /* Flow Director must have RSS enabled */
3128 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3129 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3130 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)))) {
3131 adapter
->num_tx_queues
= f_fdir
->indices
;
3132 adapter
->num_rx_queues
= f_fdir
->indices
;
3135 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3136 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3143 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3144 * @adapter: board private structure to initialize
3146 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3147 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3148 * rx queues out of the max number of rx queues, instead, it is used as the
3149 * index of the first rx queue used by FCoE.
3152 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter
*adapter
)
3155 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3157 f
->indices
= min((int)num_online_cpus(), f
->indices
);
3158 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3159 adapter
->num_rx_queues
= 1;
3160 adapter
->num_tx_queues
= 1;
3161 #ifdef CONFIG_IXGBE_DCB
3162 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3163 DPRINTK(PROBE
, INFO
, "FCoE enabled with DCB \n");
3164 ixgbe_set_dcb_queues(adapter
);
3167 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3168 DPRINTK(PROBE
, INFO
, "FCoE enabled with RSS \n");
3169 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3170 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3171 ixgbe_set_fdir_queues(adapter
);
3173 ixgbe_set_rss_queues(adapter
);
3175 /* adding FCoE rx rings to the end */
3176 f
->mask
= adapter
->num_rx_queues
;
3177 adapter
->num_rx_queues
+= f
->indices
;
3178 adapter
->num_tx_queues
+= f
->indices
;
3186 #endif /* IXGBE_FCOE */
3188 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3189 * @adapter: board private structure to initialize
3191 * This is the top level queue allocation routine. The order here is very
3192 * important, starting with the "most" number of features turned on at once,
3193 * and ending with the smallest set of features. This way large combinations
3194 * can be allocated if they're turned on, and smaller combinations are the
3195 * fallthrough conditions.
3198 static void ixgbe_set_num_queues(struct ixgbe_adapter
*adapter
)
3201 if (ixgbe_set_fcoe_queues(adapter
))
3204 #endif /* IXGBE_FCOE */
3205 #ifdef CONFIG_IXGBE_DCB
3206 if (ixgbe_set_dcb_queues(adapter
))
3210 if (ixgbe_set_fdir_queues(adapter
))
3213 if (ixgbe_set_rss_queues(adapter
))
3216 /* fallback to base case */
3217 adapter
->num_rx_queues
= 1;
3218 adapter
->num_tx_queues
= 1;
3221 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3222 adapter
->netdev
->real_num_tx_queues
= adapter
->num_tx_queues
;
3225 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter
*adapter
,
3228 int err
, vector_threshold
;
3230 /* We'll want at least 3 (vector_threshold):
3233 * 3) Other (Link Status Change, etc.)
3234 * 4) TCP Timer (optional)
3236 vector_threshold
= MIN_MSIX_COUNT
;
3238 /* The more we get, the more we will assign to Tx/Rx Cleanup
3239 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3240 * Right now, we simply care about how many we'll get; we'll
3241 * set them up later while requesting irq's.
3243 while (vectors
>= vector_threshold
) {
3244 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
3246 if (!err
) /* Success in acquiring all requested vectors. */
3249 vectors
= 0; /* Nasty failure, quit now */
3250 else /* err == number of vectors we should try again with */
3254 if (vectors
< vector_threshold
) {
3255 /* Can't allocate enough MSI-X interrupts? Oh well.
3256 * This just means we'll go with either a single MSI
3257 * vector or fall back to legacy interrupts.
3259 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI-X interrupts\n");
3260 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3261 kfree(adapter
->msix_entries
);
3262 adapter
->msix_entries
= NULL
;
3264 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
; /* Woot! */
3266 * Adjust for only the vectors we'll use, which is minimum
3267 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3268 * vectors we were allocated.
3270 adapter
->num_msix_vectors
= min(vectors
,
3271 adapter
->max_msix_q_vectors
+ NON_Q_VECTORS
);
3276 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
3277 * @adapter: board private structure to initialize
3279 * Cache the descriptor ring offsets for RSS to the assigned rings.
3282 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter
*adapter
)
3287 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3288 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3289 adapter
->rx_ring
[i
].reg_idx
= i
;
3290 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3291 adapter
->tx_ring
[i
].reg_idx
= i
;
3300 #ifdef CONFIG_IXGBE_DCB
3302 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3303 * @adapter: board private structure to initialize
3305 * Cache the descriptor ring offsets for DCB to the assigned rings.
3308 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter
*adapter
)
3312 int dcb_i
= adapter
->ring_feature
[RING_F_DCB
].indices
;
3314 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3315 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3316 /* the number of queues is assumed to be symmetric */
3317 for (i
= 0; i
< dcb_i
; i
++) {
3318 adapter
->rx_ring
[i
].reg_idx
= i
<< 3;
3319 adapter
->tx_ring
[i
].reg_idx
= i
<< 2;
3322 } else if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) {
3325 * Tx TC0 starts at: descriptor queue 0
3326 * Tx TC1 starts at: descriptor queue 32
3327 * Tx TC2 starts at: descriptor queue 64
3328 * Tx TC3 starts at: descriptor queue 80
3329 * Tx TC4 starts at: descriptor queue 96
3330 * Tx TC5 starts at: descriptor queue 104
3331 * Tx TC6 starts at: descriptor queue 112
3332 * Tx TC7 starts at: descriptor queue 120
3334 * Rx TC0-TC7 are offset by 16 queues each
3336 for (i
= 0; i
< 3; i
++) {
3337 adapter
->tx_ring
[i
].reg_idx
= i
<< 5;
3338 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3340 for ( ; i
< 5; i
++) {
3341 adapter
->tx_ring
[i
].reg_idx
=
3343 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3345 for ( ; i
< dcb_i
; i
++) {
3346 adapter
->tx_ring
[i
].reg_idx
=
3348 adapter
->rx_ring
[i
].reg_idx
= i
<< 4;
3352 } else if (dcb_i
== 4) {
3354 * Tx TC0 starts at: descriptor queue 0
3355 * Tx TC1 starts at: descriptor queue 64
3356 * Tx TC2 starts at: descriptor queue 96
3357 * Tx TC3 starts at: descriptor queue 112
3359 * Rx TC0-TC3 are offset by 32 queues each
3361 adapter
->tx_ring
[0].reg_idx
= 0;
3362 adapter
->tx_ring
[1].reg_idx
= 64;
3363 adapter
->tx_ring
[2].reg_idx
= 96;
3364 adapter
->tx_ring
[3].reg_idx
= 112;
3365 for (i
= 0 ; i
< dcb_i
; i
++)
3366 adapter
->rx_ring
[i
].reg_idx
= i
<< 5;
3384 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3385 * @adapter: board private structure to initialize
3387 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3390 static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter
*adapter
)
3395 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
&&
3396 ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3397 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))) {
3398 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3399 adapter
->rx_ring
[i
].reg_idx
= i
;
3400 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3401 adapter
->tx_ring
[i
].reg_idx
= i
;
3410 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3411 * @adapter: board private structure to initialize
3413 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3416 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter
*adapter
)
3418 int i
, fcoe_rx_i
= 0, fcoe_tx_i
= 0;
3420 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
3422 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
3423 #ifdef CONFIG_IXGBE_DCB
3424 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
3425 struct ixgbe_fcoe
*fcoe
= &adapter
->fcoe
;
3427 ixgbe_cache_ring_dcb(adapter
);
3428 /* find out queues in TC for FCoE */
3429 fcoe_rx_i
= adapter
->rx_ring
[fcoe
->tc
].reg_idx
+ 1;
3430 fcoe_tx_i
= adapter
->tx_ring
[fcoe
->tc
].reg_idx
+ 1;
3432 * In 82599, the number of Tx queues for each traffic
3433 * class for both 8-TC and 4-TC modes are:
3434 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3435 * 8 TCs: 32 32 16 16 8 8 8 8
3436 * 4 TCs: 64 64 32 32
3437 * We have max 8 queues for FCoE, where 8 the is
3438 * FCoE redirection table size. If TC for FCoE is
3439 * less than or equal to TC3, we have enough queues
3440 * to add max of 8 queues for FCoE, so we start FCoE
3441 * tx descriptor from the next one, i.e., reg_idx + 1.
3442 * If TC for FCoE is above TC3, implying 8 TC mode,
3443 * and we need 8 for FCoE, we have to take all queues
3444 * in that traffic class for FCoE.
3446 if ((f
->indices
== IXGBE_FCRETA_SIZE
) && (fcoe
->tc
> 3))
3449 #endif /* CONFIG_IXGBE_DCB */
3450 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
3451 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) ||
3452 (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
3453 ixgbe_cache_ring_fdir(adapter
);
3455 ixgbe_cache_ring_rss(adapter
);
3457 fcoe_rx_i
= f
->mask
;
3458 fcoe_tx_i
= f
->mask
;
3460 for (i
= 0; i
< f
->indices
; i
++, fcoe_rx_i
++, fcoe_tx_i
++) {
3461 adapter
->rx_ring
[f
->mask
+ i
].reg_idx
= fcoe_rx_i
;
3462 adapter
->tx_ring
[f
->mask
+ i
].reg_idx
= fcoe_tx_i
;
3469 #endif /* IXGBE_FCOE */
3471 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3472 * @adapter: board private structure to initialize
3474 * Once we know the feature-set enabled for the device, we'll cache
3475 * the register offset the descriptor ring is assigned to.
3477 * Note, the order the various feature calls is important. It must start with
3478 * the "most" features enabled at the same time, then trickle down to the
3479 * least amount of features turned on at once.
3481 static void ixgbe_cache_ring_register(struct ixgbe_adapter
*adapter
)
3483 /* start with default case */
3484 adapter
->rx_ring
[0].reg_idx
= 0;
3485 adapter
->tx_ring
[0].reg_idx
= 0;
3488 if (ixgbe_cache_ring_fcoe(adapter
))
3491 #endif /* IXGBE_FCOE */
3492 #ifdef CONFIG_IXGBE_DCB
3493 if (ixgbe_cache_ring_dcb(adapter
))
3497 if (ixgbe_cache_ring_fdir(adapter
))
3500 if (ixgbe_cache_ring_rss(adapter
))
3505 * ixgbe_alloc_queues - Allocate memory for all rings
3506 * @adapter: board private structure to initialize
3508 * We allocate one ring per queue at run-time since we don't know the
3509 * number of queues at compile-time. The polling_netdev array is
3510 * intended for Multiqueue, but should work fine with a single queue.
3512 static int ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
3516 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
3517 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3518 if (!adapter
->tx_ring
)
3519 goto err_tx_ring_allocation
;
3521 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
3522 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
3523 if (!adapter
->rx_ring
)
3524 goto err_rx_ring_allocation
;
3526 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3527 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
3528 adapter
->tx_ring
[i
].queue_index
= i
;
3531 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3532 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
3533 adapter
->rx_ring
[i
].queue_index
= i
;
3536 ixgbe_cache_ring_register(adapter
);
3540 err_rx_ring_allocation
:
3541 kfree(adapter
->tx_ring
);
3542 err_tx_ring_allocation
:
3547 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3548 * @adapter: board private structure to initialize
3550 * Attempt to configure the interrupts using the best available
3551 * capabilities of the hardware and the kernel.
3553 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter
*adapter
)
3555 struct ixgbe_hw
*hw
= &adapter
->hw
;
3557 int vector
, v_budget
;
3560 * It's easy to be greedy for MSI-X vectors, but it really
3561 * doesn't do us much good if we have a lot more vectors
3562 * than CPU's. So let's be conservative and only ask for
3563 * (roughly) twice the number of vectors as there are CPU's.
3565 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
3566 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
3569 * At the same time, hardware can only support a maximum of
3570 * hw.mac->max_msix_vectors vectors. With features
3571 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3572 * descriptor queues supported by our device. Thus, we cap it off in
3573 * those rare cases where the cpu count also exceeds our vector limit.
3575 v_budget
= min(v_budget
, (int)hw
->mac
.max_msix_vectors
);
3577 /* A failure in MSI-X entry allocation isn't fatal, but it does
3578 * mean we disable MSI-X capabilities of the adapter. */
3579 adapter
->msix_entries
= kcalloc(v_budget
,
3580 sizeof(struct msix_entry
), GFP_KERNEL
);
3581 if (adapter
->msix_entries
) {
3582 for (vector
= 0; vector
< v_budget
; vector
++)
3583 adapter
->msix_entries
[vector
].entry
= vector
;
3585 ixgbe_acquire_msix_vectors(adapter
, v_budget
);
3587 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3591 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
3592 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
3593 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3594 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
3595 adapter
->atr_sample_rate
= 0;
3596 ixgbe_set_num_queues(adapter
);
3598 err
= pci_enable_msi(adapter
->pdev
);
3600 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
3602 DPRINTK(HW
, DEBUG
, "Unable to allocate MSI interrupt, "
3603 "falling back to legacy. Error: %d\n", err
);
3613 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3614 * @adapter: board private structure to initialize
3616 * We allocate one q_vector per queue interrupt. If allocation fails we
3619 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter
*adapter
)
3621 int q_idx
, num_q_vectors
;
3622 struct ixgbe_q_vector
*q_vector
;
3624 int (*poll
)(struct napi_struct
*, int);
3626 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3627 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3628 napi_vectors
= adapter
->num_rx_queues
;
3629 poll
= &ixgbe_clean_rxtx_many
;
3636 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
3637 q_vector
= kzalloc(sizeof(struct ixgbe_q_vector
), GFP_KERNEL
);
3640 q_vector
->adapter
= adapter
;
3641 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
3642 q_vector
->eitr
= adapter
->tx_eitr_param
;
3644 q_vector
->eitr
= adapter
->rx_eitr_param
;
3645 q_vector
->v_idx
= q_idx
;
3646 netif_napi_add(adapter
->netdev
, &q_vector
->napi
, (*poll
), 64);
3647 adapter
->q_vector
[q_idx
] = q_vector
;
3655 q_vector
= adapter
->q_vector
[q_idx
];
3656 netif_napi_del(&q_vector
->napi
);
3658 adapter
->q_vector
[q_idx
] = NULL
;
3664 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3665 * @adapter: board private structure to initialize
3667 * This function frees the memory allocated to the q_vectors. In addition if
3668 * NAPI is enabled it will delete any references to the NAPI struct prior
3669 * to freeing the q_vector.
3671 static void ixgbe_free_q_vectors(struct ixgbe_adapter
*adapter
)
3673 int q_idx
, num_q_vectors
;
3675 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3676 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3680 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
3681 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
3682 adapter
->q_vector
[q_idx
] = NULL
;
3683 netif_napi_del(&q_vector
->napi
);
3688 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter
*adapter
)
3690 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3691 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3692 pci_disable_msix(adapter
->pdev
);
3693 kfree(adapter
->msix_entries
);
3694 adapter
->msix_entries
= NULL
;
3695 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
3696 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
3697 pci_disable_msi(adapter
->pdev
);
3703 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3704 * @adapter: board private structure to initialize
3706 * We determine which interrupt scheme to use based on...
3707 * - Kernel support (MSI, MSI-X)
3708 * - which can be user-defined (via MODULE_PARAM)
3709 * - Hardware queue count (num_*_queues)
3710 * - defined by miscellaneous hardware support/features (RSS, etc.)
3712 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter
*adapter
)
3716 /* Number of supported queues */
3717 ixgbe_set_num_queues(adapter
);
3719 err
= ixgbe_set_interrupt_capability(adapter
);
3721 DPRINTK(PROBE
, ERR
, "Unable to setup interrupt capabilities\n");
3722 goto err_set_interrupt
;
3725 err
= ixgbe_alloc_q_vectors(adapter
);
3727 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queue "
3729 goto err_alloc_q_vectors
;
3732 err
= ixgbe_alloc_queues(adapter
);
3734 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
3735 goto err_alloc_queues
;
3738 DPRINTK(DRV
, INFO
, "Multiqueue %s: Rx Queue count = %u, "
3739 "Tx Queue count = %u\n",
3740 (adapter
->num_rx_queues
> 1) ? "Enabled" :
3741 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
3743 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3748 ixgbe_free_q_vectors(adapter
);
3749 err_alloc_q_vectors
:
3750 ixgbe_reset_interrupt_capability(adapter
);
3756 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3757 * @adapter: board private structure to clear interrupt scheme on
3759 * We go through and clear interrupt specific resources and reset the structure
3760 * to pre-load conditions
3762 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter
*adapter
)
3764 kfree(adapter
->tx_ring
);
3765 kfree(adapter
->rx_ring
);
3766 adapter
->tx_ring
= NULL
;
3767 adapter
->rx_ring
= NULL
;
3769 ixgbe_free_q_vectors(adapter
);
3770 ixgbe_reset_interrupt_capability(adapter
);
3774 * ixgbe_sfp_timer - worker thread to find a missing module
3775 * @data: pointer to our adapter struct
3777 static void ixgbe_sfp_timer(unsigned long data
)
3779 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
3782 * Do the sfp_timer outside of interrupt context due to the
3783 * delays that sfp+ detection requires
3785 schedule_work(&adapter
->sfp_task
);
3789 * ixgbe_sfp_task - worker thread to find a missing module
3790 * @work: pointer to work_struct containing our data
3792 static void ixgbe_sfp_task(struct work_struct
*work
)
3794 struct ixgbe_adapter
*adapter
= container_of(work
,
3795 struct ixgbe_adapter
,
3797 struct ixgbe_hw
*hw
= &adapter
->hw
;
3799 if ((hw
->phy
.type
== ixgbe_phy_nl
) &&
3800 (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)) {
3801 s32 ret
= hw
->phy
.ops
.identify_sfp(hw
);
3802 if (ret
== IXGBE_ERR_SFP_NOT_PRESENT
)
3804 ret
= hw
->phy
.ops
.reset(hw
);
3805 if (ret
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
3806 dev_err(&adapter
->pdev
->dev
, "failed to initialize "
3807 "because an unsupported SFP+ module type "
3809 "Reload the driver after installing a "
3810 "supported module.\n");
3811 unregister_netdev(adapter
->netdev
);
3813 DPRINTK(PROBE
, INFO
, "detected SFP+: %d\n",
3816 /* don't need this routine any more */
3817 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
3821 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
))
3822 mod_timer(&adapter
->sfp_timer
,
3823 round_jiffies(jiffies
+ (2 * HZ
)));
3827 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3828 * @adapter: board private structure to initialize
3830 * ixgbe_sw_init initializes the Adapter private data structure.
3831 * Fields are initialized based on PCI device information and
3832 * OS network device settings (MTU size).
3834 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
3836 struct ixgbe_hw
*hw
= &adapter
->hw
;
3837 struct pci_dev
*pdev
= adapter
->pdev
;
3839 #ifdef CONFIG_IXGBE_DCB
3841 struct tc_configuration
*tc
;
3844 /* PCI config space info */
3846 hw
->vendor_id
= pdev
->vendor
;
3847 hw
->device_id
= pdev
->device
;
3848 hw
->revision_id
= pdev
->revision
;
3849 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3850 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3852 /* Set capability flags */
3853 rss
= min(IXGBE_MAX_RSS_INDICES
, (int)num_online_cpus());
3854 adapter
->ring_feature
[RING_F_RSS
].indices
= rss
;
3855 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
3856 adapter
->ring_feature
[RING_F_DCB
].indices
= IXGBE_MAX_DCB_INDICES
;
3857 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3858 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
3859 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
3860 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82598
;
3861 } else if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
3862 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82599
;
3863 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
3864 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
3865 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
3866 adapter
->ring_feature
[RING_F_FDIR
].indices
=
3867 IXGBE_MAX_FDIR_INDICES
;
3868 adapter
->atr_sample_rate
= 20;
3869 adapter
->fdir_pballoc
= 0;
3871 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
3872 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
3873 adapter
->ring_feature
[RING_F_FCOE
].indices
= 0;
3874 /* Default traffic class to use for FCoE */
3875 adapter
->fcoe
.tc
= IXGBE_FCOE_DEFTC
;
3876 #endif /* IXGBE_FCOE */
3879 #ifdef CONFIG_IXGBE_DCB
3880 /* Configure DCB traffic classes */
3881 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
3882 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
3883 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
3884 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
3885 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
3886 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
3887 tc
->dcb_pfc
= pfc_disabled
;
3889 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
3890 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
3891 adapter
->dcb_cfg
.rx_pba_cfg
= pba_equal
;
3892 adapter
->dcb_cfg
.pfc_mode_enable
= false;
3893 adapter
->dcb_cfg
.round_robin_enable
= false;
3894 adapter
->dcb_set_bitmap
= 0x00;
3895 ixgbe_copy_dcb_cfg(&adapter
->dcb_cfg
, &adapter
->temp_dcb_cfg
,
3896 adapter
->ring_feature
[RING_F_DCB
].indices
);
3900 /* default flow control settings */
3901 hw
->fc
.requested_mode
= ixgbe_fc_full
;
3902 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
3904 adapter
->last_lfc_mode
= hw
->fc
.current_mode
;
3906 hw
->fc
.high_water
= IXGBE_DEFAULT_FCRTH
;
3907 hw
->fc
.low_water
= IXGBE_DEFAULT_FCRTL
;
3908 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
3909 hw
->fc
.send_xon
= true;
3910 hw
->fc
.disable_fc_autoneg
= false;
3912 /* enable itr by default in dynamic mode */
3913 adapter
->rx_itr_setting
= 1;
3914 adapter
->rx_eitr_param
= 20000;
3915 adapter
->tx_itr_setting
= 1;
3916 adapter
->tx_eitr_param
= 10000;
3918 /* set defaults for eitr in MegaBytes */
3919 adapter
->eitr_low
= 10;
3920 adapter
->eitr_high
= 20;
3922 /* set default ring sizes */
3923 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
3924 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
3926 /* initialize eeprom parameters */
3927 if (ixgbe_init_eeprom_params_generic(hw
)) {
3928 dev_err(&pdev
->dev
, "EEPROM initialization failed\n");
3932 /* enable rx csum by default */
3933 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
3935 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3941 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3942 * @adapter: board private structure
3943 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3945 * Return 0 on success, negative on failure
3947 int ixgbe_setup_tx_resources(struct ixgbe_adapter
*adapter
,
3948 struct ixgbe_ring
*tx_ring
)
3950 struct pci_dev
*pdev
= adapter
->pdev
;
3953 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
3954 tx_ring
->tx_buffer_info
= vmalloc(size
);
3955 if (!tx_ring
->tx_buffer_info
)
3957 memset(tx_ring
->tx_buffer_info
, 0, size
);
3959 /* round up to nearest 4K */
3960 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
3961 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
3963 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
3968 tx_ring
->next_to_use
= 0;
3969 tx_ring
->next_to_clean
= 0;
3970 tx_ring
->work_limit
= tx_ring
->count
;
3974 vfree(tx_ring
->tx_buffer_info
);
3975 tx_ring
->tx_buffer_info
= NULL
;
3976 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for the transmit "
3977 "descriptor ring\n");
3982 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3983 * @adapter: board private structure
3985 * If this function returns with an error, then it's possible one or
3986 * more of the rings is populated (while the rest are not). It is the
3987 * callers duty to clean those orphaned rings.
3989 * Return 0 on success, negative on failure
3991 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
3995 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3996 err
= ixgbe_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
3999 DPRINTK(PROBE
, ERR
, "Allocation for Tx Queue %u failed\n", i
);
4007 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4008 * @adapter: board private structure
4009 * @rx_ring: rx descriptor ring (for a specific queue) to setup
4011 * Returns 0 on success, negative on failure
4013 int ixgbe_setup_rx_resources(struct ixgbe_adapter
*adapter
,
4014 struct ixgbe_ring
*rx_ring
)
4016 struct pci_dev
*pdev
= adapter
->pdev
;
4019 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
4020 rx_ring
->rx_buffer_info
= vmalloc(size
);
4021 if (!rx_ring
->rx_buffer_info
) {
4023 "vmalloc allocation failed for the rx desc ring\n");
4026 memset(rx_ring
->rx_buffer_info
, 0, size
);
4028 /* Round up to nearest 4K */
4029 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
4030 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
4032 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
, &rx_ring
->dma
);
4034 if (!rx_ring
->desc
) {
4036 "Memory allocation failed for the rx desc ring\n");
4037 vfree(rx_ring
->rx_buffer_info
);
4041 rx_ring
->next_to_clean
= 0;
4042 rx_ring
->next_to_use
= 0;
4051 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4052 * @adapter: board private structure
4054 * If this function returns with an error, then it's possible one or
4055 * more of the rings is populated (while the rest are not). It is the
4056 * callers duty to clean those orphaned rings.
4058 * Return 0 on success, negative on failure
4061 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
4065 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4066 err
= ixgbe_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
4069 DPRINTK(PROBE
, ERR
, "Allocation for Rx Queue %u failed\n", i
);
4077 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4078 * @adapter: board private structure
4079 * @tx_ring: Tx descriptor ring for a specific queue
4081 * Free all transmit software resources
4083 void ixgbe_free_tx_resources(struct ixgbe_adapter
*adapter
,
4084 struct ixgbe_ring
*tx_ring
)
4086 struct pci_dev
*pdev
= adapter
->pdev
;
4088 ixgbe_clean_tx_ring(adapter
, tx_ring
);
4090 vfree(tx_ring
->tx_buffer_info
);
4091 tx_ring
->tx_buffer_info
= NULL
;
4093 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
4095 tx_ring
->desc
= NULL
;
4099 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4100 * @adapter: board private structure
4102 * Free all transmit software resources
4104 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
4108 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4109 if (adapter
->tx_ring
[i
].desc
)
4110 ixgbe_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
4114 * ixgbe_free_rx_resources - Free Rx Resources
4115 * @adapter: board private structure
4116 * @rx_ring: ring to clean the resources from
4118 * Free all receive software resources
4120 void ixgbe_free_rx_resources(struct ixgbe_adapter
*adapter
,
4121 struct ixgbe_ring
*rx_ring
)
4123 struct pci_dev
*pdev
= adapter
->pdev
;
4125 ixgbe_clean_rx_ring(adapter
, rx_ring
);
4127 vfree(rx_ring
->rx_buffer_info
);
4128 rx_ring
->rx_buffer_info
= NULL
;
4130 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
4132 rx_ring
->desc
= NULL
;
4136 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4137 * @adapter: board private structure
4139 * Free all receive software resources
4141 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
4145 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4146 if (adapter
->rx_ring
[i
].desc
)
4147 ixgbe_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
4151 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4152 * @netdev: network interface device structure
4153 * @new_mtu: new value for maximum frame size
4155 * Returns 0 on success, negative on failure
4157 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
4159 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4160 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4162 /* MTU < 68 is an error and causes problems on some kernels */
4163 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
4166 DPRINTK(PROBE
, INFO
, "changing MTU from %d to %d\n",
4167 netdev
->mtu
, new_mtu
);
4168 /* must set new MTU before calling down or up */
4169 netdev
->mtu
= new_mtu
;
4171 if (netif_running(netdev
))
4172 ixgbe_reinit_locked(adapter
);
4178 * ixgbe_open - Called when a network interface is made active
4179 * @netdev: network interface device structure
4181 * Returns 0 on success, negative value on failure
4183 * The open entry point is called when a network interface is made
4184 * active by the system (IFF_UP). At this point all resources needed
4185 * for transmit and receive operations are allocated, the interrupt
4186 * handler is registered with the OS, the watchdog timer is started,
4187 * and the stack is notified that the interface is ready.
4189 static int ixgbe_open(struct net_device
*netdev
)
4191 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4194 /* disallow open during test */
4195 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
4198 netif_carrier_off(netdev
);
4200 /* allocate transmit descriptors */
4201 err
= ixgbe_setup_all_tx_resources(adapter
);
4205 /* allocate receive descriptors */
4206 err
= ixgbe_setup_all_rx_resources(adapter
);
4210 ixgbe_configure(adapter
);
4212 err
= ixgbe_request_irq(adapter
);
4216 err
= ixgbe_up_complete(adapter
);
4220 netif_tx_start_all_queues(netdev
);
4225 ixgbe_release_hw_control(adapter
);
4226 ixgbe_free_irq(adapter
);
4229 ixgbe_free_all_rx_resources(adapter
);
4231 ixgbe_free_all_tx_resources(adapter
);
4232 ixgbe_reset(adapter
);
4238 * ixgbe_close - Disables a network interface
4239 * @netdev: network interface device structure
4241 * Returns 0, this is not allowed to fail
4243 * The close entry point is called when an interface is de-activated
4244 * by the OS. The hardware is still under the drivers control, but
4245 * needs to be disabled. A global MAC reset is issued to stop the
4246 * hardware, and all transmit and receive resources are freed.
4248 static int ixgbe_close(struct net_device
*netdev
)
4250 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4252 ixgbe_down(adapter
);
4253 ixgbe_free_irq(adapter
);
4255 ixgbe_free_all_tx_resources(adapter
);
4256 ixgbe_free_all_rx_resources(adapter
);
4258 ixgbe_release_hw_control(adapter
);
4264 static int ixgbe_resume(struct pci_dev
*pdev
)
4266 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4267 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4270 pci_set_power_state(pdev
, PCI_D0
);
4271 pci_restore_state(pdev
);
4273 err
= pci_enable_device_mem(pdev
);
4275 printk(KERN_ERR
"ixgbe: Cannot enable PCI device from "
4279 pci_set_master(pdev
);
4281 pci_wake_from_d3(pdev
, false);
4283 err
= ixgbe_init_interrupt_scheme(adapter
);
4285 printk(KERN_ERR
"ixgbe: Cannot initialize interrupts for "
4290 ixgbe_reset(adapter
);
4292 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
4294 if (netif_running(netdev
)) {
4295 err
= ixgbe_open(adapter
->netdev
);
4300 netif_device_attach(netdev
);
4304 #endif /* CONFIG_PM */
4306 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4308 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4309 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4310 struct ixgbe_hw
*hw
= &adapter
->hw
;
4312 u32 wufc
= adapter
->wol
;
4317 netif_device_detach(netdev
);
4319 if (netif_running(netdev
)) {
4320 ixgbe_down(adapter
);
4321 ixgbe_free_irq(adapter
);
4322 ixgbe_free_all_tx_resources(adapter
);
4323 ixgbe_free_all_rx_resources(adapter
);
4325 ixgbe_clear_interrupt_scheme(adapter
);
4328 retval
= pci_save_state(pdev
);
4334 ixgbe_set_rx_mode(netdev
);
4336 /* turn on all-multi mode if wake on multicast is enabled */
4337 if (wufc
& IXGBE_WUFC_MC
) {
4338 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4339 fctrl
|= IXGBE_FCTRL_MPE
;
4340 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4343 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
4344 ctrl
|= IXGBE_CTRL_GIO_DIS
;
4345 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
4347 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
4349 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
4350 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
4353 if (wufc
&& hw
->mac
.type
== ixgbe_mac_82599EB
)
4354 pci_wake_from_d3(pdev
, true);
4356 pci_wake_from_d3(pdev
, false);
4358 *enable_wake
= !!wufc
;
4360 ixgbe_release_hw_control(adapter
);
4362 pci_disable_device(pdev
);
4368 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4373 retval
= __ixgbe_shutdown(pdev
, &wake
);
4378 pci_prepare_to_sleep(pdev
);
4380 pci_wake_from_d3(pdev
, false);
4381 pci_set_power_state(pdev
, PCI_D3hot
);
4386 #endif /* CONFIG_PM */
4388 static void ixgbe_shutdown(struct pci_dev
*pdev
)
4392 __ixgbe_shutdown(pdev
, &wake
);
4394 if (system_state
== SYSTEM_POWER_OFF
) {
4395 pci_wake_from_d3(pdev
, wake
);
4396 pci_set_power_state(pdev
, PCI_D3hot
);
4401 * ixgbe_update_stats - Update the board statistics counters.
4402 * @adapter: board private structure
4404 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
4406 struct ixgbe_hw
*hw
= &adapter
->hw
;
4408 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
4410 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4412 for (i
= 0; i
< 16; i
++)
4413 adapter
->hw_rx_no_dma_resources
+=
4414 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4415 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4416 rsc_count
+= adapter
->rx_ring
[i
].rsc_count
;
4417 adapter
->rsc_count
= rsc_count
;
4420 adapter
->stats
.crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
4421 for (i
= 0; i
< 8; i
++) {
4422 /* for packet buffers not used, the register should read 0 */
4423 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
4425 adapter
->stats
.mpc
[i
] += mpc
;
4426 total_mpc
+= adapter
->stats
.mpc
[i
];
4427 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4428 adapter
->stats
.rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
4429 adapter
->stats
.qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
4430 adapter
->stats
.qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
4431 adapter
->stats
.qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
4432 adapter
->stats
.qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
4433 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4434 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4435 IXGBE_PXONRXCNT(i
));
4436 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4437 IXGBE_PXOFFRXCNT(i
));
4438 adapter
->stats
.qprdc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
4440 adapter
->stats
.pxonrxc
[i
] += IXGBE_READ_REG(hw
,
4442 adapter
->stats
.pxoffrxc
[i
] += IXGBE_READ_REG(hw
,
4445 adapter
->stats
.pxontxc
[i
] += IXGBE_READ_REG(hw
,
4447 adapter
->stats
.pxofftxc
[i
] += IXGBE_READ_REG(hw
,
4450 adapter
->stats
.gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
4451 /* work around hardware counting issue */
4452 adapter
->stats
.gprc
-= missed_rx
;
4454 /* 82598 hardware only has a 32 bit counter in the high register */
4455 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4457 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
4458 tmp
= IXGBE_READ_REG(hw
, IXGBE_GORCH
) & 0xF; /* 4 high bits of GORC */
4459 adapter
->stats
.gorc
+= (tmp
<< 32);
4460 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
4461 tmp
= IXGBE_READ_REG(hw
, IXGBE_GOTCH
) & 0xF; /* 4 high bits of GOTC */
4462 adapter
->stats
.gotc
+= (tmp
<< 32);
4463 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
4464 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
4465 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
4466 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
4467 adapter
->stats
.fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
4468 adapter
->stats
.fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
4470 adapter
->stats
.fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
4471 adapter
->stats
.fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
4472 adapter
->stats
.fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
4473 adapter
->stats
.fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
4474 adapter
->stats
.fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
4475 adapter
->stats
.fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
4476 #endif /* IXGBE_FCOE */
4478 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
4479 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
4480 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
4481 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
4482 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
4484 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
4485 adapter
->stats
.bprc
+= bprc
;
4486 adapter
->stats
.mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
4487 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4488 adapter
->stats
.mprc
-= bprc
;
4489 adapter
->stats
.roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
4490 adapter
->stats
.prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
4491 adapter
->stats
.prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
4492 adapter
->stats
.prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
4493 adapter
->stats
.prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
4494 adapter
->stats
.prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
4495 adapter
->stats
.prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
4496 adapter
->stats
.rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
4497 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
4498 adapter
->stats
.lxontxc
+= lxon
;
4499 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
4500 adapter
->stats
.lxofftxc
+= lxoff
;
4501 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4502 adapter
->stats
.gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
4503 adapter
->stats
.mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
4505 * 82598 errata - tx of flow control packets is included in tx counters
4507 xon_off_tot
= lxon
+ lxoff
;
4508 adapter
->stats
.gptc
-= xon_off_tot
;
4509 adapter
->stats
.mptc
-= xon_off_tot
;
4510 adapter
->stats
.gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
4511 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
4512 adapter
->stats
.rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
4513 adapter
->stats
.rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
4514 adapter
->stats
.tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
4515 adapter
->stats
.ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
4516 adapter
->stats
.ptc64
-= xon_off_tot
;
4517 adapter
->stats
.ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
4518 adapter
->stats
.ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
4519 adapter
->stats
.ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
4520 adapter
->stats
.ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
4521 adapter
->stats
.ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
4522 adapter
->stats
.bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
4524 /* Fill out the OS statistics structure */
4525 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
4528 adapter
->net_stats
.rx_errors
= adapter
->stats
.crcerrs
+
4529 adapter
->stats
.rlec
;
4530 adapter
->net_stats
.rx_dropped
= 0;
4531 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
4532 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
4533 adapter
->net_stats
.rx_missed_errors
= total_mpc
;
4537 * ixgbe_watchdog - Timer Call-back
4538 * @data: pointer to adapter cast into an unsigned long
4540 static void ixgbe_watchdog(unsigned long data
)
4542 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
4543 struct ixgbe_hw
*hw
= &adapter
->hw
;
4548 * Do the watchdog outside of interrupt context due to the lovely
4549 * delays that some of the newer hardware requires
4552 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
4553 goto watchdog_short_circuit
;
4555 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
4557 * for legacy and MSI interrupts don't set any bits
4558 * that are enabled for EIAM, because this operation
4559 * would set *both* EIMS and EICS for any bit in EIAM
4561 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
4562 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
4563 goto watchdog_reschedule
;
4566 /* get one bit for every active tx/rx interrupt vector */
4567 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
4568 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
4569 if (qv
->rxr_count
|| qv
->txr_count
)
4570 eics
|= ((u64
)1 << i
);
4573 /* Cause software interrupt to ensure rx rings are cleaned */
4574 ixgbe_irq_rearm_queues(adapter
, eics
);
4576 watchdog_reschedule
:
4577 /* Reset the timer */
4578 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
4580 watchdog_short_circuit
:
4581 schedule_work(&adapter
->watchdog_task
);
4585 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4586 * @work: pointer to work_struct containing our data
4588 static void ixgbe_multispeed_fiber_task(struct work_struct
*work
)
4590 struct ixgbe_adapter
*adapter
= container_of(work
,
4591 struct ixgbe_adapter
,
4592 multispeed_fiber_task
);
4593 struct ixgbe_hw
*hw
= &adapter
->hw
;
4597 adapter
->flags
|= IXGBE_FLAG_IN_SFP_LINK_TASK
;
4598 autoneg
= hw
->phy
.autoneg_advertised
;
4599 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
4600 hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
4601 if (hw
->mac
.ops
.setup_link
)
4602 hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, true);
4603 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
4604 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_LINK_TASK
;
4608 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4609 * @work: pointer to work_struct containing our data
4611 static void ixgbe_sfp_config_module_task(struct work_struct
*work
)
4613 struct ixgbe_adapter
*adapter
= container_of(work
,
4614 struct ixgbe_adapter
,
4615 sfp_config_module_task
);
4616 struct ixgbe_hw
*hw
= &adapter
->hw
;
4619 adapter
->flags
|= IXGBE_FLAG_IN_SFP_MOD_TASK
;
4621 /* Time for electrical oscillations to settle down */
4623 err
= hw
->phy
.ops
.identify_sfp(hw
);
4625 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
4626 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
4627 "an unsupported SFP+ module type was detected.\n"
4628 "Reload the driver after installing a supported "
4630 unregister_netdev(adapter
->netdev
);
4633 hw
->mac
.ops
.setup_sfp(hw
);
4635 if (!(adapter
->flags
& IXGBE_FLAG_IN_SFP_LINK_TASK
))
4636 /* This will also work for DA Twinax connections */
4637 schedule_work(&adapter
->multispeed_fiber_task
);
4638 adapter
->flags
&= ~IXGBE_FLAG_IN_SFP_MOD_TASK
;
4642 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4643 * @work: pointer to work_struct containing our data
4645 static void ixgbe_fdir_reinit_task(struct work_struct
*work
)
4647 struct ixgbe_adapter
*adapter
= container_of(work
,
4648 struct ixgbe_adapter
,
4650 struct ixgbe_hw
*hw
= &adapter
->hw
;
4653 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
4654 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4655 set_bit(__IXGBE_FDIR_INIT_DONE
,
4656 &(adapter
->tx_ring
[i
].reinit_state
));
4658 DPRINTK(PROBE
, ERR
, "failed to finish FDIR re-initialization, "
4659 "ignored adding FDIR ATR filters \n");
4661 /* Done FDIR Re-initialization, enable transmits */
4662 netif_tx_start_all_queues(adapter
->netdev
);
4666 * ixgbe_watchdog_task - worker thread to bring link up
4667 * @work: pointer to work_struct containing our data
4669 static void ixgbe_watchdog_task(struct work_struct
*work
)
4671 struct ixgbe_adapter
*adapter
= container_of(work
,
4672 struct ixgbe_adapter
,
4674 struct net_device
*netdev
= adapter
->netdev
;
4675 struct ixgbe_hw
*hw
= &adapter
->hw
;
4676 u32 link_speed
= adapter
->link_speed
;
4677 bool link_up
= adapter
->link_up
;
4679 struct ixgbe_ring
*tx_ring
;
4680 int some_tx_pending
= 0;
4682 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
4684 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
) {
4685 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
4688 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
4689 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++)
4690 hw
->mac
.ops
.fc_enable(hw
, i
);
4692 hw
->mac
.ops
.fc_enable(hw
, 0);
4695 hw
->mac
.ops
.fc_enable(hw
, 0);
4700 time_after(jiffies
, (adapter
->link_check_timeout
+
4701 IXGBE_TRY_LINK_TIMEOUT
))) {
4702 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
4703 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
4705 adapter
->link_up
= link_up
;
4706 adapter
->link_speed
= link_speed
;
4710 if (!netif_carrier_ok(netdev
)) {
4711 bool flow_rx
, flow_tx
;
4713 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
4714 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
4715 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
4716 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
4717 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
4719 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4720 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
4721 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
4722 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
4725 printk(KERN_INFO
"ixgbe: %s NIC Link is Up %s, "
4726 "Flow Control: %s\n",
4728 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
4730 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
4731 "1 Gbps" : "unknown speed")),
4732 ((flow_rx
&& flow_tx
) ? "RX/TX" :
4734 (flow_tx
? "TX" : "None"))));
4736 netif_carrier_on(netdev
);
4738 /* Force detection of hung controller */
4739 adapter
->detect_tx_hung
= true;
4742 adapter
->link_up
= false;
4743 adapter
->link_speed
= 0;
4744 if (netif_carrier_ok(netdev
)) {
4745 printk(KERN_INFO
"ixgbe: %s NIC Link is Down\n",
4747 netif_carrier_off(netdev
);
4751 if (!netif_carrier_ok(netdev
)) {
4752 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4753 tx_ring
= &adapter
->tx_ring
[i
];
4754 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
) {
4755 some_tx_pending
= 1;
4760 if (some_tx_pending
) {
4761 /* We've lost link, so the controller stops DMA,
4762 * but we've got queued Tx work that's never going
4763 * to get done, so reset controller to flush Tx.
4764 * (Do the reset outside of interrupt context).
4766 schedule_work(&adapter
->reset_task
);
4770 ixgbe_update_stats(adapter
);
4771 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
4774 static int ixgbe_tso(struct ixgbe_adapter
*adapter
,
4775 struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
4776 u32 tx_flags
, u8
*hdr_len
)
4778 struct ixgbe_adv_tx_context_desc
*context_desc
;
4781 struct ixgbe_tx_buffer
*tx_buffer_info
;
4782 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
4783 u32 mss_l4len_idx
, l4len
;
4785 if (skb_is_gso(skb
)) {
4786 if (skb_header_cloned(skb
)) {
4787 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
4791 l4len
= tcp_hdrlen(skb
);
4794 if (skb
->protocol
== htons(ETH_P_IP
)) {
4795 struct iphdr
*iph
= ip_hdr(skb
);
4798 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
4802 adapter
->hw_tso_ctxt
++;
4803 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
4804 ipv6_hdr(skb
)->payload_len
= 0;
4805 tcp_hdr(skb
)->check
=
4806 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
4807 &ipv6_hdr(skb
)->daddr
,
4809 adapter
->hw_tso6_ctxt
++;
4812 i
= tx_ring
->next_to_use
;
4814 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4815 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
4817 /* VLAN MACLEN IPLEN */
4818 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
4820 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
4821 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
4822 IXGBE_ADVTXD_MACLEN_SHIFT
);
4823 *hdr_len
+= skb_network_offset(skb
);
4825 (skb_transport_header(skb
) - skb_network_header(skb
));
4827 (skb_transport_header(skb
) - skb_network_header(skb
));
4828 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
4829 context_desc
->seqnum_seed
= 0;
4831 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
4832 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
4833 IXGBE_ADVTXD_DTYP_CTXT
);
4835 if (skb
->protocol
== htons(ETH_P_IP
))
4836 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
4837 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4838 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
4842 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
4843 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
4844 /* use index 1 for TSO */
4845 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
4846 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
4848 tx_buffer_info
->time_stamp
= jiffies
;
4849 tx_buffer_info
->next_to_watch
= i
;
4852 if (i
== tx_ring
->count
)
4854 tx_ring
->next_to_use
= i
;
4861 static bool ixgbe_tx_csum(struct ixgbe_adapter
*adapter
,
4862 struct ixgbe_ring
*tx_ring
,
4863 struct sk_buff
*skb
, u32 tx_flags
)
4865 struct ixgbe_adv_tx_context_desc
*context_desc
;
4867 struct ixgbe_tx_buffer
*tx_buffer_info
;
4868 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
4870 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
4871 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
4872 i
= tx_ring
->next_to_use
;
4873 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4874 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
4876 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
4878 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
4879 vlan_macip_lens
|= (skb_network_offset(skb
) <<
4880 IXGBE_ADVTXD_MACLEN_SHIFT
);
4881 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
4882 vlan_macip_lens
|= (skb_transport_header(skb
) -
4883 skb_network_header(skb
));
4885 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
4886 context_desc
->seqnum_seed
= 0;
4888 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
4889 IXGBE_ADVTXD_DTYP_CTXT
);
4891 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
4892 switch (skb
->protocol
) {
4893 case cpu_to_be16(ETH_P_IP
):
4894 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
4895 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
4897 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4898 else if (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)
4900 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
4902 case cpu_to_be16(ETH_P_IPV6
):
4903 /* XXX what about other V6 headers?? */
4904 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
4906 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
4907 else if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_SCTP
)
4909 IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
4912 if (unlikely(net_ratelimit())) {
4913 DPRINTK(PROBE
, WARNING
,
4914 "partial checksum but proto=%x!\n",
4921 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
4922 /* use index zero for tx checksum offload */
4923 context_desc
->mss_l4len_idx
= 0;
4925 tx_buffer_info
->time_stamp
= jiffies
;
4926 tx_buffer_info
->next_to_watch
= i
;
4928 adapter
->hw_csum_tx_good
++;
4930 if (i
== tx_ring
->count
)
4932 tx_ring
->next_to_use
= i
;
4940 static int ixgbe_tx_map(struct ixgbe_adapter
*adapter
,
4941 struct ixgbe_ring
*tx_ring
,
4942 struct sk_buff
*skb
, u32 tx_flags
,
4945 struct ixgbe_tx_buffer
*tx_buffer_info
;
4947 unsigned int total
= skb
->len
;
4948 unsigned int offset
= 0, size
, count
= 0, i
;
4949 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
4953 i
= tx_ring
->next_to_use
;
4955 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
4956 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
4960 map
= skb_shinfo(skb
)->dma_maps
;
4962 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
)
4963 /* excluding fcoe_crc_eof for FCoE */
4964 total
-= sizeof(struct fcoe_crc_eof
);
4966 len
= min(skb_headlen(skb
), total
);
4968 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4969 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
4971 tx_buffer_info
->length
= size
;
4972 tx_buffer_info
->dma
= skb_shinfo(skb
)->dma_head
+ offset
;
4973 tx_buffer_info
->time_stamp
= jiffies
;
4974 tx_buffer_info
->next_to_watch
= i
;
4983 if (i
== tx_ring
->count
)
4988 for (f
= 0; f
< nr_frags
; f
++) {
4989 struct skb_frag_struct
*frag
;
4991 frag
= &skb_shinfo(skb
)->frags
[f
];
4992 len
= min((unsigned int)frag
->size
, total
);
4997 if (i
== tx_ring
->count
)
5000 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5001 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
5003 tx_buffer_info
->length
= size
;
5004 tx_buffer_info
->dma
= map
[f
] + offset
;
5005 tx_buffer_info
->time_stamp
= jiffies
;
5006 tx_buffer_info
->next_to_watch
= i
;
5017 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
5018 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
5023 static void ixgbe_tx_queue(struct ixgbe_adapter
*adapter
,
5024 struct ixgbe_ring
*tx_ring
,
5025 int tx_flags
, int count
, u32 paylen
, u8 hdr_len
)
5027 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
5028 struct ixgbe_tx_buffer
*tx_buffer_info
;
5029 u32 olinfo_status
= 0, cmd_type_len
= 0;
5031 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
5033 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
5035 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
5037 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
5038 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
5040 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
5041 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
5043 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
5044 IXGBE_ADVTXD_POPTS_SHIFT
;
5046 /* use index 1 context for tso */
5047 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
5048 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
5049 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
5050 IXGBE_ADVTXD_POPTS_SHIFT
;
5052 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
5053 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
5054 IXGBE_ADVTXD_POPTS_SHIFT
;
5056 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
5057 olinfo_status
|= IXGBE_ADVTXD_CC
;
5058 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
5059 if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
5060 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
5063 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
5065 i
= tx_ring
->next_to_use
;
5067 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5068 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
5069 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
5070 tx_desc
->read
.cmd_type_len
=
5071 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
5072 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
5074 if (i
== tx_ring
->count
)
5078 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
5081 * Force memory writes to complete before letting h/w
5082 * know there are new descriptors to fetch. (Only
5083 * applicable for weak-ordered memory model archs,
5088 tx_ring
->next_to_use
= i
;
5089 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
5092 static void ixgbe_atr(struct ixgbe_adapter
*adapter
, struct sk_buff
*skb
,
5093 int queue
, u32 tx_flags
)
5095 /* Right now, we support IPv4 only */
5096 struct ixgbe_atr_input atr_input
;
5098 struct iphdr
*iph
= ip_hdr(skb
);
5099 struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
5100 u16 vlan_id
, src_port
, dst_port
, flex_bytes
;
5101 u32 src_ipv4_addr
, dst_ipv4_addr
;
5104 /* check if we're UDP or TCP */
5105 if (iph
->protocol
== IPPROTO_TCP
) {
5107 src_port
= th
->source
;
5108 dst_port
= th
->dest
;
5109 l4type
|= IXGBE_ATR_L4TYPE_TCP
;
5110 /* l4type IPv4 type is 0, no need to assign */
5112 /* Unsupported L4 header, just bail here */
5116 memset(&atr_input
, 0, sizeof(struct ixgbe_atr_input
));
5118 vlan_id
= (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
) >>
5119 IXGBE_TX_FLAGS_VLAN_SHIFT
;
5120 src_ipv4_addr
= iph
->saddr
;
5121 dst_ipv4_addr
= iph
->daddr
;
5122 flex_bytes
= eth
->h_proto
;
5124 ixgbe_atr_set_vlan_id_82599(&atr_input
, vlan_id
);
5125 ixgbe_atr_set_src_port_82599(&atr_input
, dst_port
);
5126 ixgbe_atr_set_dst_port_82599(&atr_input
, src_port
);
5127 ixgbe_atr_set_flex_byte_82599(&atr_input
, flex_bytes
);
5128 ixgbe_atr_set_l4type_82599(&atr_input
, l4type
);
5129 /* src and dst are inverted, think how the receiver sees them */
5130 ixgbe_atr_set_src_ipv4_82599(&atr_input
, dst_ipv4_addr
);
5131 ixgbe_atr_set_dst_ipv4_82599(&atr_input
, src_ipv4_addr
);
5133 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5134 ixgbe_fdir_add_signature_filter_82599(&adapter
->hw
, &atr_input
, queue
);
5137 static int __ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5138 struct ixgbe_ring
*tx_ring
, int size
)
5140 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5142 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
5143 /* Herbert's original patch had:
5144 * smp_mb__after_netif_stop_queue();
5145 * but since that doesn't exist yet, just open code it. */
5148 /* We need to check again in a case another CPU has just
5149 * made room available. */
5150 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
5153 /* A reprieve! - use start_queue because it doesn't call schedule */
5154 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
5155 ++adapter
->restart_queue
;
5159 static int ixgbe_maybe_stop_tx(struct net_device
*netdev
,
5160 struct ixgbe_ring
*tx_ring
, int size
)
5162 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
5164 return __ixgbe_maybe_stop_tx(netdev
, tx_ring
, size
);
5167 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
5169 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5171 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
5172 return smp_processor_id();
5174 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
5175 return (skb
->vlan_tci
& IXGBE_TX_FLAGS_VLAN_PRIO_MASK
) >> 13;
5177 return skb_tx_hash(dev
, skb
);
5180 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
,
5181 struct net_device
*netdev
)
5183 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5184 struct ixgbe_ring
*tx_ring
;
5186 unsigned int tx_flags
= 0;
5192 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
5193 tx_flags
|= vlan_tx_tag_get(skb
);
5194 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5195 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
5196 tx_flags
|= (skb
->queue_mapping
<< 13);
5198 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5199 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5200 } else if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5201 if (skb
->priority
!= TC_PRIO_CONTROL
) {
5202 tx_flags
|= (skb
->queue_mapping
<< 13);
5203 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
5204 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
5206 skb
->queue_mapping
=
5207 adapter
->ring_feature
[RING_F_DCB
].indices
-1;
5211 r_idx
= skb
->queue_mapping
;
5212 tx_ring
= &adapter
->tx_ring
[r_idx
];
5214 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
5215 (skb
->protocol
== htons(ETH_P_FCOE
))) {
5216 tx_flags
|= IXGBE_TX_FLAGS_FCOE
;
5218 r_idx
= smp_processor_id();
5219 r_idx
&= (adapter
->ring_feature
[RING_F_FCOE
].indices
- 1);
5220 r_idx
+= adapter
->ring_feature
[RING_F_FCOE
].mask
;
5221 tx_ring
= &adapter
->tx_ring
[r_idx
];
5224 /* four things can cause us to need a context descriptor */
5225 if (skb_is_gso(skb
) ||
5226 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
5227 (tx_flags
& IXGBE_TX_FLAGS_VLAN
) ||
5228 (tx_flags
& IXGBE_TX_FLAGS_FCOE
))
5231 count
+= TXD_USE_COUNT(skb_headlen(skb
));
5232 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
5233 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
5235 if (ixgbe_maybe_stop_tx(netdev
, tx_ring
, count
)) {
5237 return NETDEV_TX_BUSY
;
5240 first
= tx_ring
->next_to_use
;
5241 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
5243 /* setup tx offload for FCoE */
5244 tso
= ixgbe_fso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5246 dev_kfree_skb_any(skb
);
5247 return NETDEV_TX_OK
;
5250 tx_flags
|= IXGBE_TX_FLAGS_FSO
;
5251 #endif /* IXGBE_FCOE */
5253 if (skb
->protocol
== htons(ETH_P_IP
))
5254 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
5255 tso
= ixgbe_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
5257 dev_kfree_skb_any(skb
);
5258 return NETDEV_TX_OK
;
5262 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
5263 else if (ixgbe_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
5264 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
5265 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
5268 count
= ixgbe_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
);
5270 /* add the ATR filter if ATR is on */
5271 if (tx_ring
->atr_sample_rate
) {
5272 ++tx_ring
->atr_count
;
5273 if ((tx_ring
->atr_count
>= tx_ring
->atr_sample_rate
) &&
5274 test_bit(__IXGBE_FDIR_INIT_DONE
,
5275 &tx_ring
->reinit_state
)) {
5276 ixgbe_atr(adapter
, skb
, tx_ring
->queue_index
,
5278 tx_ring
->atr_count
= 0;
5281 ixgbe_tx_queue(adapter
, tx_ring
, tx_flags
, count
, skb
->len
,
5283 ixgbe_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
5286 dev_kfree_skb_any(skb
);
5287 tx_ring
->tx_buffer_info
[first
].time_stamp
= 0;
5288 tx_ring
->next_to_use
= first
;
5291 return NETDEV_TX_OK
;
5295 * ixgbe_get_stats - Get System Network Statistics
5296 * @netdev: network interface device structure
5298 * Returns the address of the device statistics structure.
5299 * The statistics are actually updated from the timer callback.
5301 static struct net_device_stats
*ixgbe_get_stats(struct net_device
*netdev
)
5303 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5305 /* only return the current stats */
5306 return &adapter
->net_stats
;
5310 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5311 * @netdev: network interface device structure
5312 * @p: pointer to an address structure
5314 * Returns 0 on success, negative on failure
5316 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
5318 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5319 struct ixgbe_hw
*hw
= &adapter
->hw
;
5320 struct sockaddr
*addr
= p
;
5322 if (!is_valid_ether_addr(addr
->sa_data
))
5323 return -EADDRNOTAVAIL
;
5325 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
5326 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
5328 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0, IXGBE_RAH_AV
);
5334 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
5336 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5337 struct ixgbe_hw
*hw
= &adapter
->hw
;
5341 if (prtad
!= hw
->phy
.mdio
.prtad
)
5343 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
5349 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
5350 u16 addr
, u16 value
)
5352 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5353 struct ixgbe_hw
*hw
= &adapter
->hw
;
5355 if (prtad
!= hw
->phy
.mdio
.prtad
)
5357 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
5360 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
5362 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5364 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
5368 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5370 * @netdev: network interface device structure
5372 * Returns non-zero on failure
5374 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
5377 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5378 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5380 if (is_valid_ether_addr(mac
->san_addr
)) {
5382 err
= dev_addr_add(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5389 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5391 * @netdev: network interface device structure
5393 * Returns non-zero on failure
5395 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
5398 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5399 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
5401 if (is_valid_ether_addr(mac
->san_addr
)) {
5403 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
5409 #ifdef CONFIG_NET_POLL_CONTROLLER
5411 * Polling 'interrupt' - used by things like netconsole to send skbs
5412 * without having to re-enable interrupts. It's not called while
5413 * the interrupt routine is executing.
5415 static void ixgbe_netpoll(struct net_device
*netdev
)
5417 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5420 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
5421 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
5422 int num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
5423 for (i
= 0; i
< num_q_vectors
; i
++) {
5424 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
5425 ixgbe_msix_clean_many(0, q_vector
);
5428 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
5430 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
5434 static const struct net_device_ops ixgbe_netdev_ops
= {
5435 .ndo_open
= ixgbe_open
,
5436 .ndo_stop
= ixgbe_close
,
5437 .ndo_start_xmit
= ixgbe_xmit_frame
,
5438 .ndo_select_queue
= ixgbe_select_queue
,
5439 .ndo_get_stats
= ixgbe_get_stats
,
5440 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
5441 .ndo_set_multicast_list
= ixgbe_set_rx_mode
,
5442 .ndo_validate_addr
= eth_validate_addr
,
5443 .ndo_set_mac_address
= ixgbe_set_mac
,
5444 .ndo_change_mtu
= ixgbe_change_mtu
,
5445 .ndo_tx_timeout
= ixgbe_tx_timeout
,
5446 .ndo_vlan_rx_register
= ixgbe_vlan_rx_register
,
5447 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
5448 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
5449 .ndo_do_ioctl
= ixgbe_ioctl
,
5450 #ifdef CONFIG_NET_POLL_CONTROLLER
5451 .ndo_poll_controller
= ixgbe_netpoll
,
5454 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
5455 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
5456 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
5457 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
5458 #endif /* IXGBE_FCOE */
5462 * ixgbe_probe - Device Initialization Routine
5463 * @pdev: PCI device information struct
5464 * @ent: entry in ixgbe_pci_tbl
5466 * Returns 0 on success, negative on failure
5468 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5469 * The OS initialization, configuring of the adapter private structure,
5470 * and a hardware reset occur.
5472 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
5473 const struct pci_device_id
*ent
)
5475 struct net_device
*netdev
;
5476 struct ixgbe_adapter
*adapter
= NULL
;
5477 struct ixgbe_hw
*hw
;
5478 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
5479 static int cards_found
;
5480 int i
, err
, pci_using_dac
;
5486 err
= pci_enable_device_mem(pdev
);
5490 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
5491 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
5494 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
5496 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
5498 dev_err(&pdev
->dev
, "No usable DMA "
5499 "configuration, aborting\n");
5506 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
5507 IORESOURCE_MEM
), ixgbe_driver_name
);
5510 "pci_request_selected_regions failed 0x%x\n", err
);
5514 pci_enable_pcie_error_reporting(pdev
);
5516 pci_set_master(pdev
);
5517 pci_save_state(pdev
);
5519 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), MAX_TX_QUEUES
);
5522 goto err_alloc_etherdev
;
5525 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
5527 pci_set_drvdata(pdev
, netdev
);
5528 adapter
= netdev_priv(netdev
);
5530 adapter
->netdev
= netdev
;
5531 adapter
->pdev
= pdev
;
5534 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
5536 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
5537 pci_resource_len(pdev
, 0));
5543 for (i
= 1; i
<= 5; i
++) {
5544 if (pci_resource_len(pdev
, i
) == 0)
5548 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
5549 ixgbe_set_ethtool_ops(netdev
);
5550 netdev
->watchdog_timeo
= 5 * HZ
;
5551 strcpy(netdev
->name
, pci_name(pdev
));
5553 adapter
->bd_number
= cards_found
;
5556 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
5557 hw
->mac
.type
= ii
->mac
;
5560 memcpy(&hw
->eeprom
.ops
, ii
->eeprom_ops
, sizeof(hw
->eeprom
.ops
));
5561 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC
);
5562 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5563 if (!(eec
& (1 << 8)))
5564 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
5567 memcpy(&hw
->phy
.ops
, ii
->phy_ops
, sizeof(hw
->phy
.ops
));
5568 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
5569 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5570 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
5571 hw
->phy
.mdio
.mmds
= 0;
5572 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
5573 hw
->phy
.mdio
.dev
= netdev
;
5574 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
5575 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
5577 /* set up this timer and work struct before calling get_invariants
5578 * which might start the timer
5580 init_timer(&adapter
->sfp_timer
);
5581 adapter
->sfp_timer
.function
= &ixgbe_sfp_timer
;
5582 adapter
->sfp_timer
.data
= (unsigned long) adapter
;
5584 INIT_WORK(&adapter
->sfp_task
, ixgbe_sfp_task
);
5586 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5587 INIT_WORK(&adapter
->multispeed_fiber_task
, ixgbe_multispeed_fiber_task
);
5589 /* a new SFP+ module arrival, called from GPI SDP2 context */
5590 INIT_WORK(&adapter
->sfp_config_module_task
,
5591 ixgbe_sfp_config_module_task
);
5593 ii
->get_invariants(hw
);
5595 /* setup the private structure */
5596 err
= ixgbe_sw_init(adapter
);
5601 * If there is a fan on this device and it has failed log the
5604 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
5605 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
5606 if (esdp
& IXGBE_ESDP_SDP1
)
5607 DPRINTK(PROBE
, CRIT
,
5608 "Fan has stopped, replace the adapter\n");
5611 /* reset_hw fills in the perm_addr as well */
5612 err
= hw
->mac
.ops
.reset_hw(hw
);
5613 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
&&
5614 hw
->mac
.type
== ixgbe_mac_82598EB
) {
5616 * Start a kernel thread to watch for a module to arrive.
5617 * Only do this for 82598, since 82599 will generate
5618 * interrupts on module arrival.
5620 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5621 mod_timer(&adapter
->sfp_timer
,
5622 round_jiffies(jiffies
+ (2 * HZ
)));
5624 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
5625 dev_err(&adapter
->pdev
->dev
, "failed to initialize because "
5626 "an unsupported SFP+ module type was detected.\n"
5627 "Reload the driver after installing a supported "
5631 dev_err(&adapter
->pdev
->dev
, "HW Init failed: %d\n", err
);
5635 netdev
->features
= NETIF_F_SG
|
5637 NETIF_F_HW_VLAN_TX
|
5638 NETIF_F_HW_VLAN_RX
|
5639 NETIF_F_HW_VLAN_FILTER
;
5641 netdev
->features
|= NETIF_F_IPV6_CSUM
;
5642 netdev
->features
|= NETIF_F_TSO
;
5643 netdev
->features
|= NETIF_F_TSO6
;
5644 netdev
->features
|= NETIF_F_GRO
;
5646 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
5647 netdev
->features
|= NETIF_F_SCTP_CSUM
;
5649 netdev
->vlan_features
|= NETIF_F_TSO
;
5650 netdev
->vlan_features
|= NETIF_F_TSO6
;
5651 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
5652 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
5653 netdev
->vlan_features
|= NETIF_F_SG
;
5655 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
5656 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
5658 #ifdef CONFIG_IXGBE_DCB
5659 netdev
->dcbnl_ops
= &dcbnl_ops
;
5663 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
5664 if (hw
->mac
.ops
.get_device_caps
) {
5665 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
5666 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
5667 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
5670 #endif /* IXGBE_FCOE */
5672 netdev
->features
|= NETIF_F_HIGHDMA
;
5674 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
5675 netdev
->features
|= NETIF_F_LRO
;
5677 /* make sure the EEPROM is good */
5678 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
5679 dev_err(&pdev
->dev
, "The EEPROM Checksum Is Not Valid\n");
5684 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
5685 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
5687 if (ixgbe_validate_mac_addr(netdev
->perm_addr
)) {
5688 dev_err(&pdev
->dev
, "invalid MAC address\n");
5693 init_timer(&adapter
->watchdog_timer
);
5694 adapter
->watchdog_timer
.function
= &ixgbe_watchdog
;
5695 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
5697 INIT_WORK(&adapter
->reset_task
, ixgbe_reset_task
);
5698 INIT_WORK(&adapter
->watchdog_task
, ixgbe_watchdog_task
);
5700 err
= ixgbe_init_interrupt_scheme(adapter
);
5704 switch (pdev
->device
) {
5705 case IXGBE_DEV_ID_82599_KX4
:
5706 adapter
->wol
= (IXGBE_WUFC_MAG
| IXGBE_WUFC_EX
|
5707 IXGBE_WUFC_MC
| IXGBE_WUFC_BC
);
5708 /* Enable ACPI wakeup in GRC */
5709 IXGBE_WRITE_REG(hw
, IXGBE_GRC
,
5710 (IXGBE_READ_REG(hw
, IXGBE_GRC
) & ~IXGBE_GRC_APME
));
5716 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
5718 /* pick up the PCI bus settings for reporting later */
5719 hw
->mac
.ops
.get_bus_info(hw
);
5721 /* print bus type/speed/width info */
5722 dev_info(&pdev
->dev
, "(PCI Express:%s:%s) %pM\n",
5723 ((hw
->bus
.speed
== ixgbe_bus_speed_5000
) ? "5.0Gb/s":
5724 (hw
->bus
.speed
== ixgbe_bus_speed_2500
) ? "2.5Gb/s":"Unknown"),
5725 ((hw
->bus
.width
== ixgbe_bus_width_pcie_x8
) ? "Width x8" :
5726 (hw
->bus
.width
== ixgbe_bus_width_pcie_x4
) ? "Width x4" :
5727 (hw
->bus
.width
== ixgbe_bus_width_pcie_x1
) ? "Width x1" :
5730 ixgbe_read_pba_num_generic(hw
, &part_num
);
5731 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
5732 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5733 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
5734 (part_num
>> 8), (part_num
& 0xff));
5736 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5737 hw
->mac
.type
, hw
->phy
.type
,
5738 (part_num
>> 8), (part_num
& 0xff));
5740 if (hw
->bus
.width
<= ixgbe_bus_width_pcie_x4
) {
5741 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for "
5742 "this card is not sufficient for optimal "
5744 dev_warn(&pdev
->dev
, "For optimal performance a x8 "
5745 "PCI-Express slot is required.\n");
5748 /* save off EEPROM version number */
5749 hw
->eeprom
.ops
.read(hw
, 0x29, &adapter
->eeprom_version
);
5751 /* reset the hardware with the new settings */
5752 err
= hw
->mac
.ops
.start_hw(hw
);
5754 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
5755 /* We are running on a pre-production device, log a warning */
5756 dev_warn(&pdev
->dev
, "This device is a pre-production "
5757 "adapter/LOM. Please be aware there may be issues "
5758 "associated with your hardware. If you are "
5759 "experiencing problems please contact your Intel or "
5760 "hardware representative who provided you with this "
5763 strcpy(netdev
->name
, "eth%d");
5764 err
= register_netdev(netdev
);
5768 /* carrier off reporting is important to ethtool even BEFORE open */
5769 netif_carrier_off(netdev
);
5771 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
5772 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
5773 INIT_WORK(&adapter
->fdir_reinit_task
, ixgbe_fdir_reinit_task
);
5775 #ifdef CONFIG_IXGBE_DCA
5776 if (dca_add_requester(&pdev
->dev
) == 0) {
5777 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
5778 ixgbe_setup_dca(adapter
);
5781 /* add san mac addr to netdev */
5782 ixgbe_add_sanmac_netdev(netdev
);
5784 dev_info(&pdev
->dev
, "Intel(R) 10 Gigabit Network Connection\n");
5789 ixgbe_release_hw_control(adapter
);
5790 ixgbe_clear_interrupt_scheme(adapter
);
5793 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5794 del_timer_sync(&adapter
->sfp_timer
);
5795 cancel_work_sync(&adapter
->sfp_task
);
5796 cancel_work_sync(&adapter
->multispeed_fiber_task
);
5797 cancel_work_sync(&adapter
->sfp_config_module_task
);
5798 iounmap(hw
->hw_addr
);
5800 free_netdev(netdev
);
5802 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
5806 pci_disable_device(pdev
);
5811 * ixgbe_remove - Device Removal Routine
5812 * @pdev: PCI device information struct
5814 * ixgbe_remove is called by the PCI subsystem to alert the driver
5815 * that it should release a PCI device. The could be caused by a
5816 * Hot-Plug event, or because the driver is going to be removed from
5819 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
5821 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5822 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5824 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5825 /* clear the module not found bit to make sure the worker won't
5828 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND
, &adapter
->state
);
5829 del_timer_sync(&adapter
->watchdog_timer
);
5831 del_timer_sync(&adapter
->sfp_timer
);
5832 cancel_work_sync(&adapter
->watchdog_task
);
5833 cancel_work_sync(&adapter
->sfp_task
);
5834 cancel_work_sync(&adapter
->multispeed_fiber_task
);
5835 cancel_work_sync(&adapter
->sfp_config_module_task
);
5836 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
5837 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
5838 cancel_work_sync(&adapter
->fdir_reinit_task
);
5839 flush_scheduled_work();
5841 #ifdef CONFIG_IXGBE_DCA
5842 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
5843 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
5844 dca_remove_requester(&pdev
->dev
);
5845 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
5850 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
5851 ixgbe_cleanup_fcoe(adapter
);
5853 #endif /* IXGBE_FCOE */
5855 /* remove the added san mac */
5856 ixgbe_del_sanmac_netdev(netdev
);
5858 if (netdev
->reg_state
== NETREG_REGISTERED
)
5859 unregister_netdev(netdev
);
5861 ixgbe_clear_interrupt_scheme(adapter
);
5863 ixgbe_release_hw_control(adapter
);
5865 iounmap(adapter
->hw
.hw_addr
);
5866 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
5869 DPRINTK(PROBE
, INFO
, "complete\n");
5871 free_netdev(netdev
);
5873 pci_disable_pcie_error_reporting(pdev
);
5875 pci_disable_device(pdev
);
5879 * ixgbe_io_error_detected - called when PCI error is detected
5880 * @pdev: Pointer to PCI device
5881 * @state: The current pci connection state
5883 * This function is called after a PCI bus error affecting
5884 * this device has been detected.
5886 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
5887 pci_channel_state_t state
)
5889 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5890 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5892 netif_device_detach(netdev
);
5894 if (state
== pci_channel_io_perm_failure
)
5895 return PCI_ERS_RESULT_DISCONNECT
;
5897 if (netif_running(netdev
))
5898 ixgbe_down(adapter
);
5899 pci_disable_device(pdev
);
5901 /* Request a slot reset. */
5902 return PCI_ERS_RESULT_NEED_RESET
;
5906 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5907 * @pdev: Pointer to PCI device
5909 * Restart the card from scratch, as if from a cold-boot.
5911 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
5913 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5914 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5915 pci_ers_result_t result
;
5918 if (pci_enable_device_mem(pdev
)) {
5920 "Cannot re-enable PCI device after reset.\n");
5921 result
= PCI_ERS_RESULT_DISCONNECT
;
5923 pci_set_master(pdev
);
5924 pci_restore_state(pdev
);
5926 pci_wake_from_d3(pdev
, false);
5928 ixgbe_reset(adapter
);
5929 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
5930 result
= PCI_ERS_RESULT_RECOVERED
;
5933 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
5936 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err
);
5937 /* non-fatal, continue */
5944 * ixgbe_io_resume - called when traffic can start flowing again.
5945 * @pdev: Pointer to PCI device
5947 * This callback is called when the error recovery driver tells us that
5948 * its OK to resume normal operation.
5950 static void ixgbe_io_resume(struct pci_dev
*pdev
)
5952 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5953 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5955 if (netif_running(netdev
)) {
5956 if (ixgbe_up(adapter
)) {
5957 DPRINTK(PROBE
, INFO
, "ixgbe_up failed after reset\n");
5962 netif_device_attach(netdev
);
5965 static struct pci_error_handlers ixgbe_err_handler
= {
5966 .error_detected
= ixgbe_io_error_detected
,
5967 .slot_reset
= ixgbe_io_slot_reset
,
5968 .resume
= ixgbe_io_resume
,
5971 static struct pci_driver ixgbe_driver
= {
5972 .name
= ixgbe_driver_name
,
5973 .id_table
= ixgbe_pci_tbl
,
5974 .probe
= ixgbe_probe
,
5975 .remove
= __devexit_p(ixgbe_remove
),
5977 .suspend
= ixgbe_suspend
,
5978 .resume
= ixgbe_resume
,
5980 .shutdown
= ixgbe_shutdown
,
5981 .err_handler
= &ixgbe_err_handler
5985 * ixgbe_init_module - Driver Registration Routine
5987 * ixgbe_init_module is the first routine called when the driver is
5988 * loaded. All it does is register with the PCI subsystem.
5990 static int __init
ixgbe_init_module(void)
5993 printk(KERN_INFO
"%s: %s - version %s\n", ixgbe_driver_name
,
5994 ixgbe_driver_string
, ixgbe_driver_version
);
5996 printk(KERN_INFO
"%s: %s\n", ixgbe_driver_name
, ixgbe_copyright
);
5998 #ifdef CONFIG_IXGBE_DCA
5999 dca_register_notify(&dca_notifier
);
6002 ret
= pci_register_driver(&ixgbe_driver
);
6006 module_init(ixgbe_init_module
);
6009 * ixgbe_exit_module - Driver Exit Cleanup Routine
6011 * ixgbe_exit_module is called just before the driver is removed
6014 static void __exit
ixgbe_exit_module(void)
6016 #ifdef CONFIG_IXGBE_DCA
6017 dca_unregister_notify(&dca_notifier
);
6019 pci_unregister_driver(&ixgbe_driver
);
6022 #ifdef CONFIG_IXGBE_DCA
6023 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
6028 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
6029 __ixgbe_notify_dca
);
6031 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
6034 #endif /* CONFIG_IXGBE_DCA */
6037 * ixgbe_get_hw_dev_name - return device name string
6038 * used by hardware layer to print debugging information
6040 char *ixgbe_get_hw_dev_name(struct ixgbe_hw
*hw
)
6042 struct ixgbe_adapter
*adapter
= hw
->back
;
6043 return adapter
->netdev
->name
;
6047 module_exit(ixgbe_exit_module
);