1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
32 #include <linux/vmalloc.h>
33 #include <linux/string.h>
36 #include <linux/tcp.h>
37 #include <linux/ipv6.h>
38 #include <net/checksum.h>
39 #include <net/ip6_checksum.h>
40 #include <linux/ethtool.h>
41 #include <linux/if_vlan.h>
44 #include "ixgbe_common.h"
46 char ixgbe_driver_name[] = "ixgbe";
47 static const char ixgbe_driver_string[] =
48 "Intel(R) 10 Gigabit PCI Express Network Driver";
50 #define DRV_VERSION "1.3.30-k2"
51 const char ixgbe_driver_version[] = DRV_VERSION;
52 static char ixgbe_copyright[] = "Copyright (c) 1999-2007 Intel Corporation.";
54 static const struct ixgbe_info *ixgbe_info_tbl[] = {
55 [board_82598] = &ixgbe_82598_info,
58 /* ixgbe_pci_tbl - PCI Device ID Table
60 * Wildcard entries (PCI_ANY_ID) should come last
61 * Last entry must be all 0s
63 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
64 * Class, Class Mask, private data (not used) }
66 static struct pci_device_id ixgbe_pci_tbl[] = {
67 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
69 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
71 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
73 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
75 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
77 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
79 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
81 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
83 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
86 /* required last entry */
89 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
91 #ifdef CONFIG_IXGBE_DCA
92 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
94 static struct notifier_block dca_notifier = {
95 .notifier_call = ixgbe_notify_dca,
101 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
102 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
103 MODULE_LICENSE("GPL");
104 MODULE_VERSION(DRV_VERSION);
106 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
108 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
112 /* Let firmware take over control of h/w */
113 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
114 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
115 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
118 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
122 /* Let firmware know the driver has taken over */
123 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
124 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
125 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
128 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, u16 int_alloc_entry,
133 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
134 index = (int_alloc_entry >> 2) & 0x1F;
135 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR(index));
136 ivar &= ~(0xFF << (8 * (int_alloc_entry & 0x3)));
137 ivar |= (msix_vector << (8 * (int_alloc_entry & 0x3)));
138 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
141 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
142 struct ixgbe_tx_buffer
145 if (tx_buffer_info->dma) {
146 pci_unmap_page(adapter->pdev, tx_buffer_info->dma,
147 tx_buffer_info->length, PCI_DMA_TODEVICE);
148 tx_buffer_info->dma = 0;
150 if (tx_buffer_info->skb) {
151 dev_kfree_skb_any(tx_buffer_info->skb);
152 tx_buffer_info->skb = NULL;
154 /* tx_buffer_info must be completely set up in the transmit path */
157 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
158 struct ixgbe_ring *tx_ring,
161 struct ixgbe_hw *hw = &adapter->hw;
164 /* Detect a transmit hang in hardware, this serializes the
165 * check with the clearing of time_stamp and movement of eop */
166 head = IXGBE_READ_REG(hw, tx_ring->head);
167 tail = IXGBE_READ_REG(hw, tx_ring->tail);
168 adapter->detect_tx_hung = false;
169 if ((head != tail) &&
170 tx_ring->tx_buffer_info[eop].time_stamp &&
171 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
172 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
173 /* detected Tx unit hang */
174 union ixgbe_adv_tx_desc *tx_desc;
175 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
176 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
178 " TDH, TDT <%x>, <%x>\n"
179 " next_to_use <%x>\n"
180 " next_to_clean <%x>\n"
181 "tx_buffer_info[next_to_clean]\n"
182 " time_stamp <%lx>\n"
184 tx_ring->queue_index,
186 tx_ring->next_to_use, eop,
187 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
194 #define IXGBE_MAX_TXD_PWR 14
195 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
197 /* Tx Descriptors needed, worst case */
198 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
199 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
200 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
201 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
203 #define GET_TX_HEAD_FROM_RING(ring) (\
205 ((union ixgbe_adv_tx_desc *)(ring)->desc + (ring)->count))
206 static void ixgbe_tx_timeout(struct net_device *netdev);
209 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
210 * @adapter: board private structure
211 * @tx_ring: tx ring to clean
213 static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
214 struct ixgbe_ring *tx_ring)
216 union ixgbe_adv_tx_desc *tx_desc;
217 struct ixgbe_tx_buffer *tx_buffer_info;
218 struct net_device *netdev = adapter->netdev;
222 unsigned int count = 0;
223 unsigned int total_bytes = 0, total_packets = 0;
226 head = GET_TX_HEAD_FROM_RING(tx_ring);
227 head = le32_to_cpu(head);
228 i = tx_ring->next_to_clean;
231 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
232 tx_buffer_info = &tx_ring->tx_buffer_info[i];
233 skb = tx_buffer_info->skb;
236 unsigned int segs, bytecount;
238 /* gso_segs is currently only valid for tcp */
239 segs = skb_shinfo(skb)->gso_segs ?: 1;
240 /* multiply data chunks by size of headers */
241 bytecount = ((segs - 1) * skb_headlen(skb)) +
243 total_packets += segs;
244 total_bytes += bytecount;
247 ixgbe_unmap_and_free_tx_resource(adapter,
251 if (i == tx_ring->count)
255 if (count == tx_ring->count)
260 head = GET_TX_HEAD_FROM_RING(tx_ring);
261 head = le32_to_cpu(head);
267 tx_ring->next_to_clean = i;
269 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
270 if (unlikely(count && netif_carrier_ok(netdev) &&
271 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
272 /* Make sure that anybody stopping the queue after this
273 * sees the new next_to_clean.
276 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
277 !test_bit(__IXGBE_DOWN, &adapter->state)) {
278 netif_wake_subqueue(netdev, tx_ring->queue_index);
279 ++adapter->restart_queue;
283 if (adapter->detect_tx_hung) {
284 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
285 /* schedule immediate reset if we believe we hung */
287 "tx hang %d detected, resetting adapter\n",
288 adapter->tx_timeout_count + 1);
289 ixgbe_tx_timeout(adapter->netdev);
293 /* re-arm the interrupt */
294 if ((total_packets >= tx_ring->work_limit) ||
295 (count == tx_ring->count))
296 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
298 tx_ring->total_bytes += total_bytes;
299 tx_ring->total_packets += total_packets;
300 tx_ring->stats.bytes += total_bytes;
301 tx_ring->stats.packets += total_packets;
302 adapter->net_stats.tx_bytes += total_bytes;
303 adapter->net_stats.tx_packets += total_packets;
304 return (total_packets ? true : false);
307 #ifdef CONFIG_IXGBE_DCA
308 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
309 struct ixgbe_ring *rx_ring)
313 int q = rx_ring - adapter->rx_ring;
315 if (rx_ring->cpu != cpu) {
316 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
317 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
318 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
319 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
320 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
321 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
327 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
328 struct ixgbe_ring *tx_ring)
332 int q = tx_ring - adapter->tx_ring;
334 if (tx_ring->cpu != cpu) {
335 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
336 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
337 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
338 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
339 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
345 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
349 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
352 for (i = 0; i < adapter->num_tx_queues; i++) {
353 adapter->tx_ring[i].cpu = -1;
354 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
356 for (i = 0; i < adapter->num_rx_queues; i++) {
357 adapter->rx_ring[i].cpu = -1;
358 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
362 static int __ixgbe_notify_dca(struct device *dev, void *data)
364 struct net_device *netdev = dev_get_drvdata(dev);
365 struct ixgbe_adapter *adapter = netdev_priv(netdev);
366 unsigned long event = *(unsigned long *)data;
369 case DCA_PROVIDER_ADD:
370 /* if we're already enabled, don't do it again */
371 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
373 /* Always use CB2 mode, difference is masked
374 * in the CB driver. */
375 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
376 if (dca_add_requester(dev) == 0) {
377 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
378 ixgbe_setup_dca(adapter);
381 /* Fall Through since DCA is disabled. */
382 case DCA_PROVIDER_REMOVE:
383 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
384 dca_remove_requester(dev);
385 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
386 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
394 #endif /* CONFIG_IXGBE_DCA */
396 * ixgbe_receive_skb - Send a completed packet up the stack
397 * @adapter: board private structure
398 * @skb: packet to send up
399 * @status: hardware indication of status of receive
400 * @rx_ring: rx descriptor ring (for a specific queue) to setup
401 * @rx_desc: rx descriptor
403 static void ixgbe_receive_skb(struct ixgbe_adapter *adapter,
404 struct sk_buff *skb, u8 status,
405 struct ixgbe_ring *ring,
406 union ixgbe_adv_rx_desc *rx_desc)
408 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
409 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
411 if (adapter->netdev->features & NETIF_F_LRO &&
412 skb->ip_summed == CHECKSUM_UNNECESSARY) {
413 if (adapter->vlgrp && is_vlan && (tag != 0))
414 lro_vlan_hwaccel_receive_skb(&ring->lro_mgr, skb,
418 lro_receive_skb(&ring->lro_mgr, skb, rx_desc);
419 ring->lro_used = true;
421 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
422 if (adapter->vlgrp && is_vlan && (tag != 0))
423 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
425 netif_receive_skb(skb);
427 if (adapter->vlgrp && is_vlan && (tag != 0))
428 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
436 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
437 * @adapter: address of board private structure
438 * @status_err: hardware indication of status of receive
439 * @skb: skb currently being received and modified
441 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
442 u32 status_err, struct sk_buff *skb)
444 skb->ip_summed = CHECKSUM_NONE;
446 /* Rx csum disabled */
447 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
450 /* if IP and error */
451 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
452 (status_err & IXGBE_RXDADV_ERR_IPE)) {
453 adapter->hw_csum_rx_error++;
457 if (!(status_err & IXGBE_RXD_STAT_L4CS))
460 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
461 adapter->hw_csum_rx_error++;
465 /* It must be a TCP or UDP packet with a valid checksum */
466 skb->ip_summed = CHECKSUM_UNNECESSARY;
467 adapter->hw_csum_rx_good++;
471 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
472 * @adapter: address of board private structure
474 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
475 struct ixgbe_ring *rx_ring,
478 struct pci_dev *pdev = adapter->pdev;
479 union ixgbe_adv_rx_desc *rx_desc;
480 struct ixgbe_rx_buffer *bi;
482 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
484 i = rx_ring->next_to_use;
485 bi = &rx_ring->rx_buffer_info[i];
487 while (cleaned_count--) {
488 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
491 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
493 bi->page = alloc_page(GFP_ATOMIC);
495 adapter->alloc_rx_page_failed++;
500 /* use a half page if we're re-using */
501 bi->page_offset ^= (PAGE_SIZE / 2);
504 bi->page_dma = pci_map_page(pdev, bi->page,
511 struct sk_buff *skb = netdev_alloc_skb(adapter->netdev,
515 adapter->alloc_rx_buff_failed++;
520 * Make buffer alignment 2 beyond a 16 byte boundary
521 * this will result in a 16 byte aligned IP header after
522 * the 14 byte MAC header is removed
524 skb_reserve(skb, NET_IP_ALIGN);
527 bi->dma = pci_map_single(pdev, skb->data, bufsz,
530 /* Refresh the desc even if buffer_addrs didn't change because
531 * each write-back erases this info. */
532 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
533 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
534 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
536 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
540 if (i == rx_ring->count)
542 bi = &rx_ring->rx_buffer_info[i];
546 if (rx_ring->next_to_use != i) {
547 rx_ring->next_to_use = i;
549 i = (rx_ring->count - 1);
552 * Force memory writes to complete before letting h/w
553 * know there are new descriptors to fetch. (Only
554 * applicable for weak-ordered memory model archs,
558 writel(i, adapter->hw.hw_addr + rx_ring->tail);
562 static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
564 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
567 static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
569 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
572 static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
573 struct ixgbe_ring *rx_ring,
574 int *work_done, int work_to_do)
576 struct pci_dev *pdev = adapter->pdev;
577 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
578 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
583 bool cleaned = false;
584 int cleaned_count = 0;
585 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
587 i = rx_ring->next_to_clean;
588 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
589 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
590 rx_buffer_info = &rx_ring->rx_buffer_info[i];
592 while (staterr & IXGBE_RXD_STAT_DD) {
594 if (*work_done >= work_to_do)
598 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
599 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
600 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
601 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
602 if (hdr_info & IXGBE_RXDADV_SPH)
603 adapter->rx_hdr_split++;
604 if (len > IXGBE_RX_HDR_SIZE)
605 len = IXGBE_RX_HDR_SIZE;
606 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
608 len = le16_to_cpu(rx_desc->wb.upper.length);
612 skb = rx_buffer_info->skb;
613 prefetch(skb->data - NET_IP_ALIGN);
614 rx_buffer_info->skb = NULL;
616 if (len && !skb_shinfo(skb)->nr_frags) {
617 pci_unmap_single(pdev, rx_buffer_info->dma,
618 rx_ring->rx_buf_len + NET_IP_ALIGN,
624 pci_unmap_page(pdev, rx_buffer_info->page_dma,
625 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
626 rx_buffer_info->page_dma = 0;
627 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
628 rx_buffer_info->page,
629 rx_buffer_info->page_offset,
632 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
633 (page_count(rx_buffer_info->page) != 1))
634 rx_buffer_info->page = NULL;
636 get_page(rx_buffer_info->page);
638 skb->len += upper_len;
639 skb->data_len += upper_len;
640 skb->truesize += upper_len;
644 if (i == rx_ring->count)
646 next_buffer = &rx_ring->rx_buffer_info[i];
648 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
652 if (staterr & IXGBE_RXD_STAT_EOP) {
653 rx_ring->stats.packets++;
654 rx_ring->stats.bytes += skb->len;
656 rx_buffer_info->skb = next_buffer->skb;
657 rx_buffer_info->dma = next_buffer->dma;
658 next_buffer->skb = skb;
659 next_buffer->dma = 0;
660 adapter->non_eop_descs++;
664 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
665 dev_kfree_skb_irq(skb);
669 ixgbe_rx_checksum(adapter, staterr, skb);
671 /* probably a little skewed due to removing CRC */
672 total_rx_bytes += skb->len;
675 skb->protocol = eth_type_trans(skb, adapter->netdev);
676 ixgbe_receive_skb(adapter, skb, staterr, rx_ring, rx_desc);
679 rx_desc->wb.upper.status_error = 0;
681 /* return some buffers to hardware, one at a time is too slow */
682 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
683 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
687 /* use prefetched values */
689 rx_buffer_info = next_buffer;
691 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
694 if (rx_ring->lro_used) {
695 lro_flush_all(&rx_ring->lro_mgr);
696 rx_ring->lro_used = false;
699 rx_ring->next_to_clean = i;
700 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
703 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
705 rx_ring->total_packets += total_rx_packets;
706 rx_ring->total_bytes += total_rx_bytes;
707 adapter->net_stats.rx_bytes += total_rx_bytes;
708 adapter->net_stats.rx_packets += total_rx_packets;
713 static int ixgbe_clean_rxonly(struct napi_struct *, int);
715 * ixgbe_configure_msix - Configure MSI-X hardware
716 * @adapter: board private structure
718 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
721 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
723 struct ixgbe_q_vector *q_vector;
724 int i, j, q_vectors, v_idx, r_idx;
727 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
729 /* Populate the IVAR table and set the ITR values to the
730 * corresponding register.
732 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
733 q_vector = &adapter->q_vector[v_idx];
734 /* XXX for_each_bit(...) */
735 r_idx = find_first_bit(q_vector->rxr_idx,
736 adapter->num_rx_queues);
738 for (i = 0; i < q_vector->rxr_count; i++) {
739 j = adapter->rx_ring[r_idx].reg_idx;
740 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
741 r_idx = find_next_bit(q_vector->rxr_idx,
742 adapter->num_rx_queues,
745 r_idx = find_first_bit(q_vector->txr_idx,
746 adapter->num_tx_queues);
748 for (i = 0; i < q_vector->txr_count; i++) {
749 j = adapter->tx_ring[r_idx].reg_idx;
750 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
751 r_idx = find_next_bit(q_vector->txr_idx,
752 adapter->num_tx_queues,
756 /* if this is a tx only vector halve the interrupt rate */
757 if (q_vector->txr_count && !q_vector->rxr_count)
758 q_vector->eitr = (adapter->eitr_param >> 1);
761 q_vector->eitr = adapter->eitr_param;
763 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
764 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
767 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
768 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
770 /* set up to autoclear timer, and the vectors */
771 mask = IXGBE_EIMS_ENABLE_MASK;
772 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
780 latency_invalid = 255
784 * ixgbe_update_itr - update the dynamic ITR value based on statistics
785 * @adapter: pointer to adapter
786 * @eitr: eitr setting (ints per sec) to give last timeslice
787 * @itr_setting: current throttle rate in ints/second
788 * @packets: the number of packets during this measurement interval
789 * @bytes: the number of bytes during this measurement interval
791 * Stores a new ITR value based on packets and byte
792 * counts during the last interrupt. The advantage of per interrupt
793 * computation is faster updates and more accurate ITR for the current
794 * traffic pattern. Constants in this function were computed
795 * based on theoretical maximum wire speed and thresholds were set based
796 * on testing data as well as attempting to minimize response time
797 * while increasing bulk throughput.
798 * this functionality is controlled by the InterruptThrottleRate module
799 * parameter (see ixgbe_param.c)
801 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
802 u32 eitr, u8 itr_setting,
803 int packets, int bytes)
805 unsigned int retval = itr_setting;
810 goto update_itr_done;
813 /* simple throttlerate management
814 * 0-20MB/s lowest (100000 ints/s)
815 * 20-100MB/s low (20000 ints/s)
816 * 100-1249MB/s bulk (8000 ints/s)
818 /* what was last interrupt timeslice? */
819 timepassed_us = 1000000/eitr;
820 bytes_perint = bytes / timepassed_us; /* bytes/usec */
822 switch (itr_setting) {
824 if (bytes_perint > adapter->eitr_low)
825 retval = low_latency;
828 if (bytes_perint > adapter->eitr_high)
829 retval = bulk_latency;
830 else if (bytes_perint <= adapter->eitr_low)
831 retval = lowest_latency;
834 if (bytes_perint <= adapter->eitr_high)
835 retval = low_latency;
843 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
845 struct ixgbe_adapter *adapter = q_vector->adapter;
846 struct ixgbe_hw *hw = &adapter->hw;
848 u8 current_itr, ret_itr;
849 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
850 sizeof(struct ixgbe_q_vector);
851 struct ixgbe_ring *rx_ring, *tx_ring;
853 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
854 for (i = 0; i < q_vector->txr_count; i++) {
855 tx_ring = &(adapter->tx_ring[r_idx]);
856 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
858 tx_ring->total_packets,
859 tx_ring->total_bytes);
860 /* if the result for this queue would decrease interrupt
861 * rate for this vector then use that result */
862 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
863 q_vector->tx_itr - 1 : ret_itr);
864 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
868 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
869 for (i = 0; i < q_vector->rxr_count; i++) {
870 rx_ring = &(adapter->rx_ring[r_idx]);
871 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
873 rx_ring->total_packets,
874 rx_ring->total_bytes);
875 /* if the result for this queue would decrease interrupt
876 * rate for this vector then use that result */
877 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
878 q_vector->rx_itr - 1 : ret_itr);
879 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
883 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
885 switch (current_itr) {
886 /* counts and packets in update_itr are dependent on these numbers */
891 new_itr = 20000; /* aka hwitr = ~200 */
899 if (new_itr != q_vector->eitr) {
901 /* do an exponential smoothing */
902 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
903 q_vector->eitr = new_itr;
904 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
905 /* must write high and low 16 bits to reset counter */
906 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
908 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
914 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
916 struct ixgbe_hw *hw = &adapter->hw;
918 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
919 (eicr & IXGBE_EICR_GPI_SDP1)) {
920 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
921 /* write to clear the interrupt */
922 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
926 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
928 struct ixgbe_hw *hw = &adapter->hw;
931 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
932 adapter->link_check_timeout = jiffies;
933 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
934 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
935 schedule_work(&adapter->watchdog_task);
939 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
941 struct net_device *netdev = data;
942 struct ixgbe_adapter *adapter = netdev_priv(netdev);
943 struct ixgbe_hw *hw = &adapter->hw;
944 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
946 if (eicr & IXGBE_EICR_LSC)
947 ixgbe_check_lsc(adapter);
949 ixgbe_check_fan_failure(adapter, eicr);
951 if (!test_bit(__IXGBE_DOWN, &adapter->state))
952 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
957 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
959 struct ixgbe_q_vector *q_vector = data;
960 struct ixgbe_adapter *adapter = q_vector->adapter;
961 struct ixgbe_ring *tx_ring;
964 if (!q_vector->txr_count)
967 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
968 for (i = 0; i < q_vector->txr_count; i++) {
969 tx_ring = &(adapter->tx_ring[r_idx]);
970 #ifdef CONFIG_IXGBE_DCA
971 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
972 ixgbe_update_tx_dca(adapter, tx_ring);
974 tx_ring->total_bytes = 0;
975 tx_ring->total_packets = 0;
976 ixgbe_clean_tx_irq(adapter, tx_ring);
977 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
985 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
987 * @data: pointer to our q_vector struct for this interrupt vector
989 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
991 struct ixgbe_q_vector *q_vector = data;
992 struct ixgbe_adapter *adapter = q_vector->adapter;
993 struct ixgbe_ring *rx_ring;
997 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
998 for (i = 0; i < q_vector->rxr_count; i++) {
999 rx_ring = &(adapter->rx_ring[r_idx]);
1000 rx_ring->total_bytes = 0;
1001 rx_ring->total_packets = 0;
1002 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1006 if (!q_vector->rxr_count)
1009 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1010 rx_ring = &(adapter->rx_ring[r_idx]);
1011 /* disable interrupts on this vector only */
1012 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
1013 netif_rx_schedule(adapter->netdev, &q_vector->napi);
1018 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1020 ixgbe_msix_clean_rx(irq, data);
1021 ixgbe_msix_clean_tx(irq, data);
1027 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1028 * @napi: napi struct with our devices info in it
1029 * @budget: amount of work driver is allowed to do this pass, in packets
1031 * This function is optimized for cleaning one queue only on a single
1034 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1036 struct ixgbe_q_vector *q_vector =
1037 container_of(napi, struct ixgbe_q_vector, napi);
1038 struct ixgbe_adapter *adapter = q_vector->adapter;
1039 struct ixgbe_ring *rx_ring = NULL;
1043 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1044 rx_ring = &(adapter->rx_ring[r_idx]);
1045 #ifdef CONFIG_IXGBE_DCA
1046 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1047 ixgbe_update_rx_dca(adapter, rx_ring);
1050 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
1052 /* If all Rx work done, exit the polling mode */
1053 if (work_done < budget) {
1054 netif_rx_complete(adapter->netdev, napi);
1055 if (adapter->itr_setting & 3)
1056 ixgbe_set_itr_msix(q_vector);
1057 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1058 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
1065 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1066 * @napi: napi struct with our devices info in it
1067 * @budget: amount of work driver is allowed to do this pass, in packets
1069 * This function will clean more than one rx queue associated with a
1072 static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1074 struct ixgbe_q_vector *q_vector =
1075 container_of(napi, struct ixgbe_q_vector, napi);
1076 struct ixgbe_adapter *adapter = q_vector->adapter;
1077 struct ixgbe_ring *rx_ring = NULL;
1078 int work_done = 0, i;
1080 u16 enable_mask = 0;
1082 /* attempt to distribute budget to each queue fairly, but don't allow
1083 * the budget to go below 1 because we'll exit polling */
1084 budget /= (q_vector->rxr_count ?: 1);
1085 budget = max(budget, 1);
1086 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1087 for (i = 0; i < q_vector->rxr_count; i++) {
1088 rx_ring = &(adapter->rx_ring[r_idx]);
1089 #ifdef CONFIG_IXGBE_DCA
1090 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1091 ixgbe_update_rx_dca(adapter, rx_ring);
1093 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
1094 enable_mask |= rx_ring->v_idx;
1095 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1099 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1100 rx_ring = &(adapter->rx_ring[r_idx]);
1101 /* If all Rx work done, exit the polling mode */
1102 if (work_done < budget) {
1103 netif_rx_complete(adapter->netdev, napi);
1104 if (adapter->itr_setting & 3)
1105 ixgbe_set_itr_msix(q_vector);
1106 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1107 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1113 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
1116 a->q_vector[v_idx].adapter = a;
1117 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1118 a->q_vector[v_idx].rxr_count++;
1119 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1122 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
1125 a->q_vector[v_idx].adapter = a;
1126 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1127 a->q_vector[v_idx].txr_count++;
1128 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1132 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1133 * @adapter: board private structure to initialize
1134 * @vectors: allotted vector count for descriptor rings
1136 * This function maps descriptor rings to the queue-specific vectors
1137 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1138 * one vector per ring/queue, but on a constrained vector budget, we
1139 * group the rings as "efficiently" as possible. You would add new
1140 * mapping configurations in here.
1142 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
1146 int rxr_idx = 0, txr_idx = 0;
1147 int rxr_remaining = adapter->num_rx_queues;
1148 int txr_remaining = adapter->num_tx_queues;
1153 /* No mapping required if MSI-X is disabled. */
1154 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1158 * The ideal configuration...
1159 * We have enough vectors to map one per queue.
1161 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1162 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1163 map_vector_to_rxq(adapter, v_start, rxr_idx);
1165 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1166 map_vector_to_txq(adapter, v_start, txr_idx);
1172 * If we don't have enough vectors for a 1-to-1
1173 * mapping, we'll have to group them so there are
1174 * multiple queues per vector.
1176 /* Re-adjusting *qpv takes care of the remainder. */
1177 for (i = v_start; i < vectors; i++) {
1178 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1179 for (j = 0; j < rqpv; j++) {
1180 map_vector_to_rxq(adapter, i, rxr_idx);
1185 for (i = v_start; i < vectors; i++) {
1186 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1187 for (j = 0; j < tqpv; j++) {
1188 map_vector_to_txq(adapter, i, txr_idx);
1199 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1200 * @adapter: board private structure
1202 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1203 * interrupts from the kernel.
1205 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1207 struct net_device *netdev = adapter->netdev;
1208 irqreturn_t (*handler)(int, void *);
1209 int i, vector, q_vectors, err;
1211 /* Decrement for Other and TCP Timer vectors */
1212 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1214 /* Map the Tx/Rx rings to the vectors we were allotted. */
1215 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1219 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1220 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1221 &ixgbe_msix_clean_many)
1222 for (vector = 0; vector < q_vectors; vector++) {
1223 handler = SET_HANDLER(&adapter->q_vector[vector]);
1224 sprintf(adapter->name[vector], "%s:v%d-%s",
1225 netdev->name, vector,
1226 (handler == &ixgbe_msix_clean_rx) ? "Rx" :
1227 ((handler == &ixgbe_msix_clean_tx) ? "Tx" : "TxRx"));
1228 err = request_irq(adapter->msix_entries[vector].vector,
1229 handler, 0, adapter->name[vector],
1230 &(adapter->q_vector[vector]));
1233 "request_irq failed for MSIX interrupt "
1234 "Error: %d\n", err);
1235 goto free_queue_irqs;
1239 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1240 err = request_irq(adapter->msix_entries[vector].vector,
1241 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
1244 "request_irq for msix_lsc failed: %d\n", err);
1245 goto free_queue_irqs;
1251 for (i = vector - 1; i >= 0; i--)
1252 free_irq(adapter->msix_entries[--vector].vector,
1253 &(adapter->q_vector[i]));
1254 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1255 pci_disable_msix(adapter->pdev);
1256 kfree(adapter->msix_entries);
1257 adapter->msix_entries = NULL;
1262 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1264 struct ixgbe_hw *hw = &adapter->hw;
1265 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1267 u32 new_itr = q_vector->eitr;
1268 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1269 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1271 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
1273 tx_ring->total_packets,
1274 tx_ring->total_bytes);
1275 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
1277 rx_ring->total_packets,
1278 rx_ring->total_bytes);
1280 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1282 switch (current_itr) {
1283 /* counts and packets in update_itr are dependent on these numbers */
1284 case lowest_latency:
1288 new_itr = 20000; /* aka hwitr = ~200 */
1297 if (new_itr != q_vector->eitr) {
1299 /* do an exponential smoothing */
1300 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1301 q_vector->eitr = new_itr;
1302 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1303 /* must write high and low 16 bits to reset counter */
1304 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1311 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1312 * @adapter: board private structure
1314 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1316 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1317 IXGBE_WRITE_FLUSH(&adapter->hw);
1318 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1320 for (i = 0; i < adapter->num_msix_vectors; i++)
1321 synchronize_irq(adapter->msix_entries[i].vector);
1323 synchronize_irq(adapter->pdev->irq);
1328 * ixgbe_irq_enable - Enable default interrupt generation settings
1329 * @adapter: board private structure
1331 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1334 mask = IXGBE_EIMS_ENABLE_MASK;
1335 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1336 mask |= IXGBE_EIMS_GPI_SDP1;
1337 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1338 IXGBE_WRITE_FLUSH(&adapter->hw);
1342 * ixgbe_intr - legacy mode Interrupt Handler
1343 * @irq: interrupt number
1344 * @data: pointer to a network interface device structure
1345 * @pt_regs: CPU registers structure
1347 static irqreturn_t ixgbe_intr(int irq, void *data)
1349 struct net_device *netdev = data;
1350 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1351 struct ixgbe_hw *hw = &adapter->hw;
1354 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1355 * therefore no explict interrupt disable is necessary */
1356 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1358 /* shared interrupt alert!
1359 * make sure interrupts are enabled because the read will
1360 * have disabled interrupts due to EIAM */
1361 ixgbe_irq_enable(adapter);
1362 return IRQ_NONE; /* Not our interrupt */
1365 if (eicr & IXGBE_EICR_LSC)
1366 ixgbe_check_lsc(adapter);
1368 ixgbe_check_fan_failure(adapter, eicr);
1370 if (netif_rx_schedule_prep(netdev, &adapter->q_vector[0].napi)) {
1371 adapter->tx_ring[0].total_packets = 0;
1372 adapter->tx_ring[0].total_bytes = 0;
1373 adapter->rx_ring[0].total_packets = 0;
1374 adapter->rx_ring[0].total_bytes = 0;
1375 /* would disable interrupts here but EIAM disabled it */
1376 __netif_rx_schedule(netdev, &adapter->q_vector[0].napi);
1382 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1384 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1386 for (i = 0; i < q_vectors; i++) {
1387 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1388 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1389 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1390 q_vector->rxr_count = 0;
1391 q_vector->txr_count = 0;
1396 * ixgbe_request_irq - initialize interrupts
1397 * @adapter: board private structure
1399 * Attempts to configure interrupts using the best available
1400 * capabilities of the hardware and kernel.
1402 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
1404 struct net_device *netdev = adapter->netdev;
1407 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1408 err = ixgbe_request_msix_irqs(adapter);
1409 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1410 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
1411 netdev->name, netdev);
1413 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
1414 netdev->name, netdev);
1418 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1423 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1425 struct net_device *netdev = adapter->netdev;
1427 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1430 q_vectors = adapter->num_msix_vectors;
1433 free_irq(adapter->msix_entries[i].vector, netdev);
1436 for (; i >= 0; i--) {
1437 free_irq(adapter->msix_entries[i].vector,
1438 &(adapter->q_vector[i]));
1441 ixgbe_reset_q_vectors(adapter);
1443 free_irq(adapter->pdev->irq, netdev);
1448 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1451 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1453 struct ixgbe_hw *hw = &adapter->hw;
1455 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
1456 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
1458 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
1459 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1461 map_vector_to_rxq(adapter, 0, 0);
1462 map_vector_to_txq(adapter, 0, 0);
1464 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
1468 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1469 * @adapter: board private structure
1471 * Configure the Tx unit of the MAC after a reset.
1473 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1476 struct ixgbe_hw *hw = &adapter->hw;
1477 u32 i, j, tdlen, txctrl;
1479 /* Setup the HW Tx Head and Tail descriptor pointers */
1480 for (i = 0; i < adapter->num_tx_queues; i++) {
1481 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1484 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1485 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
1486 (tdba & DMA_32BIT_MASK));
1487 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1489 (ring->count * sizeof(union ixgbe_adv_tx_desc));
1490 tdwba |= IXGBE_TDWBAL_HEAD_WB_ENABLE;
1491 IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(j), tdwba & DMA_32BIT_MASK);
1492 IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(j), (tdwba >> 32));
1493 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1494 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1495 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1496 adapter->tx_ring[i].head = IXGBE_TDH(j);
1497 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1498 /* Disable Tx Head Writeback RO bit, since this hoses
1499 * bookkeeping if things aren't delivered in order.
1501 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1502 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1503 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1507 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1509 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1511 struct ixgbe_ring *rx_ring;
1516 /* program one srrctl register per VMDq index */
1517 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1519 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1520 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1521 shift = find_first_bit(&mask, len);
1522 queue0 = index & mask;
1523 index = (index & mask) >> shift;
1524 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
1526 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1527 queue0 = index & mask;
1528 index = index & mask;
1531 rx_ring = &adapter->rx_ring[queue0];
1533 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1535 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1536 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1538 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1539 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1540 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1541 srrctl |= ((IXGBE_RX_HDR_SIZE <<
1542 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1543 IXGBE_SRRCTL_BSIZEHDR_MASK);
1545 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1547 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1548 srrctl |= IXGBE_RXBUFFER_2048 >>
1549 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1551 srrctl |= rx_ring->rx_buf_len >>
1552 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1554 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1558 * ixgbe_get_skb_hdr - helper function for LRO header processing
1559 * @skb: pointer to sk_buff to be added to LRO packet
1560 * @iphdr: pointer to ip header structure
1561 * @tcph: pointer to tcp header structure
1562 * @hdr_flags: pointer to header flags
1563 * @priv: private data
1565 static int ixgbe_get_skb_hdr(struct sk_buff *skb, void **iphdr, void **tcph,
1566 u64 *hdr_flags, void *priv)
1568 union ixgbe_adv_rx_desc *rx_desc = priv;
1570 /* Verify that this is a valid IPv4 TCP packet */
1571 if (!((ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_IPV4) &&
1572 (ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_TCP)))
1575 /* Set network headers */
1576 skb_reset_network_header(skb);
1577 skb_set_transport_header(skb, ip_hdrlen(skb));
1578 *iphdr = ip_hdr(skb);
1579 *tcph = tcp_hdr(skb);
1580 *hdr_flags = LRO_IPV4 | LRO_TCP;
1584 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1585 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1588 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
1589 * @adapter: board private structure
1591 * Configure the Rx unit of the MAC after a reset.
1593 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1596 struct ixgbe_hw *hw = &adapter->hw;
1597 struct net_device *netdev = adapter->netdev;
1598 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1600 u32 rdlen, rxctrl, rxcsum;
1601 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1602 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1603 0x6A3E67EA, 0x14364D17, 0x3BED200D};
1610 /* Decide whether to use packet split mode or not */
1611 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1613 /* Set the RX buffer length according to the mode */
1614 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1615 rx_buf_len = IXGBE_RX_HDR_SIZE;
1617 if (netdev->mtu <= ETH_DATA_LEN)
1618 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1620 rx_buf_len = ALIGN(max_frame, 1024);
1623 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1624 fctrl |= IXGBE_FCTRL_BAM;
1625 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
1626 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1628 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1629 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1630 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1632 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1633 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1635 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1637 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1638 /* disable receives while setting up the descriptors */
1639 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1640 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1642 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1643 * the Base and Length of the Rx Descriptor Ring */
1644 for (i = 0; i < adapter->num_rx_queues; i++) {
1645 rdba = adapter->rx_ring[i].dma;
1646 j = adapter->rx_ring[i].reg_idx;
1647 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1648 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1649 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1650 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1651 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1652 adapter->rx_ring[i].head = IXGBE_RDH(j);
1653 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1654 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
1655 /* Intitial LRO Settings */
1656 adapter->rx_ring[i].lro_mgr.max_aggr = IXGBE_MAX_LRO_AGGREGATE;
1657 adapter->rx_ring[i].lro_mgr.max_desc = IXGBE_MAX_LRO_DESCRIPTORS;
1658 adapter->rx_ring[i].lro_mgr.get_skb_header = ixgbe_get_skb_hdr;
1659 adapter->rx_ring[i].lro_mgr.features = LRO_F_EXTRACT_VLAN_ID;
1660 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1661 adapter->rx_ring[i].lro_mgr.features |= LRO_F_NAPI;
1662 adapter->rx_ring[i].lro_mgr.dev = adapter->netdev;
1663 adapter->rx_ring[i].lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1664 adapter->rx_ring[i].lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1666 ixgbe_configure_srrctl(adapter, j);
1670 * For VMDq support of different descriptor types or
1671 * buffer sizes through the use of multiple SRRCTL
1672 * registers, RDRXCTL.MVMEN must be set to 1
1674 * also, the manual doesn't mention it clearly but DCA hints
1675 * will only use queue 0's tags unless this bit is set. Side
1676 * effects of setting this bit are only that SRRCTL must be
1677 * fully programmed [0..15]
1679 if (adapter->flags &
1680 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1681 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1682 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1683 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1686 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
1687 /* Fill out redirection table */
1688 for (i = 0, j = 0; i < 128; i++, j++) {
1689 if (j == adapter->ring_feature[RING_F_RSS].indices)
1691 /* reta = 4-byte sliding window of
1692 * 0x00..(indices-1)(indices-1)00..etc. */
1693 reta = (reta << 8) | (j * 0x11);
1695 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
1698 /* Fill out hash function seeds */
1699 for (i = 0; i < 10; i++)
1700 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
1702 mrqc = IXGBE_MRQC_RSSEN
1703 /* Perform hash on these packet types */
1704 | IXGBE_MRQC_RSS_FIELD_IPV4
1705 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1706 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1707 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1708 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1709 | IXGBE_MRQC_RSS_FIELD_IPV6
1710 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1711 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1712 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
1713 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
1716 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1718 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1719 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1720 /* Disable indicating checksum in descriptor, enables
1722 rxcsum |= IXGBE_RXCSUM_PCSD;
1724 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1725 /* Enable IPv4 payload checksum for UDP fragments
1726 * if PCSD is not set */
1727 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1730 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1733 static void ixgbe_vlan_rx_register(struct net_device *netdev,
1734 struct vlan_group *grp)
1736 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1739 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1740 ixgbe_irq_disable(adapter);
1741 adapter->vlgrp = grp;
1744 * For a DCB driver, always enable VLAN tag stripping so we can
1745 * still receive traffic from a DCB-enabled host even if we're
1748 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1749 ctrl |= IXGBE_VLNCTRL_VME;
1750 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1751 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1754 /* enable VLAN tag insert/strip */
1755 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1756 ctrl |= IXGBE_VLNCTRL_VME;
1757 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1758 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1761 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1762 ixgbe_irq_enable(adapter);
1765 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1767 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1768 struct ixgbe_hw *hw = &adapter->hw;
1770 /* add VID to filter table */
1771 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
1774 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1776 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1777 struct ixgbe_hw *hw = &adapter->hw;
1779 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1780 ixgbe_irq_disable(adapter);
1782 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1784 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1785 ixgbe_irq_enable(adapter);
1787 /* remove VID from filter table */
1788 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
1791 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1793 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1795 if (adapter->vlgrp) {
1797 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1798 if (!vlan_group_get_device(adapter->vlgrp, vid))
1800 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1805 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1807 struct dev_mc_list *mc_ptr;
1808 u8 *addr = *mc_addr_ptr;
1811 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1813 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1815 *mc_addr_ptr = NULL;
1821 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
1822 * @netdev: network interface device structure
1824 * The set_rx_method entry point is called whenever the unicast/multicast
1825 * address list or the network interface flags are updated. This routine is
1826 * responsible for configuring the hardware for proper unicast, multicast and
1829 static void ixgbe_set_rx_mode(struct net_device *netdev)
1831 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1832 struct ixgbe_hw *hw = &adapter->hw;
1834 u8 *addr_list = NULL;
1837 /* Check for Promiscuous and All Multicast modes */
1839 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1840 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1842 if (netdev->flags & IFF_PROMISC) {
1843 hw->addr_ctrl.user_set_promisc = 1;
1844 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1845 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1847 if (netdev->flags & IFF_ALLMULTI) {
1848 fctrl |= IXGBE_FCTRL_MPE;
1849 fctrl &= ~IXGBE_FCTRL_UPE;
1851 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1853 vlnctrl |= IXGBE_VLNCTRL_VFE;
1854 hw->addr_ctrl.user_set_promisc = 0;
1857 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1858 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1860 /* reprogram secondary unicast list */
1861 addr_count = netdev->uc_count;
1863 addr_list = netdev->uc_list->dmi_addr;
1864 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1865 ixgbe_addr_list_itr);
1867 /* reprogram multicast list */
1868 addr_count = netdev->mc_count;
1870 addr_list = netdev->mc_list->dmi_addr;
1871 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1872 ixgbe_addr_list_itr);
1875 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1878 struct ixgbe_q_vector *q_vector;
1879 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1881 /* legacy and MSI only use one vector */
1882 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1885 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1886 struct napi_struct *napi;
1887 q_vector = &adapter->q_vector[q_idx];
1888 if (!q_vector->rxr_count)
1890 napi = &q_vector->napi;
1891 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1892 (q_vector->rxr_count > 1))
1893 napi->poll = &ixgbe_clean_rxonly_many;
1899 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1902 struct ixgbe_q_vector *q_vector;
1903 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1905 /* legacy and MSI only use one vector */
1906 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1909 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1910 q_vector = &adapter->q_vector[q_idx];
1911 if (!q_vector->rxr_count)
1913 napi_disable(&q_vector->napi);
1917 #ifdef CONFIG_IXGBE_DCBNL
1919 * ixgbe_configure_dcb - Configure DCB hardware
1920 * @adapter: ixgbe adapter struct
1922 * This is called by the driver on open to configure the DCB hardware.
1923 * This is also called by the gennetlink interface when reconfiguring
1926 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1928 struct ixgbe_hw *hw = &adapter->hw;
1929 u32 txdctl, vlnctrl;
1932 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1933 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1934 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1936 /* reconfigure the hardware */
1937 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1939 for (i = 0; i < adapter->num_tx_queues; i++) {
1940 j = adapter->tx_ring[i].reg_idx;
1941 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1942 /* PThresh workaround for Tx hang with DFP enabled. */
1944 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1946 /* Enable VLAN tag insert/strip */
1947 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1948 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1949 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1950 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1951 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1955 static void ixgbe_configure(struct ixgbe_adapter *adapter)
1957 struct net_device *netdev = adapter->netdev;
1960 ixgbe_set_rx_mode(netdev);
1962 ixgbe_restore_vlan(adapter);
1963 #ifdef CONFIG_IXGBE_DCBNL
1964 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1965 netif_set_gso_max_size(netdev, 32768);
1966 ixgbe_configure_dcb(adapter);
1968 netif_set_gso_max_size(netdev, 65536);
1971 netif_set_gso_max_size(netdev, 65536);
1974 ixgbe_configure_tx(adapter);
1975 ixgbe_configure_rx(adapter);
1976 for (i = 0; i < adapter->num_rx_queues; i++)
1977 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
1978 (adapter->rx_ring[i].count - 1));
1981 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1983 struct net_device *netdev = adapter->netdev;
1984 struct ixgbe_hw *hw = &adapter->hw;
1986 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1987 u32 txdctl, rxdctl, mhadd;
1990 ixgbe_get_hw_control(adapter);
1992 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
1993 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
1994 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1995 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
1996 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
2001 /* XXX: to interrupt immediately for EICS writes, enable this */
2002 /* gpie |= IXGBE_GPIE_EIMEN; */
2003 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2006 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2007 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2008 * specifically only auto mask tx and rx interrupts */
2009 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
2012 /* Enable fan failure interrupt if media type is copper */
2013 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2014 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2015 gpie |= IXGBE_SDP1_GPIEN;
2016 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2019 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2020 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2021 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2022 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2024 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2027 for (i = 0; i < adapter->num_tx_queues; i++) {
2028 j = adapter->tx_ring[i].reg_idx;
2029 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2030 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2031 txdctl |= (8 << 16);
2032 txdctl |= IXGBE_TXDCTL_ENABLE;
2033 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2036 for (i = 0; i < adapter->num_rx_queues; i++) {
2037 j = adapter->rx_ring[i].reg_idx;
2038 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2039 /* enable PTHRESH=32 descriptors (half the internal cache)
2040 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2041 * this also removes a pesky rx_no_buffer_count increment */
2043 rxdctl |= IXGBE_RXDCTL_ENABLE;
2044 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
2046 /* enable all receives */
2047 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2048 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2049 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2051 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2052 ixgbe_configure_msix(adapter);
2054 ixgbe_configure_msi_and_legacy(adapter);
2056 clear_bit(__IXGBE_DOWN, &adapter->state);
2057 ixgbe_napi_enable_all(adapter);
2059 /* clear any pending interrupts, may auto mask */
2060 IXGBE_READ_REG(hw, IXGBE_EICR);
2062 ixgbe_irq_enable(adapter);
2064 /* bring the link up in the watchdog, this could race with our first
2065 * link up interrupt but shouldn't be a problem */
2066 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2067 adapter->link_check_timeout = jiffies;
2068 mod_timer(&adapter->watchdog_timer, jiffies);
2072 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2074 WARN_ON(in_interrupt());
2075 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2077 ixgbe_down(adapter);
2079 clear_bit(__IXGBE_RESETTING, &adapter->state);
2082 int ixgbe_up(struct ixgbe_adapter *adapter)
2084 /* hardware has been reset, we need to reload some things */
2085 ixgbe_configure(adapter);
2087 return ixgbe_up_complete(adapter);
2090 void ixgbe_reset(struct ixgbe_adapter *adapter)
2092 struct ixgbe_hw *hw = &adapter->hw;
2093 if (hw->mac.ops.init_hw(hw))
2094 dev_err(&adapter->pdev->dev, "Hardware Error\n");
2096 /* reprogram the RAR[0] in case user changed it. */
2097 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2102 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2103 * @adapter: board private structure
2104 * @rx_ring: ring to free buffers from
2106 static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
2107 struct ixgbe_ring *rx_ring)
2109 struct pci_dev *pdev = adapter->pdev;
2113 /* Free all the Rx ring sk_buffs */
2115 for (i = 0; i < rx_ring->count; i++) {
2116 struct ixgbe_rx_buffer *rx_buffer_info;
2118 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2119 if (rx_buffer_info->dma) {
2120 pci_unmap_single(pdev, rx_buffer_info->dma,
2121 rx_ring->rx_buf_len,
2122 PCI_DMA_FROMDEVICE);
2123 rx_buffer_info->dma = 0;
2125 if (rx_buffer_info->skb) {
2126 dev_kfree_skb(rx_buffer_info->skb);
2127 rx_buffer_info->skb = NULL;
2129 if (!rx_buffer_info->page)
2131 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2132 PCI_DMA_FROMDEVICE);
2133 rx_buffer_info->page_dma = 0;
2134 put_page(rx_buffer_info->page);
2135 rx_buffer_info->page = NULL;
2136 rx_buffer_info->page_offset = 0;
2139 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2140 memset(rx_ring->rx_buffer_info, 0, size);
2142 /* Zero out the descriptor ring */
2143 memset(rx_ring->desc, 0, rx_ring->size);
2145 rx_ring->next_to_clean = 0;
2146 rx_ring->next_to_use = 0;
2148 writel(0, adapter->hw.hw_addr + rx_ring->head);
2149 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2153 * ixgbe_clean_tx_ring - Free Tx Buffers
2154 * @adapter: board private structure
2155 * @tx_ring: ring to be cleaned
2157 static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
2158 struct ixgbe_ring *tx_ring)
2160 struct ixgbe_tx_buffer *tx_buffer_info;
2164 /* Free all the Tx ring sk_buffs */
2166 for (i = 0; i < tx_ring->count; i++) {
2167 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2168 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2171 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2172 memset(tx_ring->tx_buffer_info, 0, size);
2174 /* Zero out the descriptor ring */
2175 memset(tx_ring->desc, 0, tx_ring->size);
2177 tx_ring->next_to_use = 0;
2178 tx_ring->next_to_clean = 0;
2180 writel(0, adapter->hw.hw_addr + tx_ring->head);
2181 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2185 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2186 * @adapter: board private structure
2188 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2192 for (i = 0; i < adapter->num_rx_queues; i++)
2193 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2197 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2198 * @adapter: board private structure
2200 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2204 for (i = 0; i < adapter->num_tx_queues; i++)
2205 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2208 void ixgbe_down(struct ixgbe_adapter *adapter)
2210 struct net_device *netdev = adapter->netdev;
2211 struct ixgbe_hw *hw = &adapter->hw;
2216 /* signal that we are down to the interrupt handler */
2217 set_bit(__IXGBE_DOWN, &adapter->state);
2219 /* disable receives */
2220 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2221 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2223 netif_tx_disable(netdev);
2225 IXGBE_WRITE_FLUSH(hw);
2228 netif_tx_stop_all_queues(netdev);
2230 ixgbe_irq_disable(adapter);
2232 ixgbe_napi_disable_all(adapter);
2234 del_timer_sync(&adapter->watchdog_timer);
2235 cancel_work_sync(&adapter->watchdog_task);
2237 /* disable transmits in the hardware now that interrupts are off */
2238 for (i = 0; i < adapter->num_tx_queues; i++) {
2239 j = adapter->tx_ring[i].reg_idx;
2240 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2241 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2242 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2245 netif_carrier_off(netdev);
2247 #ifdef CONFIG_IXGBE_DCA
2248 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2249 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2250 dca_remove_requester(&adapter->pdev->dev);
2254 if (!pci_channel_offline(adapter->pdev))
2255 ixgbe_reset(adapter);
2256 ixgbe_clean_all_tx_rings(adapter);
2257 ixgbe_clean_all_rx_rings(adapter);
2259 #ifdef CONFIG_IXGBE_DCA
2260 /* since we reset the hardware DCA settings were cleared */
2261 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2262 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2263 /* always use CB2 mode, difference is masked
2264 * in the CB driver */
2265 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
2266 ixgbe_setup_dca(adapter);
2272 * ixgbe_poll - NAPI Rx polling callback
2273 * @napi: structure for representing this polling device
2274 * @budget: how many packets driver is allowed to clean
2276 * This function is used for legacy and MSI, NAPI mode
2278 static int ixgbe_poll(struct napi_struct *napi, int budget)
2280 struct ixgbe_q_vector *q_vector = container_of(napi,
2281 struct ixgbe_q_vector, napi);
2282 struct ixgbe_adapter *adapter = q_vector->adapter;
2283 int tx_cleaned, work_done = 0;
2285 #ifdef CONFIG_IXGBE_DCA
2286 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2287 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2288 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2292 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
2293 ixgbe_clean_rx_irq(adapter, adapter->rx_ring, &work_done, budget);
2298 /* If budget not fully consumed, exit the polling mode */
2299 if (work_done < budget) {
2300 netif_rx_complete(adapter->netdev, napi);
2301 if (adapter->itr_setting & 3)
2302 ixgbe_set_itr(adapter);
2303 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2304 ixgbe_irq_enable(adapter);
2310 * ixgbe_tx_timeout - Respond to a Tx Hang
2311 * @netdev: network interface device structure
2313 static void ixgbe_tx_timeout(struct net_device *netdev)
2315 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2317 /* Do the reset outside of interrupt context */
2318 schedule_work(&adapter->reset_task);
2321 static void ixgbe_reset_task(struct work_struct *work)
2323 struct ixgbe_adapter *adapter;
2324 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2326 /* If we're already down or resetting, just bail */
2327 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2328 test_bit(__IXGBE_RESETTING, &adapter->state))
2331 adapter->tx_timeout_count++;
2333 ixgbe_reinit_locked(adapter);
2336 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2338 int nrq = 1, ntq = 1;
2339 int feature_mask = 0, rss_i, rss_m;
2342 /* Number of supported queues */
2343 switch (adapter->hw.mac.type) {
2344 case ixgbe_mac_82598EB:
2345 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2347 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2349 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2350 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
2352 switch (adapter->flags & feature_mask) {
2353 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2355 rss_i = min(8, rss_i);
2357 nrq = dcb_i * rss_i;
2358 ntq = min(MAX_TX_QUEUES, dcb_i * rss_i);
2360 case (IXGBE_FLAG_DCB_ENABLED):
2365 case (IXGBE_FLAG_RSS_ENABLED):
2381 /* Sanity check, we should never have zero queues */
2385 adapter->ring_feature[RING_F_DCB].indices = dcb_i;
2386 adapter->ring_feature[RING_F_DCB].mask = dcb_m;
2387 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2388 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2396 adapter->num_rx_queues = nrq;
2397 adapter->num_tx_queues = ntq;
2400 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
2403 int err, vector_threshold;
2405 /* We'll want at least 3 (vector_threshold):
2408 * 3) Other (Link Status Change, etc.)
2409 * 4) TCP Timer (optional)
2411 vector_threshold = MIN_MSIX_COUNT;
2413 /* The more we get, the more we will assign to Tx/Rx Cleanup
2414 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2415 * Right now, we simply care about how many we'll get; we'll
2416 * set them up later while requesting irq's.
2418 while (vectors >= vector_threshold) {
2419 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2421 if (!err) /* Success in acquiring all requested vectors. */
2424 vectors = 0; /* Nasty failure, quit now */
2425 else /* err == number of vectors we should try again with */
2429 if (vectors < vector_threshold) {
2430 /* Can't allocate enough MSI-X interrupts? Oh well.
2431 * This just means we'll go with either a single MSI
2432 * vector or fall back to legacy interrupts.
2434 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2435 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2436 kfree(adapter->msix_entries);
2437 adapter->msix_entries = NULL;
2438 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2439 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2440 ixgbe_set_num_queues(adapter);
2442 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2443 adapter->num_msix_vectors = vectors;
2448 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2449 * @adapter: board private structure to initialize
2451 * Once we know the feature-set enabled for the device, we'll cache
2452 * the register offset the descriptor ring is assigned to.
2454 static void __devinit ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2456 int feature_mask = 0, rss_i;
2457 int i, txr_idx, rxr_idx;
2460 /* Number of supported queues */
2461 switch (adapter->hw.mac.type) {
2462 case ixgbe_mac_82598EB:
2463 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2464 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2467 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
2468 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2469 switch (adapter->flags & feature_mask) {
2470 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2471 for (i = 0; i < dcb_i; i++) {
2474 for (j = 0; j < adapter->num_rx_queues; j++) {
2475 adapter->rx_ring[rxr_idx].reg_idx =
2480 for (j = 0; j < adapter->num_tx_queues; j++) {
2481 adapter->tx_ring[txr_idx].reg_idx =
2487 case (IXGBE_FLAG_DCB_ENABLED):
2488 /* the number of queues is assumed to be symmetric */
2489 for (i = 0; i < dcb_i; i++) {
2490 adapter->rx_ring[i].reg_idx = i << 3;
2491 adapter->tx_ring[i].reg_idx = i << 2;
2494 case (IXGBE_FLAG_RSS_ENABLED):
2495 for (i = 0; i < adapter->num_rx_queues; i++)
2496 adapter->rx_ring[i].reg_idx = i;
2497 for (i = 0; i < adapter->num_tx_queues; i++)
2498 adapter->tx_ring[i].reg_idx = i;
2511 * ixgbe_alloc_queues - Allocate memory for all rings
2512 * @adapter: board private structure to initialize
2514 * We allocate one ring per queue at run-time since we don't know the
2515 * number of queues at compile-time. The polling_netdev array is
2516 * intended for Multiqueue, but should work fine with a single queue.
2518 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
2522 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
2523 sizeof(struct ixgbe_ring), GFP_KERNEL);
2524 if (!adapter->tx_ring)
2525 goto err_tx_ring_allocation;
2527 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
2528 sizeof(struct ixgbe_ring), GFP_KERNEL);
2529 if (!adapter->rx_ring)
2530 goto err_rx_ring_allocation;
2532 for (i = 0; i < adapter->num_tx_queues; i++) {
2533 adapter->tx_ring[i].count = adapter->tx_ring_count;
2534 adapter->tx_ring[i].queue_index = i;
2537 for (i = 0; i < adapter->num_rx_queues; i++) {
2538 adapter->rx_ring[i].count = adapter->rx_ring_count;
2539 adapter->rx_ring[i].queue_index = i;
2542 ixgbe_cache_ring_register(adapter);
2546 err_rx_ring_allocation:
2547 kfree(adapter->tx_ring);
2548 err_tx_ring_allocation:
2553 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2554 * @adapter: board private structure to initialize
2556 * Attempt to configure the interrupts using the best available
2557 * capabilities of the hardware and the kernel.
2559 static int __devinit ixgbe_set_interrupt_capability(struct ixgbe_adapter
2563 int vector, v_budget;
2566 * It's easy to be greedy for MSI-X vectors, but it really
2567 * doesn't do us much good if we have a lot more vectors
2568 * than CPU's. So let's be conservative and only ask for
2569 * (roughly) twice the number of vectors as there are CPU's.
2571 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2572 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2575 * At the same time, hardware can only support a maximum of
2576 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2577 * we can easily reach upwards of 64 Rx descriptor queues and
2578 * 32 Tx queues. Thus, we cap it off in those rare cases where
2579 * the cpu count also exceeds our vector limit.
2581 v_budget = min(v_budget, MAX_MSIX_COUNT);
2583 /* A failure in MSI-X entry allocation isn't fatal, but it does
2584 * mean we disable MSI-X capabilities of the adapter. */
2585 adapter->msix_entries = kcalloc(v_budget,
2586 sizeof(struct msix_entry), GFP_KERNEL);
2587 if (!adapter->msix_entries) {
2588 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2589 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2590 ixgbe_set_num_queues(adapter);
2591 kfree(adapter->tx_ring);
2592 kfree(adapter->rx_ring);
2593 err = ixgbe_alloc_queues(adapter);
2595 DPRINTK(PROBE, ERR, "Unable to allocate memory "
2603 for (vector = 0; vector < v_budget; vector++)
2604 adapter->msix_entries[vector].entry = vector;
2606 ixgbe_acquire_msix_vectors(adapter, v_budget);
2608 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2612 err = pci_enable_msi(adapter->pdev);
2614 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2616 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
2617 "falling back to legacy. Error: %d\n", err);
2623 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2624 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
2629 void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
2631 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2632 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2633 pci_disable_msix(adapter->pdev);
2634 kfree(adapter->msix_entries);
2635 adapter->msix_entries = NULL;
2636 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2637 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2638 pci_disable_msi(adapter->pdev);
2644 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2645 * @adapter: board private structure to initialize
2647 * We determine which interrupt scheme to use based on...
2648 * - Kernel support (MSI, MSI-X)
2649 * - which can be user-defined (via MODULE_PARAM)
2650 * - Hardware queue count (num_*_queues)
2651 * - defined by miscellaneous hardware support/features (RSS, etc.)
2653 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
2657 /* Number of supported queues */
2658 ixgbe_set_num_queues(adapter);
2660 err = ixgbe_alloc_queues(adapter);
2662 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2663 goto err_alloc_queues;
2666 err = ixgbe_set_interrupt_capability(adapter);
2668 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2669 goto err_set_interrupt;
2672 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
2673 "Tx Queue count = %u\n",
2674 (adapter->num_rx_queues > 1) ? "Enabled" :
2675 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2677 set_bit(__IXGBE_DOWN, &adapter->state);
2682 kfree(adapter->tx_ring);
2683 kfree(adapter->rx_ring);
2689 * ixgbe_sfp_timer - worker thread to find a missing module
2690 * @data: pointer to our adapter struct
2692 static void ixgbe_sfp_timer(unsigned long data)
2694 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2696 /* Do the sfp_timer outside of interrupt context due to the
2697 * delays that sfp+ detection requires
2699 schedule_work(&adapter->sfp_task);
2703 * ixgbe_sfp_task - worker thread to find a missing module
2704 * @work: pointer to work_struct containing our data
2706 static void ixgbe_sfp_task(struct work_struct *work)
2708 struct ixgbe_adapter *adapter = container_of(work,
2709 struct ixgbe_adapter,
2711 struct ixgbe_hw *hw = &adapter->hw;
2713 if ((hw->phy.type == ixgbe_phy_nl) &&
2714 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2715 s32 ret = hw->phy.ops.identify_sfp(hw);
2718 ret = hw->phy.ops.reset(hw);
2719 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2720 DPRINTK(PROBE, ERR, "failed to initialize because an "
2721 "unsupported SFP+ module type was detected.\n"
2722 "Reload the driver after installing a "
2723 "supported module.\n");
2724 unregister_netdev(adapter->netdev);
2726 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2729 /* don't need this routine any more */
2730 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2734 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2735 mod_timer(&adapter->sfp_timer,
2736 round_jiffies(jiffies + (2 * HZ)));
2740 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2741 * @adapter: board private structure to initialize
2743 * ixgbe_sw_init initializes the Adapter private data structure.
2744 * Fields are initialized based on PCI device information and
2745 * OS network device settings (MTU size).
2747 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2749 struct ixgbe_hw *hw = &adapter->hw;
2750 struct pci_dev *pdev = adapter->pdev;
2752 #ifdef CONFIG_IXGBE_DCBNL
2754 struct tc_configuration *tc;
2757 /* PCI config space info */
2759 hw->vendor_id = pdev->vendor;
2760 hw->device_id = pdev->device;
2761 hw->revision_id = pdev->revision;
2762 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2763 hw->subsystem_device_id = pdev->subsystem_device;
2765 /* Set capability flags */
2766 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2767 adapter->ring_feature[RING_F_RSS].indices = rss;
2768 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
2769 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
2771 #ifdef CONFIG_IXGBE_DCBNL
2772 /* Configure DCB traffic classes */
2773 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2774 tc = &adapter->dcb_cfg.tc_config[j];
2775 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2776 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2777 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2778 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2779 tc->dcb_pfc = pfc_disabled;
2781 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2782 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2783 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2784 adapter->dcb_cfg.round_robin_enable = false;
2785 adapter->dcb_set_bitmap = 0x00;
2786 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2787 adapter->ring_feature[RING_F_DCB].indices);
2790 if (hw->mac.ops.get_media_type &&
2791 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2792 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
2794 /* default flow control settings */
2795 hw->fc.original_type = ixgbe_fc_none;
2796 hw->fc.type = ixgbe_fc_none;
2797 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2798 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2799 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2800 hw->fc.send_xon = true;
2802 /* select 10G link by default */
2803 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2805 /* enable itr by default in dynamic mode */
2806 adapter->itr_setting = 1;
2807 adapter->eitr_param = 20000;
2809 /* set defaults for eitr in MegaBytes */
2810 adapter->eitr_low = 10;
2811 adapter->eitr_high = 20;
2813 /* set default ring sizes */
2814 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2815 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2817 /* initialize eeprom parameters */
2818 if (ixgbe_init_eeprom_params_generic(hw)) {
2819 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2823 /* enable rx csum by default */
2824 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2826 set_bit(__IXGBE_DOWN, &adapter->state);
2832 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2833 * @adapter: board private structure
2834 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2836 * Return 0 on success, negative on failure
2838 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
2839 struct ixgbe_ring *tx_ring)
2841 struct pci_dev *pdev = adapter->pdev;
2844 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2845 tx_ring->tx_buffer_info = vmalloc(size);
2846 if (!tx_ring->tx_buffer_info)
2848 memset(tx_ring->tx_buffer_info, 0, size);
2850 /* round up to nearest 4K */
2851 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc) +
2853 tx_ring->size = ALIGN(tx_ring->size, 4096);
2855 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2860 tx_ring->next_to_use = 0;
2861 tx_ring->next_to_clean = 0;
2862 tx_ring->work_limit = tx_ring->count;
2866 vfree(tx_ring->tx_buffer_info);
2867 tx_ring->tx_buffer_info = NULL;
2868 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2869 "descriptor ring\n");
2874 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2875 * @adapter: board private structure
2877 * If this function returns with an error, then it's possible one or
2878 * more of the rings is populated (while the rest are not). It is the
2879 * callers duty to clean those orphaned rings.
2881 * Return 0 on success, negative on failure
2883 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2887 for (i = 0; i < adapter->num_tx_queues; i++) {
2888 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2891 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2899 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2900 * @adapter: board private structure
2901 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2903 * Returns 0 on success, negative on failure
2905 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
2906 struct ixgbe_ring *rx_ring)
2908 struct pci_dev *pdev = adapter->pdev;
2911 size = sizeof(struct net_lro_desc) * IXGBE_MAX_LRO_DESCRIPTORS;
2912 rx_ring->lro_mgr.lro_arr = vmalloc(size);
2913 if (!rx_ring->lro_mgr.lro_arr)
2915 memset(rx_ring->lro_mgr.lro_arr, 0, size);
2917 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2918 rx_ring->rx_buffer_info = vmalloc(size);
2919 if (!rx_ring->rx_buffer_info) {
2921 "vmalloc allocation failed for the rx desc ring\n");
2924 memset(rx_ring->rx_buffer_info, 0, size);
2926 /* Round up to nearest 4K */
2927 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2928 rx_ring->size = ALIGN(rx_ring->size, 4096);
2930 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
2932 if (!rx_ring->desc) {
2934 "Memory allocation failed for the rx desc ring\n");
2935 vfree(rx_ring->rx_buffer_info);
2939 rx_ring->next_to_clean = 0;
2940 rx_ring->next_to_use = 0;
2945 vfree(rx_ring->lro_mgr.lro_arr);
2946 rx_ring->lro_mgr.lro_arr = NULL;
2951 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2952 * @adapter: board private structure
2954 * If this function returns with an error, then it's possible one or
2955 * more of the rings is populated (while the rest are not). It is the
2956 * callers duty to clean those orphaned rings.
2958 * Return 0 on success, negative on failure
2961 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2965 for (i = 0; i < adapter->num_rx_queues; i++) {
2966 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2969 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2977 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2978 * @adapter: board private structure
2979 * @tx_ring: Tx descriptor ring for a specific queue
2981 * Free all transmit software resources
2983 void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2984 struct ixgbe_ring *tx_ring)
2986 struct pci_dev *pdev = adapter->pdev;
2988 ixgbe_clean_tx_ring(adapter, tx_ring);
2990 vfree(tx_ring->tx_buffer_info);
2991 tx_ring->tx_buffer_info = NULL;
2993 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2995 tx_ring->desc = NULL;
2999 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3000 * @adapter: board private structure
3002 * Free all transmit software resources
3004 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3008 for (i = 0; i < adapter->num_tx_queues; i++)
3009 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3013 * ixgbe_free_rx_resources - Free Rx Resources
3014 * @adapter: board private structure
3015 * @rx_ring: ring to clean the resources from
3017 * Free all receive software resources
3019 void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3020 struct ixgbe_ring *rx_ring)
3022 struct pci_dev *pdev = adapter->pdev;
3024 vfree(rx_ring->lro_mgr.lro_arr);
3025 rx_ring->lro_mgr.lro_arr = NULL;
3027 ixgbe_clean_rx_ring(adapter, rx_ring);
3029 vfree(rx_ring->rx_buffer_info);
3030 rx_ring->rx_buffer_info = NULL;
3032 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3034 rx_ring->desc = NULL;
3038 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3039 * @adapter: board private structure
3041 * Free all receive software resources
3043 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3047 for (i = 0; i < adapter->num_rx_queues; i++)
3048 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3052 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3053 * @netdev: network interface device structure
3054 * @new_mtu: new value for maximum frame size
3056 * Returns 0 on success, negative on failure
3058 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3060 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3061 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3063 /* MTU < 68 is an error and causes problems on some kernels */
3064 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
3067 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
3068 netdev->mtu, new_mtu);
3069 /* must set new MTU before calling down or up */
3070 netdev->mtu = new_mtu;
3072 if (netif_running(netdev))
3073 ixgbe_reinit_locked(adapter);
3079 * ixgbe_open - Called when a network interface is made active
3080 * @netdev: network interface device structure
3082 * Returns 0 on success, negative value on failure
3084 * The open entry point is called when a network interface is made
3085 * active by the system (IFF_UP). At this point all resources needed
3086 * for transmit and receive operations are allocated, the interrupt
3087 * handler is registered with the OS, the watchdog timer is started,
3088 * and the stack is notified that the interface is ready.
3090 static int ixgbe_open(struct net_device *netdev)
3092 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3095 /* disallow open during test */
3096 if (test_bit(__IXGBE_TESTING, &adapter->state))
3099 /* allocate transmit descriptors */
3100 err = ixgbe_setup_all_tx_resources(adapter);
3104 /* allocate receive descriptors */
3105 err = ixgbe_setup_all_rx_resources(adapter);
3109 ixgbe_configure(adapter);
3111 err = ixgbe_request_irq(adapter);
3115 err = ixgbe_up_complete(adapter);
3119 netif_tx_start_all_queues(netdev);
3124 ixgbe_release_hw_control(adapter);
3125 ixgbe_free_irq(adapter);
3127 ixgbe_free_all_rx_resources(adapter);
3129 ixgbe_free_all_tx_resources(adapter);
3131 ixgbe_reset(adapter);
3137 * ixgbe_close - Disables a network interface
3138 * @netdev: network interface device structure
3140 * Returns 0, this is not allowed to fail
3142 * The close entry point is called when an interface is de-activated
3143 * by the OS. The hardware is still under the drivers control, but
3144 * needs to be disabled. A global MAC reset is issued to stop the
3145 * hardware, and all transmit and receive resources are freed.
3147 static int ixgbe_close(struct net_device *netdev)
3149 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3151 ixgbe_down(adapter);
3152 ixgbe_free_irq(adapter);
3154 ixgbe_free_all_tx_resources(adapter);
3155 ixgbe_free_all_rx_resources(adapter);
3157 ixgbe_release_hw_control(adapter);
3163 * ixgbe_napi_add_all - prep napi structs for use
3164 * @adapter: private struct
3165 * helper function to napi_add each possible q_vector->napi
3167 void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
3169 int q_idx, q_vectors;
3170 int (*poll)(struct napi_struct *, int);
3172 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3173 poll = &ixgbe_clean_rxonly;
3174 /* Only enable as many vectors as we have rx queues. */
3175 q_vectors = adapter->num_rx_queues;
3178 /* only one q_vector for legacy modes */
3182 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3183 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3184 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3188 void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
3191 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3193 /* legacy and MSI only use one vector */
3194 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3197 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3198 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3199 if (!q_vector->rxr_count)
3201 netif_napi_del(&q_vector->napi);
3206 static int ixgbe_resume(struct pci_dev *pdev)
3208 struct net_device *netdev = pci_get_drvdata(pdev);
3209 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3212 pci_set_power_state(pdev, PCI_D0);
3213 pci_restore_state(pdev);
3214 err = pci_enable_device(pdev);
3216 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
3220 pci_set_master(pdev);
3222 pci_enable_wake(pdev, PCI_D3hot, 0);
3223 pci_enable_wake(pdev, PCI_D3cold, 0);
3225 err = ixgbe_init_interrupt_scheme(adapter);
3227 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3232 ixgbe_napi_add_all(adapter);
3233 ixgbe_reset(adapter);
3235 if (netif_running(netdev)) {
3236 err = ixgbe_open(adapter->netdev);
3241 netif_device_attach(netdev);
3246 #endif /* CONFIG_PM */
3247 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3249 struct net_device *netdev = pci_get_drvdata(pdev);
3250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3255 netif_device_detach(netdev);
3257 if (netif_running(netdev)) {
3258 ixgbe_down(adapter);
3259 ixgbe_free_irq(adapter);
3260 ixgbe_free_all_tx_resources(adapter);
3261 ixgbe_free_all_rx_resources(adapter);
3263 ixgbe_reset_interrupt_capability(adapter);
3264 ixgbe_napi_del_all(adapter);
3265 kfree(adapter->tx_ring);
3266 kfree(adapter->rx_ring);
3269 retval = pci_save_state(pdev);
3274 pci_enable_wake(pdev, PCI_D3hot, 0);
3275 pci_enable_wake(pdev, PCI_D3cold, 0);
3277 ixgbe_release_hw_control(adapter);
3279 pci_disable_device(pdev);
3281 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3286 static void ixgbe_shutdown(struct pci_dev *pdev)
3288 ixgbe_suspend(pdev, PMSG_SUSPEND);
3292 * ixgbe_update_stats - Update the board statistics counters.
3293 * @adapter: board private structure
3295 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3297 struct ixgbe_hw *hw = &adapter->hw;
3299 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
3301 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
3302 for (i = 0; i < 8; i++) {
3303 /* for packet buffers not used, the register should read 0 */
3304 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3306 adapter->stats.mpc[i] += mpc;
3307 total_mpc += adapter->stats.mpc[i];
3308 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
3309 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3310 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3311 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3312 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3313 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3315 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3317 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3319 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3322 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3323 /* work around hardware counting issue */
3324 adapter->stats.gprc -= missed_rx;
3326 /* 82598 hardware only has a 32 bit counter in the high register */
3327 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3328 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3329 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3330 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3331 adapter->stats.bprc += bprc;
3332 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3333 adapter->stats.mprc -= bprc;
3334 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3335 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3336 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3337 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3338 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3339 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3340 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
3341 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3342 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3343 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3344 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3345 adapter->stats.lxontxc += lxon;
3346 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3347 adapter->stats.lxofftxc += lxoff;
3348 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3349 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
3350 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3352 * 82598 errata - tx of flow control packets is included in tx counters
3354 xon_off_tot = lxon + lxoff;
3355 adapter->stats.gptc -= xon_off_tot;
3356 adapter->stats.mptc -= xon_off_tot;
3357 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
3358 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3359 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3360 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
3361 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3362 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
3363 adapter->stats.ptc64 -= xon_off_tot;
3364 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3365 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3366 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3367 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3368 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
3369 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3371 /* Fill out the OS statistics structure */
3372 adapter->net_stats.multicast = adapter->stats.mprc;
3375 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
3376 adapter->stats.rlec;
3377 adapter->net_stats.rx_dropped = 0;
3378 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3379 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3380 adapter->net_stats.rx_missed_errors = total_mpc;
3384 * ixgbe_watchdog - Timer Call-back
3385 * @data: pointer to adapter cast into an unsigned long
3387 static void ixgbe_watchdog(unsigned long data)
3389 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3390 struct ixgbe_hw *hw = &adapter->hw;
3392 /* Do the watchdog outside of interrupt context due to the lovely
3393 * delays that some of the newer hardware requires */
3394 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3395 /* Cause software interrupt to ensure rx rings are cleaned */
3396 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3398 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3399 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3401 /* For legacy and MSI interrupts don't set any bits that
3402 * are enabled for EIAM, because this operation would
3403 * set *both* EIMS and EICS for any bit in EIAM */
3404 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3405 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3407 /* Reset the timer */
3408 mod_timer(&adapter->watchdog_timer,
3409 round_jiffies(jiffies + 2 * HZ));
3412 schedule_work(&adapter->watchdog_task);
3416 * ixgbe_watchdog_task - worker thread to bring link up
3417 * @work: pointer to work_struct containing our data
3419 static void ixgbe_watchdog_task(struct work_struct *work)
3421 struct ixgbe_adapter *adapter = container_of(work,
3422 struct ixgbe_adapter,
3424 struct net_device *netdev = adapter->netdev;
3425 struct ixgbe_hw *hw = &adapter->hw;
3426 u32 link_speed = adapter->link_speed;
3427 bool link_up = adapter->link_up;
3429 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3431 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3432 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3434 time_after(jiffies, (adapter->link_check_timeout +
3435 IXGBE_TRY_LINK_TIMEOUT))) {
3436 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3437 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3439 adapter->link_up = link_up;
3440 adapter->link_speed = link_speed;
3444 if (!netif_carrier_ok(netdev)) {
3445 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3446 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
3447 #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3448 #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
3449 DPRINTK(LINK, INFO, "NIC Link is Up %s, "
3450 "Flow Control: %s\n",
3451 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3453 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3454 "1 Gbps" : "unknown speed")),
3455 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3457 (FLOW_TX ? "TX" : "None"))));
3459 netif_carrier_on(netdev);
3460 netif_tx_wake_all_queues(netdev);
3462 /* Force detection of hung controller */
3463 adapter->detect_tx_hung = true;
3466 adapter->link_up = false;
3467 adapter->link_speed = 0;
3468 if (netif_carrier_ok(netdev)) {
3469 DPRINTK(LINK, INFO, "NIC Link is Down\n");
3470 netif_carrier_off(netdev);
3471 netif_tx_stop_all_queues(netdev);
3475 ixgbe_update_stats(adapter);
3476 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
3479 static int ixgbe_tso(struct ixgbe_adapter *adapter,
3480 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3481 u32 tx_flags, u8 *hdr_len)
3483 struct ixgbe_adv_tx_context_desc *context_desc;
3486 struct ixgbe_tx_buffer *tx_buffer_info;
3487 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3488 u32 mss_l4len_idx, l4len;
3490 if (skb_is_gso(skb)) {
3491 if (skb_header_cloned(skb)) {
3492 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3496 l4len = tcp_hdrlen(skb);
3499 if (skb->protocol == htons(ETH_P_IP)) {
3500 struct iphdr *iph = ip_hdr(skb);
3503 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3507 adapter->hw_tso_ctxt++;
3508 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3509 ipv6_hdr(skb)->payload_len = 0;
3510 tcp_hdr(skb)->check =
3511 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3512 &ipv6_hdr(skb)->daddr,
3514 adapter->hw_tso6_ctxt++;
3517 i = tx_ring->next_to_use;
3519 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3520 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3522 /* VLAN MACLEN IPLEN */
3523 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3525 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3526 vlan_macip_lens |= ((skb_network_offset(skb)) <<
3527 IXGBE_ADVTXD_MACLEN_SHIFT);
3528 *hdr_len += skb_network_offset(skb);
3530 (skb_transport_header(skb) - skb_network_header(skb));
3532 (skb_transport_header(skb) - skb_network_header(skb));
3533 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3534 context_desc->seqnum_seed = 0;
3536 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
3537 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
3538 IXGBE_ADVTXD_DTYP_CTXT);
3540 if (skb->protocol == htons(ETH_P_IP))
3541 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3542 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3543 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3547 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3548 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
3549 /* use index 1 for TSO */
3550 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3551 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3553 tx_buffer_info->time_stamp = jiffies;
3554 tx_buffer_info->next_to_watch = i;
3557 if (i == tx_ring->count)
3559 tx_ring->next_to_use = i;
3566 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
3567 struct ixgbe_ring *tx_ring,
3568 struct sk_buff *skb, u32 tx_flags)
3570 struct ixgbe_adv_tx_context_desc *context_desc;
3572 struct ixgbe_tx_buffer *tx_buffer_info;
3573 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3575 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3576 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3577 i = tx_ring->next_to_use;
3578 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3579 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3581 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3583 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3584 vlan_macip_lens |= (skb_network_offset(skb) <<
3585 IXGBE_ADVTXD_MACLEN_SHIFT);
3586 if (skb->ip_summed == CHECKSUM_PARTIAL)
3587 vlan_macip_lens |= (skb_transport_header(skb) -
3588 skb_network_header(skb));
3590 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3591 context_desc->seqnum_seed = 0;
3593 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
3594 IXGBE_ADVTXD_DTYP_CTXT);
3596 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3597 switch (skb->protocol) {
3598 case __constant_htons(ETH_P_IP):
3599 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3600 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3602 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3604 case __constant_htons(ETH_P_IPV6):
3605 /* XXX what about other V6 headers?? */
3606 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3608 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3611 if (unlikely(net_ratelimit())) {
3612 DPRINTK(PROBE, WARNING,
3613 "partial checksum but proto=%x!\n",
3620 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3621 /* use index zero for tx checksum offload */
3622 context_desc->mss_l4len_idx = 0;
3624 tx_buffer_info->time_stamp = jiffies;
3625 tx_buffer_info->next_to_watch = i;
3627 adapter->hw_csum_tx_good++;
3629 if (i == tx_ring->count)
3631 tx_ring->next_to_use = i;
3639 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
3640 struct ixgbe_ring *tx_ring,
3641 struct sk_buff *skb, unsigned int first)
3643 struct ixgbe_tx_buffer *tx_buffer_info;
3644 unsigned int len = skb->len;
3645 unsigned int offset = 0, size, count = 0, i;
3646 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3649 len -= skb->data_len;
3651 i = tx_ring->next_to_use;
3654 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3655 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3657 tx_buffer_info->length = size;
3658 tx_buffer_info->dma = pci_map_single(adapter->pdev,
3660 size, PCI_DMA_TODEVICE);
3661 tx_buffer_info->time_stamp = jiffies;
3662 tx_buffer_info->next_to_watch = i;
3668 if (i == tx_ring->count)
3672 for (f = 0; f < nr_frags; f++) {
3673 struct skb_frag_struct *frag;
3675 frag = &skb_shinfo(skb)->frags[f];
3677 offset = frag->page_offset;
3680 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3681 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3683 tx_buffer_info->length = size;
3684 tx_buffer_info->dma = pci_map_page(adapter->pdev,
3689 tx_buffer_info->time_stamp = jiffies;
3690 tx_buffer_info->next_to_watch = i;
3696 if (i == tx_ring->count)
3701 i = tx_ring->count - 1;
3704 tx_ring->tx_buffer_info[i].skb = skb;
3705 tx_ring->tx_buffer_info[first].next_to_watch = i;
3710 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
3711 struct ixgbe_ring *tx_ring,
3712 int tx_flags, int count, u32 paylen, u8 hdr_len)
3714 union ixgbe_adv_tx_desc *tx_desc = NULL;
3715 struct ixgbe_tx_buffer *tx_buffer_info;
3716 u32 olinfo_status = 0, cmd_type_len = 0;
3718 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3720 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3722 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3724 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3725 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3727 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3728 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3730 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3731 IXGBE_ADVTXD_POPTS_SHIFT;
3733 /* use index 1 context for tso */
3734 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3735 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3736 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
3737 IXGBE_ADVTXD_POPTS_SHIFT;
3739 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3740 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3741 IXGBE_ADVTXD_POPTS_SHIFT;
3743 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3745 i = tx_ring->next_to_use;
3747 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3748 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3749 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3750 tx_desc->read.cmd_type_len =
3751 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3752 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3754 if (i == tx_ring->count)
3758 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3761 * Force memory writes to complete before letting h/w
3762 * know there are new descriptors to fetch. (Only
3763 * applicable for weak-ordered memory model archs,
3768 tx_ring->next_to_use = i;
3769 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3772 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
3773 struct ixgbe_ring *tx_ring, int size)
3775 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3777 netif_stop_subqueue(netdev, tx_ring->queue_index);
3778 /* Herbert's original patch had:
3779 * smp_mb__after_netif_stop_queue();
3780 * but since that doesn't exist yet, just open code it. */
3783 /* We need to check again in a case another CPU has just
3784 * made room available. */
3785 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3788 /* A reprieve! - use start_queue because it doesn't call schedule */
3789 netif_start_subqueue(netdev, tx_ring->queue_index);
3790 ++adapter->restart_queue;
3794 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
3795 struct ixgbe_ring *tx_ring, int size)
3797 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3799 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3802 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3804 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3805 struct ixgbe_ring *tx_ring;
3807 unsigned int tx_flags = 0;
3813 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
3814 tx_ring = &adapter->tx_ring[r_idx];
3816 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3817 tx_flags |= vlan_tx_tag_get(skb);
3818 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3819 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3820 tx_flags |= (skb->queue_mapping << 13);
3822 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3823 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3824 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3825 tx_flags |= (skb->queue_mapping << 13);
3826 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3827 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3829 /* three things can cause us to need a context descriptor */
3830 if (skb_is_gso(skb) ||
3831 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3832 (tx_flags & IXGBE_TX_FLAGS_VLAN))
3835 count += TXD_USE_COUNT(skb_headlen(skb));
3836 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
3837 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3839 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
3841 return NETDEV_TX_BUSY;
3844 if (skb->protocol == htons(ETH_P_IP))
3845 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3846 first = tx_ring->next_to_use;
3847 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3849 dev_kfree_skb_any(skb);
3850 return NETDEV_TX_OK;
3854 tx_flags |= IXGBE_TX_FLAGS_TSO;
3855 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
3856 (skb->ip_summed == CHECKSUM_PARTIAL))
3857 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3859 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
3860 ixgbe_tx_map(adapter, tx_ring, skb, first),
3863 netdev->trans_start = jiffies;
3865 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
3867 return NETDEV_TX_OK;
3871 * ixgbe_get_stats - Get System Network Statistics
3872 * @netdev: network interface device structure
3874 * Returns the address of the device statistics structure.
3875 * The statistics are actually updated from the timer callback.
3877 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3879 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3881 /* only return the current stats */
3882 return &adapter->net_stats;
3886 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3887 * @netdev: network interface device structure
3888 * @p: pointer to an address structure
3890 * Returns 0 on success, negative on failure
3892 static int ixgbe_set_mac(struct net_device *netdev, void *p)
3894 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3895 struct ixgbe_hw *hw = &adapter->hw;
3896 struct sockaddr *addr = p;
3898 if (!is_valid_ether_addr(addr->sa_data))
3899 return -EADDRNOTAVAIL;
3901 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3902 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
3904 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
3909 #ifdef CONFIG_NET_POLL_CONTROLLER
3911 * Polling 'interrupt' - used by things like netconsole to send skbs
3912 * without having to re-enable interrupts. It's not called while
3913 * the interrupt routine is executing.
3915 static void ixgbe_netpoll(struct net_device *netdev)
3917 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3919 disable_irq(adapter->pdev->irq);
3920 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3921 ixgbe_intr(adapter->pdev->irq, netdev);
3922 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3923 enable_irq(adapter->pdev->irq);
3928 * ixgbe_link_config - set up initial link with default speed and duplex
3929 * @hw: pointer to private hardware struct
3931 * Returns 0 on success, negative on failure
3933 static int ixgbe_link_config(struct ixgbe_hw *hw)
3935 u32 autoneg = IXGBE_LINK_SPEED_10GB_FULL;
3937 /* must always autoneg for both 1G and 10G link */
3938 hw->mac.autoneg = true;
3940 if ((hw->mac.type == ixgbe_mac_82598EB) &&
3941 (hw->phy.media_type == ixgbe_media_type_copper))
3942 autoneg = IXGBE_LINK_SPEED_82598_AUTONEG;
3944 return hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3947 static const struct net_device_ops ixgbe_netdev_ops = {
3948 .ndo_open = ixgbe_open,
3949 .ndo_stop = ixgbe_close,
3950 .ndo_start_xmit = ixgbe_xmit_frame,
3951 .ndo_get_stats = ixgbe_get_stats,
3952 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3953 .ndo_validate_addr = eth_validate_addr,
3954 .ndo_set_mac_address = ixgbe_set_mac,
3955 .ndo_change_mtu = ixgbe_change_mtu,
3956 .ndo_tx_timeout = ixgbe_tx_timeout,
3957 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3958 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3959 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3960 #ifdef CONFIG_NET_POLL_CONTROLLER
3961 .ndo_poll_controller = ixgbe_netpoll,
3966 * ixgbe_probe - Device Initialization Routine
3967 * @pdev: PCI device information struct
3968 * @ent: entry in ixgbe_pci_tbl
3970 * Returns 0 on success, negative on failure
3972 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3973 * The OS initialization, configuring of the adapter private structure,
3974 * and a hardware reset occur.
3976 static int __devinit ixgbe_probe(struct pci_dev *pdev,
3977 const struct pci_device_id *ent)
3979 struct net_device *netdev;
3980 struct ixgbe_adapter *adapter = NULL;
3981 struct ixgbe_hw *hw;
3982 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
3983 static int cards_found;
3984 int i, err, pci_using_dac;
3985 u16 link_status, link_speed, link_width;
3988 err = pci_enable_device(pdev);
3992 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3993 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3996 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3998 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4000 dev_err(&pdev->dev, "No usable DMA "
4001 "configuration, aborting\n");
4008 err = pci_request_regions(pdev, ixgbe_driver_name);
4010 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4014 pci_set_master(pdev);
4015 pci_save_state(pdev);
4017 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
4020 goto err_alloc_etherdev;
4023 SET_NETDEV_DEV(netdev, &pdev->dev);
4025 pci_set_drvdata(pdev, netdev);
4026 adapter = netdev_priv(netdev);
4028 adapter->netdev = netdev;
4029 adapter->pdev = pdev;
4032 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4034 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4035 pci_resource_len(pdev, 0));
4041 for (i = 1; i <= 5; i++) {
4042 if (pci_resource_len(pdev, i) == 0)
4046 netdev->netdev_ops = &ixgbe_netdev_ops;
4047 ixgbe_set_ethtool_ops(netdev);
4048 netdev->watchdog_timeo = 5 * HZ;
4049 strcpy(netdev->name, pci_name(pdev));
4051 adapter->bd_number = cards_found;
4054 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
4055 hw->mac.type = ii->mac;
4058 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4059 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4060 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4061 if (!(eec & (1 << 8)))
4062 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4065 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
4066 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4068 /* set up this timer and work struct before calling get_invariants
4069 * which might start the timer
4071 init_timer(&adapter->sfp_timer);
4072 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4073 adapter->sfp_timer.data = (unsigned long) adapter;
4075 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
4077 err = ii->get_invariants(hw);
4078 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4079 /* start a kernel thread to watch for a module to arrive */
4080 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4081 mod_timer(&adapter->sfp_timer,
4082 round_jiffies(jiffies + (2 * HZ)));
4084 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4085 DPRINTK(PROBE, ERR, "failed to load because an "
4086 "unsupported SFP+ module type was detected.\n");
4092 /* setup the private structure */
4093 err = ixgbe_sw_init(adapter);
4097 /* reset_hw fills in the perm_addr as well */
4098 err = hw->mac.ops.reset_hw(hw);
4100 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4104 netdev->features = NETIF_F_SG |
4106 NETIF_F_HW_VLAN_TX |
4107 NETIF_F_HW_VLAN_RX |
4108 NETIF_F_HW_VLAN_FILTER;
4110 netdev->features |= NETIF_F_IPV6_CSUM;
4111 netdev->features |= NETIF_F_TSO;
4112 netdev->features |= NETIF_F_TSO6;
4113 netdev->features |= NETIF_F_LRO;
4115 netdev->vlan_features |= NETIF_F_TSO;
4116 netdev->vlan_features |= NETIF_F_TSO6;
4117 netdev->vlan_features |= NETIF_F_IP_CSUM;
4118 netdev->vlan_features |= NETIF_F_SG;
4120 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4121 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4123 #ifdef CONFIG_IXGBE_DCBNL
4124 netdev->dcbnl_ops = &dcbnl_ops;
4128 netdev->features |= NETIF_F_HIGHDMA;
4130 /* make sure the EEPROM is good */
4131 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
4132 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4137 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4138 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4140 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4141 dev_err(&pdev->dev, "invalid MAC address\n");
4146 init_timer(&adapter->watchdog_timer);
4147 adapter->watchdog_timer.function = &ixgbe_watchdog;
4148 adapter->watchdog_timer.data = (unsigned long)adapter;
4150 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
4151 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
4153 err = ixgbe_init_interrupt_scheme(adapter);
4157 /* print bus type/speed/width info */
4158 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4159 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4160 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
4161 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
4162 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4163 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4165 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4166 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4167 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4168 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4171 ixgbe_read_pba_num_generic(hw, &part_num);
4172 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4173 hw->mac.type, hw->phy.type,
4174 (part_num >> 8), (part_num & 0xff));
4176 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4177 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
4178 "this card is not sufficient for optimal "
4180 dev_warn(&pdev->dev, "For optimal performance a x8 "
4181 "PCI-Express slot is required.\n");
4184 /* reset the hardware with the new settings */
4185 hw->mac.ops.start_hw(hw);
4187 /* link_config depends on start_hw being called at least once */
4188 err = ixgbe_link_config(hw);
4190 dev_err(&pdev->dev, "setup_link_speed FAILED %d\n", err);
4194 netif_carrier_off(netdev);
4195 netif_tx_stop_all_queues(netdev);
4197 ixgbe_napi_add_all(adapter);
4199 strcpy(netdev->name, "eth%d");
4200 err = register_netdev(netdev);
4204 #ifdef CONFIG_IXGBE_DCA
4205 if (dca_add_requester(&pdev->dev) == 0) {
4206 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4207 /* always use CB2 mode, difference is masked
4208 * in the CB driver */
4209 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4210 ixgbe_setup_dca(adapter);
4214 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4219 ixgbe_release_hw_control(adapter);
4222 ixgbe_reset_interrupt_capability(adapter);
4224 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4225 del_timer_sync(&adapter->sfp_timer);
4226 cancel_work_sync(&adapter->sfp_task);
4227 iounmap(hw->hw_addr);
4229 free_netdev(netdev);
4231 pci_release_regions(pdev);
4234 pci_disable_device(pdev);
4239 * ixgbe_remove - Device Removal Routine
4240 * @pdev: PCI device information struct
4242 * ixgbe_remove is called by the PCI subsystem to alert the driver
4243 * that it should release a PCI device. The could be caused by a
4244 * Hot-Plug event, or because the driver is going to be removed from
4247 static void __devexit ixgbe_remove(struct pci_dev *pdev)
4249 struct net_device *netdev = pci_get_drvdata(pdev);
4250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4252 set_bit(__IXGBE_DOWN, &adapter->state);
4253 /* clear the module not found bit to make sure the worker won't
4256 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4257 del_timer_sync(&adapter->watchdog_timer);
4259 del_timer_sync(&adapter->sfp_timer);
4260 cancel_work_sync(&adapter->watchdog_task);
4261 cancel_work_sync(&adapter->sfp_task);
4262 flush_scheduled_work();
4264 #ifdef CONFIG_IXGBE_DCA
4265 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4266 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4267 dca_remove_requester(&pdev->dev);
4268 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4272 if (netdev->reg_state == NETREG_REGISTERED)
4273 unregister_netdev(netdev);
4275 ixgbe_reset_interrupt_capability(adapter);
4277 ixgbe_release_hw_control(adapter);
4279 iounmap(adapter->hw.hw_addr);
4280 pci_release_regions(pdev);
4282 DPRINTK(PROBE, INFO, "complete\n");
4283 ixgbe_napi_del_all(adapter);
4284 kfree(adapter->tx_ring);
4285 kfree(adapter->rx_ring);
4287 free_netdev(netdev);
4289 pci_disable_device(pdev);
4293 * ixgbe_io_error_detected - called when PCI error is detected
4294 * @pdev: Pointer to PCI device
4295 * @state: The current pci connection state
4297 * This function is called after a PCI bus error affecting
4298 * this device has been detected.
4300 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
4301 pci_channel_state_t state)
4303 struct net_device *netdev = pci_get_drvdata(pdev);
4304 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4306 netif_device_detach(netdev);
4308 if (netif_running(netdev))
4309 ixgbe_down(adapter);
4310 pci_disable_device(pdev);
4312 /* Request a slot reset. */
4313 return PCI_ERS_RESULT_NEED_RESET;
4317 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4318 * @pdev: Pointer to PCI device
4320 * Restart the card from scratch, as if from a cold-boot.
4322 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4324 struct net_device *netdev = pci_get_drvdata(pdev);
4325 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4327 if (pci_enable_device(pdev)) {
4329 "Cannot re-enable PCI device after reset.\n");
4330 return PCI_ERS_RESULT_DISCONNECT;
4332 pci_set_master(pdev);
4333 pci_restore_state(pdev);
4335 pci_enable_wake(pdev, PCI_D3hot, 0);
4336 pci_enable_wake(pdev, PCI_D3cold, 0);
4338 ixgbe_reset(adapter);
4340 return PCI_ERS_RESULT_RECOVERED;
4344 * ixgbe_io_resume - called when traffic can start flowing again.
4345 * @pdev: Pointer to PCI device
4347 * This callback is called when the error recovery driver tells us that
4348 * its OK to resume normal operation.
4350 static void ixgbe_io_resume(struct pci_dev *pdev)
4352 struct net_device *netdev = pci_get_drvdata(pdev);
4353 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4355 if (netif_running(netdev)) {
4356 if (ixgbe_up(adapter)) {
4357 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4362 netif_device_attach(netdev);
4365 static struct pci_error_handlers ixgbe_err_handler = {
4366 .error_detected = ixgbe_io_error_detected,
4367 .slot_reset = ixgbe_io_slot_reset,
4368 .resume = ixgbe_io_resume,
4371 static struct pci_driver ixgbe_driver = {
4372 .name = ixgbe_driver_name,
4373 .id_table = ixgbe_pci_tbl,
4374 .probe = ixgbe_probe,
4375 .remove = __devexit_p(ixgbe_remove),
4377 .suspend = ixgbe_suspend,
4378 .resume = ixgbe_resume,
4380 .shutdown = ixgbe_shutdown,
4381 .err_handler = &ixgbe_err_handler
4385 * ixgbe_init_module - Driver Registration Routine
4387 * ixgbe_init_module is the first routine called when the driver is
4388 * loaded. All it does is register with the PCI subsystem.
4390 static int __init ixgbe_init_module(void)
4393 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4394 ixgbe_driver_string, ixgbe_driver_version);
4396 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4398 #ifdef CONFIG_IXGBE_DCA
4399 dca_register_notify(&dca_notifier);
4402 ret = pci_register_driver(&ixgbe_driver);
4406 module_init(ixgbe_init_module);
4409 * ixgbe_exit_module - Driver Exit Cleanup Routine
4411 * ixgbe_exit_module is called just before the driver is removed
4414 static void __exit ixgbe_exit_module(void)
4416 #ifdef CONFIG_IXGBE_DCA
4417 dca_unregister_notify(&dca_notifier);
4419 pci_unregister_driver(&ixgbe_driver);
4422 #ifdef CONFIG_IXGBE_DCA
4423 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
4428 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
4429 __ixgbe_notify_dca);
4431 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4433 #endif /* CONFIG_IXGBE_DCA */
4435 module_exit(ixgbe_exit_module);