1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2007 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 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/types.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <linux/netdevice.h>
33 #include <linux/vmalloc.h>
34 #include <linux/string.h>
37 #include <linux/tcp.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>
45 #include "ixgbe_common.h"
47 char ixgbe_driver_name
[] = "ixgbe";
48 static const char ixgbe_driver_string
[] =
49 "Intel(R) 10 Gigabit PCI Express Network Driver";
51 #define DRV_VERSION "1.1.18"
52 const char ixgbe_driver_version
[] = DRV_VERSION
;
53 static const char ixgbe_copyright
[] =
54 "Copyright (c) 1999-2007 Intel Corporation.";
56 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
57 [board_82598
] = &ixgbe_82598_info
,
60 /* ixgbe_pci_tbl - PCI Device ID Table
62 * Wildcard entries (PCI_ANY_ID) should come last
63 * Last entry must be all 0s
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
68 static struct pci_device_id ixgbe_pci_tbl
[] = {
69 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
),
71 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
),
73 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT_DUAL_PORT
),
75 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
),
78 /* required last entry */
81 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
83 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
84 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
85 MODULE_LICENSE("GPL");
86 MODULE_VERSION(DRV_VERSION
);
88 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
90 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
94 /* Let firmware take over control of h/w */
95 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
96 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
97 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
100 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
104 /* Let firmware know the driver has taken over */
105 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
106 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
107 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
112 * ixgbe_get_hw_dev_name - return device name string
113 * used by hardware layer to print debugging information
115 char *ixgbe_get_hw_dev_name(struct ixgbe_hw
*hw
)
117 struct ixgbe_adapter
*adapter
= hw
->back
;
118 struct net_device
*netdev
= adapter
->netdev
;
123 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, u16 int_alloc_entry
,
128 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
129 index
= (int_alloc_entry
>> 2) & 0x1F;
130 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR(index
));
131 ivar
&= ~(0xFF << (8 * (int_alloc_entry
& 0x3)));
132 ivar
|= (msix_vector
<< (8 * (int_alloc_entry
& 0x3)));
133 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR(index
), ivar
);
136 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter
*adapter
,
137 struct ixgbe_tx_buffer
140 if (tx_buffer_info
->dma
) {
141 pci_unmap_page(adapter
->pdev
,
143 tx_buffer_info
->length
, PCI_DMA_TODEVICE
);
144 tx_buffer_info
->dma
= 0;
146 if (tx_buffer_info
->skb
) {
147 dev_kfree_skb_any(tx_buffer_info
->skb
);
148 tx_buffer_info
->skb
= NULL
;
150 /* tx_buffer_info must be completely set up in the transmit path */
153 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter
*adapter
,
154 struct ixgbe_ring
*tx_ring
,
156 union ixgbe_adv_tx_desc
*eop_desc
)
158 /* Detect a transmit hang in hardware, this serializes the
159 * check with the clearing of time_stamp and movement of i */
160 adapter
->detect_tx_hung
= false;
161 if (tx_ring
->tx_buffer_info
[eop
].dma
&&
162 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
) &&
163 !(IXGBE_READ_REG(&adapter
->hw
, IXGBE_TFCS
) & IXGBE_TFCS_TXOFF
)) {
164 /* detected Tx unit hang */
165 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
168 " next_to_use <%x>\n"
169 " next_to_clean <%x>\n"
170 "tx_buffer_info[next_to_clean]\n"
171 " time_stamp <%lx>\n"
172 " next_to_watch <%x>\n"
174 " next_to_watch.status <%x>\n",
175 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
176 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
177 tx_ring
->next_to_use
,
178 tx_ring
->next_to_clean
,
179 tx_ring
->tx_buffer_info
[eop
].time_stamp
,
180 eop
, jiffies
, eop_desc
->wb
.status
);
187 #define IXGBE_MAX_TXD_PWR 14
188 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
190 /* Tx Descriptors needed, worst case */
191 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
192 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
193 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
194 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
197 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
198 * @adapter: board private structure
200 static bool ixgbe_clean_tx_irq(struct ixgbe_adapter
*adapter
,
201 struct ixgbe_ring
*tx_ring
)
203 struct net_device
*netdev
= adapter
->netdev
;
204 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
205 struct ixgbe_tx_buffer
*tx_buffer_info
;
207 bool cleaned
= false;
208 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
210 i
= tx_ring
->next_to_clean
;
211 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
212 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
213 while (eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) {
216 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
217 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
218 cleaned
= (i
== eop
);
220 tx_ring
->stats
.bytes
+= tx_buffer_info
->length
;
222 struct sk_buff
*skb
= tx_buffer_info
->skb
;
223 unsigned int segs
, bytecount
;
224 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
225 /* multiply data chunks by size of headers */
226 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
228 total_tx_packets
+= segs
;
229 total_tx_bytes
+= bytecount
;
231 ixgbe_unmap_and_free_tx_resource(adapter
,
233 tx_desc
->wb
.status
= 0;
236 if (i
== tx_ring
->count
)
240 tx_ring
->stats
.packets
++;
242 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
243 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
245 /* weight of a sort for tx, avoid endless transmit cleanup */
246 if (total_tx_packets
>= tx_ring
->work_limit
)
250 tx_ring
->next_to_clean
= i
;
252 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
253 if (total_tx_packets
&& netif_carrier_ok(netdev
) &&
254 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
255 /* Make sure that anybody stopping the queue after this
256 * sees the new next_to_clean.
259 if (netif_queue_stopped(netdev
) &&
260 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
261 netif_wake_queue(netdev
);
262 adapter
->restart_queue
++;
266 if (adapter
->detect_tx_hung
)
267 if (ixgbe_check_tx_hang(adapter
, tx_ring
, eop
, eop_desc
))
268 netif_stop_queue(netdev
);
270 if (total_tx_packets
>= tx_ring
->work_limit
)
271 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, tx_ring
->eims_value
);
273 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
274 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
275 cleaned
= total_tx_packets
? true : false;
280 * ixgbe_receive_skb - Send a completed packet up the stack
281 * @adapter: board private structure
282 * @skb: packet to send up
283 * @is_vlan: packet has a VLAN tag
284 * @tag: VLAN tag from descriptor
286 static void ixgbe_receive_skb(struct ixgbe_adapter
*adapter
,
287 struct sk_buff
*skb
, bool is_vlan
,
290 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
291 if (adapter
->vlgrp
&& is_vlan
)
292 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
, tag
);
294 netif_receive_skb(skb
);
297 if (adapter
->vlgrp
&& is_vlan
)
298 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
305 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
306 * @adapter: address of board private structure
307 * @status_err: hardware indication of status of receive
308 * @skb: skb currently being received and modified
310 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
314 skb
->ip_summed
= CHECKSUM_NONE
;
316 /* Ignore Checksum bit is set, or rx csum disabled */
317 if ((status_err
& IXGBE_RXD_STAT_IXSM
) ||
318 !(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
321 /* if IP and error */
322 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
323 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
324 adapter
->hw_csum_rx_error
++;
328 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
331 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
332 adapter
->hw_csum_rx_error
++;
336 /* It must be a TCP or UDP packet with a valid checksum */
337 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
338 adapter
->hw_csum_rx_good
++;
342 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
343 * @adapter: address of board private structure
345 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter
*adapter
,
346 struct ixgbe_ring
*rx_ring
,
349 struct net_device
*netdev
= adapter
->netdev
;
350 struct pci_dev
*pdev
= adapter
->pdev
;
351 union ixgbe_adv_rx_desc
*rx_desc
;
352 struct ixgbe_rx_buffer
*rx_buffer_info
;
355 unsigned int bufsz
= adapter
->rx_buf_len
+ NET_IP_ALIGN
;
357 i
= rx_ring
->next_to_use
;
358 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
360 while (cleaned_count
--) {
361 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
363 if (!rx_buffer_info
->page
&&
364 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
365 rx_buffer_info
->page
= alloc_page(GFP_ATOMIC
);
366 if (!rx_buffer_info
->page
) {
367 adapter
->alloc_rx_page_failed
++;
370 rx_buffer_info
->page_dma
=
371 pci_map_page(pdev
, rx_buffer_info
->page
,
372 0, PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
375 if (!rx_buffer_info
->skb
) {
376 skb
= netdev_alloc_skb(netdev
, bufsz
);
379 adapter
->alloc_rx_buff_failed
++;
384 * Make buffer alignment 2 beyond a 16 byte boundary
385 * this will result in a 16 byte aligned IP header after
386 * the 14 byte MAC header is removed
388 skb_reserve(skb
, NET_IP_ALIGN
);
390 rx_buffer_info
->skb
= skb
;
391 rx_buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
395 /* Refresh the desc even if buffer_addrs didn't change because
396 * each write-back erases this info. */
397 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
398 rx_desc
->read
.pkt_addr
=
399 cpu_to_le64(rx_buffer_info
->page_dma
);
400 rx_desc
->read
.hdr_addr
=
401 cpu_to_le64(rx_buffer_info
->dma
);
403 rx_desc
->read
.pkt_addr
=
404 cpu_to_le64(rx_buffer_info
->dma
);
408 if (i
== rx_ring
->count
)
410 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
413 if (rx_ring
->next_to_use
!= i
) {
414 rx_ring
->next_to_use
= i
;
416 i
= (rx_ring
->count
- 1);
419 * Force memory writes to complete before letting h/w
420 * know there are new descriptors to fetch. (Only
421 * applicable for weak-ordered memory model archs,
425 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
429 static bool ixgbe_clean_rx_irq(struct ixgbe_adapter
*adapter
,
430 struct ixgbe_ring
*rx_ring
,
431 int *work_done
, int work_to_do
)
433 struct net_device
*netdev
= adapter
->netdev
;
434 struct pci_dev
*pdev
= adapter
->pdev
;
435 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
436 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
439 u32 upper_len
, len
, staterr
;
440 u16 hdr_info
, vlan_tag
;
441 bool is_vlan
, cleaned
= false;
442 int cleaned_count
= 0;
443 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
445 i
= rx_ring
->next_to_clean
;
447 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
448 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
449 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
450 is_vlan
= (staterr
& IXGBE_RXD_STAT_VP
);
451 vlan_tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
453 while (staterr
& IXGBE_RXD_STAT_DD
) {
454 if (*work_done
>= work_to_do
)
458 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
460 le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hdr_info
);
462 ((hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
463 IXGBE_RXDADV_HDRBUFLEN_SHIFT
);
464 if (hdr_info
& IXGBE_RXDADV_SPH
)
465 adapter
->rx_hdr_split
++;
466 if (len
> IXGBE_RX_HDR_SIZE
)
467 len
= IXGBE_RX_HDR_SIZE
;
468 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
470 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
473 skb
= rx_buffer_info
->skb
;
474 prefetch(skb
->data
- NET_IP_ALIGN
);
475 rx_buffer_info
->skb
= NULL
;
477 if (len
&& !skb_shinfo(skb
)->nr_frags
) {
478 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
479 adapter
->rx_buf_len
+ NET_IP_ALIGN
,
485 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
486 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
487 rx_buffer_info
->page_dma
= 0;
488 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
489 rx_buffer_info
->page
, 0, upper_len
);
490 rx_buffer_info
->page
= NULL
;
492 skb
->len
+= upper_len
;
493 skb
->data_len
+= upper_len
;
494 skb
->truesize
+= upper_len
;
498 if (i
== rx_ring
->count
)
500 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
502 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
506 if (staterr
& IXGBE_RXD_STAT_EOP
) {
507 rx_ring
->stats
.packets
++;
508 rx_ring
->stats
.bytes
+= skb
->len
;
510 rx_buffer_info
->skb
= next_buffer
->skb
;
511 rx_buffer_info
->dma
= next_buffer
->dma
;
512 next_buffer
->skb
= skb
;
513 adapter
->non_eop_descs
++;
517 if (staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) {
518 dev_kfree_skb_irq(skb
);
522 ixgbe_rx_checksum(adapter
, staterr
, skb
);
524 /* probably a little skewed due to removing CRC */
525 total_rx_bytes
+= skb
->len
;
528 skb
->protocol
= eth_type_trans(skb
, netdev
);
529 ixgbe_receive_skb(adapter
, skb
, is_vlan
, vlan_tag
);
530 netdev
->last_rx
= jiffies
;
533 rx_desc
->wb
.upper
.status_error
= 0;
535 /* return some buffers to hardware, one at a time is too slow */
536 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
537 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
541 /* use prefetched values */
543 rx_buffer_info
= next_buffer
;
545 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
546 is_vlan
= (staterr
& IXGBE_RXD_STAT_VP
);
547 vlan_tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
550 rx_ring
->next_to_clean
= i
;
551 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
554 ixgbe_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
556 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
557 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
562 #define IXGBE_MAX_INTR 10
564 * ixgbe_configure_msix - Configure MSI-X hardware
565 * @adapter: board private structure
567 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
570 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
574 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
575 ixgbe_set_ivar(adapter
, IXGBE_IVAR_TX_QUEUE(i
),
576 IXGBE_MSIX_VECTOR(vector
));
577 writel(EITR_INTS_PER_SEC_TO_REG(adapter
->tx_eitr
),
578 adapter
->hw
.hw_addr
+ adapter
->tx_ring
[i
].itr_register
);
582 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
583 ixgbe_set_ivar(adapter
, IXGBE_IVAR_RX_QUEUE(i
),
584 IXGBE_MSIX_VECTOR(vector
));
585 writel(EITR_INTS_PER_SEC_TO_REG(adapter
->rx_eitr
),
586 adapter
->hw
.hw_addr
+ adapter
->rx_ring
[i
].itr_register
);
590 vector
= adapter
->num_tx_queues
+ adapter
->num_rx_queues
;
591 ixgbe_set_ivar(adapter
, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
592 IXGBE_MSIX_VECTOR(vector
));
593 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(vector
), 1950);
596 static irqreturn_t
ixgbe_msix_lsc(int irq
, void *data
)
598 struct net_device
*netdev
= data
;
599 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
600 struct ixgbe_hw
*hw
= &adapter
->hw
;
601 u32 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
603 if (eicr
& IXGBE_EICR_LSC
) {
605 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
606 mod_timer(&adapter
->watchdog_timer
, jiffies
);
609 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
610 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_OTHER
);
615 static irqreturn_t
ixgbe_msix_clean_tx(int irq
, void *data
)
617 struct ixgbe_ring
*txr
= data
;
618 struct ixgbe_adapter
*adapter
= txr
->adapter
;
620 ixgbe_clean_tx_irq(adapter
, txr
);
625 static irqreturn_t
ixgbe_msix_clean_rx(int irq
, void *data
)
627 struct ixgbe_ring
*rxr
= data
;
628 struct ixgbe_adapter
*adapter
= rxr
->adapter
;
630 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, rxr
->eims_value
);
631 netif_rx_schedule(adapter
->netdev
, &adapter
->napi
);
635 static int ixgbe_clean_rxonly(struct napi_struct
*napi
, int budget
)
637 struct ixgbe_adapter
*adapter
= container_of(napi
,
638 struct ixgbe_adapter
, napi
);
639 struct net_device
*netdev
= adapter
->netdev
;
641 struct ixgbe_ring
*rxr
= adapter
->rx_ring
;
643 /* Keep link state information with original netdev */
644 if (!netif_carrier_ok(netdev
))
647 ixgbe_clean_rx_irq(adapter
, rxr
, &work_done
, budget
);
649 /* If no Tx and not enough Rx work done, exit the polling mode */
650 if ((work_done
< budget
) || !netif_running(netdev
)) {
652 netif_rx_complete(netdev
, napi
);
653 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
654 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
,
662 * ixgbe_setup_msix - Initialize MSI-X interrupts
664 * ixgbe_setup_msix allocates MSI-X vectors and requests
665 * interrutps from the kernel.
667 static int ixgbe_setup_msix(struct ixgbe_adapter
*adapter
)
669 struct net_device
*netdev
= adapter
->netdev
;
670 int i
, int_vector
= 0, err
= 0;
673 /* +1 for the LSC interrupt */
674 max_msix_count
= adapter
->num_rx_queues
+ adapter
->num_tx_queues
+ 1;
675 adapter
->msix_entries
= kcalloc(max_msix_count
,
676 sizeof(struct msix_entry
), GFP_KERNEL
);
677 if (!adapter
->msix_entries
)
680 for (i
= 0; i
< max_msix_count
; i
++)
681 adapter
->msix_entries
[i
].entry
= i
;
683 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
688 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
689 sprintf(adapter
->tx_ring
[i
].name
, "%s-tx%d", netdev
->name
, i
);
690 err
= request_irq(adapter
->msix_entries
[int_vector
].vector
,
691 &ixgbe_msix_clean_tx
,
693 adapter
->tx_ring
[i
].name
,
694 &(adapter
->tx_ring
[i
]));
697 "request_irq failed for MSIX interrupt "
701 adapter
->tx_ring
[i
].eims_value
=
702 (1 << IXGBE_MSIX_VECTOR(int_vector
));
703 adapter
->tx_ring
[i
].itr_register
= IXGBE_EITR(int_vector
);
707 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
708 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
709 sprintf(adapter
->rx_ring
[i
].name
,
710 "%s-rx%d", netdev
->name
, i
);
712 memcpy(adapter
->rx_ring
[i
].name
,
713 netdev
->name
, IFNAMSIZ
);
714 err
= request_irq(adapter
->msix_entries
[int_vector
].vector
,
715 &ixgbe_msix_clean_rx
, 0,
716 adapter
->rx_ring
[i
].name
,
717 &(adapter
->rx_ring
[i
]));
720 "request_irq failed for MSIX interrupt "
725 adapter
->rx_ring
[i
].eims_value
=
726 (1 << IXGBE_MSIX_VECTOR(int_vector
));
727 adapter
->rx_ring
[i
].itr_register
= IXGBE_EITR(int_vector
);
731 sprintf(adapter
->lsc_name
, "%s-lsc", netdev
->name
);
732 err
= request_irq(adapter
->msix_entries
[int_vector
].vector
,
733 &ixgbe_msix_lsc
, 0, adapter
->lsc_name
, netdev
);
736 "request_irq for msix_lsc failed: %d\n", err
);
740 /* FIXME: implement netif_napi_remove() instead */
741 adapter
->napi
.poll
= ixgbe_clean_rxonly
;
742 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
;
747 for (; int_vector
>= adapter
->num_tx_queues
; int_vector
--)
748 free_irq(adapter
->msix_entries
[int_vector
].vector
,
749 &(adapter
->rx_ring
[int_vector
-
750 adapter
->num_tx_queues
]));
752 for (; int_vector
>= 0; int_vector
--)
753 free_irq(adapter
->msix_entries
[int_vector
].vector
,
754 &(adapter
->tx_ring
[int_vector
]));
756 kfree(adapter
->msix_entries
);
757 adapter
->msix_entries
= NULL
;
758 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
763 * ixgbe_intr - Interrupt Handler
764 * @irq: interrupt number
765 * @data: pointer to a network interface device structure
766 * @pt_regs: CPU registers structure
768 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
770 struct net_device
*netdev
= data
;
771 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
772 struct ixgbe_hw
*hw
= &adapter
->hw
;
775 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
778 return IRQ_NONE
; /* Not our interrupt */
780 if (eicr
& IXGBE_EICR_LSC
) {
782 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
783 mod_timer(&adapter
->watchdog_timer
, jiffies
);
785 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
786 /* Disable interrupts and register for poll. The flush of the
787 * posted write is intentionally left out. */
788 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
789 __netif_rx_schedule(netdev
, &adapter
->napi
);
796 * ixgbe_request_irq - initialize interrupts
797 * @adapter: board private structure
799 * Attempts to configure interrupts using the best available
800 * capabilities of the hardware and kernel.
802 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
, u32
*num_rx_queues
)
804 struct net_device
*netdev
= adapter
->netdev
;
806 irq_handler_t handler
= ixgbe_intr
;
810 err
= ixgbe_setup_msix(adapter
);
815 * if we can't do MSI-X, fall through and try MSI
816 * No need to reallocate memory since we're decreasing the number of
817 * queues. We just won't use the other ones, also it is freed correctly
823 err
= pci_enable_msi(adapter
->pdev
);
825 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
826 flags
&= ~IRQF_SHARED
;
827 handler
= &ixgbe_intr
;
830 err
= request_irq(adapter
->pdev
->irq
, handler
, flags
,
831 netdev
->name
, netdev
);
833 DPRINTK(PROBE
, ERR
, "request_irq failed, Error %d\n", err
);
839 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
841 struct net_device
*netdev
= adapter
->netdev
;
843 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
846 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
847 free_irq(adapter
->msix_entries
[i
].vector
,
848 &(adapter
->tx_ring
[i
]));
849 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
850 free_irq(adapter
->msix_entries
[i
+
851 adapter
->num_tx_queues
].vector
,
852 &(adapter
->rx_ring
[i
]));
853 i
= adapter
->num_rx_queues
+ adapter
->num_tx_queues
;
854 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
855 pci_disable_msix(adapter
->pdev
);
856 kfree(adapter
->msix_entries
);
857 adapter
->msix_entries
= NULL
;
858 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
862 free_irq(adapter
->pdev
->irq
, netdev
);
863 if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
864 pci_disable_msi(adapter
->pdev
);
865 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
870 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
871 * @adapter: board private structure
873 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
875 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
876 IXGBE_WRITE_FLUSH(&adapter
->hw
);
877 synchronize_irq(adapter
->pdev
->irq
);
881 * ixgbe_irq_enable - Enable default interrupt generation settings
882 * @adapter: board private structure
884 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
)
886 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
887 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
,
888 (IXGBE_EIMS_ENABLE_MASK
&
889 ~(IXGBE_EIMS_OTHER
| IXGBE_EIMS_LSC
)));
890 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
,
891 IXGBE_EIMS_ENABLE_MASK
);
892 IXGBE_WRITE_FLUSH(&adapter
->hw
);
896 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
899 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
902 struct ixgbe_hw
*hw
= &adapter
->hw
;
904 if (adapter
->rx_eitr
)
905 IXGBE_WRITE_REG(hw
, IXGBE_EITR(0),
906 EITR_INTS_PER_SEC_TO_REG(adapter
->rx_eitr
));
908 /* for re-triggering the interrupt in non-NAPI mode */
909 adapter
->rx_ring
[0].eims_value
= (1 << IXGBE_MSIX_VECTOR(0));
910 adapter
->tx_ring
[0].eims_value
= (1 << IXGBE_MSIX_VECTOR(0));
912 ixgbe_set_ivar(adapter
, IXGBE_IVAR_RX_QUEUE(0), 0);
913 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
914 ixgbe_set_ivar(adapter
, IXGBE_IVAR_TX_QUEUE(i
), i
);
918 * ixgbe_configure_tx - Configure 8254x Transmit Unit after Reset
919 * @adapter: board private structure
921 * Configure the Tx unit of the MAC after a reset.
923 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
926 struct ixgbe_hw
*hw
= &adapter
->hw
;
929 /* Setup the HW Tx Head and Tail descriptor pointers */
930 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
931 tdba
= adapter
->tx_ring
[i
].dma
;
932 tdlen
= adapter
->tx_ring
[i
].count
*
933 sizeof(union ixgbe_adv_tx_desc
);
934 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(i
), (tdba
& DMA_32BIT_MASK
));
935 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(i
), (tdba
>> 32));
936 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(i
), tdlen
);
937 IXGBE_WRITE_REG(hw
, IXGBE_TDH(i
), 0);
938 IXGBE_WRITE_REG(hw
, IXGBE_TDT(i
), 0);
939 adapter
->tx_ring
[i
].head
= IXGBE_TDH(i
);
940 adapter
->tx_ring
[i
].tail
= IXGBE_TDT(i
);
943 IXGBE_WRITE_REG(hw
, IXGBE_TIPG
, IXGBE_TIPG_FIBER_DEFAULT
);
946 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
947 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
949 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
951 * ixgbe_configure_rx - Configure 8254x Receive Unit after Reset
952 * @adapter: board private structure
954 * Configure the Rx unit of the MAC after a reset.
956 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
959 struct ixgbe_hw
*hw
= &adapter
->hw
;
960 struct net_device
*netdev
= adapter
->netdev
;
961 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
962 u32 rdlen
, rxctrl
, rxcsum
;
970 /* Decide whether to use packet split mode or not */
971 if (netdev
->mtu
> ETH_DATA_LEN
)
972 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
974 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
976 /* Set the RX buffer length according to the mode */
977 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
978 adapter
->rx_buf_len
= IXGBE_RX_HDR_SIZE
;
980 if (netdev
->mtu
<= ETH_DATA_LEN
)
981 adapter
->rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
983 adapter
->rx_buf_len
= ALIGN(max_frame
, 1024);
986 fctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_FCTRL
);
987 fctrl
|= IXGBE_FCTRL_BAM
;
988 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_FCTRL
, fctrl
);
990 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
991 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
992 hlreg0
&= ~IXGBE_HLREG0_JUMBOEN
;
994 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
995 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
997 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
999 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(0));
1000 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
1001 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
1003 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1004 srrctl
|= PAGE_SIZE
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1005 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1006 srrctl
|= ((IXGBE_RX_HDR_SIZE
<<
1007 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1008 IXGBE_SRRCTL_BSIZEHDR_MASK
);
1010 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1012 if (adapter
->rx_buf_len
== MAXIMUM_ETHERNET_VLAN_SIZE
)
1014 IXGBE_RXBUFFER_2048
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1017 adapter
->rx_buf_len
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1019 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(0), srrctl
);
1021 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1022 /* disable receives while setting up the descriptors */
1023 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
1024 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
1026 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1027 * the Base and Length of the Rx Descriptor Ring */
1028 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1029 rdba
= adapter
->rx_ring
[i
].dma
;
1030 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(i
), (rdba
& DMA_32BIT_MASK
));
1031 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(i
), (rdba
>> 32));
1032 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(i
), rdlen
);
1033 IXGBE_WRITE_REG(hw
, IXGBE_RDH(i
), 0);
1034 IXGBE_WRITE_REG(hw
, IXGBE_RDT(i
), 0);
1035 adapter
->rx_ring
[i
].head
= IXGBE_RDH(i
);
1036 adapter
->rx_ring
[i
].tail
= IXGBE_RDT(i
);
1039 if (adapter
->num_rx_queues
> 1) {
1040 /* Random 40bytes used as random key in RSS hash function */
1041 get_random_bytes(&random
[0], 40);
1043 switch (adapter
->num_rx_queues
) {
1046 /* Bits [3:0] in each byte refers the Rx queue no */
1057 /* Fill out redirection table */
1058 for (i
= 0; i
< 32; i
++) {
1059 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_RETA(0), i
, reta
);
1060 if (adapter
->num_rx_queues
> 4) {
1062 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_RETA(0), i
,
1067 /* Fill out hash function seeds */
1068 for (i
= 0; i
< 10; i
++)
1069 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_RSSRK(0), i
, random
[i
]);
1071 mrqc
= IXGBE_MRQC_RSSEN
1072 /* Perform hash on these packet types */
1073 | IXGBE_MRQC_RSS_FIELD_IPV4
1074 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1075 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1076 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1077 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1078 | IXGBE_MRQC_RSS_FIELD_IPV6
1079 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1080 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1081 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP
;
1082 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
1084 /* Multiqueue and packet checksumming are mutually exclusive. */
1085 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
1086 rxcsum
|= IXGBE_RXCSUM_PCSD
;
1087 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
1089 /* Enable Receive Checksum Offload for TCP and UDP */
1090 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
1091 if (adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
) {
1092 /* Enable IPv4 payload checksum for UDP fragments
1093 * Must be used in conjunction with packet-split. */
1094 rxcsum
|= IXGBE_RXCSUM_IPPCSE
;
1096 /* don't need to clear IPPCSE as it defaults to 0 */
1098 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
1100 /* Enable Receives */
1101 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
);
1102 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
1105 static void ixgbe_vlan_rx_register(struct net_device
*netdev
,
1106 struct vlan_group
*grp
)
1108 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1111 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1112 ixgbe_irq_disable(adapter
);
1113 adapter
->vlgrp
= grp
;
1116 /* enable VLAN tag insert/strip */
1117 ctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_VLNCTRL
);
1118 ctrl
|= IXGBE_VLNCTRL_VME
| IXGBE_VLNCTRL_VFE
;
1119 ctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
1120 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VLNCTRL
, ctrl
);
1123 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1124 ixgbe_irq_enable(adapter
);
1127 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1129 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1131 /* add VID to filter table */
1132 ixgbe_set_vfta(&adapter
->hw
, vid
, 0, true);
1135 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1137 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1139 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1140 ixgbe_irq_disable(adapter
);
1142 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1144 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1145 ixgbe_irq_enable(adapter
);
1147 /* remove VID from filter table */
1148 ixgbe_set_vfta(&adapter
->hw
, vid
, 0, false);
1151 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
1153 ixgbe_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1155 if (adapter
->vlgrp
) {
1157 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1158 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1160 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
1166 * ixgbe_set_multi - Multicast and Promiscuous mode set
1167 * @netdev: network interface device structure
1169 * The set_multi entry point is called whenever the multicast address
1170 * list or the network interface flags are updated. This routine is
1171 * responsible for configuring the hardware for proper multicast,
1172 * promiscuous mode, and all-multi behavior.
1174 static void ixgbe_set_multi(struct net_device
*netdev
)
1176 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1177 struct ixgbe_hw
*hw
= &adapter
->hw
;
1178 struct dev_mc_list
*mc_ptr
;
1183 /* Check for Promiscuous and All Multicast modes */
1185 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
1187 if (netdev
->flags
& IFF_PROMISC
) {
1188 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
1189 } else if (netdev
->flags
& IFF_ALLMULTI
) {
1190 fctrl
|= IXGBE_FCTRL_MPE
;
1191 fctrl
&= ~IXGBE_FCTRL_UPE
;
1193 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
1196 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
1198 if (netdev
->mc_count
) {
1199 mta_list
= kcalloc(netdev
->mc_count
, ETH_ALEN
, GFP_ATOMIC
);
1203 /* Shared function expects packed array of only addresses. */
1204 mc_ptr
= netdev
->mc_list
;
1206 for (i
= 0; i
< netdev
->mc_count
; i
++) {
1209 memcpy(mta_list
+ (i
* ETH_ALEN
), mc_ptr
->dmi_addr
,
1211 mc_ptr
= mc_ptr
->next
;
1214 ixgbe_update_mc_addr_list(hw
, mta_list
, i
, 0);
1217 ixgbe_update_mc_addr_list(hw
, NULL
, 0, 0);
1222 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
1224 struct net_device
*netdev
= adapter
->netdev
;
1227 ixgbe_set_multi(netdev
);
1229 ixgbe_restore_vlan(adapter
);
1231 ixgbe_configure_tx(adapter
);
1232 ixgbe_configure_rx(adapter
);
1233 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1234 ixgbe_alloc_rx_buffers(adapter
, &adapter
->rx_ring
[i
],
1235 (adapter
->rx_ring
[i
].count
- 1));
1238 static int ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
1240 struct net_device
*netdev
= adapter
->netdev
;
1243 struct ixgbe_hw
*hw
= &adapter
->hw
;
1244 u32 txdctl
, rxdctl
, mhadd
;
1245 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1247 ixgbe_get_hw_control(adapter
);
1249 if (adapter
->flags
& (IXGBE_FLAG_MSIX_ENABLED
|
1250 IXGBE_FLAG_MSI_ENABLED
)) {
1251 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
1252 gpie
= (IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_EIAME
|
1253 IXGBE_GPIE_PBA_SUPPORT
| IXGBE_GPIE_OCD
);
1256 gpie
= (IXGBE_GPIE_EIAME
|
1257 IXGBE_GPIE_PBA_SUPPORT
);
1259 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_GPIE
, gpie
);
1260 gpie
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_GPIE
);
1263 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
1265 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
1266 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
1267 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
1269 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
1272 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1273 txdctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_TXDCTL(i
));
1274 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1275 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_TXDCTL(i
), txdctl
);
1278 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1279 rxdctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_RXDCTL(i
));
1280 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
1281 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_RXDCTL(i
), rxdctl
);
1283 /* enable all receives */
1284 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
1285 rxdctl
|= (IXGBE_RXCTRL_DMBYPS
| IXGBE_RXCTRL_RXEN
);
1286 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxdctl
);
1288 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
1289 ixgbe_configure_msix(adapter
);
1291 ixgbe_configure_msi_and_legacy(adapter
);
1293 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
1294 napi_enable(&adapter
->napi
);
1295 ixgbe_irq_enable(adapter
);
1297 /* bring the link up in the watchdog, this could race with our first
1298 * link up interrupt but shouldn't be a problem */
1299 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1303 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
1305 WARN_ON(in_interrupt());
1306 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
1308 ixgbe_down(adapter
);
1310 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
1313 int ixgbe_up(struct ixgbe_adapter
*adapter
)
1315 /* hardware has been reset, we need to reload some things */
1316 ixgbe_configure(adapter
);
1318 return ixgbe_up_complete(adapter
);
1321 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
1323 if (ixgbe_init_hw(&adapter
->hw
))
1324 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
1326 /* reprogram the RAR[0] in case user changed it. */
1327 ixgbe_set_rar(&adapter
->hw
, 0, adapter
->hw
.mac
.addr
, 0, IXGBE_RAH_AV
);
1332 static int ixgbe_resume(struct pci_dev
*pdev
)
1334 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1335 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1336 u32 err
, num_rx_queues
= adapter
->num_rx_queues
;
1338 pci_set_power_state(pdev
, PCI_D0
);
1339 pci_restore_state(pdev
);
1340 err
= pci_enable_device(pdev
);
1342 printk(KERN_ERR
"ixgbe: Cannot enable PCI device from " \
1346 pci_set_master(pdev
);
1348 pci_enable_wake(pdev
, PCI_D3hot
, 0);
1349 pci_enable_wake(pdev
, PCI_D3cold
, 0);
1351 if (netif_running(netdev
)) {
1352 err
= ixgbe_request_irq(adapter
, &num_rx_queues
);
1357 ixgbe_reset(adapter
);
1359 if (netif_running(netdev
))
1362 netif_device_attach(netdev
);
1369 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
1370 * @adapter: board private structure
1371 * @rx_ring: ring to free buffers from
1373 static void ixgbe_clean_rx_ring(struct ixgbe_adapter
*adapter
,
1374 struct ixgbe_ring
*rx_ring
)
1376 struct pci_dev
*pdev
= adapter
->pdev
;
1380 /* Free all the Rx ring sk_buffs */
1382 for (i
= 0; i
< rx_ring
->count
; i
++) {
1383 struct ixgbe_rx_buffer
*rx_buffer_info
;
1385 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1386 if (rx_buffer_info
->dma
) {
1387 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
1388 adapter
->rx_buf_len
,
1389 PCI_DMA_FROMDEVICE
);
1390 rx_buffer_info
->dma
= 0;
1392 if (rx_buffer_info
->skb
) {
1393 dev_kfree_skb(rx_buffer_info
->skb
);
1394 rx_buffer_info
->skb
= NULL
;
1396 if (!rx_buffer_info
->page
)
1398 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
, PAGE_SIZE
,
1399 PCI_DMA_FROMDEVICE
);
1400 rx_buffer_info
->page_dma
= 0;
1402 put_page(rx_buffer_info
->page
);
1403 rx_buffer_info
->page
= NULL
;
1406 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
1407 memset(rx_ring
->rx_buffer_info
, 0, size
);
1409 /* Zero out the descriptor ring */
1410 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1412 rx_ring
->next_to_clean
= 0;
1413 rx_ring
->next_to_use
= 0;
1415 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1416 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1420 * ixgbe_clean_tx_ring - Free Tx Buffers
1421 * @adapter: board private structure
1422 * @tx_ring: ring to be cleaned
1424 static void ixgbe_clean_tx_ring(struct ixgbe_adapter
*adapter
,
1425 struct ixgbe_ring
*tx_ring
)
1427 struct ixgbe_tx_buffer
*tx_buffer_info
;
1431 /* Free all the Tx ring sk_buffs */
1433 for (i
= 0; i
< tx_ring
->count
; i
++) {
1434 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1435 ixgbe_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
1438 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
1439 memset(tx_ring
->tx_buffer_info
, 0, size
);
1441 /* Zero out the descriptor ring */
1442 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1444 tx_ring
->next_to_use
= 0;
1445 tx_ring
->next_to_clean
= 0;
1447 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1448 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1452 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
1453 * @adapter: board private structure
1455 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
1459 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1460 ixgbe_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1464 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
1465 * @adapter: board private structure
1467 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
1471 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1472 ixgbe_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1475 void ixgbe_down(struct ixgbe_adapter
*adapter
)
1477 struct net_device
*netdev
= adapter
->netdev
;
1480 /* signal that we are down to the interrupt handler */
1481 set_bit(__IXGBE_DOWN
, &adapter
->state
);
1483 /* disable receives */
1484 rxctrl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_RXCTRL
);
1485 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_RXCTRL
,
1486 rxctrl
& ~IXGBE_RXCTRL_RXEN
);
1488 netif_tx_disable(netdev
);
1490 /* disable transmits in the hardware */
1492 /* flush both disables */
1493 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1496 napi_disable(&adapter
->napi
);
1498 ixgbe_irq_disable(adapter
);
1500 del_timer_sync(&adapter
->watchdog_timer
);
1502 netif_carrier_off(netdev
);
1503 netif_stop_queue(netdev
);
1505 ixgbe_reset(adapter
);
1506 ixgbe_clean_all_tx_rings(adapter
);
1507 ixgbe_clean_all_rx_rings(adapter
);
1511 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1513 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1514 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1519 netif_device_detach(netdev
);
1521 if (netif_running(netdev
)) {
1522 ixgbe_down(adapter
);
1523 ixgbe_free_irq(adapter
);
1527 retval
= pci_save_state(pdev
);
1532 pci_enable_wake(pdev
, PCI_D3hot
, 0);
1533 pci_enable_wake(pdev
, PCI_D3cold
, 0);
1535 ixgbe_release_hw_control(adapter
);
1537 pci_disable_device(pdev
);
1539 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1544 static void ixgbe_shutdown(struct pci_dev
*pdev
)
1546 ixgbe_suspend(pdev
, PMSG_SUSPEND
);
1550 * ixgbe_clean - NAPI Rx polling callback
1551 * @adapter: board private structure
1553 static int ixgbe_clean(struct napi_struct
*napi
, int budget
)
1555 struct ixgbe_adapter
*adapter
= container_of(napi
,
1556 struct ixgbe_adapter
, napi
);
1557 struct net_device
*netdev
= adapter
->netdev
;
1558 int tx_cleaned
= 0, work_done
= 0;
1560 /* In non-MSIX case, there is no multi-Tx/Rx queue */
1561 tx_cleaned
= ixgbe_clean_tx_irq(adapter
, adapter
->tx_ring
);
1562 ixgbe_clean_rx_irq(adapter
, &adapter
->rx_ring
[0], &work_done
,
1568 /* If budget not fully consumed, exit the polling mode */
1569 if (work_done
< budget
) {
1570 netif_rx_complete(netdev
, napi
);
1571 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1572 ixgbe_irq_enable(adapter
);
1579 * ixgbe_tx_timeout - Respond to a Tx Hang
1580 * @netdev: network interface device structure
1582 static void ixgbe_tx_timeout(struct net_device
*netdev
)
1584 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1586 /* Do the reset outside of interrupt context */
1587 schedule_work(&adapter
->reset_task
);
1590 static void ixgbe_reset_task(struct work_struct
*work
)
1592 struct ixgbe_adapter
*adapter
;
1593 adapter
= container_of(work
, struct ixgbe_adapter
, reset_task
);
1595 adapter
->tx_timeout_count
++;
1597 ixgbe_reinit_locked(adapter
);
1601 * ixgbe_alloc_queues - Allocate memory for all rings
1602 * @adapter: board private structure to initialize
1604 * We allocate one ring per queue at run-time since we don't know the
1605 * number of queues at compile-time. The polling_netdev array is
1606 * intended for Multiqueue, but should work fine with a single queue.
1608 static int __devinit
ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
1612 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1613 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
1614 if (!adapter
->tx_ring
)
1617 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1618 adapter
->tx_ring
[i
].count
= IXGBE_DEFAULT_TXD
;
1620 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1621 sizeof(struct ixgbe_ring
), GFP_KERNEL
);
1622 if (!adapter
->rx_ring
) {
1623 kfree(adapter
->tx_ring
);
1627 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1628 adapter
->rx_ring
[i
].adapter
= adapter
;
1629 adapter
->rx_ring
[i
].itr_register
= IXGBE_EITR(i
);
1630 adapter
->rx_ring
[i
].count
= IXGBE_DEFAULT_RXD
;
1637 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
1638 * @adapter: board private structure to initialize
1640 * ixgbe_sw_init initializes the Adapter private data structure.
1641 * Fields are initialized based on PCI device information and
1642 * OS network device settings (MTU size).
1644 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
1646 struct ixgbe_hw
*hw
= &adapter
->hw
;
1647 struct pci_dev
*pdev
= adapter
->pdev
;
1649 /* default flow control settings */
1650 hw
->fc
.original_type
= ixgbe_fc_full
;
1651 hw
->fc
.type
= ixgbe_fc_full
;
1653 hw
->mac
.link_mode_select
= IXGBE_AUTOC_LMS_10G_LINK_NO_AN
;
1654 if (hw
->mac
.ops
.reset(hw
)) {
1655 dev_err(&pdev
->dev
, "HW Init failed\n");
1658 if (hw
->mac
.ops
.setup_link_speed(hw
, IXGBE_LINK_SPEED_10GB_FULL
, true,
1660 dev_err(&pdev
->dev
, "Link Speed setup failed\n");
1664 /* initialize eeprom parameters */
1665 if (ixgbe_init_eeprom(hw
)) {
1666 dev_err(&pdev
->dev
, "EEPROM initialization failed\n");
1670 /* Set the default values */
1671 adapter
->num_rx_queues
= IXGBE_DEFAULT_RXQ
;
1672 adapter
->num_tx_queues
= 1;
1673 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
1675 if (ixgbe_alloc_queues(adapter
)) {
1676 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
1680 set_bit(__IXGBE_DOWN
, &adapter
->state
);
1686 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
1687 * @adapter: board private structure
1688 * @txdr: tx descriptor ring (for a specific queue) to setup
1690 * Return 0 on success, negative on failure
1692 int ixgbe_setup_tx_resources(struct ixgbe_adapter
*adapter
,
1693 struct ixgbe_ring
*txdr
)
1695 struct pci_dev
*pdev
= adapter
->pdev
;
1698 size
= sizeof(struct ixgbe_tx_buffer
) * txdr
->count
;
1699 txdr
->tx_buffer_info
= vmalloc(size
);
1700 if (!txdr
->tx_buffer_info
) {
1702 "Unable to allocate memory for the transmit descriptor ring\n");
1705 memset(txdr
->tx_buffer_info
, 0, size
);
1707 /* round up to nearest 4K */
1708 txdr
->size
= txdr
->count
* sizeof(union ixgbe_adv_tx_desc
);
1709 txdr
->size
= ALIGN(txdr
->size
, 4096);
1711 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1713 vfree(txdr
->tx_buffer_info
);
1715 "Memory allocation failed for the tx desc ring\n");
1719 txdr
->adapter
= adapter
;
1720 txdr
->next_to_use
= 0;
1721 txdr
->next_to_clean
= 0;
1722 txdr
->work_limit
= txdr
->count
;
1728 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
1729 * @adapter: board private structure
1730 * @rxdr: rx descriptor ring (for a specific queue) to setup
1732 * Returns 0 on success, negative on failure
1734 int ixgbe_setup_rx_resources(struct ixgbe_adapter
*adapter
,
1735 struct ixgbe_ring
*rxdr
)
1737 struct pci_dev
*pdev
= adapter
->pdev
;
1740 size
= sizeof(struct ixgbe_rx_buffer
) * rxdr
->count
;
1741 rxdr
->rx_buffer_info
= vmalloc(size
);
1742 if (!rxdr
->rx_buffer_info
) {
1744 "vmalloc allocation failed for the rx desc ring\n");
1747 memset(rxdr
->rx_buffer_info
, 0, size
);
1749 desc_len
= sizeof(union ixgbe_adv_rx_desc
);
1751 /* Round up to nearest 4K */
1752 rxdr
->size
= rxdr
->count
* desc_len
;
1753 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1755 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1759 "Memory allocation failed for the rx desc ring\n");
1760 vfree(rxdr
->rx_buffer_info
);
1764 rxdr
->next_to_clean
= 0;
1765 rxdr
->next_to_use
= 0;
1766 rxdr
->adapter
= adapter
;
1772 * ixgbe_free_tx_resources - Free Tx Resources per Queue
1773 * @adapter: board private structure
1774 * @tx_ring: Tx descriptor ring for a specific queue
1776 * Free all transmit software resources
1778 static void ixgbe_free_tx_resources(struct ixgbe_adapter
*adapter
,
1779 struct ixgbe_ring
*tx_ring
)
1781 struct pci_dev
*pdev
= adapter
->pdev
;
1783 ixgbe_clean_tx_ring(adapter
, tx_ring
);
1785 vfree(tx_ring
->tx_buffer_info
);
1786 tx_ring
->tx_buffer_info
= NULL
;
1788 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1790 tx_ring
->desc
= NULL
;
1794 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
1795 * @adapter: board private structure
1797 * Free all transmit software resources
1799 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
1803 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1804 ixgbe_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1808 * ixgbe_free_rx_resources - Free Rx Resources
1809 * @adapter: board private structure
1810 * @rx_ring: ring to clean the resources from
1812 * Free all receive software resources
1814 static void ixgbe_free_rx_resources(struct ixgbe_adapter
*adapter
,
1815 struct ixgbe_ring
*rx_ring
)
1817 struct pci_dev
*pdev
= adapter
->pdev
;
1819 ixgbe_clean_rx_ring(adapter
, rx_ring
);
1821 vfree(rx_ring
->rx_buffer_info
);
1822 rx_ring
->rx_buffer_info
= NULL
;
1824 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1826 rx_ring
->desc
= NULL
;
1830 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
1831 * @adapter: board private structure
1833 * Free all receive software resources
1835 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
1839 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1840 ixgbe_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1844 * ixgbe_setup_all_tx_resources - wrapper to allocate Tx resources
1845 * (Descriptors) for all queues
1846 * @adapter: board private structure
1848 * If this function returns with an error, then it's possible one or
1849 * more of the rings is populated (while the rest are not). It is the
1850 * callers duty to clean those orphaned rings.
1852 * Return 0 on success, negative on failure
1854 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
1858 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1859 err
= ixgbe_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1862 "Allocation for Tx Queue %u failed\n", i
);
1871 * ixgbe_setup_all_rx_resources - wrapper to allocate Rx resources
1872 * (Descriptors) for all queues
1873 * @adapter: board private structure
1875 * If this function returns with an error, then it's possible one or
1876 * more of the rings is populated (while the rest are not). It is the
1877 * callers duty to clean those orphaned rings.
1879 * Return 0 on success, negative on failure
1882 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
1886 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1887 err
= ixgbe_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1890 "Allocation for Rx Queue %u failed\n", i
);
1899 * ixgbe_change_mtu - Change the Maximum Transfer Unit
1900 * @netdev: network interface device structure
1901 * @new_mtu: new value for maximum frame size
1903 * Returns 0 on success, negative on failure
1905 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
1907 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1908 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1910 if ((max_frame
< (ETH_ZLEN
+ ETH_FCS_LEN
)) ||
1911 (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
1914 netdev
->mtu
= new_mtu
;
1916 if (netif_running(netdev
))
1917 ixgbe_reinit_locked(adapter
);
1923 * ixgbe_open - Called when a network interface is made active
1924 * @netdev: network interface device structure
1926 * Returns 0 on success, negative value on failure
1928 * The open entry point is called when a network interface is made
1929 * active by the system (IFF_UP). At this point all resources needed
1930 * for transmit and receive operations are allocated, the interrupt
1931 * handler is registered with the OS, the watchdog timer is started,
1932 * and the stack is notified that the interface is ready.
1934 static int ixgbe_open(struct net_device
*netdev
)
1936 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1938 u32 num_rx_queues
= adapter
->num_rx_queues
;
1940 /* disallow open during test */
1941 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
1945 /* allocate transmit descriptors */
1946 err
= ixgbe_setup_all_tx_resources(adapter
);
1950 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
1952 adapter
->num_rx_queues
= num_rx_queues
;
1955 /* allocate receive descriptors */
1956 err
= ixgbe_setup_all_rx_resources(adapter
);
1960 ixgbe_configure(adapter
);
1962 err
= ixgbe_request_irq(adapter
, &num_rx_queues
);
1966 /* ixgbe_request might have reduced num_rx_queues */
1967 if (num_rx_queues
< adapter
->num_rx_queues
) {
1968 /* We didn't get MSI-X, so we need to release everything,
1969 * set our Rx queue count to num_rx_queues, and redo the
1970 * whole init process.
1972 ixgbe_free_irq(adapter
);
1973 if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
1974 pci_disable_msi(adapter
->pdev
);
1975 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
1977 ixgbe_free_all_rx_resources(adapter
);
1978 ixgbe_free_all_tx_resources(adapter
);
1979 adapter
->num_rx_queues
= num_rx_queues
;
1981 /* Reset the hardware, and start over. */
1982 ixgbe_reset(adapter
);
1984 goto try_intr_reinit
;
1987 err
= ixgbe_up_complete(adapter
);
1994 ixgbe_release_hw_control(adapter
);
1995 ixgbe_free_irq(adapter
);
1997 ixgbe_free_all_rx_resources(adapter
);
1999 ixgbe_free_all_tx_resources(adapter
);
2001 ixgbe_reset(adapter
);
2007 * ixgbe_close - Disables a network interface
2008 * @netdev: network interface device structure
2010 * Returns 0, this is not allowed to fail
2012 * The close entry point is called when an interface is de-activated
2013 * by the OS. The hardware is still under the drivers control, but
2014 * needs to be disabled. A global MAC reset is issued to stop the
2015 * hardware, and all transmit and receive resources are freed.
2017 static int ixgbe_close(struct net_device
*netdev
)
2019 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2021 ixgbe_down(adapter
);
2022 ixgbe_free_irq(adapter
);
2024 ixgbe_free_all_tx_resources(adapter
);
2025 ixgbe_free_all_rx_resources(adapter
);
2027 ixgbe_release_hw_control(adapter
);
2033 * ixgbe_update_stats - Update the board statistics counters.
2034 * @adapter: board private structure
2036 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
2038 struct ixgbe_hw
*hw
= &adapter
->hw
;
2040 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
2042 adapter
->stats
.crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
2043 for (i
= 0; i
< 8; i
++) {
2044 /* for packet buffers not used, the register should read 0 */
2045 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
2047 adapter
->stats
.mpc
[i
] += mpc
;
2048 total_mpc
+= adapter
->stats
.mpc
[i
];
2049 adapter
->stats
.rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
2051 adapter
->stats
.gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
2052 /* work around hardware counting issue */
2053 adapter
->stats
.gprc
-= missed_rx
;
2055 /* 82598 hardware only has a 32 bit counter in the high register */
2056 adapter
->stats
.gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
2057 adapter
->stats
.gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
2058 adapter
->stats
.tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
2059 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
2060 adapter
->stats
.bprc
+= bprc
;
2061 adapter
->stats
.mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
2062 adapter
->stats
.mprc
-= bprc
;
2063 adapter
->stats
.roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
2064 adapter
->stats
.prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
2065 adapter
->stats
.prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
2066 adapter
->stats
.prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
2067 adapter
->stats
.prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
2068 adapter
->stats
.prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
2069 adapter
->stats
.prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
2070 adapter
->stats
.rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
2071 adapter
->stats
.lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
2072 adapter
->stats
.lxoffrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
2073 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
2074 adapter
->stats
.lxontxc
+= lxon
;
2075 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
2076 adapter
->stats
.lxofftxc
+= lxoff
;
2077 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
2078 adapter
->stats
.gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
2079 adapter
->stats
.mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
2081 * 82598 errata - tx of flow control packets is included in tx counters
2083 xon_off_tot
= lxon
+ lxoff
;
2084 adapter
->stats
.gptc
-= xon_off_tot
;
2085 adapter
->stats
.mptc
-= xon_off_tot
;
2086 adapter
->stats
.gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
2087 adapter
->stats
.ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
2088 adapter
->stats
.rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
2089 adapter
->stats
.rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
2090 adapter
->stats
.tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
2091 adapter
->stats
.ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
2092 adapter
->stats
.ptc64
-= xon_off_tot
;
2093 adapter
->stats
.ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
2094 adapter
->stats
.ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
2095 adapter
->stats
.ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
2096 adapter
->stats
.ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
2097 adapter
->stats
.ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
2098 adapter
->stats
.bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
2100 /* Fill out the OS statistics structure */
2101 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
2104 adapter
->net_stats
.rx_errors
= adapter
->stats
.crcerrs
+
2105 adapter
->stats
.rlec
;
2106 adapter
->net_stats
.rx_dropped
= 0;
2107 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
2108 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
2109 adapter
->net_stats
.rx_missed_errors
= total_mpc
;
2113 * ixgbe_watchdog - Timer Call-back
2114 * @data: pointer to adapter cast into an unsigned long
2116 static void ixgbe_watchdog(unsigned long data
)
2118 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
2119 struct net_device
*netdev
= adapter
->netdev
;
2123 adapter
->hw
.mac
.ops
.check_link(&adapter
->hw
, &(link_speed
), &link_up
);
2126 if (!netif_carrier_ok(netdev
)) {
2127 u32 frctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_FCTRL
);
2128 u32 rmcs
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_RMCS
);
2129 #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
2130 #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
2131 DPRINTK(LINK
, INFO
, "NIC Link is Up %s, "
2132 "Flow Control: %s\n",
2133 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
2135 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
2136 "1 Gbps" : "unknown speed")),
2137 ((FLOW_RX
&& FLOW_TX
) ? "RX/TX" :
2139 (FLOW_TX
? "TX" : "None"))));
2141 netif_carrier_on(netdev
);
2142 netif_wake_queue(netdev
);
2144 /* Force detection of hung controller */
2145 adapter
->detect_tx_hung
= true;
2148 if (netif_carrier_ok(netdev
)) {
2149 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2150 netif_carrier_off(netdev
);
2151 netif_stop_queue(netdev
);
2155 ixgbe_update_stats(adapter
);
2157 /* Reset the timer */
2158 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2159 mod_timer(&adapter
->watchdog_timer
,
2160 round_jiffies(jiffies
+ 2 * HZ
));
2163 static int ixgbe_tso(struct ixgbe_adapter
*adapter
,
2164 struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
2165 u32 tx_flags
, u8
*hdr_len
)
2167 struct ixgbe_adv_tx_context_desc
*context_desc
;
2170 struct ixgbe_tx_buffer
*tx_buffer_info
;
2171 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2172 u32 mss_l4len_idx
= 0, l4len
;
2175 if (skb_is_gso(skb
)) {
2176 if (skb_header_cloned(skb
)) {
2177 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2181 l4len
= tcp_hdrlen(skb
);
2184 if (skb
->protocol
== htons(ETH_P_IP
)) {
2185 struct iphdr
*iph
= ip_hdr(skb
);
2188 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2192 adapter
->hw_tso_ctxt
++;
2193 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
2194 ipv6_hdr(skb
)->payload_len
= 0;
2195 tcp_hdr(skb
)->check
=
2196 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2197 &ipv6_hdr(skb
)->daddr
,
2199 adapter
->hw_tso6_ctxt
++;
2202 i
= tx_ring
->next_to_use
;
2204 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2205 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2207 /* VLAN MACLEN IPLEN */
2208 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2210 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2211 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
2212 IXGBE_ADVTXD_MACLEN_SHIFT
);
2213 *hdr_len
+= skb_network_offset(skb
);
2215 (skb_transport_header(skb
) - skb_network_header(skb
));
2217 (skb_transport_header(skb
) - skb_network_header(skb
));
2218 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2219 context_desc
->seqnum_seed
= 0;
2221 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2222 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2223 IXGBE_ADVTXD_DTYP_CTXT
);
2225 if (skb
->protocol
== htons(ETH_P_IP
))
2226 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2227 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2228 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2232 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
2233 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
2234 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2236 tx_buffer_info
->time_stamp
= jiffies
;
2237 tx_buffer_info
->next_to_watch
= i
;
2240 if (i
== tx_ring
->count
)
2242 tx_ring
->next_to_use
= i
;
2249 static bool ixgbe_tx_csum(struct ixgbe_adapter
*adapter
,
2250 struct ixgbe_ring
*tx_ring
,
2251 struct sk_buff
*skb
, u32 tx_flags
)
2253 struct ixgbe_adv_tx_context_desc
*context_desc
;
2255 struct ixgbe_tx_buffer
*tx_buffer_info
;
2256 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2258 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
2259 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
2260 i
= tx_ring
->next_to_use
;
2261 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2262 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2264 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2266 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2267 vlan_macip_lens
|= (skb_network_offset(skb
) <<
2268 IXGBE_ADVTXD_MACLEN_SHIFT
);
2269 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2270 vlan_macip_lens
|= (skb_transport_header(skb
) -
2271 skb_network_header(skb
));
2273 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2274 context_desc
->seqnum_seed
= 0;
2276 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2277 IXGBE_ADVTXD_DTYP_CTXT
);
2279 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2280 switch (skb
->protocol
) {
2281 case __constant_htons(ETH_P_IP
):
2282 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2283 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2285 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2288 case __constant_htons(ETH_P_IPV6
):
2289 /* XXX what about other V6 headers?? */
2290 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2292 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2296 if (unlikely(net_ratelimit())) {
2297 DPRINTK(PROBE
, WARNING
,
2298 "partial checksum but proto=%x!\n",
2305 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2306 context_desc
->mss_l4len_idx
= 0;
2308 tx_buffer_info
->time_stamp
= jiffies
;
2309 tx_buffer_info
->next_to_watch
= i
;
2310 adapter
->hw_csum_tx_good
++;
2312 if (i
== tx_ring
->count
)
2314 tx_ring
->next_to_use
= i
;
2321 static int ixgbe_tx_map(struct ixgbe_adapter
*adapter
,
2322 struct ixgbe_ring
*tx_ring
,
2323 struct sk_buff
*skb
, unsigned int first
)
2325 struct ixgbe_tx_buffer
*tx_buffer_info
;
2326 unsigned int len
= skb
->len
;
2327 unsigned int offset
= 0, size
, count
= 0, i
;
2328 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2331 len
-= skb
->data_len
;
2333 i
= tx_ring
->next_to_use
;
2336 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2337 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
2339 tx_buffer_info
->length
= size
;
2340 tx_buffer_info
->dma
= pci_map_single(adapter
->pdev
,
2342 size
, PCI_DMA_TODEVICE
);
2343 tx_buffer_info
->time_stamp
= jiffies
;
2344 tx_buffer_info
->next_to_watch
= i
;
2350 if (i
== tx_ring
->count
)
2354 for (f
= 0; f
< nr_frags
; f
++) {
2355 struct skb_frag_struct
*frag
;
2357 frag
= &skb_shinfo(skb
)->frags
[f
];
2359 offset
= frag
->page_offset
;
2362 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2363 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
2365 tx_buffer_info
->length
= size
;
2366 tx_buffer_info
->dma
= pci_map_page(adapter
->pdev
,
2369 size
, PCI_DMA_TODEVICE
);
2370 tx_buffer_info
->time_stamp
= jiffies
;
2371 tx_buffer_info
->next_to_watch
= i
;
2377 if (i
== tx_ring
->count
)
2382 i
= tx_ring
->count
- 1;
2385 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
2386 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
2391 static void ixgbe_tx_queue(struct ixgbe_adapter
*adapter
,
2392 struct ixgbe_ring
*tx_ring
,
2393 int tx_flags
, int count
, u32 paylen
, u8 hdr_len
)
2395 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
2396 struct ixgbe_tx_buffer
*tx_buffer_info
;
2397 u32 olinfo_status
= 0, cmd_type_len
= 0;
2399 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
2401 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
2403 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
2405 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2406 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
2408 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
2409 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
2411 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
2412 IXGBE_ADVTXD_POPTS_SHIFT
;
2414 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
2415 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
2416 IXGBE_ADVTXD_POPTS_SHIFT
;
2418 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
2419 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
2420 IXGBE_ADVTXD_POPTS_SHIFT
;
2422 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
2424 i
= tx_ring
->next_to_use
;
2426 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2427 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
2428 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
2429 tx_desc
->read
.cmd_type_len
=
2430 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
2431 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
2434 if (i
== tx_ring
->count
)
2438 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
2441 * Force memory writes to complete before letting h/w
2442 * know there are new descriptors to fetch. (Only
2443 * applicable for weak-ordered memory model archs,
2448 tx_ring
->next_to_use
= i
;
2449 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2452 static int __ixgbe_maybe_stop_tx(struct net_device
*netdev
,
2453 struct ixgbe_ring
*tx_ring
, int size
)
2455 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2457 netif_stop_queue(netdev
);
2458 /* Herbert's original patch had:
2459 * smp_mb__after_netif_stop_queue();
2460 * but since that doesn't exist yet, just open code it. */
2463 /* We need to check again in a case another CPU has just
2464 * made room available. */
2465 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
2468 /* A reprieve! - use start_queue because it doesn't call schedule */
2469 netif_wake_queue(netdev
);
2470 ++adapter
->restart_queue
;
2474 static int ixgbe_maybe_stop_tx(struct net_device
*netdev
,
2475 struct ixgbe_ring
*tx_ring
, int size
)
2477 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
2479 return __ixgbe_maybe_stop_tx(netdev
, tx_ring
, size
);
2483 static int ixgbe_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2485 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2486 struct ixgbe_ring
*tx_ring
;
2487 unsigned int len
= skb
->len
;
2489 unsigned int tx_flags
= 0;
2492 unsigned int mss
= 0;
2495 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2496 len
-= skb
->data_len
;
2498 tx_ring
= adapter
->tx_ring
;
2500 if (skb
->len
<= 0) {
2502 return NETDEV_TX_OK
;
2504 mss
= skb_shinfo(skb
)->gso_size
;
2508 else if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2511 count
+= TXD_USE_COUNT(len
);
2512 for (f
= 0; f
< nr_frags
; f
++)
2513 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
2515 if (ixgbe_maybe_stop_tx(netdev
, tx_ring
, count
)) {
2517 return NETDEV_TX_BUSY
;
2519 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
2520 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
2521 tx_flags
|= (vlan_tx_tag_get(skb
) << IXGBE_TX_FLAGS_VLAN_SHIFT
);
2524 if (skb
->protocol
== htons(ETH_P_IP
))
2525 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
2526 first
= tx_ring
->next_to_use
;
2527 tso
= ixgbe_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
2529 dev_kfree_skb_any(skb
);
2530 return NETDEV_TX_OK
;
2534 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
2535 else if (ixgbe_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
2536 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
2537 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
2539 ixgbe_tx_queue(adapter
, tx_ring
, tx_flags
,
2540 ixgbe_tx_map(adapter
, tx_ring
, skb
, first
),
2543 netdev
->trans_start
= jiffies
;
2545 ixgbe_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
2547 return NETDEV_TX_OK
;
2551 * ixgbe_get_stats - Get System Network Statistics
2552 * @netdev: network interface device structure
2554 * Returns the address of the device statistics structure.
2555 * The statistics are actually updated from the timer callback.
2557 static struct net_device_stats
*ixgbe_get_stats(struct net_device
*netdev
)
2559 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2561 /* only return the current stats */
2562 return &adapter
->net_stats
;
2566 * ixgbe_set_mac - Change the Ethernet Address of the NIC
2567 * @netdev: network interface device structure
2568 * @p: pointer to an address structure
2570 * Returns 0 on success, negative on failure
2572 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
2574 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2575 struct sockaddr
*addr
= p
;
2577 if (!is_valid_ether_addr(addr
->sa_data
))
2578 return -EADDRNOTAVAIL
;
2580 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2581 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
2583 ixgbe_set_rar(&adapter
->hw
, 0, adapter
->hw
.mac
.addr
, 0, IXGBE_RAH_AV
);
2588 #ifdef CONFIG_NET_POLL_CONTROLLER
2590 * Polling 'interrupt' - used by things like netconsole to send skbs
2591 * without having to re-enable interrupts. It's not called while
2592 * the interrupt routine is executing.
2594 static void ixgbe_netpoll(struct net_device
*netdev
)
2596 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2598 disable_irq(adapter
->pdev
->irq
);
2599 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
2600 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
2601 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
2602 enable_irq(adapter
->pdev
->irq
);
2607 * ixgbe_probe - Device Initialization Routine
2608 * @pdev: PCI device information struct
2609 * @ent: entry in ixgbe_pci_tbl
2611 * Returns 0 on success, negative on failure
2613 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
2614 * The OS initialization, configuring of the adapter private structure,
2615 * and a hardware reset occur.
2617 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
2618 const struct pci_device_id
*ent
)
2620 struct net_device
*netdev
;
2621 struct ixgbe_adapter
*adapter
= NULL
;
2622 struct ixgbe_hw
*hw
;
2623 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
2624 unsigned long mmio_start
, mmio_len
;
2625 static int cards_found
;
2626 int i
, err
, pci_using_dac
;
2627 u16 link_status
, link_speed
, link_width
;
2630 err
= pci_enable_device(pdev
);
2634 if (!pci_set_dma_mask(pdev
, DMA_64BIT_MASK
) &&
2635 !pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
)) {
2638 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
2640 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
2642 dev_err(&pdev
->dev
, "No usable DMA "
2643 "configuration, aborting\n");
2650 err
= pci_request_regions(pdev
, ixgbe_driver_name
);
2652 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
2656 pci_set_master(pdev
);
2658 netdev
= alloc_etherdev(sizeof(struct ixgbe_adapter
));
2661 goto err_alloc_etherdev
;
2664 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2666 pci_set_drvdata(pdev
, netdev
);
2667 adapter
= netdev_priv(netdev
);
2669 adapter
->netdev
= netdev
;
2670 adapter
->pdev
= pdev
;
2673 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2675 mmio_start
= pci_resource_start(pdev
, 0);
2676 mmio_len
= pci_resource_len(pdev
, 0);
2678 hw
->hw_addr
= ioremap(mmio_start
, mmio_len
);
2684 for (i
= 1; i
<= 5; i
++) {
2685 if (pci_resource_len(pdev
, i
) == 0)
2689 netdev
->open
= &ixgbe_open
;
2690 netdev
->stop
= &ixgbe_close
;
2691 netdev
->hard_start_xmit
= &ixgbe_xmit_frame
;
2692 netdev
->get_stats
= &ixgbe_get_stats
;
2693 netdev
->set_multicast_list
= &ixgbe_set_multi
;
2694 netdev
->set_mac_address
= &ixgbe_set_mac
;
2695 netdev
->change_mtu
= &ixgbe_change_mtu
;
2696 ixgbe_set_ethtool_ops(netdev
);
2697 netdev
->tx_timeout
= &ixgbe_tx_timeout
;
2698 netdev
->watchdog_timeo
= 5 * HZ
;
2699 netif_napi_add(netdev
, &adapter
->napi
, ixgbe_clean
, 64);
2700 netdev
->vlan_rx_register
= ixgbe_vlan_rx_register
;
2701 netdev
->vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
;
2702 netdev
->vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
;
2703 #ifdef CONFIG_NET_POLL_CONTROLLER
2704 netdev
->poll_controller
= ixgbe_netpoll
;
2706 strcpy(netdev
->name
, pci_name(pdev
));
2708 netdev
->mem_start
= mmio_start
;
2709 netdev
->mem_end
= mmio_start
+ mmio_len
;
2711 adapter
->bd_number
= cards_found
;
2713 /* PCI config space info */
2714 hw
->vendor_id
= pdev
->vendor
;
2715 hw
->device_id
= pdev
->device
;
2716 hw
->revision_id
= pdev
->revision
;
2717 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2718 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2721 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
2723 err
= ii
->get_invariants(hw
);
2727 /* setup the private structure */
2728 err
= ixgbe_sw_init(adapter
);
2732 netdev
->features
= NETIF_F_SG
|
2734 NETIF_F_HW_VLAN_TX
|
2735 NETIF_F_HW_VLAN_RX
|
2736 NETIF_F_HW_VLAN_FILTER
;
2738 netdev
->features
|= NETIF_F_TSO
;
2740 netdev
->features
|= NETIF_F_TSO6
;
2742 netdev
->features
|= NETIF_F_HIGHDMA
;
2745 /* make sure the EEPROM is good */
2746 if (ixgbe_validate_eeprom_checksum(hw
, NULL
) < 0) {
2747 dev_err(&pdev
->dev
, "The EEPROM Checksum Is Not Valid\n");
2752 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
2753 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
2755 if (ixgbe_validate_mac_addr(netdev
->dev_addr
)) {
2760 init_timer(&adapter
->watchdog_timer
);
2761 adapter
->watchdog_timer
.function
= &ixgbe_watchdog
;
2762 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2764 INIT_WORK(&adapter
->reset_task
, ixgbe_reset_task
);
2766 /* initialize default flow control settings */
2767 hw
->fc
.original_type
= ixgbe_fc_full
;
2768 hw
->fc
.type
= ixgbe_fc_full
;
2769 hw
->fc
.high_water
= IXGBE_DEFAULT_FCRTH
;
2770 hw
->fc
.low_water
= IXGBE_DEFAULT_FCRTL
;
2771 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
2773 /* Interrupt Throttle Rate */
2774 adapter
->rx_eitr
= (1000000 / IXGBE_DEFAULT_ITR_RX_USECS
);
2775 adapter
->tx_eitr
= (1000000 / IXGBE_DEFAULT_ITR_TX_USECS
);
2777 /* print bus type/speed/width info */
2778 pci_read_config_word(pdev
, IXGBE_PCI_LINK_STATUS
, &link_status
);
2779 link_speed
= link_status
& IXGBE_PCI_LINK_SPEED
;
2780 link_width
= link_status
& IXGBE_PCI_LINK_WIDTH
;
2781 dev_info(&pdev
->dev
, "(PCI Express:%s:%s) "
2782 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2783 ((link_speed
== IXGBE_PCI_LINK_SPEED_5000
) ? "5.0Gb/s" :
2784 (link_speed
== IXGBE_PCI_LINK_SPEED_2500
) ? "2.5Gb/s" :
2786 ((link_width
== IXGBE_PCI_LINK_WIDTH_8
) ? "Width x8" :
2787 (link_width
== IXGBE_PCI_LINK_WIDTH_4
) ? "Width x4" :
2788 (link_width
== IXGBE_PCI_LINK_WIDTH_2
) ? "Width x2" :
2789 (link_width
== IXGBE_PCI_LINK_WIDTH_1
) ? "Width x1" :
2791 netdev
->dev_addr
[0], netdev
->dev_addr
[1], netdev
->dev_addr
[2],
2792 netdev
->dev_addr
[3], netdev
->dev_addr
[4], netdev
->dev_addr
[5]);
2793 ixgbe_read_part_num(hw
, &part_num
);
2794 dev_info(&pdev
->dev
, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
2795 hw
->mac
.type
, hw
->phy
.type
,
2796 (part_num
>> 8), (part_num
& 0xff));
2798 if (link_width
<= IXGBE_PCI_LINK_WIDTH_4
) {
2799 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for "
2800 "this card is not sufficient for optimal "
2802 dev_warn(&pdev
->dev
, "For optimal performance a x8 "
2803 "PCI-Express slot is required.\n");
2806 /* reset the hardware with the new settings */
2809 netif_carrier_off(netdev
);
2810 netif_stop_queue(netdev
);
2812 strcpy(netdev
->name
, "eth%d");
2813 err
= register_netdev(netdev
);
2818 dev_info(&pdev
->dev
, "Intel(R) 10 Gigabit Network Connection\n");
2823 ixgbe_release_hw_control(adapter
);
2827 iounmap(hw
->hw_addr
);
2829 free_netdev(netdev
);
2831 pci_release_regions(pdev
);
2834 pci_disable_device(pdev
);
2839 * ixgbe_remove - Device Removal Routine
2840 * @pdev: PCI device information struct
2842 * ixgbe_remove is called by the PCI subsystem to alert the driver
2843 * that it should release a PCI device. The could be caused by a
2844 * Hot-Plug event, or because the driver is going to be removed from
2847 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
2849 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2850 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
2852 set_bit(__IXGBE_DOWN
, &adapter
->state
);
2853 del_timer_sync(&adapter
->watchdog_timer
);
2855 flush_scheduled_work();
2857 unregister_netdev(netdev
);
2859 ixgbe_release_hw_control(adapter
);
2861 kfree(adapter
->tx_ring
);
2862 kfree(adapter
->rx_ring
);
2864 iounmap(adapter
->hw
.hw_addr
);
2865 pci_release_regions(pdev
);
2867 free_netdev(netdev
);
2869 pci_disable_device(pdev
);
2873 * ixgbe_io_error_detected - called when PCI error is detected
2874 * @pdev: Pointer to PCI device
2875 * @state: The current pci connection state
2877 * This function is called after a PCI bus error affecting
2878 * this device has been detected.
2880 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
2881 pci_channel_state_t state
)
2883 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2884 struct ixgbe_adapter
*adapter
= netdev
->priv
;
2886 netif_device_detach(netdev
);
2888 if (netif_running(netdev
))
2889 ixgbe_down(adapter
);
2890 pci_disable_device(pdev
);
2892 /* Request a slot slot reset. */
2893 return PCI_ERS_RESULT_NEED_RESET
;
2897 * ixgbe_io_slot_reset - called after the pci bus has been reset.
2898 * @pdev: Pointer to PCI device
2900 * Restart the card from scratch, as if from a cold-boot.
2902 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
2904 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2905 struct ixgbe_adapter
*adapter
= netdev
->priv
;
2907 if (pci_enable_device(pdev
)) {
2909 "Cannot re-enable PCI device after reset.\n");
2910 return PCI_ERS_RESULT_DISCONNECT
;
2912 pci_set_master(pdev
);
2914 pci_enable_wake(pdev
, PCI_D3hot
, 0);
2915 pci_enable_wake(pdev
, PCI_D3cold
, 0);
2917 ixgbe_reset(adapter
);
2919 return PCI_ERS_RESULT_RECOVERED
;
2923 * ixgbe_io_resume - called when traffic can start flowing again.
2924 * @pdev: Pointer to PCI device
2926 * This callback is called when the error recovery driver tells us that
2927 * its OK to resume normal operation.
2929 static void ixgbe_io_resume(struct pci_dev
*pdev
)
2931 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2932 struct ixgbe_adapter
*adapter
= netdev
->priv
;
2934 if (netif_running(netdev
)) {
2935 if (ixgbe_up(adapter
)) {
2936 DPRINTK(PROBE
, INFO
, "ixgbe_up failed after reset\n");
2941 netif_device_attach(netdev
);
2945 static struct pci_error_handlers ixgbe_err_handler
= {
2946 .error_detected
= ixgbe_io_error_detected
,
2947 .slot_reset
= ixgbe_io_slot_reset
,
2948 .resume
= ixgbe_io_resume
,
2951 static struct pci_driver ixgbe_driver
= {
2952 .name
= ixgbe_driver_name
,
2953 .id_table
= ixgbe_pci_tbl
,
2954 .probe
= ixgbe_probe
,
2955 .remove
= __devexit_p(ixgbe_remove
),
2957 .suspend
= ixgbe_suspend
,
2958 .resume
= ixgbe_resume
,
2960 .shutdown
= ixgbe_shutdown
,
2961 .err_handler
= &ixgbe_err_handler
2965 * ixgbe_init_module - Driver Registration Routine
2967 * ixgbe_init_module is the first routine called when the driver is
2968 * loaded. All it does is register with the PCI subsystem.
2970 static int __init
ixgbe_init_module(void)
2973 printk(KERN_INFO
"%s: %s - version %s\n", ixgbe_driver_name
,
2974 ixgbe_driver_string
, ixgbe_driver_version
);
2976 printk(KERN_INFO
"%s: %s\n", ixgbe_driver_name
, ixgbe_copyright
);
2978 ret
= pci_register_driver(&ixgbe_driver
);
2981 module_init(ixgbe_init_module
);
2984 * ixgbe_exit_module - Driver Exit Cleanup Routine
2986 * ixgbe_exit_module is called just before the driver is removed
2989 static void __exit
ixgbe_exit_module(void)
2991 pci_unregister_driver(&ixgbe_driver
);
2993 module_exit(ixgbe_exit_module
);