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 ixgbe_reset(adapter);
1973 ixgbe_clean_all_tx_rings(adapter);
1974 ixgbe_clean_all_rx_rings(adapter);
1978 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
1980 struct net_device *netdev = pci_get_drvdata(pdev);
1981 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1986 netif_device_detach(netdev);
1988 if (netif_running(netdev)) {
1989 ixgbe_down(adapter);
1990 ixgbe_free_irq(adapter);
1994 retval = pci_save_state(pdev);
1999 pci_enable_wake(pdev, PCI_D3hot, 0);
2000 pci_enable_wake(pdev, PCI_D3cold, 0);
2002 ixgbe_release_hw_control(adapter);
2004 pci_disable_device(pdev);
2006 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2011 static void ixgbe_shutdown(struct pci_dev *pdev)
2013 ixgbe_suspend(pdev, PMSG_SUSPEND);
2017 * ixgbe_poll - NAPI Rx polling callback
2018 * @napi: structure for representing this polling device
2019 * @budget: how many packets driver is allowed to clean
2021 * This function is used for legacy and MSI, NAPI mode
2023 static int ixgbe_poll(struct napi_struct *napi, int budget)
2025 struct ixgbe_q_vector *q_vector = container_of(napi,
2026 struct ixgbe_q_vector, napi);
2027 struct ixgbe_adapter *adapter = q_vector->adapter;
2028 int tx_cleaned = 0, work_done = 0;
2031 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2032 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2033 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2037 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
2038 ixgbe_clean_rx_irq(adapter, adapter->rx_ring, &work_done, budget);
2043 /* If budget not fully consumed, exit the polling mode */
2044 if (work_done < budget) {
2045 netif_rx_complete(adapter->netdev, napi);
2046 if (adapter->rx_eitr < IXGBE_MIN_ITR_USECS)
2047 ixgbe_set_itr(adapter);
2048 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2049 ixgbe_irq_enable(adapter);
2056 * ixgbe_tx_timeout - Respond to a Tx Hang
2057 * @netdev: network interface device structure
2059 static void ixgbe_tx_timeout(struct net_device *netdev)
2061 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2063 /* Do the reset outside of interrupt context */
2064 schedule_work(&adapter->reset_task);
2067 static void ixgbe_reset_task(struct work_struct *work)
2069 struct ixgbe_adapter *adapter;
2070 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2072 adapter->tx_timeout_count++;
2074 ixgbe_reinit_locked(adapter);
2077 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
2080 int err, vector_threshold;
2082 /* We'll want at least 3 (vector_threshold):
2085 * 3) Other (Link Status Change, etc.)
2086 * 4) TCP Timer (optional)
2088 vector_threshold = MIN_MSIX_COUNT;
2090 /* The more we get, the more we will assign to Tx/Rx Cleanup
2091 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2092 * Right now, we simply care about how many we'll get; we'll
2093 * set them up later while requesting irq's.
2095 while (vectors >= vector_threshold) {
2096 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2098 if (!err) /* Success in acquiring all requested vectors. */
2101 vectors = 0; /* Nasty failure, quit now */
2102 else /* err == number of vectors we should try again with */
2106 if (vectors < vector_threshold) {
2107 /* Can't allocate enough MSI-X interrupts? Oh well.
2108 * This just means we'll go with either a single MSI
2109 * vector or fall back to legacy interrupts.
2111 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2112 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2113 kfree(adapter->msix_entries);
2114 adapter->msix_entries = NULL;
2115 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2116 adapter->num_tx_queues = 1;
2117 adapter->num_rx_queues = 1;
2119 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2120 adapter->num_msix_vectors = vectors;
2124 static void __devinit ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2127 int feature_mask = 0, rss_i, rss_m;
2129 /* Number of supported queues */
2130 switch (adapter->hw.mac.type) {
2131 case ixgbe_mac_82598EB:
2132 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2134 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2136 switch (adapter->flags & feature_mask) {
2137 case (IXGBE_FLAG_RSS_ENABLED):
2140 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2155 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2156 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2164 adapter->num_rx_queues = nrq;
2165 adapter->num_tx_queues = ntq;
2169 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2170 * @adapter: board private structure to initialize
2172 * Once we know the feature-set enabled for the device, we'll cache
2173 * the register offset the descriptor ring is assigned to.
2175 static void __devinit ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2177 /* TODO: Remove all uses of the indices in the cases where multiple
2178 * features are OR'd together, if the feature set makes sense.
2180 int feature_mask = 0, rss_i;
2181 int i, txr_idx, rxr_idx;
2183 /* Number of supported queues */
2184 switch (adapter->hw.mac.type) {
2185 case ixgbe_mac_82598EB:
2186 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2189 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2190 switch (adapter->flags & feature_mask) {
2191 case (IXGBE_FLAG_RSS_ENABLED):
2192 for (i = 0; i < adapter->num_rx_queues; i++)
2193 adapter->rx_ring[i].reg_idx = i;
2194 for (i = 0; i < adapter->num_tx_queues; i++)
2195 adapter->tx_ring[i].reg_idx = i;
2208 * ixgbe_alloc_queues - Allocate memory for all rings
2209 * @adapter: board private structure to initialize
2211 * We allocate one ring per queue at run-time since we don't know the
2212 * number of queues at compile-time. The polling_netdev array is
2213 * intended for Multiqueue, but should work fine with a single queue.
2215 static int __devinit ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
2219 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
2220 sizeof(struct ixgbe_ring), GFP_KERNEL);
2221 if (!adapter->tx_ring)
2222 goto err_tx_ring_allocation;
2224 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
2225 sizeof(struct ixgbe_ring), GFP_KERNEL);
2226 if (!adapter->rx_ring)
2227 goto err_rx_ring_allocation;
2229 for (i = 0; i < adapter->num_tx_queues; i++) {
2230 adapter->tx_ring[i].count = IXGBE_DEFAULT_TXD;
2231 adapter->tx_ring[i].queue_index = i;
2233 for (i = 0; i < adapter->num_rx_queues; i++) {
2234 adapter->rx_ring[i].count = IXGBE_DEFAULT_RXD;
2235 adapter->rx_ring[i].queue_index = i;
2238 ixgbe_cache_ring_register(adapter);
2242 err_rx_ring_allocation:
2243 kfree(adapter->tx_ring);
2244 err_tx_ring_allocation:
2249 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2250 * @adapter: board private structure to initialize
2252 * Attempt to configure the interrupts using the best available
2253 * capabilities of the hardware and the kernel.
2255 static int __devinit ixgbe_set_interrupt_capability(struct ixgbe_adapter
2259 int vector, v_budget;
2262 * It's easy to be greedy for MSI-X vectors, but it really
2263 * doesn't do us much good if we have a lot more vectors
2264 * than CPU's. So let's be conservative and only ask for
2265 * (roughly) twice the number of vectors as there are CPU's.
2267 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2268 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2271 * At the same time, hardware can only support a maximum of
2272 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2273 * we can easily reach upwards of 64 Rx descriptor queues and
2274 * 32 Tx queues. Thus, we cap it off in those rare cases where
2275 * the cpu count also exceeds our vector limit.
2277 v_budget = min(v_budget, MAX_MSIX_COUNT);
2279 /* A failure in MSI-X entry allocation isn't fatal, but it does
2280 * mean we disable MSI-X capabilities of the adapter. */
2281 adapter->msix_entries = kcalloc(v_budget,
2282 sizeof(struct msix_entry), GFP_KERNEL);
2283 if (!adapter->msix_entries) {
2284 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2285 ixgbe_set_num_queues(adapter);
2286 kfree(adapter->tx_ring);
2287 kfree(adapter->rx_ring);
2288 err = ixgbe_alloc_queues(adapter);
2290 DPRINTK(PROBE, ERR, "Unable to allocate memory "
2298 for (vector = 0; vector < v_budget; vector++)
2299 adapter->msix_entries[vector].entry = vector;
2301 ixgbe_acquire_msix_vectors(adapter, v_budget);
2303 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2307 err = pci_enable_msi(adapter->pdev);
2309 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2311 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
2312 "falling back to legacy. Error: %d\n", err);
2318 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2319 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2320 adapter->netdev->egress_subqueue_count = adapter->num_tx_queues;
2326 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
2328 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2329 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2330 pci_disable_msix(adapter->pdev);
2331 kfree(adapter->msix_entries);
2332 adapter->msix_entries = NULL;
2333 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2334 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2335 pci_disable_msi(adapter->pdev);
2341 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2342 * @adapter: board private structure to initialize
2344 * We determine which interrupt scheme to use based on...
2345 * - Kernel support (MSI, MSI-X)
2346 * - which can be user-defined (via MODULE_PARAM)
2347 * - Hardware queue count (num_*_queues)
2348 * - defined by miscellaneous hardware support/features (RSS, etc.)
2350 static int __devinit ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
2354 /* Number of supported queues */
2355 ixgbe_set_num_queues(adapter);
2357 err = ixgbe_alloc_queues(adapter);
2359 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2360 goto err_alloc_queues;
2363 err = ixgbe_set_interrupt_capability(adapter);
2365 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2366 goto err_set_interrupt;
2369 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
2370 "Tx Queue count = %u\n",
2371 (adapter->num_rx_queues > 1) ? "Enabled" :
2372 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2374 set_bit(__IXGBE_DOWN, &adapter->state);
2379 kfree(adapter->tx_ring);
2380 kfree(adapter->rx_ring);
2386 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2387 * @adapter: board private structure to initialize
2389 * ixgbe_sw_init initializes the Adapter private data structure.
2390 * Fields are initialized based on PCI device information and
2391 * OS network device settings (MTU size).
2393 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2395 struct ixgbe_hw *hw = &adapter->hw;
2396 struct pci_dev *pdev = adapter->pdev;
2399 /* Set capability flags */
2400 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2401 adapter->ring_feature[RING_F_RSS].indices = rss;
2402 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
2404 /* Enable Dynamic interrupt throttling by default */
2405 adapter->rx_eitr = 1;
2406 adapter->tx_eitr = 1;
2408 /* default flow control settings */
2409 hw->fc.original_type = ixgbe_fc_full;
2410 hw->fc.type = ixgbe_fc_full;
2412 /* select 10G link by default */
2413 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2414 if (hw->mac.ops.reset(hw)) {
2415 dev_err(&pdev->dev, "HW Init failed\n");
2418 if (hw->mac.ops.setup_link_speed(hw, IXGBE_LINK_SPEED_10GB_FULL, true,
2420 dev_err(&pdev->dev, "Link Speed setup failed\n");
2424 /* initialize eeprom parameters */
2425 if (ixgbe_init_eeprom(hw)) {
2426 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2430 /* enable rx csum by default */
2431 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2433 set_bit(__IXGBE_DOWN, &adapter->state);
2439 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2440 * @adapter: board private structure
2441 * @txdr: tx descriptor ring (for a specific queue) to setup
2443 * Return 0 on success, negative on failure
2445 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
2446 struct ixgbe_ring *txdr)
2448 struct pci_dev *pdev = adapter->pdev;
2451 size = sizeof(struct ixgbe_tx_buffer) * txdr->count;
2452 txdr->tx_buffer_info = vmalloc(size);
2453 if (!txdr->tx_buffer_info) {
2455 "Unable to allocate memory for the transmit descriptor ring\n");
2458 memset(txdr->tx_buffer_info, 0, size);
2460 /* round up to nearest 4K */
2461 txdr->size = txdr->count * sizeof(union ixgbe_adv_tx_desc);
2462 txdr->size = ALIGN(txdr->size, 4096);
2464 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
2466 vfree(txdr->tx_buffer_info);
2468 "Memory allocation failed for the tx desc ring\n");
2472 txdr->next_to_use = 0;
2473 txdr->next_to_clean = 0;
2474 txdr->work_limit = txdr->count;
2480 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2481 * @adapter: board private structure
2482 * @rxdr: rx descriptor ring (for a specific queue) to setup
2484 * Returns 0 on success, negative on failure
2486 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
2487 struct ixgbe_ring *rxdr)
2489 struct pci_dev *pdev = adapter->pdev;
2492 size = sizeof(struct ixgbe_rx_buffer) * rxdr->count;
2493 rxdr->rx_buffer_info = vmalloc(size);
2494 if (!rxdr->rx_buffer_info) {
2496 "vmalloc allocation failed for the rx desc ring\n");
2499 memset(rxdr->rx_buffer_info, 0, size);
2501 /* Round up to nearest 4K */
2502 rxdr->size = rxdr->count * sizeof(union ixgbe_adv_rx_desc);
2503 rxdr->size = ALIGN(rxdr->size, 4096);
2505 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
2509 "Memory allocation failed for the rx desc ring\n");
2510 vfree(rxdr->rx_buffer_info);
2514 rxdr->next_to_clean = 0;
2515 rxdr->next_to_use = 0;
2521 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2522 * @adapter: board private structure
2523 * @tx_ring: Tx descriptor ring for a specific queue
2525 * Free all transmit software resources
2527 static void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2528 struct ixgbe_ring *tx_ring)
2530 struct pci_dev *pdev = adapter->pdev;
2532 ixgbe_clean_tx_ring(adapter, tx_ring);
2534 vfree(tx_ring->tx_buffer_info);
2535 tx_ring->tx_buffer_info = NULL;
2537 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2539 tx_ring->desc = NULL;
2543 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
2544 * @adapter: board private structure
2546 * Free all transmit software resources
2548 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
2552 for (i = 0; i < adapter->num_tx_queues; i++)
2553 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
2557 * ixgbe_free_rx_resources - Free Rx Resources
2558 * @adapter: board private structure
2559 * @rx_ring: ring to clean the resources from
2561 * Free all receive software resources
2563 static void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
2564 struct ixgbe_ring *rx_ring)
2566 struct pci_dev *pdev = adapter->pdev;
2568 ixgbe_clean_rx_ring(adapter, rx_ring);
2570 vfree(rx_ring->rx_buffer_info);
2571 rx_ring->rx_buffer_info = NULL;
2573 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2575 rx_ring->desc = NULL;
2579 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
2580 * @adapter: board private structure
2582 * Free all receive software resources
2584 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
2588 for (i = 0; i < adapter->num_rx_queues; i++)
2589 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
2593 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2594 * @adapter: board private structure
2596 * If this function returns with an error, then it's possible one or
2597 * more of the rings is populated (while the rest are not). It is the
2598 * callers duty to clean those orphaned rings.
2600 * Return 0 on success, negative on failure
2602 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2606 for (i = 0; i < adapter->num_tx_queues; i++) {
2607 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2610 "Allocation for Tx Queue %u failed\n", i);
2619 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2620 * @adapter: board private structure
2622 * If this function returns with an error, then it's possible one or
2623 * more of the rings is populated (while the rest are not). It is the
2624 * callers duty to clean those orphaned rings.
2626 * Return 0 on success, negative on failure
2629 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2633 for (i = 0; i < adapter->num_rx_queues; i++) {
2634 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2637 "Allocation for Rx Queue %u failed\n", i);
2646 * ixgbe_change_mtu - Change the Maximum Transfer Unit
2647 * @netdev: network interface device structure
2648 * @new_mtu: new value for maximum frame size
2650 * Returns 0 on success, negative on failure
2652 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
2654 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2655 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2657 if ((max_frame < (ETH_ZLEN + ETH_FCS_LEN)) ||
2658 (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
2661 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
2662 netdev->mtu, new_mtu);
2663 /* must set new MTU before calling down or up */
2664 netdev->mtu = new_mtu;
2666 if (netif_running(netdev))
2667 ixgbe_reinit_locked(adapter);
2673 * ixgbe_open - Called when a network interface is made active
2674 * @netdev: network interface device structure
2676 * Returns 0 on success, negative value on failure
2678 * The open entry point is called when a network interface is made
2679 * active by the system (IFF_UP). At this point all resources needed
2680 * for transmit and receive operations are allocated, the interrupt
2681 * handler is registered with the OS, the watchdog timer is started,
2682 * and the stack is notified that the interface is ready.
2684 static int ixgbe_open(struct net_device *netdev)
2686 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2689 /* disallow open during test */
2690 if (test_bit(__IXGBE_TESTING, &adapter->state))
2693 /* allocate transmit descriptors */
2694 err = ixgbe_setup_all_tx_resources(adapter);
2698 /* allocate receive descriptors */
2699 err = ixgbe_setup_all_rx_resources(adapter);
2703 ixgbe_configure(adapter);
2705 err = ixgbe_request_irq(adapter);
2709 err = ixgbe_up_complete(adapter);
2716 ixgbe_release_hw_control(adapter);
2717 ixgbe_free_irq(adapter);
2719 ixgbe_free_all_rx_resources(adapter);
2721 ixgbe_free_all_tx_resources(adapter);
2723 ixgbe_reset(adapter);
2729 * ixgbe_close - Disables a network interface
2730 * @netdev: network interface device structure
2732 * Returns 0, this is not allowed to fail
2734 * The close entry point is called when an interface is de-activated
2735 * by the OS. The hardware is still under the drivers control, but
2736 * needs to be disabled. A global MAC reset is issued to stop the
2737 * hardware, and all transmit and receive resources are freed.
2739 static int ixgbe_close(struct net_device *netdev)
2741 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2743 ixgbe_down(adapter);
2744 ixgbe_free_irq(adapter);
2746 ixgbe_free_all_tx_resources(adapter);
2747 ixgbe_free_all_rx_resources(adapter);
2749 ixgbe_release_hw_control(adapter);
2755 * ixgbe_update_stats - Update the board statistics counters.
2756 * @adapter: board private structure
2758 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
2760 struct ixgbe_hw *hw = &adapter->hw;
2762 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
2764 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
2765 for (i = 0; i < 8; i++) {
2766 /* for packet buffers not used, the register should read 0 */
2767 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
2769 adapter->stats.mpc[i] += mpc;
2770 total_mpc += adapter->stats.mpc[i];
2771 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2773 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
2774 /* work around hardware counting issue */
2775 adapter->stats.gprc -= missed_rx;
2777 /* 82598 hardware only has a 32 bit counter in the high register */
2778 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2779 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2780 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2781 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2782 adapter->stats.bprc += bprc;
2783 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2784 adapter->stats.mprc -= bprc;
2785 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2786 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2787 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2788 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2789 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2790 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2791 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2792 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2793 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2794 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
2795 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2796 adapter->stats.lxontxc += lxon;
2797 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2798 adapter->stats.lxofftxc += lxoff;
2799 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2800 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
2801 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2803 * 82598 errata - tx of flow control packets is included in tx counters
2805 xon_off_tot = lxon + lxoff;
2806 adapter->stats.gptc -= xon_off_tot;
2807 adapter->stats.mptc -= xon_off_tot;
2808 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
2809 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2810 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2811 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2812 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2813 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2814 adapter->stats.ptc64 -= xon_off_tot;
2815 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2816 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2817 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2818 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2819 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2820 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2822 /* Fill out the OS statistics structure */
2823 adapter->net_stats.multicast = adapter->stats.mprc;
2826 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
2827 adapter->stats.rlec;
2828 adapter->net_stats.rx_dropped = 0;
2829 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2830 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2831 adapter->net_stats.rx_missed_errors = total_mpc;
2835 * ixgbe_watchdog - Timer Call-back
2836 * @data: pointer to adapter cast into an unsigned long
2838 static void ixgbe_watchdog(unsigned long data)
2840 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2841 struct net_device *netdev = adapter->netdev;
2844 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2848 adapter->hw.mac.ops.check_link(&adapter->hw, &(link_speed), &link_up);
2851 if (!netif_carrier_ok(netdev)) {
2852 u32 frctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2853 u32 rmcs = IXGBE_READ_REG(&adapter->hw, IXGBE_RMCS);
2854 #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
2855 #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
2856 DPRINTK(LINK, INFO, "NIC Link is Up %s, "
2857 "Flow Control: %s\n",
2858 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
2860 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
2861 "1 Gbps" : "unknown speed")),
2862 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
2864 (FLOW_TX ? "TX" : "None"))));
2866 netif_carrier_on(netdev);
2867 netif_wake_queue(netdev);
2868 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2869 for (i = 0; i < adapter->num_tx_queues; i++)
2870 netif_wake_subqueue(netdev, i);
2873 /* Force detection of hung controller */
2874 adapter->detect_tx_hung = true;
2877 if (netif_carrier_ok(netdev)) {
2878 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2879 netif_carrier_off(netdev);
2880 netif_stop_queue(netdev);
2884 ixgbe_update_stats(adapter);
2886 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2887 /* Cause software interrupt to ensure rx rings are cleaned */
2888 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2890 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
2891 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, eics);
2893 /* for legacy and MSI interrupts don't set any bits that
2894 * are enabled for EIAM, because this operation would
2895 * set *both* EIMS and EICS for any bit in EIAM */
2896 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
2897 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
2899 /* Reset the timer */
2900 mod_timer(&adapter->watchdog_timer,
2901 round_jiffies(jiffies + 2 * HZ));
2905 static int ixgbe_tso(struct ixgbe_adapter *adapter,
2906 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
2907 u32 tx_flags, u8 *hdr_len)
2909 struct ixgbe_adv_tx_context_desc *context_desc;
2912 struct ixgbe_tx_buffer *tx_buffer_info;
2913 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2914 u32 mss_l4len_idx = 0, l4len;
2916 if (skb_is_gso(skb)) {
2917 if (skb_header_cloned(skb)) {
2918 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2922 l4len = tcp_hdrlen(skb);
2925 if (skb->protocol == htons(ETH_P_IP)) {
2926 struct iphdr *iph = ip_hdr(skb);
2929 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2933 adapter->hw_tso_ctxt++;
2934 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
2935 ipv6_hdr(skb)->payload_len = 0;
2936 tcp_hdr(skb)->check =
2937 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2938 &ipv6_hdr(skb)->daddr,
2940 adapter->hw_tso6_ctxt++;
2943 i = tx_ring->next_to_use;
2945 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2946 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
2948 /* VLAN MACLEN IPLEN */
2949 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
2951 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
2952 vlan_macip_lens |= ((skb_network_offset(skb)) <<
2953 IXGBE_ADVTXD_MACLEN_SHIFT);
2954 *hdr_len += skb_network_offset(skb);
2956 (skb_transport_header(skb) - skb_network_header(skb));
2958 (skb_transport_header(skb) - skb_network_header(skb));
2959 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
2960 context_desc->seqnum_seed = 0;
2962 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2963 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
2964 IXGBE_ADVTXD_DTYP_CTXT);
2966 if (skb->protocol == htons(ETH_P_IP))
2967 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2968 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2969 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
2973 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
2974 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
2975 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2977 tx_buffer_info->time_stamp = jiffies;
2978 tx_buffer_info->next_to_watch = i;
2981 if (i == tx_ring->count)
2983 tx_ring->next_to_use = i;
2990 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
2991 struct ixgbe_ring *tx_ring,
2992 struct sk_buff *skb, u32 tx_flags)
2994 struct ixgbe_adv_tx_context_desc *context_desc;
2996 struct ixgbe_tx_buffer *tx_buffer_info;
2997 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2999 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3000 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3001 i = tx_ring->next_to_use;
3002 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3003 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3005 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3007 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3008 vlan_macip_lens |= (skb_network_offset(skb) <<
3009 IXGBE_ADVTXD_MACLEN_SHIFT);
3010 if (skb->ip_summed == CHECKSUM_PARTIAL)
3011 vlan_macip_lens |= (skb_transport_header(skb) -
3012 skb_network_header(skb));
3014 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3015 context_desc->seqnum_seed = 0;
3017 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
3018 IXGBE_ADVTXD_DTYP_CTXT);
3020 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3021 switch (skb->protocol) {
3022 case __constant_htons(ETH_P_IP):
3023 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3024 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3026 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3029 case __constant_htons(ETH_P_IPV6):
3030 /* XXX what about other V6 headers?? */
3031 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3033 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3037 if (unlikely(net_ratelimit())) {
3038 DPRINTK(PROBE, WARNING,
3039 "partial checksum but proto=%x!\n",
3046 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3047 context_desc->mss_l4len_idx = 0;
3049 tx_buffer_info->time_stamp = jiffies;
3050 tx_buffer_info->next_to_watch = i;
3051 adapter->hw_csum_tx_good++;
3053 if (i == tx_ring->count)
3055 tx_ring->next_to_use = i;
3062 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
3063 struct ixgbe_ring *tx_ring,
3064 struct sk_buff *skb, unsigned int first)
3066 struct ixgbe_tx_buffer *tx_buffer_info;
3067 unsigned int len = skb->len;
3068 unsigned int offset = 0, size, count = 0, i;
3069 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3072 len -= skb->data_len;
3074 i = tx_ring->next_to_use;
3077 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3078 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3080 tx_buffer_info->length = size;
3081 tx_buffer_info->dma = pci_map_single(adapter->pdev,
3083 size, PCI_DMA_TODEVICE);
3084 tx_buffer_info->time_stamp = jiffies;
3085 tx_buffer_info->next_to_watch = i;
3091 if (i == tx_ring->count)
3095 for (f = 0; f < nr_frags; f++) {
3096 struct skb_frag_struct *frag;
3098 frag = &skb_shinfo(skb)->frags[f];
3100 offset = frag->page_offset;
3103 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3104 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3106 tx_buffer_info->length = size;
3107 tx_buffer_info->dma = pci_map_page(adapter->pdev,
3110 size, PCI_DMA_TODEVICE);
3111 tx_buffer_info->time_stamp = jiffies;
3112 tx_buffer_info->next_to_watch = i;
3118 if (i == tx_ring->count)
3123 i = tx_ring->count - 1;
3126 tx_ring->tx_buffer_info[i].skb = skb;
3127 tx_ring->tx_buffer_info[first].next_to_watch = i;
3132 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
3133 struct ixgbe_ring *tx_ring,
3134 int tx_flags, int count, u32 paylen, u8 hdr_len)
3136 union ixgbe_adv_tx_desc *tx_desc = NULL;
3137 struct ixgbe_tx_buffer *tx_buffer_info;
3138 u32 olinfo_status = 0, cmd_type_len = 0;
3140 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3142 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3144 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3146 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3147 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3149 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3150 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3152 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3153 IXGBE_ADVTXD_POPTS_SHIFT;
3155 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3156 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
3157 IXGBE_ADVTXD_POPTS_SHIFT;
3159 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3160 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3161 IXGBE_ADVTXD_POPTS_SHIFT;
3163 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3165 i = tx_ring->next_to_use;
3167 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3168 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3169 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3170 tx_desc->read.cmd_type_len =
3171 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3172 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3175 if (i == tx_ring->count)
3179 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3182 * Force memory writes to complete before letting h/w
3183 * know there are new descriptors to fetch. (Only
3184 * applicable for weak-ordered memory model archs,
3189 tx_ring->next_to_use = i;
3190 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3193 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
3194 struct ixgbe_ring *tx_ring, int size)
3196 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3198 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3199 netif_stop_subqueue(netdev, tx_ring->queue_index);
3201 netif_stop_queue(netdev);
3203 /* Herbert's original patch had:
3204 * smp_mb__after_netif_stop_queue();
3205 * but since that doesn't exist yet, just open code it. */
3208 /* We need to check again in a case another CPU has just
3209 * made room available. */
3210 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3213 /* A reprieve! - use start_queue because it doesn't call schedule */
3214 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3215 netif_wake_subqueue(netdev, tx_ring->queue_index);
3217 netif_wake_queue(netdev);
3219 ++adapter->restart_queue;
3223 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
3224 struct ixgbe_ring *tx_ring, int size)
3226 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3228 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3232 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3235 struct ixgbe_ring *tx_ring;
3236 unsigned int len = skb->len;
3238 unsigned int tx_flags = 0;
3241 unsigned int mss = 0;
3244 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3245 len -= skb->data_len;
3246 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3247 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
3249 tx_ring = &adapter->tx_ring[r_idx];
3252 if (skb->len <= 0) {
3254 return NETDEV_TX_OK;
3256 mss = skb_shinfo(skb)->gso_size;
3260 else if (skb->ip_summed == CHECKSUM_PARTIAL)
3263 count += TXD_USE_COUNT(len);
3264 for (f = 0; f < nr_frags; f++)
3265 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3267 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
3269 return NETDEV_TX_BUSY;
3271 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3272 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3273 tx_flags |= (vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT);
3276 if (skb->protocol == htons(ETH_P_IP))
3277 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3278 first = tx_ring->next_to_use;
3279 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3281 dev_kfree_skb_any(skb);
3282 return NETDEV_TX_OK;
3286 tx_flags |= IXGBE_TX_FLAGS_TSO;
3287 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
3288 (skb->ip_summed == CHECKSUM_PARTIAL))
3289 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3291 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
3292 ixgbe_tx_map(adapter, tx_ring, skb, first),
3295 netdev->trans_start = jiffies;
3297 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
3299 return NETDEV_TX_OK;
3303 * ixgbe_get_stats - Get System Network Statistics
3304 * @netdev: network interface device structure
3306 * Returns the address of the device statistics structure.
3307 * The statistics are actually updated from the timer callback.
3309 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3311 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3313 /* only return the current stats */
3314 return &adapter->net_stats;
3318 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3319 * @netdev: network interface device structure
3320 * @p: pointer to an address structure
3322 * Returns 0 on success, negative on failure
3324 static int ixgbe_set_mac(struct net_device *netdev, void *p)
3326 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3327 struct sockaddr *addr = p;
3329 if (!is_valid_ether_addr(addr->sa_data))
3330 return -EADDRNOTAVAIL;
3332 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3333 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
3335 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
3340 #ifdef CONFIG_NET_POLL_CONTROLLER
3342 * Polling 'interrupt' - used by things like netconsole to send skbs
3343 * without having to re-enable interrupts. It's not called while
3344 * the interrupt routine is executing.
3346 static void ixgbe_netpoll(struct net_device *netdev)
3348 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3350 disable_irq(adapter->pdev->irq);
3351 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3352 ixgbe_intr(adapter->pdev->irq, netdev);
3353 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3354 enable_irq(adapter->pdev->irq);
3359 * ixgbe_napi_add_all - prep napi structs for use
3360 * @adapter: private struct
3361 * helper function to napi_add each possible q_vector->napi
3363 static void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
3365 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3366 int (*poll)(struct napi_struct *, int);
3368 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3369 poll = &ixgbe_clean_rxonly;
3372 /* only one q_vector for legacy modes */
3376 for (i = 0; i < q_vectors; i++) {
3377 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
3378 netif_napi_add(adapter->netdev, &q_vector->napi,
3384 * ixgbe_probe - Device Initialization Routine
3385 * @pdev: PCI device information struct
3386 * @ent: entry in ixgbe_pci_tbl
3388 * Returns 0 on success, negative on failure
3390 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3391 * The OS initialization, configuring of the adapter private structure,
3392 * and a hardware reset occur.
3394 static int __devinit ixgbe_probe(struct pci_dev *pdev,
3395 const struct pci_device_id *ent)
3397 struct net_device *netdev;
3398 struct ixgbe_adapter *adapter = NULL;
3399 struct ixgbe_hw *hw;
3400 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
3401 unsigned long mmio_start, mmio_len;
3402 static int cards_found;
3403 int i, err, pci_using_dac;
3404 u16 link_status, link_speed, link_width;
3407 err = pci_enable_device(pdev);
3411 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3412 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3415 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3417 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3419 dev_err(&pdev->dev, "No usable DMA "
3420 "configuration, aborting\n");
3427 err = pci_request_regions(pdev, ixgbe_driver_name);
3429 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
3433 pci_set_master(pdev);
3434 pci_save_state(pdev);
3436 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3437 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
3439 netdev = alloc_etherdev(sizeof(struct ixgbe_adapter));
3443 goto err_alloc_etherdev;
3446 SET_NETDEV_DEV(netdev, &pdev->dev);
3448 pci_set_drvdata(pdev, netdev);
3449 adapter = netdev_priv(netdev);
3451 adapter->netdev = netdev;
3452 adapter->pdev = pdev;
3455 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
3457 mmio_start = pci_resource_start(pdev, 0);
3458 mmio_len = pci_resource_len(pdev, 0);
3460 hw->hw_addr = ioremap(mmio_start, mmio_len);
3466 for (i = 1; i <= 5; i++) {
3467 if (pci_resource_len(pdev, i) == 0)
3471 netdev->open = &ixgbe_open;
3472 netdev->stop = &ixgbe_close;
3473 netdev->hard_start_xmit = &ixgbe_xmit_frame;
3474 netdev->get_stats = &ixgbe_get_stats;
3475 netdev->set_multicast_list = &ixgbe_set_multi;
3476 netdev->set_mac_address = &ixgbe_set_mac;
3477 netdev->change_mtu = &ixgbe_change_mtu;
3478 ixgbe_set_ethtool_ops(netdev);
3479 netdev->tx_timeout = &ixgbe_tx_timeout;
3480 netdev->watchdog_timeo = 5 * HZ;
3481 netdev->vlan_rx_register = ixgbe_vlan_rx_register;
3482 netdev->vlan_rx_add_vid = ixgbe_vlan_rx_add_vid;
3483 netdev->vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid;
3484 #ifdef CONFIG_NET_POLL_CONTROLLER
3485 netdev->poll_controller = ixgbe_netpoll;
3487 strcpy(netdev->name, pci_name(pdev));
3489 netdev->mem_start = mmio_start;
3490 netdev->mem_end = mmio_start + mmio_len;
3492 adapter->bd_number = cards_found;
3494 /* PCI config space info */
3495 hw->vendor_id = pdev->vendor;
3496 hw->device_id = pdev->device;
3497 hw->revision_id = pdev->revision;
3498 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3499 hw->subsystem_device_id = pdev->subsystem_device;
3502 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
3503 hw->mac.type = ii->mac;
3505 err = ii->get_invariants(hw);
3509 /* setup the private structure */
3510 err = ixgbe_sw_init(adapter);
3514 netdev->features = NETIF_F_SG |
3516 NETIF_F_HW_VLAN_TX |
3517 NETIF_F_HW_VLAN_RX |
3518 NETIF_F_HW_VLAN_FILTER;
3520 netdev->features |= NETIF_F_TSO;
3522 netdev->features |= NETIF_F_TSO6;
3524 netdev->features |= NETIF_F_HIGHDMA;
3526 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3527 netdev->features |= NETIF_F_MULTI_QUEUE;
3530 /* make sure the EEPROM is good */
3531 if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) {
3532 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
3537 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
3538 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
3540 if (ixgbe_validate_mac_addr(netdev->dev_addr)) {
3545 init_timer(&adapter->watchdog_timer);
3546 adapter->watchdog_timer.function = &ixgbe_watchdog;
3547 adapter->watchdog_timer.data = (unsigned long)adapter;
3549 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
3551 /* initialize default flow control settings */
3552 hw->fc.original_type = ixgbe_fc_full;
3553 hw->fc.type = ixgbe_fc_full;
3554 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3555 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3556 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3558 err = ixgbe_init_interrupt_scheme(adapter);
3562 /* print bus type/speed/width info */
3563 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
3564 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
3565 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
3566 dev_info(&pdev->dev, "(PCI Express:%s:%s) "
3567 "%02x:%02x:%02x:%02x:%02x:%02x\n",
3568 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
3569 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
3571 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
3572 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
3573 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
3574 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
3576 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
3577 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
3578 ixgbe_read_part_num(hw, &part_num);
3579 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
3580 hw->mac.type, hw->phy.type,
3581 (part_num >> 8), (part_num & 0xff));
3583 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
3584 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
3585 "this card is not sufficient for optimal "
3587 dev_warn(&pdev->dev, "For optimal performance a x8 "
3588 "PCI-Express slot is required.\n");
3591 /* reset the hardware with the new settings */
3594 netif_carrier_off(netdev);
3595 netif_stop_queue(netdev);
3596 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3597 for (i = 0; i < adapter->num_tx_queues; i++)
3598 netif_stop_subqueue(netdev, i);
3601 ixgbe_napi_add_all(adapter);
3603 strcpy(netdev->name, "eth%d");
3604 err = register_netdev(netdev);
3609 if (dca_add_requester(&pdev->dev) == 0) {
3610 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
3611 /* always use CB2 mode, difference is masked
3612 * in the CB driver */
3613 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
3614 ixgbe_setup_dca(adapter);
3618 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
3623 ixgbe_release_hw_control(adapter);
3626 ixgbe_reset_interrupt_capability(adapter);
3628 iounmap(hw->hw_addr);
3630 free_netdev(netdev);
3632 pci_release_regions(pdev);
3635 pci_disable_device(pdev);
3640 * ixgbe_remove - Device Removal Routine
3641 * @pdev: PCI device information struct
3643 * ixgbe_remove is called by the PCI subsystem to alert the driver
3644 * that it should release a PCI device. The could be caused by a
3645 * Hot-Plug event, or because the driver is going to be removed from
3648 static void __devexit ixgbe_remove(struct pci_dev *pdev)
3650 struct net_device *netdev = pci_get_drvdata(pdev);
3651 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3653 set_bit(__IXGBE_DOWN, &adapter->state);
3654 del_timer_sync(&adapter->watchdog_timer);
3656 flush_scheduled_work();
3659 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3660 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
3661 dca_remove_requester(&pdev->dev);
3662 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
3666 unregister_netdev(netdev);
3668 ixgbe_reset_interrupt_capability(adapter);
3670 ixgbe_release_hw_control(adapter);
3672 iounmap(adapter->hw.hw_addr);
3673 pci_release_regions(pdev);
3675 DPRINTK(PROBE, INFO, "complete\n");
3676 kfree(adapter->tx_ring);
3677 kfree(adapter->rx_ring);
3679 free_netdev(netdev);
3681 pci_disable_device(pdev);
3685 * ixgbe_io_error_detected - called when PCI error is detected
3686 * @pdev: Pointer to PCI device
3687 * @state: The current pci connection state
3689 * This function is called after a PCI bus error affecting
3690 * this device has been detected.
3692 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
3693 pci_channel_state_t state)
3695 struct net_device *netdev = pci_get_drvdata(pdev);
3696 struct ixgbe_adapter *adapter = netdev->priv;
3698 netif_device_detach(netdev);
3700 if (netif_running(netdev))
3701 ixgbe_down(adapter);
3702 pci_disable_device(pdev);
3704 /* Request a slot slot reset. */
3705 return PCI_ERS_RESULT_NEED_RESET;
3709 * ixgbe_io_slot_reset - called after the pci bus has been reset.
3710 * @pdev: Pointer to PCI device
3712 * Restart the card from scratch, as if from a cold-boot.
3714 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
3716 struct net_device *netdev = pci_get_drvdata(pdev);
3717 struct ixgbe_adapter *adapter = netdev->priv;
3719 if (pci_enable_device(pdev)) {
3721 "Cannot re-enable PCI device after reset.\n");
3722 return PCI_ERS_RESULT_DISCONNECT;
3724 pci_set_master(pdev);
3725 pci_restore_state(pdev);
3727 pci_enable_wake(pdev, PCI_D3hot, 0);
3728 pci_enable_wake(pdev, PCI_D3cold, 0);
3730 ixgbe_reset(adapter);
3732 return PCI_ERS_RESULT_RECOVERED;
3736 * ixgbe_io_resume - called when traffic can start flowing again.
3737 * @pdev: Pointer to PCI device
3739 * This callback is called when the error recovery driver tells us that
3740 * its OK to resume normal operation.
3742 static void ixgbe_io_resume(struct pci_dev *pdev)
3744 struct net_device *netdev = pci_get_drvdata(pdev);
3745 struct ixgbe_adapter *adapter = netdev->priv;
3747 if (netif_running(netdev)) {
3748 if (ixgbe_up(adapter)) {
3749 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
3754 netif_device_attach(netdev);
3758 static struct pci_error_handlers ixgbe_err_handler = {
3759 .error_detected = ixgbe_io_error_detected,
3760 .slot_reset = ixgbe_io_slot_reset,
3761 .resume = ixgbe_io_resume,
3764 static struct pci_driver ixgbe_driver = {
3765 .name = ixgbe_driver_name,
3766 .id_table = ixgbe_pci_tbl,
3767 .probe = ixgbe_probe,
3768 .remove = __devexit_p(ixgbe_remove),
3770 .suspend = ixgbe_suspend,
3771 .resume = ixgbe_resume,
3773 .shutdown = ixgbe_shutdown,
3774 .err_handler = &ixgbe_err_handler
3778 * ixgbe_init_module - Driver Registration Routine
3780 * ixgbe_init_module is the first routine called when the driver is
3781 * loaded. All it does is register with the PCI subsystem.
3783 static int __init ixgbe_init_module(void)
3786 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
3787 ixgbe_driver_string, ixgbe_driver_version);
3789 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
3792 dca_register_notify(&dca_notifier);
3795 ret = pci_register_driver(&ixgbe_driver);
3798 module_init(ixgbe_init_module);
3801 * ixgbe_exit_module - Driver Exit Cleanup Routine
3803 * ixgbe_exit_module is called just before the driver is removed
3806 static void __exit ixgbe_exit_module(void)
3809 dca_unregister_notify(&dca_notifier);
3811 pci_unregister_driver(&ixgbe_driver);
3815 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
3820 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
3821 __ixgbe_notify_dca);
3823 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
3825 #endif /* CONFIG_DCA */
3827 module_exit(ixgbe_exit_module);