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.3.18-k2"
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);
84 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
86 static struct notifier_block dca_notifier = {
87 .notifier_call = ixgbe_notify_dca,
93 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
94 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
95 MODULE_LICENSE("GPL");
96 MODULE_VERSION(DRV_VERSION);
98 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
100 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
104 /* Let firmware take over control of h/w */
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);
110 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
114 /* Let firmware know the driver has taken over */
115 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
116 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
117 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
122 * ixgbe_get_hw_dev_name - return device name string
123 * used by hardware layer to print debugging information
125 char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
127 struct ixgbe_adapter *adapter = hw->back;
128 struct net_device *netdev = adapter->netdev;
133 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, u16 int_alloc_entry,
138 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
139 index = (int_alloc_entry >> 2) & 0x1F;
140 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR(index));
141 ivar &= ~(0xFF << (8 * (int_alloc_entry & 0x3)));
142 ivar |= (msix_vector << (8 * (int_alloc_entry & 0x3)));
143 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
146 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
147 struct ixgbe_tx_buffer
150 if (tx_buffer_info->dma) {
151 pci_unmap_page(adapter->pdev,
153 tx_buffer_info->length, PCI_DMA_TODEVICE);
154 tx_buffer_info->dma = 0;
156 if (tx_buffer_info->skb) {
157 dev_kfree_skb_any(tx_buffer_info->skb);
158 tx_buffer_info->skb = NULL;
160 /* tx_buffer_info must be completely set up in the transmit path */
163 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
164 struct ixgbe_ring *tx_ring,
166 union ixgbe_adv_tx_desc *eop_desc)
168 /* Detect a transmit hang in hardware, this serializes the
169 * check with the clearing of time_stamp and movement of i */
170 adapter->detect_tx_hung = false;
171 if (tx_ring->tx_buffer_info[eop].dma &&
172 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
173 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
174 /* detected Tx unit hang */
175 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
178 " next_to_use <%x>\n"
179 " next_to_clean <%x>\n"
180 "tx_buffer_info[next_to_clean]\n"
181 " time_stamp <%lx>\n"
182 " next_to_watch <%x>\n"
184 " next_to_watch.status <%x>\n",
185 readl(adapter->hw.hw_addr + tx_ring->head),
186 readl(adapter->hw.hw_addr + tx_ring->tail),
187 tx_ring->next_to_use,
188 tx_ring->next_to_clean,
189 tx_ring->tx_buffer_info[eop].time_stamp,
190 eop, jiffies, eop_desc->wb.status);
197 #define IXGBE_MAX_TXD_PWR 14
198 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
200 /* Tx Descriptors needed, worst case */
201 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
202 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
203 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
204 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
207 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
208 * @adapter: board private structure
210 static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
211 struct ixgbe_ring *tx_ring)
213 struct net_device *netdev = adapter->netdev;
214 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
215 struct ixgbe_tx_buffer *tx_buffer_info;
217 bool cleaned = false;
218 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
220 i = tx_ring->next_to_clean;
221 eop = tx_ring->tx_buffer_info[i].next_to_watch;
222 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
223 while (eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) {
226 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
227 tx_buffer_info = &tx_ring->tx_buffer_info[i];
228 cleaned = (i == eop);
230 tx_ring->stats.bytes += tx_buffer_info->length;
232 struct sk_buff *skb = tx_buffer_info->skb;
233 unsigned int segs, bytecount;
234 segs = skb_shinfo(skb)->gso_segs ?: 1;
235 /* multiply data chunks by size of headers */
236 bytecount = ((segs - 1) * skb_headlen(skb)) +
238 total_tx_packets += segs;
239 total_tx_bytes += bytecount;
241 ixgbe_unmap_and_free_tx_resource(adapter,
243 tx_desc->wb.status = 0;
246 if (i == tx_ring->count)
250 tx_ring->stats.packets++;
252 eop = tx_ring->tx_buffer_info[i].next_to_watch;
253 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
255 /* weight of a sort for tx, avoid endless transmit cleanup */
256 if (total_tx_packets >= tx_ring->work_limit)
260 tx_ring->next_to_clean = i;
262 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
263 if (total_tx_packets && netif_carrier_ok(netdev) &&
264 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
265 /* Make sure that anybody stopping the queue after this
266 * sees the new next_to_clean.
269 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
270 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
271 !test_bit(__IXGBE_DOWN, &adapter->state)) {
272 netif_wake_subqueue(netdev, tx_ring->queue_index);
273 adapter->restart_queue++;
276 if (netif_queue_stopped(netdev) &&
277 !test_bit(__IXGBE_DOWN, &adapter->state)) {
278 netif_wake_queue(netdev);
279 adapter->restart_queue++;
284 if (adapter->detect_tx_hung)
285 if (ixgbe_check_tx_hang(adapter, tx_ring, eop, eop_desc))
286 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
287 netif_stop_subqueue(netdev, tx_ring->queue_index);
289 netif_stop_queue(netdev);
292 if (total_tx_packets >= tx_ring->work_limit)
293 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->eims_value);
295 tx_ring->total_bytes += total_tx_bytes;
296 tx_ring->total_packets += total_tx_packets;
297 adapter->net_stats.tx_bytes += total_tx_bytes;
298 adapter->net_stats.tx_packets += total_tx_packets;
299 cleaned = total_tx_packets ? true : false;
304 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
305 struct ixgbe_ring *rxr)
309 int q = rxr - adapter->rx_ring;
311 if (rxr->cpu != cpu) {
312 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
313 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
314 rxctrl |= dca_get_tag(cpu);
315 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
316 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
317 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
323 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
324 struct ixgbe_ring *txr)
328 int q = txr - adapter->tx_ring;
330 if (txr->cpu != cpu) {
331 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
332 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
333 txctrl |= dca_get_tag(cpu);
334 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
335 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
341 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
345 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
348 for (i = 0; i < adapter->num_tx_queues; i++) {
349 adapter->tx_ring[i].cpu = -1;
350 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
352 for (i = 0; i < adapter->num_rx_queues; i++) {
353 adapter->rx_ring[i].cpu = -1;
354 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
358 static int __ixgbe_notify_dca(struct device *dev, void *data)
360 struct net_device *netdev = dev_get_drvdata(dev);
361 struct ixgbe_adapter *adapter = netdev_priv(netdev);
362 unsigned long event = *(unsigned long *)data;
365 case DCA_PROVIDER_ADD:
366 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
367 /* Always use CB2 mode, difference is masked
368 * in the CB driver. */
369 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
370 if (dca_add_requester(dev) == 0) {
371 ixgbe_setup_dca(adapter);
374 /* Fall Through since DCA is disabled. */
375 case DCA_PROVIDER_REMOVE:
376 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
377 dca_remove_requester(dev);
378 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
379 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
387 #endif /* CONFIG_DCA */
389 * ixgbe_receive_skb - Send a completed packet up the stack
390 * @adapter: board private structure
391 * @skb: packet to send up
392 * @is_vlan: packet has a VLAN tag
393 * @tag: VLAN tag from descriptor
395 static void ixgbe_receive_skb(struct ixgbe_adapter *adapter,
396 struct sk_buff *skb, bool is_vlan,
399 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
400 if (adapter->vlgrp && is_vlan)
401 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
403 netif_receive_skb(skb);
406 if (adapter->vlgrp && is_vlan)
407 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
414 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
415 * @adapter: address of board private structure
416 * @status_err: hardware indication of status of receive
417 * @skb: skb currently being received and modified
419 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
423 skb->ip_summed = CHECKSUM_NONE;
425 /* Ignore Checksum bit is set, or rx csum disabled */
426 if ((status_err & IXGBE_RXD_STAT_IXSM) ||
427 !(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
430 /* if IP and error */
431 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
432 (status_err & IXGBE_RXDADV_ERR_IPE)) {
433 adapter->hw_csum_rx_error++;
437 if (!(status_err & IXGBE_RXD_STAT_L4CS))
440 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
441 adapter->hw_csum_rx_error++;
445 /* It must be a TCP or UDP packet with a valid checksum */
446 skb->ip_summed = CHECKSUM_UNNECESSARY;
447 adapter->hw_csum_rx_good++;
451 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
452 * @adapter: address of board private structure
454 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
455 struct ixgbe_ring *rx_ring,
458 struct net_device *netdev = adapter->netdev;
459 struct pci_dev *pdev = adapter->pdev;
460 union ixgbe_adv_rx_desc *rx_desc;
461 struct ixgbe_rx_buffer *rx_buffer_info;
464 unsigned int bufsz = adapter->rx_buf_len + NET_IP_ALIGN;
466 i = rx_ring->next_to_use;
467 rx_buffer_info = &rx_ring->rx_buffer_info[i];
469 while (cleaned_count--) {
470 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
472 if (!rx_buffer_info->page &&
473 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
474 rx_buffer_info->page = alloc_page(GFP_ATOMIC);
475 if (!rx_buffer_info->page) {
476 adapter->alloc_rx_page_failed++;
479 rx_buffer_info->page_dma =
480 pci_map_page(pdev, rx_buffer_info->page,
481 0, PAGE_SIZE, PCI_DMA_FROMDEVICE);
484 if (!rx_buffer_info->skb) {
485 skb = netdev_alloc_skb(netdev, bufsz);
488 adapter->alloc_rx_buff_failed++;
493 * Make buffer alignment 2 beyond a 16 byte boundary
494 * this will result in a 16 byte aligned IP header after
495 * the 14 byte MAC header is removed
497 skb_reserve(skb, NET_IP_ALIGN);
499 rx_buffer_info->skb = skb;
500 rx_buffer_info->dma = pci_map_single(pdev, skb->data,
504 /* Refresh the desc even if buffer_addrs didn't change because
505 * each write-back erases this info. */
506 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
507 rx_desc->read.pkt_addr =
508 cpu_to_le64(rx_buffer_info->page_dma);
509 rx_desc->read.hdr_addr =
510 cpu_to_le64(rx_buffer_info->dma);
512 rx_desc->read.pkt_addr =
513 cpu_to_le64(rx_buffer_info->dma);
517 if (i == rx_ring->count)
519 rx_buffer_info = &rx_ring->rx_buffer_info[i];
522 if (rx_ring->next_to_use != i) {
523 rx_ring->next_to_use = i;
525 i = (rx_ring->count - 1);
528 * Force memory writes to complete before letting h/w
529 * know there are new descriptors to fetch. (Only
530 * applicable for weak-ordered memory model archs,
534 writel(i, adapter->hw.hw_addr + rx_ring->tail);
538 static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
539 struct ixgbe_ring *rx_ring,
540 int *work_done, int work_to_do)
542 struct net_device *netdev = adapter->netdev;
543 struct pci_dev *pdev = adapter->pdev;
544 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
545 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
548 u32 upper_len, len, staterr;
549 u16 hdr_info, vlan_tag;
550 bool is_vlan, cleaned = false;
551 int cleaned_count = 0;
552 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
554 i = rx_ring->next_to_clean;
556 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
557 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
558 rx_buffer_info = &rx_ring->rx_buffer_info[i];
559 is_vlan = (staterr & IXGBE_RXD_STAT_VP);
560 vlan_tag = le16_to_cpu(rx_desc->wb.upper.vlan);
562 while (staterr & IXGBE_RXD_STAT_DD) {
563 if (*work_done >= work_to_do)
567 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
569 le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info);
571 ((hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
572 IXGBE_RXDADV_HDRBUFLEN_SHIFT);
573 if (hdr_info & IXGBE_RXDADV_SPH)
574 adapter->rx_hdr_split++;
575 if (len > IXGBE_RX_HDR_SIZE)
576 len = IXGBE_RX_HDR_SIZE;
577 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
579 len = le16_to_cpu(rx_desc->wb.upper.length);
582 skb = rx_buffer_info->skb;
583 prefetch(skb->data - NET_IP_ALIGN);
584 rx_buffer_info->skb = NULL;
586 if (len && !skb_shinfo(skb)->nr_frags) {
587 pci_unmap_single(pdev, rx_buffer_info->dma,
588 adapter->rx_buf_len + NET_IP_ALIGN,
594 pci_unmap_page(pdev, rx_buffer_info->page_dma,
595 PAGE_SIZE, PCI_DMA_FROMDEVICE);
596 rx_buffer_info->page_dma = 0;
597 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
598 rx_buffer_info->page, 0, upper_len);
599 rx_buffer_info->page = NULL;
601 skb->len += upper_len;
602 skb->data_len += upper_len;
603 skb->truesize += upper_len;
607 if (i == rx_ring->count)
609 next_buffer = &rx_ring->rx_buffer_info[i];
611 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
615 if (staterr & IXGBE_RXD_STAT_EOP) {
616 rx_ring->stats.packets++;
617 rx_ring->stats.bytes += skb->len;
619 rx_buffer_info->skb = next_buffer->skb;
620 rx_buffer_info->dma = next_buffer->dma;
621 next_buffer->skb = skb;
622 adapter->non_eop_descs++;
626 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
627 dev_kfree_skb_irq(skb);
631 ixgbe_rx_checksum(adapter, staterr, skb);
633 /* probably a little skewed due to removing CRC */
634 total_rx_bytes += skb->len;
637 skb->protocol = eth_type_trans(skb, netdev);
638 ixgbe_receive_skb(adapter, skb, is_vlan, vlan_tag);
639 netdev->last_rx = jiffies;
642 rx_desc->wb.upper.status_error = 0;
644 /* return some buffers to hardware, one at a time is too slow */
645 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
646 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
650 /* use prefetched values */
652 rx_buffer_info = next_buffer;
654 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
655 is_vlan = (staterr & IXGBE_RXD_STAT_VP);
656 vlan_tag = le16_to_cpu(rx_desc->wb.upper.vlan);
659 rx_ring->next_to_clean = i;
660 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
663 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
665 adapter->net_stats.rx_bytes += total_rx_bytes;
666 adapter->net_stats.rx_packets += total_rx_packets;
668 rx_ring->total_packets += total_rx_packets;
669 rx_ring->total_bytes += total_rx_bytes;
670 adapter->net_stats.rx_bytes += total_rx_bytes;
671 adapter->net_stats.rx_packets += total_rx_packets;
676 static int ixgbe_clean_rxonly(struct napi_struct *, int);
678 * ixgbe_configure_msix - Configure MSI-X hardware
679 * @adapter: board private structure
681 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
684 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
686 struct ixgbe_q_vector *q_vector;
687 int i, j, q_vectors, v_idx, r_idx;
690 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
692 /* Populate the IVAR table and set the ITR values to the
693 * corresponding register.
695 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
696 q_vector = &adapter->q_vector[v_idx];
697 /* XXX for_each_bit(...) */
698 r_idx = find_first_bit(q_vector->rxr_idx,
699 adapter->num_rx_queues);
701 for (i = 0; i < q_vector->rxr_count; i++) {
702 j = adapter->rx_ring[r_idx].reg_idx;
703 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
704 r_idx = find_next_bit(q_vector->rxr_idx,
705 adapter->num_rx_queues,
708 r_idx = find_first_bit(q_vector->txr_idx,
709 adapter->num_tx_queues);
711 for (i = 0; i < q_vector->txr_count; i++) {
712 j = adapter->tx_ring[r_idx].reg_idx;
713 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
714 r_idx = find_next_bit(q_vector->txr_idx,
715 adapter->num_tx_queues,
719 /* if this is a tx only vector use half the irq (tx) rate */
720 if (q_vector->txr_count && !q_vector->rxr_count)
721 q_vector->eitr = adapter->tx_eitr;
723 /* rx only or mixed */
724 q_vector->eitr = adapter->rx_eitr;
726 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
727 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
730 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
731 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
733 /* set up to autoclear timer, lsc, and the vectors */
734 mask = IXGBE_EIMS_ENABLE_MASK;
735 mask &= ~IXGBE_EIMS_OTHER;
736 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
743 latency_invalid = 255
747 * ixgbe_update_itr - update the dynamic ITR value based on statistics
748 * @adapter: pointer to adapter
749 * @eitr: eitr setting (ints per sec) to give last timeslice
750 * @itr_setting: current throttle rate in ints/second
751 * @packets: the number of packets during this measurement interval
752 * @bytes: the number of bytes during this measurement interval
754 * Stores a new ITR value based on packets and byte
755 * counts during the last interrupt. The advantage of per interrupt
756 * computation is faster updates and more accurate ITR for the current
757 * traffic pattern. Constants in this function were computed
758 * based on theoretical maximum wire speed and thresholds were set based
759 * on testing data as well as attempting to minimize response time
760 * while increasing bulk throughput.
761 * this functionality is controlled by the InterruptThrottleRate module
762 * parameter (see ixgbe_param.c)
764 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
765 u32 eitr, u8 itr_setting,
766 int packets, int bytes)
768 unsigned int retval = itr_setting;
773 goto update_itr_done;
776 /* simple throttlerate management
777 * 0-20MB/s lowest (100000 ints/s)
778 * 20-100MB/s low (20000 ints/s)
779 * 100-1249MB/s bulk (8000 ints/s)
781 /* what was last interrupt timeslice? */
782 timepassed_us = 1000000/eitr;
783 bytes_perint = bytes / timepassed_us; /* bytes/usec */
785 switch (itr_setting) {
787 if (bytes_perint > adapter->eitr_low)
788 retval = low_latency;
791 if (bytes_perint > adapter->eitr_high)
792 retval = bulk_latency;
793 else if (bytes_perint <= adapter->eitr_low)
794 retval = lowest_latency;
797 if (bytes_perint <= adapter->eitr_high)
798 retval = low_latency;
806 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
808 struct ixgbe_adapter *adapter = q_vector->adapter;
809 struct ixgbe_hw *hw = &adapter->hw;
811 u8 current_itr, ret_itr;
812 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
813 sizeof(struct ixgbe_q_vector);
814 struct ixgbe_ring *rx_ring, *tx_ring;
816 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
817 for (i = 0; i < q_vector->txr_count; i++) {
818 tx_ring = &(adapter->tx_ring[r_idx]);
819 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
821 tx_ring->total_packets,
822 tx_ring->total_bytes);
823 /* if the result for this queue would decrease interrupt
824 * rate for this vector then use that result */
825 q_vector->tx_eitr = ((q_vector->tx_eitr > ret_itr) ?
826 q_vector->tx_eitr - 1 : ret_itr);
827 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
831 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
832 for (i = 0; i < q_vector->rxr_count; i++) {
833 rx_ring = &(adapter->rx_ring[r_idx]);
834 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
836 rx_ring->total_packets,
837 rx_ring->total_bytes);
838 /* if the result for this queue would decrease interrupt
839 * rate for this vector then use that result */
840 q_vector->rx_eitr = ((q_vector->rx_eitr > ret_itr) ?
841 q_vector->rx_eitr - 1 : ret_itr);
842 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
846 current_itr = max(q_vector->rx_eitr, q_vector->tx_eitr);
848 switch (current_itr) {
849 /* counts and packets in update_itr are dependent on these numbers */
854 new_itr = 20000; /* aka hwitr = ~200 */
862 if (new_itr != q_vector->eitr) {
864 /* do an exponential smoothing */
865 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
866 q_vector->eitr = new_itr;
867 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
868 /* must write high and low 16 bits to reset counter */
869 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
871 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
877 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
879 struct net_device *netdev = data;
880 struct ixgbe_adapter *adapter = netdev_priv(netdev);
881 struct ixgbe_hw *hw = &adapter->hw;
882 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
884 if (eicr & IXGBE_EICR_LSC) {
886 if (!test_bit(__IXGBE_DOWN, &adapter->state))
887 mod_timer(&adapter->watchdog_timer, jiffies);
890 if (!test_bit(__IXGBE_DOWN, &adapter->state))
891 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
896 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
898 struct ixgbe_q_vector *q_vector = data;
899 struct ixgbe_adapter *adapter = q_vector->adapter;
900 struct ixgbe_ring *txr;
903 if (!q_vector->txr_count)
906 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
907 for (i = 0; i < q_vector->txr_count; i++) {
908 txr = &(adapter->tx_ring[r_idx]);
910 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
911 ixgbe_update_tx_dca(adapter, txr);
913 txr->total_bytes = 0;
914 txr->total_packets = 0;
915 ixgbe_clean_tx_irq(adapter, txr);
916 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
924 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
926 * @data: pointer to our q_vector struct for this interrupt vector
928 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
930 struct ixgbe_q_vector *q_vector = data;
931 struct ixgbe_adapter *adapter = q_vector->adapter;
932 struct ixgbe_ring *rxr;
935 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
936 if (!q_vector->rxr_count)
939 rxr = &(adapter->rx_ring[r_idx]);
940 /* disable interrupts on this vector only */
941 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rxr->v_idx);
942 rxr->total_bytes = 0;
943 rxr->total_packets = 0;
944 netif_rx_schedule(adapter->netdev, &q_vector->napi);
949 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
951 ixgbe_msix_clean_rx(irq, data);
952 ixgbe_msix_clean_tx(irq, data);
958 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
959 * @napi: napi struct with our devices info in it
960 * @budget: amount of work driver is allowed to do this pass, in packets
963 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
965 struct ixgbe_q_vector *q_vector =
966 container_of(napi, struct ixgbe_q_vector, napi);
967 struct ixgbe_adapter *adapter = q_vector->adapter;
968 struct ixgbe_ring *rxr;
972 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
973 rxr = &(adapter->rx_ring[r_idx]);
975 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
976 ixgbe_update_rx_dca(adapter, rxr);
979 ixgbe_clean_rx_irq(adapter, rxr, &work_done, budget);
981 /* If all Rx work done, exit the polling mode */
982 if (work_done < budget) {
983 netif_rx_complete(adapter->netdev, napi);
984 if (adapter->rx_eitr < IXGBE_MIN_ITR_USECS)
985 ixgbe_set_itr_msix(q_vector);
986 if (!test_bit(__IXGBE_DOWN, &adapter->state))
987 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rxr->v_idx);
993 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
996 a->q_vector[v_idx].adapter = a;
997 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
998 a->q_vector[v_idx].rxr_count++;
999 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1002 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
1005 a->q_vector[v_idx].adapter = a;
1006 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1007 a->q_vector[v_idx].txr_count++;
1008 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1012 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1013 * @adapter: board private structure to initialize
1014 * @vectors: allotted vector count for descriptor rings
1016 * This function maps descriptor rings to the queue-specific vectors
1017 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1018 * one vector per ring/queue, but on a constrained vector budget, we
1019 * group the rings as "efficiently" as possible. You would add new
1020 * mapping configurations in here.
1022 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
1026 int rxr_idx = 0, txr_idx = 0;
1027 int rxr_remaining = adapter->num_rx_queues;
1028 int txr_remaining = adapter->num_tx_queues;
1033 /* No mapping required if MSI-X is disabled. */
1034 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1038 * The ideal configuration...
1039 * We have enough vectors to map one per queue.
1041 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1042 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1043 map_vector_to_rxq(adapter, v_start, rxr_idx);
1045 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1046 map_vector_to_txq(adapter, v_start, txr_idx);
1052 * If we don't have enough vectors for a 1-to-1
1053 * mapping, we'll have to group them so there are
1054 * multiple queues per vector.
1056 /* Re-adjusting *qpv takes care of the remainder. */
1057 for (i = v_start; i < vectors; i++) {
1058 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1059 for (j = 0; j < rqpv; j++) {
1060 map_vector_to_rxq(adapter, i, rxr_idx);
1065 for (i = v_start; i < vectors; i++) {
1066 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1067 for (j = 0; j < tqpv; j++) {
1068 map_vector_to_txq(adapter, i, txr_idx);
1079 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1080 * @adapter: board private structure
1082 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1083 * interrupts from the kernel.
1085 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1087 struct net_device *netdev = adapter->netdev;
1088 irqreturn_t (*handler)(int, void *);
1089 int i, vector, q_vectors, err;
1091 /* Decrement for Other and TCP Timer vectors */
1092 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1094 /* Map the Tx/Rx rings to the vectors we were allotted. */
1095 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1099 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1100 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1101 &ixgbe_msix_clean_many)
1102 for (vector = 0; vector < q_vectors; vector++) {
1103 handler = SET_HANDLER(&adapter->q_vector[vector]);
1104 sprintf(adapter->name[vector], "%s:v%d-%s",
1105 netdev->name, vector,
1106 (handler == &ixgbe_msix_clean_rx) ? "Rx" :
1107 ((handler == &ixgbe_msix_clean_tx) ? "Tx" : "TxRx"));
1108 err = request_irq(adapter->msix_entries[vector].vector,
1109 handler, 0, adapter->name[vector],
1110 &(adapter->q_vector[vector]));
1113 "request_irq failed for MSIX interrupt "
1114 "Error: %d\n", err);
1115 goto free_queue_irqs;
1119 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1120 err = request_irq(adapter->msix_entries[vector].vector,
1121 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
1124 "request_irq for msix_lsc failed: %d\n", err);
1125 goto free_queue_irqs;
1131 for (i = vector - 1; i >= 0; i--)
1132 free_irq(adapter->msix_entries[--vector].vector,
1133 &(adapter->q_vector[i]));
1134 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1135 pci_disable_msix(adapter->pdev);
1136 kfree(adapter->msix_entries);
1137 adapter->msix_entries = NULL;
1142 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1144 struct ixgbe_hw *hw = &adapter->hw;
1145 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1147 u32 new_itr = q_vector->eitr;
1148 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1149 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1151 q_vector->tx_eitr = ixgbe_update_itr(adapter, new_itr,
1153 tx_ring->total_packets,
1154 tx_ring->total_bytes);
1155 q_vector->rx_eitr = ixgbe_update_itr(adapter, new_itr,
1157 rx_ring->total_packets,
1158 rx_ring->total_bytes);
1160 current_itr = max(q_vector->rx_eitr, q_vector->tx_eitr);
1162 switch (current_itr) {
1163 /* counts and packets in update_itr are dependent on these numbers */
1164 case lowest_latency:
1168 new_itr = 20000; /* aka hwitr = ~200 */
1177 if (new_itr != q_vector->eitr) {
1179 /* do an exponential smoothing */
1180 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1181 q_vector->eitr = new_itr;
1182 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1183 /* must write high and low 16 bits to reset counter */
1184 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1190 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter);
1193 * ixgbe_intr - legacy mode Interrupt Handler
1194 * @irq: interrupt number
1195 * @data: pointer to a network interface device structure
1196 * @pt_regs: CPU registers structure
1198 static irqreturn_t ixgbe_intr(int irq, void *data)
1200 struct net_device *netdev = data;
1201 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1202 struct ixgbe_hw *hw = &adapter->hw;
1206 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1207 * therefore no explict interrupt disable is necessary */
1208 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1210 return IRQ_NONE; /* Not our interrupt */
1212 if (eicr & IXGBE_EICR_LSC) {
1214 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1215 mod_timer(&adapter->watchdog_timer, jiffies);
1219 if (netif_rx_schedule_prep(netdev, &adapter->q_vector[0].napi)) {
1220 adapter->tx_ring[0].total_packets = 0;
1221 adapter->tx_ring[0].total_bytes = 0;
1222 adapter->rx_ring[0].total_packets = 0;
1223 adapter->rx_ring[0].total_bytes = 0;
1224 /* would disable interrupts here but EIAM disabled it */
1225 __netif_rx_schedule(netdev, &adapter->q_vector[0].napi);
1231 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1233 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1235 for (i = 0; i < q_vectors; i++) {
1236 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1237 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1238 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1239 q_vector->rxr_count = 0;
1240 q_vector->txr_count = 0;
1245 * ixgbe_request_irq - initialize interrupts
1246 * @adapter: board private structure
1248 * Attempts to configure interrupts using the best available
1249 * capabilities of the hardware and kernel.
1251 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
1253 struct net_device *netdev = adapter->netdev;
1256 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1257 err = ixgbe_request_msix_irqs(adapter);
1258 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1259 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
1260 netdev->name, netdev);
1262 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
1263 netdev->name, netdev);
1267 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1272 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1274 struct net_device *netdev = adapter->netdev;
1276 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1279 q_vectors = adapter->num_msix_vectors;
1282 free_irq(adapter->msix_entries[i].vector, netdev);
1285 for (; i >= 0; i--) {
1286 free_irq(adapter->msix_entries[i].vector,
1287 &(adapter->q_vector[i]));
1290 ixgbe_reset_q_vectors(adapter);
1292 free_irq(adapter->pdev->irq, netdev);
1297 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1298 * @adapter: board private structure
1300 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1302 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1303 IXGBE_WRITE_FLUSH(&adapter->hw);
1304 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1306 for (i = 0; i < adapter->num_msix_vectors; i++)
1307 synchronize_irq(adapter->msix_entries[i].vector);
1309 synchronize_irq(adapter->pdev->irq);
1314 * ixgbe_irq_enable - Enable default interrupt generation settings
1315 * @adapter: board private structure
1317 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1320 mask = IXGBE_EIMS_ENABLE_MASK;
1321 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1322 IXGBE_WRITE_FLUSH(&adapter->hw);
1326 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1329 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1331 struct ixgbe_hw *hw = &adapter->hw;
1333 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
1334 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr));
1336 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
1337 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1339 map_vector_to_rxq(adapter, 0, 0);
1340 map_vector_to_txq(adapter, 0, 0);
1342 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
1346 * ixgbe_configure_tx - Configure 8254x Transmit Unit after Reset
1347 * @adapter: board private structure
1349 * Configure the Tx unit of the MAC after a reset.
1351 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1354 struct ixgbe_hw *hw = &adapter->hw;
1355 u32 i, j, tdlen, txctrl;
1357 /* Setup the HW Tx Head and Tail descriptor pointers */
1358 for (i = 0; i < adapter->num_tx_queues; i++) {
1359 j = adapter->tx_ring[i].reg_idx;
1360 tdba = adapter->tx_ring[i].dma;
1361 tdlen = adapter->tx_ring[i].count *
1362 sizeof(union ixgbe_adv_tx_desc);
1363 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
1364 (tdba & DMA_32BIT_MASK));
1365 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1366 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1367 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1368 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1369 adapter->tx_ring[i].head = IXGBE_TDH(j);
1370 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1371 /* Disable Tx Head Writeback RO bit, since this hoses
1372 * bookkeeping if things aren't delivered in order.
1374 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
1375 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1376 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), txctrl);
1380 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1381 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1383 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1385 * ixgbe_configure_rx - Configure 8254x Receive Unit after Reset
1386 * @adapter: board private structure
1388 * Configure the Rx unit of the MAC after a reset.
1390 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1393 struct ixgbe_hw *hw = &adapter->hw;
1394 struct net_device *netdev = adapter->netdev;
1395 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1397 u32 rdlen, rxctrl, rxcsum;
1401 u32 reta = 0, mrqc, srrctl;
1403 /* Decide whether to use packet split mode or not */
1404 if (netdev->mtu > ETH_DATA_LEN)
1405 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1407 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
1409 /* Set the RX buffer length according to the mode */
1410 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1411 adapter->rx_buf_len = IXGBE_RX_HDR_SIZE;
1413 if (netdev->mtu <= ETH_DATA_LEN)
1414 adapter->rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1416 adapter->rx_buf_len = ALIGN(max_frame, 1024);
1419 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1420 fctrl |= IXGBE_FCTRL_BAM;
1421 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
1422 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1424 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1425 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1426 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1428 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1429 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1431 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1433 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(0));
1434 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1435 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1437 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1438 srrctl |= PAGE_SIZE >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1439 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1440 srrctl |= ((IXGBE_RX_HDR_SIZE <<
1441 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1442 IXGBE_SRRCTL_BSIZEHDR_MASK);
1444 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1446 if (adapter->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1448 IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1451 adapter->rx_buf_len >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1453 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(0), srrctl);
1455 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1456 /* disable receives while setting up the descriptors */
1457 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1458 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1460 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1461 * the Base and Length of the Rx Descriptor Ring */
1462 for (i = 0; i < adapter->num_rx_queues; i++) {
1463 rdba = adapter->rx_ring[i].dma;
1464 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(i), (rdba & DMA_32BIT_MASK));
1465 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(i), (rdba >> 32));
1466 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(i), rdlen);
1467 IXGBE_WRITE_REG(hw, IXGBE_RDH(i), 0);
1468 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), 0);
1469 adapter->rx_ring[i].head = IXGBE_RDH(i);
1470 adapter->rx_ring[i].tail = IXGBE_RDT(i);
1473 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
1474 /* Fill out redirection table */
1475 for (i = 0, j = 0; i < 128; i++, j++) {
1476 if (j == adapter->ring_feature[RING_F_RSS].indices)
1478 /* reta = 4-byte sliding window of
1479 * 0x00..(indices-1)(indices-1)00..etc. */
1480 reta = (reta << 8) | (j * 0x11);
1482 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
1485 /* Fill out hash function seeds */
1486 /* XXX use a random constant here to glue certain flows */
1487 get_random_bytes(&random[0], 40);
1488 for (i = 0; i < 10; i++)
1489 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random[i]);
1491 mrqc = IXGBE_MRQC_RSSEN
1492 /* Perform hash on these packet types */
1493 | IXGBE_MRQC_RSS_FIELD_IPV4
1494 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1495 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1496 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1497 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1498 | IXGBE_MRQC_RSS_FIELD_IPV6
1499 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1500 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1501 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
1502 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
1505 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1507 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1508 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1509 /* Disable indicating checksum in descriptor, enables
1511 rxcsum |= IXGBE_RXCSUM_PCSD;
1513 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1514 /* Enable IPv4 payload checksum for UDP fragments
1515 * if PCSD is not set */
1516 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1519 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1522 static void ixgbe_vlan_rx_register(struct net_device *netdev,
1523 struct vlan_group *grp)
1525 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1528 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1529 ixgbe_irq_disable(adapter);
1530 adapter->vlgrp = grp;
1533 /* enable VLAN tag insert/strip */
1534 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1535 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1536 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1537 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1540 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1541 ixgbe_irq_enable(adapter);
1544 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1546 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1548 /* add VID to filter table */
1549 ixgbe_set_vfta(&adapter->hw, vid, 0, true);
1552 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1554 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1556 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1557 ixgbe_irq_disable(adapter);
1559 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1561 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1562 ixgbe_irq_enable(adapter);
1564 /* remove VID from filter table */
1565 ixgbe_set_vfta(&adapter->hw, vid, 0, false);
1568 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1570 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1572 if (adapter->vlgrp) {
1574 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1575 if (!vlan_group_get_device(adapter->vlgrp, vid))
1577 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1583 * ixgbe_set_multi - Multicast and Promiscuous mode set
1584 * @netdev: network interface device structure
1586 * The set_multi entry point is called whenever the multicast address
1587 * list or the network interface flags are updated. This routine is
1588 * responsible for configuring the hardware for proper multicast,
1589 * promiscuous mode, and all-multi behavior.
1591 static void ixgbe_set_multi(struct net_device *netdev)
1593 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1594 struct ixgbe_hw *hw = &adapter->hw;
1595 struct dev_mc_list *mc_ptr;
1600 /* Check for Promiscuous and All Multicast modes */
1602 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1604 if (netdev->flags & IFF_PROMISC) {
1605 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1606 } else if (netdev->flags & IFF_ALLMULTI) {
1607 fctrl |= IXGBE_FCTRL_MPE;
1608 fctrl &= ~IXGBE_FCTRL_UPE;
1610 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1613 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1615 if (netdev->mc_count) {
1616 mta_list = kcalloc(netdev->mc_count, ETH_ALEN, GFP_ATOMIC);
1620 /* Shared function expects packed array of only addresses. */
1621 mc_ptr = netdev->mc_list;
1623 for (i = 0; i < netdev->mc_count; i++) {
1626 memcpy(mta_list + (i * ETH_ALEN), mc_ptr->dmi_addr,
1628 mc_ptr = mc_ptr->next;
1631 ixgbe_update_mc_addr_list(hw, mta_list, i, 0);
1634 ixgbe_update_mc_addr_list(hw, NULL, 0, 0);
1639 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1642 struct ixgbe_q_vector *q_vector;
1643 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1645 /* legacy and MSI only use one vector */
1646 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1649 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1650 q_vector = &adapter->q_vector[q_idx];
1651 if (!q_vector->rxr_count)
1653 napi_enable(&q_vector->napi);
1657 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1660 struct ixgbe_q_vector *q_vector;
1661 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1663 /* legacy and MSI only use one vector */
1664 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1667 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1668 q_vector = &adapter->q_vector[q_idx];
1669 if (!q_vector->rxr_count)
1671 napi_disable(&q_vector->napi);
1675 static void ixgbe_configure(struct ixgbe_adapter *adapter)
1677 struct net_device *netdev = adapter->netdev;
1680 ixgbe_set_multi(netdev);
1682 ixgbe_restore_vlan(adapter);
1684 ixgbe_configure_tx(adapter);
1685 ixgbe_configure_rx(adapter);
1686 for (i = 0; i < adapter->num_rx_queues; i++)
1687 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
1688 (adapter->rx_ring[i].count - 1));
1691 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1693 struct net_device *netdev = adapter->netdev;
1694 struct ixgbe_hw *hw = &adapter->hw;
1696 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1697 u32 txdctl, rxdctl, mhadd;
1700 ixgbe_get_hw_control(adapter);
1702 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
1703 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
1704 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1705 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
1706 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
1711 /* XXX: to interrupt immediately for EICS writes, enable this */
1712 /* gpie |= IXGBE_GPIE_EIMEN; */
1713 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1716 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
1717 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
1718 * specifically only auto mask tx and rx interrupts */
1719 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1722 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1723 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
1724 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1725 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
1727 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1730 for (i = 0; i < adapter->num_tx_queues; i++) {
1731 j = adapter->tx_ring[i].reg_idx;
1732 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1733 txdctl |= IXGBE_TXDCTL_ENABLE;
1734 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1737 for (i = 0; i < adapter->num_rx_queues; i++) {
1738 j = adapter->rx_ring[i].reg_idx;
1739 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
1740 /* enable PTHRESH=32 descriptors (half the internal cache)
1741 * and HTHRESH=0 descriptors (to minimize latency on fetch),
1742 * this also removes a pesky rx_no_buffer_count increment */
1744 rxdctl |= IXGBE_RXDCTL_ENABLE;
1745 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
1747 /* enable all receives */
1748 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1749 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
1750 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
1752 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1753 ixgbe_configure_msix(adapter);
1755 ixgbe_configure_msi_and_legacy(adapter);
1757 clear_bit(__IXGBE_DOWN, &adapter->state);
1758 ixgbe_napi_enable_all(adapter);
1760 /* clear any pending interrupts, may auto mask */
1761 IXGBE_READ_REG(hw, IXGBE_EICR);
1763 ixgbe_irq_enable(adapter);
1765 /* bring the link up in the watchdog, this could race with our first
1766 * link up interrupt but shouldn't be a problem */
1767 mod_timer(&adapter->watchdog_timer, jiffies);
1771 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
1773 WARN_ON(in_interrupt());
1774 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
1776 ixgbe_down(adapter);
1778 clear_bit(__IXGBE_RESETTING, &adapter->state);
1781 int ixgbe_up(struct ixgbe_adapter *adapter)
1783 /* hardware has been reset, we need to reload some things */
1784 ixgbe_configure(adapter);
1786 return ixgbe_up_complete(adapter);
1789 void ixgbe_reset(struct ixgbe_adapter *adapter)
1791 if (ixgbe_init_hw(&adapter->hw))
1792 DPRINTK(PROBE, ERR, "Hardware Error\n");
1794 /* reprogram the RAR[0] in case user changed it. */
1795 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
1800 static int ixgbe_resume(struct pci_dev *pdev)
1802 struct net_device *netdev = pci_get_drvdata(pdev);
1803 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1806 pci_set_power_state(pdev, PCI_D0);
1807 pci_restore_state(pdev);
1808 err = pci_enable_device(pdev);
1810 printk(KERN_ERR "ixgbe: Cannot enable PCI device from " \
1814 pci_set_master(pdev);
1816 pci_enable_wake(pdev, PCI_D3hot, 0);
1817 pci_enable_wake(pdev, PCI_D3cold, 0);
1819 if (netif_running(netdev)) {
1820 err = ixgbe_request_irq(adapter);
1825 ixgbe_reset(adapter);
1827 if (netif_running(netdev))
1830 netif_device_attach(netdev);
1837 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
1838 * @adapter: board private structure
1839 * @rx_ring: ring to free buffers from
1841 static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
1842 struct ixgbe_ring *rx_ring)
1844 struct pci_dev *pdev = adapter->pdev;
1848 /* Free all the Rx ring sk_buffs */
1850 for (i = 0; i < rx_ring->count; i++) {
1851 struct ixgbe_rx_buffer *rx_buffer_info;
1853 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1854 if (rx_buffer_info->dma) {
1855 pci_unmap_single(pdev, rx_buffer_info->dma,
1856 adapter->rx_buf_len,
1857 PCI_DMA_FROMDEVICE);
1858 rx_buffer_info->dma = 0;
1860 if (rx_buffer_info->skb) {
1861 dev_kfree_skb(rx_buffer_info->skb);
1862 rx_buffer_info->skb = NULL;
1864 if (!rx_buffer_info->page)
1866 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE,
1867 PCI_DMA_FROMDEVICE);
1868 rx_buffer_info->page_dma = 0;
1870 put_page(rx_buffer_info->page);
1871 rx_buffer_info->page = NULL;
1874 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
1875 memset(rx_ring->rx_buffer_info, 0, size);
1877 /* Zero out the descriptor ring */
1878 memset(rx_ring->desc, 0, rx_ring->size);
1880 rx_ring->next_to_clean = 0;
1881 rx_ring->next_to_use = 0;
1883 writel(0, adapter->hw.hw_addr + rx_ring->head);
1884 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1888 * ixgbe_clean_tx_ring - Free Tx Buffers
1889 * @adapter: board private structure
1890 * @tx_ring: ring to be cleaned
1892 static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
1893 struct ixgbe_ring *tx_ring)
1895 struct ixgbe_tx_buffer *tx_buffer_info;
1899 /* Free all the Tx ring sk_buffs */
1901 for (i = 0; i < tx_ring->count; i++) {
1902 tx_buffer_info = &tx_ring->tx_buffer_info[i];
1903 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
1906 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
1907 memset(tx_ring->tx_buffer_info, 0, size);
1909 /* Zero out the descriptor ring */
1910 memset(tx_ring->desc, 0, tx_ring->size);
1912 tx_ring->next_to_use = 0;
1913 tx_ring->next_to_clean = 0;
1915 writel(0, adapter->hw.hw_addr + tx_ring->head);
1916 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1920 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
1921 * @adapter: board private structure
1923 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
1927 for (i = 0; i < adapter->num_rx_queues; i++)
1928 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1932 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
1933 * @adapter: board private structure
1935 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
1939 for (i = 0; i < adapter->num_tx_queues; i++)
1940 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1943 void ixgbe_down(struct ixgbe_adapter *adapter)
1945 struct net_device *netdev = adapter->netdev;
1948 /* signal that we are down to the interrupt handler */
1949 set_bit(__IXGBE_DOWN, &adapter->state);
1951 /* disable receives */
1952 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXCTRL);
1953 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL,
1954 rxctrl & ~IXGBE_RXCTRL_RXEN);
1956 netif_tx_disable(netdev);
1958 /* disable transmits in the hardware */
1960 /* flush both disables */
1961 IXGBE_WRITE_FLUSH(&adapter->hw);
1964 ixgbe_irq_disable(adapter);
1966 ixgbe_napi_disable_all(adapter);
1967 del_timer_sync(&adapter->watchdog_timer);
1969 netif_carrier_off(netdev);
1970 netif_stop_queue(netdev);
1972 if (!pci_channel_offline(adapter->pdev))
1973 ixgbe_reset(adapter);
1974 ixgbe_clean_all_tx_rings(adapter);
1975 ixgbe_clean_all_rx_rings(adapter);
1979 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
1981 struct net_device *netdev = pci_get_drvdata(pdev);
1982 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1987 netif_device_detach(netdev);
1989 if (netif_running(netdev)) {
1990 ixgbe_down(adapter);
1991 ixgbe_free_irq(adapter);
1995 retval = pci_save_state(pdev);
2000 pci_enable_wake(pdev, PCI_D3hot, 0);
2001 pci_enable_wake(pdev, PCI_D3cold, 0);
2003 ixgbe_release_hw_control(adapter);
2005 pci_disable_device(pdev);
2007 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2012 static void ixgbe_shutdown(struct pci_dev *pdev)
2014 ixgbe_suspend(pdev, PMSG_SUSPEND);
2018 * ixgbe_poll - NAPI Rx polling callback
2019 * @napi: structure for representing this polling device
2020 * @budget: how many packets driver is allowed to clean
2022 * This function is used for legacy and MSI, NAPI mode
2024 static int ixgbe_poll(struct napi_struct *napi, int budget)
2026 struct ixgbe_q_vector *q_vector = container_of(napi,
2027 struct ixgbe_q_vector, napi);
2028 struct ixgbe_adapter *adapter = q_vector->adapter;
2029 int tx_cleaned = 0, work_done = 0;
2032 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2033 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2034 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2038 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
2039 ixgbe_clean_rx_irq(adapter, adapter->rx_ring, &work_done, budget);
2044 /* If budget not fully consumed, exit the polling mode */
2045 if (work_done < budget) {
2046 netif_rx_complete(adapter->netdev, napi);
2047 if (adapter->rx_eitr < IXGBE_MIN_ITR_USECS)
2048 ixgbe_set_itr(adapter);
2049 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2050 ixgbe_irq_enable(adapter);
2057 * ixgbe_tx_timeout - Respond to a Tx Hang
2058 * @netdev: network interface device structure
2060 static void ixgbe_tx_timeout(struct net_device *netdev)
2062 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2064 /* Do the reset outside of interrupt context */
2065 schedule_work(&adapter->reset_task);
2068 static void ixgbe_reset_task(struct work_struct *work)
2070 struct ixgbe_adapter *adapter;
2071 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2073 adapter->tx_timeout_count++;
2075 ixgbe_reinit_locked(adapter);
2078 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
2081 int err, vector_threshold;
2083 /* We'll want at least 3 (vector_threshold):
2086 * 3) Other (Link Status Change, etc.)
2087 * 4) TCP Timer (optional)
2089 vector_threshold = MIN_MSIX_COUNT;
2091 /* The more we get, the more we will assign to Tx/Rx Cleanup
2092 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2093 * Right now, we simply care about how many we'll get; we'll
2094 * set them up later while requesting irq's.
2096 while (vectors >= vector_threshold) {
2097 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2099 if (!err) /* Success in acquiring all requested vectors. */
2102 vectors = 0; /* Nasty failure, quit now */
2103 else /* err == number of vectors we should try again with */
2107 if (vectors < vector_threshold) {
2108 /* Can't allocate enough MSI-X interrupts? Oh well.
2109 * This just means we'll go with either a single MSI
2110 * vector or fall back to legacy interrupts.
2112 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2113 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2114 kfree(adapter->msix_entries);
2115 adapter->msix_entries = NULL;
2116 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2117 adapter->num_tx_queues = 1;
2118 adapter->num_rx_queues = 1;
2120 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2121 adapter->num_msix_vectors = vectors;
2125 static void __devinit ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2128 int feature_mask = 0, rss_i, rss_m;
2130 /* Number of supported queues */
2131 switch (adapter->hw.mac.type) {
2132 case ixgbe_mac_82598EB:
2133 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2135 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2137 switch (adapter->flags & feature_mask) {
2138 case (IXGBE_FLAG_RSS_ENABLED):
2141 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2156 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2157 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2165 adapter->num_rx_queues = nrq;
2166 adapter->num_tx_queues = ntq;
2170 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2171 * @adapter: board private structure to initialize
2173 * Once we know the feature-set enabled for the device, we'll cache
2174 * the register offset the descriptor ring is assigned to.
2176 static void __devinit ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2178 /* TODO: Remove all uses of the indices in the cases where multiple
2179 * features are OR'd together, if the feature set makes sense.
2181 int feature_mask = 0, rss_i;
2182 int i, txr_idx, rxr_idx;
2184 /* Number of supported queues */
2185 switch (adapter->hw.mac.type) {
2186 case ixgbe_mac_82598EB:
2187 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2190 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2191 switch (adapter->flags & feature_mask) {
2192 case (IXGBE_FLAG_RSS_ENABLED):
2193 for (i = 0; i < adapter->num_rx_queues; i++)
2194 adapter->rx_ring[i].reg_idx = i;
2195 for (i = 0; i < adapter->num_tx_queues; i++)
2196 adapter->tx_ring[i].reg_idx = i;
2209 * ixgbe_alloc_queues - Allocate memory for all rings
2210 * @adapter: board private structure to initialize
2212 * We allocate one ring per queue at run-time since we don't know the
2213 * number of queues at compile-time. The polling_netdev array is
2214 * intended for Multiqueue, but should work fine with a single queue.
2216 static int __devinit ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
2220 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
2221 sizeof(struct ixgbe_ring), GFP_KERNEL);
2222 if (!adapter->tx_ring)
2223 goto err_tx_ring_allocation;
2225 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
2226 sizeof(struct ixgbe_ring), GFP_KERNEL);
2227 if (!adapter->rx_ring)
2228 goto err_rx_ring_allocation;
2230 for (i = 0; i < adapter->num_tx_queues; i++) {
2231 adapter->tx_ring[i].count = IXGBE_DEFAULT_TXD;
2232 adapter->tx_ring[i].queue_index = i;
2234 for (i = 0; i < adapter->num_rx_queues; i++) {
2235 adapter->rx_ring[i].count = IXGBE_DEFAULT_RXD;
2236 adapter->rx_ring[i].queue_index = i;
2239 ixgbe_cache_ring_register(adapter);
2243 err_rx_ring_allocation:
2244 kfree(adapter->tx_ring);
2245 err_tx_ring_allocation:
2250 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2251 * @adapter: board private structure to initialize
2253 * Attempt to configure the interrupts using the best available
2254 * capabilities of the hardware and the kernel.
2256 static int __devinit ixgbe_set_interrupt_capability(struct ixgbe_adapter
2260 int vector, v_budget;
2263 * It's easy to be greedy for MSI-X vectors, but it really
2264 * doesn't do us much good if we have a lot more vectors
2265 * than CPU's. So let's be conservative and only ask for
2266 * (roughly) twice the number of vectors as there are CPU's.
2268 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2269 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2272 * At the same time, hardware can only support a maximum of
2273 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2274 * we can easily reach upwards of 64 Rx descriptor queues and
2275 * 32 Tx queues. Thus, we cap it off in those rare cases where
2276 * the cpu count also exceeds our vector limit.
2278 v_budget = min(v_budget, MAX_MSIX_COUNT);
2280 /* A failure in MSI-X entry allocation isn't fatal, but it does
2281 * mean we disable MSI-X capabilities of the adapter. */
2282 adapter->msix_entries = kcalloc(v_budget,
2283 sizeof(struct msix_entry), GFP_KERNEL);
2284 if (!adapter->msix_entries) {
2285 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2286 ixgbe_set_num_queues(adapter);
2287 kfree(adapter->tx_ring);
2288 kfree(adapter->rx_ring);
2289 err = ixgbe_alloc_queues(adapter);
2291 DPRINTK(PROBE, ERR, "Unable to allocate memory "
2299 for (vector = 0; vector < v_budget; vector++)
2300 adapter->msix_entries[vector].entry = vector;
2302 ixgbe_acquire_msix_vectors(adapter, v_budget);
2304 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2308 err = pci_enable_msi(adapter->pdev);
2310 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2312 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
2313 "falling back to legacy. Error: %d\n", err);
2319 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2320 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2321 adapter->netdev->egress_subqueue_count = adapter->num_tx_queues;
2327 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
2329 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2330 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2331 pci_disable_msix(adapter->pdev);
2332 kfree(adapter->msix_entries);
2333 adapter->msix_entries = NULL;
2334 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2335 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2336 pci_disable_msi(adapter->pdev);
2342 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2343 * @adapter: board private structure to initialize
2345 * We determine which interrupt scheme to use based on...
2346 * - Kernel support (MSI, MSI-X)
2347 * - which can be user-defined (via MODULE_PARAM)
2348 * - Hardware queue count (num_*_queues)
2349 * - defined by miscellaneous hardware support/features (RSS, etc.)
2351 static int __devinit ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
2355 /* Number of supported queues */
2356 ixgbe_set_num_queues(adapter);
2358 err = ixgbe_alloc_queues(adapter);
2360 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2361 goto err_alloc_queues;
2364 err = ixgbe_set_interrupt_capability(adapter);
2366 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2367 goto err_set_interrupt;
2370 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
2371 "Tx Queue count = %u\n",
2372 (adapter->num_rx_queues > 1) ? "Enabled" :
2373 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2375 set_bit(__IXGBE_DOWN, &adapter->state);
2380 kfree(adapter->tx_ring);
2381 kfree(adapter->rx_ring);
2387 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2388 * @adapter: board private structure to initialize
2390 * ixgbe_sw_init initializes the Adapter private data structure.
2391 * Fields are initialized based on PCI device information and
2392 * OS network device settings (MTU size).
2394 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2396 struct ixgbe_hw *hw = &adapter->hw;
2397 struct pci_dev *pdev = adapter->pdev;
2400 /* Set capability flags */
2401 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2402 adapter->ring_feature[RING_F_RSS].indices = rss;
2403 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
2405 /* Enable Dynamic interrupt throttling by default */
2406 adapter->rx_eitr = 1;
2407 adapter->tx_eitr = 1;
2409 /* default flow control settings */
2410 hw->fc.original_type = ixgbe_fc_full;
2411 hw->fc.type = ixgbe_fc_full;
2413 /* select 10G link by default */
2414 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2415 if (hw->mac.ops.reset(hw)) {
2416 dev_err(&pdev->dev, "HW Init failed\n");
2419 if (hw->mac.ops.setup_link_speed(hw, IXGBE_LINK_SPEED_10GB_FULL, true,
2421 dev_err(&pdev->dev, "Link Speed setup failed\n");
2425 /* initialize eeprom parameters */
2426 if (ixgbe_init_eeprom(hw)) {
2427 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2431 /* enable rx csum by default */
2432 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2434 set_bit(__IXGBE_DOWN, &adapter->state);
2440 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2441 * @adapter: board private structure
2442 * @txdr: tx descriptor ring (for a specific queue) to setup
2444 * Return 0 on success, negative on failure
2446 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
2447 struct ixgbe_ring *txdr)
2449 struct pci_dev *pdev = adapter->pdev;
2452 size = sizeof(struct ixgbe_tx_buffer) * txdr->count;
2453 txdr->tx_buffer_info = vmalloc(size);
2454 if (!txdr->tx_buffer_info) {
2456 "Unable to allocate memory for the transmit descriptor ring\n");
2459 memset(txdr->tx_buffer_info, 0, size);
2461 /* round up to nearest 4K */
2462 txdr->size = txdr->count * sizeof(union ixgbe_adv_tx_desc);
2463 txdr->size = ALIGN(txdr->size, 4096);
2465 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
2467 vfree(txdr->tx_buffer_info);
2469 "Memory allocation failed for the tx desc ring\n");
2473 txdr->next_to_use = 0;
2474 txdr->next_to_clean = 0;
2475 txdr->work_limit = txdr->count;
2481 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2482 * @adapter: board private structure
2483 * @rxdr: rx descriptor ring (for a specific queue) to setup
2485 * Returns 0 on success, negative on failure
2487 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
2488 struct ixgbe_ring *rxdr)
2490 struct pci_dev *pdev = adapter->pdev;
2493 size = sizeof(struct ixgbe_rx_buffer) * rxdr->count;
2494 rxdr->rx_buffer_info = vmalloc(size);
2495 if (!rxdr->rx_buffer_info) {
2497 "vmalloc allocation failed for the rx desc ring\n");
2500 memset(rxdr->rx_buffer_info, 0, size);
2502 /* Round up to nearest 4K */
2503 rxdr->size = rxdr->count * sizeof(union ixgbe_adv_rx_desc);
2504 rxdr->size = ALIGN(rxdr->size, 4096);
2506 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
2510 "Memory allocation failed for the rx desc ring\n");
2511 vfree(rxdr->rx_buffer_info);
2515 rxdr->next_to_clean = 0;
2516 rxdr->next_to_use = 0;
2522 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2523 * @adapter: board private structure
2524 * @tx_ring: Tx descriptor ring for a specific queue
2526 * Free all transmit software resources
2528 static void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2529 struct ixgbe_ring *tx_ring)
2531 struct pci_dev *pdev = adapter->pdev;
2533 ixgbe_clean_tx_ring(adapter, tx_ring);
2535 vfree(tx_ring->tx_buffer_info);
2536 tx_ring->tx_buffer_info = NULL;
2538 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2540 tx_ring->desc = NULL;
2544 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
2545 * @adapter: board private structure
2547 * Free all transmit software resources
2549 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
2553 for (i = 0; i < adapter->num_tx_queues; i++)
2554 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
2558 * ixgbe_free_rx_resources - Free Rx Resources
2559 * @adapter: board private structure
2560 * @rx_ring: ring to clean the resources from
2562 * Free all receive software resources
2564 static void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
2565 struct ixgbe_ring *rx_ring)
2567 struct pci_dev *pdev = adapter->pdev;
2569 ixgbe_clean_rx_ring(adapter, rx_ring);
2571 vfree(rx_ring->rx_buffer_info);
2572 rx_ring->rx_buffer_info = NULL;
2574 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2576 rx_ring->desc = NULL;
2580 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
2581 * @adapter: board private structure
2583 * Free all receive software resources
2585 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
2589 for (i = 0; i < adapter->num_rx_queues; i++)
2590 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
2594 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2595 * @adapter: board private structure
2597 * If this function returns with an error, then it's possible one or
2598 * more of the rings is populated (while the rest are not). It is the
2599 * callers duty to clean those orphaned rings.
2601 * Return 0 on success, negative on failure
2603 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2607 for (i = 0; i < adapter->num_tx_queues; i++) {
2608 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2611 "Allocation for Tx Queue %u failed\n", i);
2620 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2621 * @adapter: board private structure
2623 * If this function returns with an error, then it's possible one or
2624 * more of the rings is populated (while the rest are not). It is the
2625 * callers duty to clean those orphaned rings.
2627 * Return 0 on success, negative on failure
2630 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2634 for (i = 0; i < adapter->num_rx_queues; i++) {
2635 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2638 "Allocation for Rx Queue %u failed\n", i);
2647 * ixgbe_change_mtu - Change the Maximum Transfer Unit
2648 * @netdev: network interface device structure
2649 * @new_mtu: new value for maximum frame size
2651 * Returns 0 on success, negative on failure
2653 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
2655 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2656 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2658 if ((max_frame < (ETH_ZLEN + ETH_FCS_LEN)) ||
2659 (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
2662 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
2663 netdev->mtu, new_mtu);
2664 /* must set new MTU before calling down or up */
2665 netdev->mtu = new_mtu;
2667 if (netif_running(netdev))
2668 ixgbe_reinit_locked(adapter);
2674 * ixgbe_open - Called when a network interface is made active
2675 * @netdev: network interface device structure
2677 * Returns 0 on success, negative value on failure
2679 * The open entry point is called when a network interface is made
2680 * active by the system (IFF_UP). At this point all resources needed
2681 * for transmit and receive operations are allocated, the interrupt
2682 * handler is registered with the OS, the watchdog timer is started,
2683 * and the stack is notified that the interface is ready.
2685 static int ixgbe_open(struct net_device *netdev)
2687 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2690 /* disallow open during test */
2691 if (test_bit(__IXGBE_TESTING, &adapter->state))
2694 /* allocate transmit descriptors */
2695 err = ixgbe_setup_all_tx_resources(adapter);
2699 /* allocate receive descriptors */
2700 err = ixgbe_setup_all_rx_resources(adapter);
2704 ixgbe_configure(adapter);
2706 err = ixgbe_request_irq(adapter);
2710 err = ixgbe_up_complete(adapter);
2717 ixgbe_release_hw_control(adapter);
2718 ixgbe_free_irq(adapter);
2720 ixgbe_free_all_rx_resources(adapter);
2722 ixgbe_free_all_tx_resources(adapter);
2724 ixgbe_reset(adapter);
2730 * ixgbe_close - Disables a network interface
2731 * @netdev: network interface device structure
2733 * Returns 0, this is not allowed to fail
2735 * The close entry point is called when an interface is de-activated
2736 * by the OS. The hardware is still under the drivers control, but
2737 * needs to be disabled. A global MAC reset is issued to stop the
2738 * hardware, and all transmit and receive resources are freed.
2740 static int ixgbe_close(struct net_device *netdev)
2742 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2744 ixgbe_down(adapter);
2745 ixgbe_free_irq(adapter);
2747 ixgbe_free_all_tx_resources(adapter);
2748 ixgbe_free_all_rx_resources(adapter);
2750 ixgbe_release_hw_control(adapter);
2756 * ixgbe_update_stats - Update the board statistics counters.
2757 * @adapter: board private structure
2759 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
2761 struct ixgbe_hw *hw = &adapter->hw;
2763 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
2765 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
2766 for (i = 0; i < 8; i++) {
2767 /* for packet buffers not used, the register should read 0 */
2768 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
2770 adapter->stats.mpc[i] += mpc;
2771 total_mpc += adapter->stats.mpc[i];
2772 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2774 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
2775 /* work around hardware counting issue */
2776 adapter->stats.gprc -= missed_rx;
2778 /* 82598 hardware only has a 32 bit counter in the high register */
2779 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2780 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2781 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2782 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2783 adapter->stats.bprc += bprc;
2784 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2785 adapter->stats.mprc -= bprc;
2786 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2787 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2788 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2789 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2790 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2791 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2792 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2793 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2794 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2795 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
2796 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2797 adapter->stats.lxontxc += lxon;
2798 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2799 adapter->stats.lxofftxc += lxoff;
2800 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2801 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
2802 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2804 * 82598 errata - tx of flow control packets is included in tx counters
2806 xon_off_tot = lxon + lxoff;
2807 adapter->stats.gptc -= xon_off_tot;
2808 adapter->stats.mptc -= xon_off_tot;
2809 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
2810 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2811 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2812 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2813 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2814 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2815 adapter->stats.ptc64 -= xon_off_tot;
2816 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2817 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2818 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2819 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2820 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2821 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2823 /* Fill out the OS statistics structure */
2824 adapter->net_stats.multicast = adapter->stats.mprc;
2827 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
2828 adapter->stats.rlec;
2829 adapter->net_stats.rx_dropped = 0;
2830 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2831 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2832 adapter->net_stats.rx_missed_errors = total_mpc;
2836 * ixgbe_watchdog - Timer Call-back
2837 * @data: pointer to adapter cast into an unsigned long
2839 static void ixgbe_watchdog(unsigned long data)
2841 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2842 struct net_device *netdev = adapter->netdev;
2845 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2849 adapter->hw.mac.ops.check_link(&adapter->hw, &(link_speed), &link_up);
2852 if (!netif_carrier_ok(netdev)) {
2853 u32 frctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2854 u32 rmcs = IXGBE_READ_REG(&adapter->hw, IXGBE_RMCS);
2855 #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
2856 #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
2857 DPRINTK(LINK, INFO, "NIC Link is Up %s, "
2858 "Flow Control: %s\n",
2859 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
2861 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
2862 "1 Gbps" : "unknown speed")),
2863 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
2865 (FLOW_TX ? "TX" : "None"))));
2867 netif_carrier_on(netdev);
2868 netif_wake_queue(netdev);
2869 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2870 for (i = 0; i < adapter->num_tx_queues; i++)
2871 netif_wake_subqueue(netdev, i);
2874 /* Force detection of hung controller */
2875 adapter->detect_tx_hung = true;
2878 if (netif_carrier_ok(netdev)) {
2879 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2880 netif_carrier_off(netdev);
2881 netif_stop_queue(netdev);
2885 ixgbe_update_stats(adapter);
2887 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2888 /* Cause software interrupt to ensure rx rings are cleaned */
2889 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2891 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
2892 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, eics);
2894 /* for legacy and MSI interrupts don't set any bits that
2895 * are enabled for EIAM, because this operation would
2896 * set *both* EIMS and EICS for any bit in EIAM */
2897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
2898 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
2900 /* Reset the timer */
2901 mod_timer(&adapter->watchdog_timer,
2902 round_jiffies(jiffies + 2 * HZ));
2906 static int ixgbe_tso(struct ixgbe_adapter *adapter,
2907 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
2908 u32 tx_flags, u8 *hdr_len)
2910 struct ixgbe_adv_tx_context_desc *context_desc;
2913 struct ixgbe_tx_buffer *tx_buffer_info;
2914 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2915 u32 mss_l4len_idx = 0, l4len;
2917 if (skb_is_gso(skb)) {
2918 if (skb_header_cloned(skb)) {
2919 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2923 l4len = tcp_hdrlen(skb);
2926 if (skb->protocol == htons(ETH_P_IP)) {
2927 struct iphdr *iph = ip_hdr(skb);
2930 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2934 adapter->hw_tso_ctxt++;
2935 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
2936 ipv6_hdr(skb)->payload_len = 0;
2937 tcp_hdr(skb)->check =
2938 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2939 &ipv6_hdr(skb)->daddr,
2941 adapter->hw_tso6_ctxt++;
2944 i = tx_ring->next_to_use;
2946 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2947 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
2949 /* VLAN MACLEN IPLEN */
2950 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
2952 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
2953 vlan_macip_lens |= ((skb_network_offset(skb)) <<
2954 IXGBE_ADVTXD_MACLEN_SHIFT);
2955 *hdr_len += skb_network_offset(skb);
2957 (skb_transport_header(skb) - skb_network_header(skb));
2959 (skb_transport_header(skb) - skb_network_header(skb));
2960 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
2961 context_desc->seqnum_seed = 0;
2963 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2964 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
2965 IXGBE_ADVTXD_DTYP_CTXT);
2967 if (skb->protocol == htons(ETH_P_IP))
2968 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2969 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2970 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
2974 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
2975 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
2976 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2978 tx_buffer_info->time_stamp = jiffies;
2979 tx_buffer_info->next_to_watch = i;
2982 if (i == tx_ring->count)
2984 tx_ring->next_to_use = i;
2991 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
2992 struct ixgbe_ring *tx_ring,
2993 struct sk_buff *skb, u32 tx_flags)
2995 struct ixgbe_adv_tx_context_desc *context_desc;
2997 struct ixgbe_tx_buffer *tx_buffer_info;
2998 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3000 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3001 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3002 i = tx_ring->next_to_use;
3003 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3004 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3006 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3008 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3009 vlan_macip_lens |= (skb_network_offset(skb) <<
3010 IXGBE_ADVTXD_MACLEN_SHIFT);
3011 if (skb->ip_summed == CHECKSUM_PARTIAL)
3012 vlan_macip_lens |= (skb_transport_header(skb) -
3013 skb_network_header(skb));
3015 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3016 context_desc->seqnum_seed = 0;
3018 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
3019 IXGBE_ADVTXD_DTYP_CTXT);
3021 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3022 switch (skb->protocol) {
3023 case __constant_htons(ETH_P_IP):
3024 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3025 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3027 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3030 case __constant_htons(ETH_P_IPV6):
3031 /* XXX what about other V6 headers?? */
3032 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3034 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3038 if (unlikely(net_ratelimit())) {
3039 DPRINTK(PROBE, WARNING,
3040 "partial checksum but proto=%x!\n",
3047 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3048 context_desc->mss_l4len_idx = 0;
3050 tx_buffer_info->time_stamp = jiffies;
3051 tx_buffer_info->next_to_watch = i;
3052 adapter->hw_csum_tx_good++;
3054 if (i == tx_ring->count)
3056 tx_ring->next_to_use = i;
3063 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
3064 struct ixgbe_ring *tx_ring,
3065 struct sk_buff *skb, unsigned int first)
3067 struct ixgbe_tx_buffer *tx_buffer_info;
3068 unsigned int len = skb->len;
3069 unsigned int offset = 0, size, count = 0, i;
3070 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3073 len -= skb->data_len;
3075 i = tx_ring->next_to_use;
3078 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3079 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3081 tx_buffer_info->length = size;
3082 tx_buffer_info->dma = pci_map_single(adapter->pdev,
3084 size, PCI_DMA_TODEVICE);
3085 tx_buffer_info->time_stamp = jiffies;
3086 tx_buffer_info->next_to_watch = i;
3092 if (i == tx_ring->count)
3096 for (f = 0; f < nr_frags; f++) {
3097 struct skb_frag_struct *frag;
3099 frag = &skb_shinfo(skb)->frags[f];
3101 offset = frag->page_offset;
3104 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3105 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3107 tx_buffer_info->length = size;
3108 tx_buffer_info->dma = pci_map_page(adapter->pdev,
3111 size, PCI_DMA_TODEVICE);
3112 tx_buffer_info->time_stamp = jiffies;
3113 tx_buffer_info->next_to_watch = i;
3119 if (i == tx_ring->count)
3124 i = tx_ring->count - 1;
3127 tx_ring->tx_buffer_info[i].skb = skb;
3128 tx_ring->tx_buffer_info[first].next_to_watch = i;
3133 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
3134 struct ixgbe_ring *tx_ring,
3135 int tx_flags, int count, u32 paylen, u8 hdr_len)
3137 union ixgbe_adv_tx_desc *tx_desc = NULL;
3138 struct ixgbe_tx_buffer *tx_buffer_info;
3139 u32 olinfo_status = 0, cmd_type_len = 0;
3141 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3143 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3145 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3147 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3148 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3150 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3151 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3153 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3154 IXGBE_ADVTXD_POPTS_SHIFT;
3156 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3157 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
3158 IXGBE_ADVTXD_POPTS_SHIFT;
3160 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3161 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3162 IXGBE_ADVTXD_POPTS_SHIFT;
3164 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3166 i = tx_ring->next_to_use;
3168 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3169 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3170 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3171 tx_desc->read.cmd_type_len =
3172 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3173 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3176 if (i == tx_ring->count)
3180 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3183 * Force memory writes to complete before letting h/w
3184 * know there are new descriptors to fetch. (Only
3185 * applicable for weak-ordered memory model archs,
3190 tx_ring->next_to_use = i;
3191 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3194 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
3195 struct ixgbe_ring *tx_ring, int size)
3197 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3199 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3200 netif_stop_subqueue(netdev, tx_ring->queue_index);
3202 netif_stop_queue(netdev);
3204 /* Herbert's original patch had:
3205 * smp_mb__after_netif_stop_queue();
3206 * but since that doesn't exist yet, just open code it. */
3209 /* We need to check again in a case another CPU has just
3210 * made room available. */
3211 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3214 /* A reprieve! - use start_queue because it doesn't call schedule */
3215 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3216 netif_wake_subqueue(netdev, tx_ring->queue_index);
3218 netif_wake_queue(netdev);
3220 ++adapter->restart_queue;
3224 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
3225 struct ixgbe_ring *tx_ring, int size)
3227 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3229 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3233 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3235 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3236 struct ixgbe_ring *tx_ring;
3237 unsigned int len = skb->len;
3239 unsigned int tx_flags = 0;
3242 unsigned int mss = 0;
3245 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3246 len -= skb->data_len;
3247 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3248 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
3250 tx_ring = &adapter->tx_ring[r_idx];
3253 if (skb->len <= 0) {
3255 return NETDEV_TX_OK;
3257 mss = skb_shinfo(skb)->gso_size;
3261 else if (skb->ip_summed == CHECKSUM_PARTIAL)
3264 count += TXD_USE_COUNT(len);
3265 for (f = 0; f < nr_frags; f++)
3266 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3268 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
3270 return NETDEV_TX_BUSY;
3272 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3273 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3274 tx_flags |= (vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT);
3277 if (skb->protocol == htons(ETH_P_IP))
3278 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3279 first = tx_ring->next_to_use;
3280 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3282 dev_kfree_skb_any(skb);
3283 return NETDEV_TX_OK;
3287 tx_flags |= IXGBE_TX_FLAGS_TSO;
3288 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
3289 (skb->ip_summed == CHECKSUM_PARTIAL))
3290 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3292 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
3293 ixgbe_tx_map(adapter, tx_ring, skb, first),
3296 netdev->trans_start = jiffies;
3298 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
3300 return NETDEV_TX_OK;
3304 * ixgbe_get_stats - Get System Network Statistics
3305 * @netdev: network interface device structure
3307 * Returns the address of the device statistics structure.
3308 * The statistics are actually updated from the timer callback.
3310 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3314 /* only return the current stats */
3315 return &adapter->net_stats;
3319 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3320 * @netdev: network interface device structure
3321 * @p: pointer to an address structure
3323 * Returns 0 on success, negative on failure
3325 static int ixgbe_set_mac(struct net_device *netdev, void *p)
3327 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3328 struct sockaddr *addr = p;
3330 if (!is_valid_ether_addr(addr->sa_data))
3331 return -EADDRNOTAVAIL;
3333 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3334 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3336 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
3341 #ifdef CONFIG_NET_POLL_CONTROLLER
3343 * Polling 'interrupt' - used by things like netconsole to send skbs
3344 * without having to re-enable interrupts. It's not called while
3345 * the interrupt routine is executing.
3347 static void ixgbe_netpoll(struct net_device *netdev)
3349 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3351 disable_irq(adapter->pdev->irq);
3352 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3353 ixgbe_intr(adapter->pdev->irq, netdev);
3354 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3355 enable_irq(adapter->pdev->irq);
3360 * ixgbe_napi_add_all - prep napi structs for use
3361 * @adapter: private struct
3362 * helper function to napi_add each possible q_vector->napi
3364 static void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
3366 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3367 int (*poll)(struct napi_struct *, int);
3369 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3370 poll = &ixgbe_clean_rxonly;
3373 /* only one q_vector for legacy modes */
3377 for (i = 0; i < q_vectors; i++) {
3378 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
3379 netif_napi_add(adapter->netdev, &q_vector->napi,
3385 * ixgbe_probe - Device Initialization Routine
3386 * @pdev: PCI device information struct
3387 * @ent: entry in ixgbe_pci_tbl
3389 * Returns 0 on success, negative on failure
3391 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3392 * The OS initialization, configuring of the adapter private structure,
3393 * and a hardware reset occur.
3395 static int __devinit ixgbe_probe(struct pci_dev *pdev,
3396 const struct pci_device_id *ent)
3398 struct net_device *netdev;
3399 struct ixgbe_adapter *adapter = NULL;
3400 struct ixgbe_hw *hw;
3401 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
3402 unsigned long mmio_start, mmio_len;
3403 static int cards_found;
3404 int i, err, pci_using_dac;
3405 u16 link_status, link_speed, link_width;
3408 err = pci_enable_device(pdev);
3412 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3413 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3416 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3418 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3420 dev_err(&pdev->dev, "No usable DMA "
3421 "configuration, aborting\n");
3428 err = pci_request_regions(pdev, ixgbe_driver_name);
3430 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
3434 pci_set_master(pdev);
3435 pci_save_state(pdev);
3437 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3438 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
3440 netdev = alloc_etherdev(sizeof(struct ixgbe_adapter));
3444 goto err_alloc_etherdev;
3447 SET_NETDEV_DEV(netdev, &pdev->dev);
3449 pci_set_drvdata(pdev, netdev);
3450 adapter = netdev_priv(netdev);
3452 adapter->netdev = netdev;
3453 adapter->pdev = pdev;
3456 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
3458 mmio_start = pci_resource_start(pdev, 0);
3459 mmio_len = pci_resource_len(pdev, 0);
3461 hw->hw_addr = ioremap(mmio_start, mmio_len);
3467 for (i = 1; i <= 5; i++) {
3468 if (pci_resource_len(pdev, i) == 0)
3472 netdev->open = &ixgbe_open;
3473 netdev->stop = &ixgbe_close;
3474 netdev->hard_start_xmit = &ixgbe_xmit_frame;
3475 netdev->get_stats = &ixgbe_get_stats;
3476 netdev->set_multicast_list = &ixgbe_set_multi;
3477 netdev->set_mac_address = &ixgbe_set_mac;
3478 netdev->change_mtu = &ixgbe_change_mtu;
3479 ixgbe_set_ethtool_ops(netdev);
3480 netdev->tx_timeout = &ixgbe_tx_timeout;
3481 netdev->watchdog_timeo = 5 * HZ;
3482 netdev->vlan_rx_register = ixgbe_vlan_rx_register;
3483 netdev->vlan_rx_add_vid = ixgbe_vlan_rx_add_vid;
3484 netdev->vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid;
3485 #ifdef CONFIG_NET_POLL_CONTROLLER
3486 netdev->poll_controller = ixgbe_netpoll;
3488 strcpy(netdev->name, pci_name(pdev));
3490 netdev->mem_start = mmio_start;
3491 netdev->mem_end = mmio_start + mmio_len;
3493 adapter->bd_number = cards_found;
3495 /* PCI config space info */
3496 hw->vendor_id = pdev->vendor;
3497 hw->device_id = pdev->device;
3498 hw->revision_id = pdev->revision;
3499 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3500 hw->subsystem_device_id = pdev->subsystem_device;
3503 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
3504 hw->mac.type = ii->mac;
3506 err = ii->get_invariants(hw);
3510 /* setup the private structure */
3511 err = ixgbe_sw_init(adapter);
3515 netdev->features = NETIF_F_SG |
3517 NETIF_F_HW_VLAN_TX |
3518 NETIF_F_HW_VLAN_RX |
3519 NETIF_F_HW_VLAN_FILTER;
3521 netdev->features |= NETIF_F_TSO;
3523 netdev->features |= NETIF_F_TSO6;
3525 netdev->features |= NETIF_F_HIGHDMA;
3527 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3528 netdev->features |= NETIF_F_MULTI_QUEUE;
3531 /* make sure the EEPROM is good */
3532 if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) {
3533 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
3538 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
3539 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
3541 if (ixgbe_validate_mac_addr(netdev->dev_addr)) {
3546 init_timer(&adapter->watchdog_timer);
3547 adapter->watchdog_timer.function = &ixgbe_watchdog;
3548 adapter->watchdog_timer.data = (unsigned long)adapter;
3550 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
3552 /* initialize default flow control settings */
3553 hw->fc.original_type = ixgbe_fc_full;
3554 hw->fc.type = ixgbe_fc_full;
3555 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3556 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3557 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3559 err = ixgbe_init_interrupt_scheme(adapter);
3563 /* print bus type/speed/width info */
3564 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
3565 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
3566 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
3567 dev_info(&pdev->dev, "(PCI Express:%s:%s) "
3568 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3569 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
3570 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
3572 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
3573 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
3574 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
3575 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
3577 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
3578 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
3579 ixgbe_read_part_num(hw, &part_num);
3580 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3581 hw->mac.type, hw->phy.type,
3582 (part_num >> 8), (part_num & 0xff));
3584 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
3585 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
3586 "this card is not sufficient for optimal "
3588 dev_warn(&pdev->dev, "For optimal performance a x8 "
3589 "PCI-Express slot is required.\n");
3592 /* reset the hardware with the new settings */
3595 netif_carrier_off(netdev);
3596 netif_stop_queue(netdev);
3597 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3598 for (i = 0; i < adapter->num_tx_queues; i++)
3599 netif_stop_subqueue(netdev, i);
3602 ixgbe_napi_add_all(adapter);
3604 strcpy(netdev->name, "eth%d");
3605 err = register_netdev(netdev);
3610 if (dca_add_requester(&pdev->dev) == 0) {
3611 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
3612 /* always use CB2 mode, difference is masked
3613 * in the CB driver */
3614 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
3615 ixgbe_setup_dca(adapter);
3619 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
3624 ixgbe_release_hw_control(adapter);
3627 ixgbe_reset_interrupt_capability(adapter);
3629 iounmap(hw->hw_addr);
3631 free_netdev(netdev);
3633 pci_release_regions(pdev);
3636 pci_disable_device(pdev);
3641 * ixgbe_remove - Device Removal Routine
3642 * @pdev: PCI device information struct
3644 * ixgbe_remove is called by the PCI subsystem to alert the driver
3645 * that it should release a PCI device. The could be caused by a
3646 * Hot-Plug event, or because the driver is going to be removed from
3649 static void __devexit ixgbe_remove(struct pci_dev *pdev)
3651 struct net_device *netdev = pci_get_drvdata(pdev);
3652 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3654 set_bit(__IXGBE_DOWN, &adapter->state);
3655 del_timer_sync(&adapter->watchdog_timer);
3657 flush_scheduled_work();
3660 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3661 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
3662 dca_remove_requester(&pdev->dev);
3663 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
3667 unregister_netdev(netdev);
3669 ixgbe_reset_interrupt_capability(adapter);
3671 ixgbe_release_hw_control(adapter);
3673 iounmap(adapter->hw.hw_addr);
3674 pci_release_regions(pdev);
3676 DPRINTK(PROBE, INFO, "complete\n");
3677 kfree(adapter->tx_ring);
3678 kfree(adapter->rx_ring);
3680 free_netdev(netdev);
3682 pci_disable_device(pdev);
3686 * ixgbe_io_error_detected - called when PCI error is detected
3687 * @pdev: Pointer to PCI device
3688 * @state: The current pci connection state
3690 * This function is called after a PCI bus error affecting
3691 * this device has been detected.
3693 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
3694 pci_channel_state_t state)
3696 struct net_device *netdev = pci_get_drvdata(pdev);
3697 struct ixgbe_adapter *adapter = netdev->priv;
3699 netif_device_detach(netdev);
3701 if (netif_running(netdev))
3702 ixgbe_down(adapter);
3703 pci_disable_device(pdev);
3705 /* Request a slot slot reset. */
3706 return PCI_ERS_RESULT_NEED_RESET;
3710 * ixgbe_io_slot_reset - called after the pci bus has been reset.
3711 * @pdev: Pointer to PCI device
3713 * Restart the card from scratch, as if from a cold-boot.
3715 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
3717 struct net_device *netdev = pci_get_drvdata(pdev);
3718 struct ixgbe_adapter *adapter = netdev->priv;
3720 if (pci_enable_device(pdev)) {
3722 "Cannot re-enable PCI device after reset.\n");
3723 return PCI_ERS_RESULT_DISCONNECT;
3725 pci_set_master(pdev);
3726 pci_restore_state(pdev);
3728 pci_enable_wake(pdev, PCI_D3hot, 0);
3729 pci_enable_wake(pdev, PCI_D3cold, 0);
3731 ixgbe_reset(adapter);
3733 return PCI_ERS_RESULT_RECOVERED;
3737 * ixgbe_io_resume - called when traffic can start flowing again.
3738 * @pdev: Pointer to PCI device
3740 * This callback is called when the error recovery driver tells us that
3741 * its OK to resume normal operation.
3743 static void ixgbe_io_resume(struct pci_dev *pdev)
3745 struct net_device *netdev = pci_get_drvdata(pdev);
3746 struct ixgbe_adapter *adapter = netdev->priv;
3748 if (netif_running(netdev)) {
3749 if (ixgbe_up(adapter)) {
3750 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
3755 netif_device_attach(netdev);
3759 static struct pci_error_handlers ixgbe_err_handler = {
3760 .error_detected = ixgbe_io_error_detected,
3761 .slot_reset = ixgbe_io_slot_reset,
3762 .resume = ixgbe_io_resume,
3765 static struct pci_driver ixgbe_driver = {
3766 .name = ixgbe_driver_name,
3767 .id_table = ixgbe_pci_tbl,
3768 .probe = ixgbe_probe,
3769 .remove = __devexit_p(ixgbe_remove),
3771 .suspend = ixgbe_suspend,
3772 .resume = ixgbe_resume,
3774 .shutdown = ixgbe_shutdown,
3775 .err_handler = &ixgbe_err_handler
3779 * ixgbe_init_module - Driver Registration Routine
3781 * ixgbe_init_module is the first routine called when the driver is
3782 * loaded. All it does is register with the PCI subsystem.
3784 static int __init ixgbe_init_module(void)
3787 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
3788 ixgbe_driver_string, ixgbe_driver_version);
3790 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
3793 dca_register_notify(&dca_notifier);
3796 ret = pci_register_driver(&ixgbe_driver);
3799 module_init(ixgbe_init_module);
3802 * ixgbe_exit_module - Driver Exit Cleanup Routine
3804 * ixgbe_exit_module is called just before the driver is removed
3807 static void __exit ixgbe_exit_module(void)
3810 dca_unregister_notify(&dca_notifier);
3812 pci_unregister_driver(&ixgbe_driver);
3816 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
3821 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
3822 __ixgbe_notify_dca);
3824 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
3826 #endif /* CONFIG_DCA */
3828 module_exit(ixgbe_exit_module);