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 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
322 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
323 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
324 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
330 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
331 struct ixgbe_ring *tx_ring)
335 int q = tx_ring - adapter->tx_ring;
337 if (tx_ring->cpu != cpu) {
338 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
339 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
340 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
341 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
342 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
348 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
352 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
355 for (i = 0; i < adapter->num_tx_queues; i++) {
356 adapter->tx_ring[i].cpu = -1;
357 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
359 for (i = 0; i < adapter->num_rx_queues; i++) {
360 adapter->rx_ring[i].cpu = -1;
361 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
365 static int __ixgbe_notify_dca(struct device *dev, void *data)
367 struct net_device *netdev = dev_get_drvdata(dev);
368 struct ixgbe_adapter *adapter = netdev_priv(netdev);
369 unsigned long event = *(unsigned long *)data;
372 case DCA_PROVIDER_ADD:
373 /* if we're already enabled, don't do it again */
374 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
376 /* Always use CB2 mode, difference is masked
377 * in the CB driver. */
378 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
379 if (dca_add_requester(dev) == 0) {
380 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
381 ixgbe_setup_dca(adapter);
384 /* Fall Through since DCA is disabled. */
385 case DCA_PROVIDER_REMOVE:
386 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
387 dca_remove_requester(dev);
388 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
389 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
397 #endif /* CONFIG_IXGBE_DCA */
399 * ixgbe_receive_skb - Send a completed packet up the stack
400 * @adapter: board private structure
401 * @skb: packet to send up
402 * @status: hardware indication of status of receive
403 * @rx_ring: rx descriptor ring (for a specific queue) to setup
404 * @rx_desc: rx descriptor
406 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
407 struct sk_buff *skb, u8 status,
408 union ixgbe_adv_rx_desc *rx_desc)
410 struct ixgbe_adapter *adapter = q_vector->adapter;
411 struct napi_struct *napi = &q_vector->napi;
412 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
413 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
415 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
416 if (adapter->vlgrp && is_vlan && (tag != 0))
417 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
419 napi_gro_receive(napi, skb);
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;
483 i = rx_ring->next_to_use;
484 bi = &rx_ring->rx_buffer_info[i];
486 while (cleaned_count--) {
487 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
490 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
492 bi->page = alloc_page(GFP_ATOMIC);
494 adapter->alloc_rx_page_failed++;
499 /* use a half page if we're re-using */
500 bi->page_offset ^= (PAGE_SIZE / 2);
503 bi->page_dma = pci_map_page(pdev, bi->page,
511 skb = netdev_alloc_skb(adapter->netdev,
512 (rx_ring->rx_buf_len +
516 adapter->alloc_rx_buff_failed++;
521 * Make buffer alignment 2 beyond a 16 byte boundary
522 * this will result in a 16 byte aligned IP header after
523 * the 14 byte MAC header is removed
525 skb_reserve(skb, NET_IP_ALIGN);
528 bi->dma = pci_map_single(pdev, skb->data,
532 /* Refresh the desc even if buffer_addrs didn't change because
533 * each write-back erases this info. */
534 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
535 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
536 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
538 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
542 if (i == rx_ring->count)
544 bi = &rx_ring->rx_buffer_info[i];
548 if (rx_ring->next_to_use != i) {
549 rx_ring->next_to_use = i;
551 i = (rx_ring->count - 1);
554 * Force memory writes to complete before letting h/w
555 * know there are new descriptors to fetch. (Only
556 * applicable for weak-ordered memory model archs,
560 writel(i, adapter->hw.hw_addr + rx_ring->tail);
564 static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
566 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
569 static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
571 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
574 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
575 struct ixgbe_ring *rx_ring,
576 int *work_done, int work_to_do)
578 struct ixgbe_adapter *adapter = q_vector->adapter;
579 struct pci_dev *pdev = adapter->pdev;
580 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
581 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
586 bool cleaned = false;
587 int cleaned_count = 0;
588 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
590 i = rx_ring->next_to_clean;
591 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
592 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
593 rx_buffer_info = &rx_ring->rx_buffer_info[i];
595 while (staterr & IXGBE_RXD_STAT_DD) {
597 if (*work_done >= work_to_do)
601 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
602 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
603 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
604 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
605 if (hdr_info & IXGBE_RXDADV_SPH)
606 adapter->rx_hdr_split++;
607 if (len > IXGBE_RX_HDR_SIZE)
608 len = IXGBE_RX_HDR_SIZE;
609 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
611 len = le16_to_cpu(rx_desc->wb.upper.length);
615 skb = rx_buffer_info->skb;
616 prefetch(skb->data - NET_IP_ALIGN);
617 rx_buffer_info->skb = NULL;
619 if (len && !skb_shinfo(skb)->nr_frags) {
620 pci_unmap_single(pdev, rx_buffer_info->dma,
627 pci_unmap_page(pdev, rx_buffer_info->page_dma,
628 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
629 rx_buffer_info->page_dma = 0;
630 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
631 rx_buffer_info->page,
632 rx_buffer_info->page_offset,
635 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
636 (page_count(rx_buffer_info->page) != 1))
637 rx_buffer_info->page = NULL;
639 get_page(rx_buffer_info->page);
641 skb->len += upper_len;
642 skb->data_len += upper_len;
643 skb->truesize += upper_len;
647 if (i == rx_ring->count)
649 next_buffer = &rx_ring->rx_buffer_info[i];
651 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
655 if (staterr & IXGBE_RXD_STAT_EOP) {
656 rx_ring->stats.packets++;
657 rx_ring->stats.bytes += skb->len;
659 rx_buffer_info->skb = next_buffer->skb;
660 rx_buffer_info->dma = next_buffer->dma;
661 next_buffer->skb = skb;
662 next_buffer->dma = 0;
663 adapter->non_eop_descs++;
667 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
668 dev_kfree_skb_irq(skb);
672 ixgbe_rx_checksum(adapter, staterr, skb);
674 /* probably a little skewed due to removing CRC */
675 total_rx_bytes += skb->len;
678 skb->protocol = eth_type_trans(skb, adapter->netdev);
679 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
682 rx_desc->wb.upper.status_error = 0;
684 /* return some buffers to hardware, one at a time is too slow */
685 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
686 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
690 /* use prefetched values */
692 rx_buffer_info = next_buffer;
694 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
697 rx_ring->next_to_clean = i;
698 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
701 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
703 rx_ring->total_packets += total_rx_packets;
704 rx_ring->total_bytes += total_rx_bytes;
705 adapter->net_stats.rx_bytes += total_rx_bytes;
706 adapter->net_stats.rx_packets += total_rx_packets;
711 static int ixgbe_clean_rxonly(struct napi_struct *, int);
713 * ixgbe_configure_msix - Configure MSI-X hardware
714 * @adapter: board private structure
716 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
719 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
721 struct ixgbe_q_vector *q_vector;
722 int i, j, q_vectors, v_idx, r_idx;
725 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
727 /* Populate the IVAR table and set the ITR values to the
728 * corresponding register.
730 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
731 q_vector = &adapter->q_vector[v_idx];
732 /* XXX for_each_bit(...) */
733 r_idx = find_first_bit(q_vector->rxr_idx,
734 adapter->num_rx_queues);
736 for (i = 0; i < q_vector->rxr_count; i++) {
737 j = adapter->rx_ring[r_idx].reg_idx;
738 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
739 r_idx = find_next_bit(q_vector->rxr_idx,
740 adapter->num_rx_queues,
743 r_idx = find_first_bit(q_vector->txr_idx,
744 adapter->num_tx_queues);
746 for (i = 0; i < q_vector->txr_count; i++) {
747 j = adapter->tx_ring[r_idx].reg_idx;
748 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
749 r_idx = find_next_bit(q_vector->txr_idx,
750 adapter->num_tx_queues,
754 /* if this is a tx only vector halve the interrupt rate */
755 if (q_vector->txr_count && !q_vector->rxr_count)
756 q_vector->eitr = (adapter->eitr_param >> 1);
759 q_vector->eitr = adapter->eitr_param;
761 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
762 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
765 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
766 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
768 /* set up to autoclear timer, and the vectors */
769 mask = IXGBE_EIMS_ENABLE_MASK;
770 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
771 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
778 latency_invalid = 255
782 * ixgbe_update_itr - update the dynamic ITR value based on statistics
783 * @adapter: pointer to adapter
784 * @eitr: eitr setting (ints per sec) to give last timeslice
785 * @itr_setting: current throttle rate in ints/second
786 * @packets: the number of packets during this measurement interval
787 * @bytes: the number of bytes during this measurement interval
789 * Stores a new ITR value based on packets and byte
790 * counts during the last interrupt. The advantage of per interrupt
791 * computation is faster updates and more accurate ITR for the current
792 * traffic pattern. Constants in this function were computed
793 * based on theoretical maximum wire speed and thresholds were set based
794 * on testing data as well as attempting to minimize response time
795 * while increasing bulk throughput.
796 * this functionality is controlled by the InterruptThrottleRate module
797 * parameter (see ixgbe_param.c)
799 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
800 u32 eitr, u8 itr_setting,
801 int packets, int bytes)
803 unsigned int retval = itr_setting;
808 goto update_itr_done;
811 /* simple throttlerate management
812 * 0-20MB/s lowest (100000 ints/s)
813 * 20-100MB/s low (20000 ints/s)
814 * 100-1249MB/s bulk (8000 ints/s)
816 /* what was last interrupt timeslice? */
817 timepassed_us = 1000000/eitr;
818 bytes_perint = bytes / timepassed_us; /* bytes/usec */
820 switch (itr_setting) {
822 if (bytes_perint > adapter->eitr_low)
823 retval = low_latency;
826 if (bytes_perint > adapter->eitr_high)
827 retval = bulk_latency;
828 else if (bytes_perint <= adapter->eitr_low)
829 retval = lowest_latency;
832 if (bytes_perint <= adapter->eitr_high)
833 retval = low_latency;
841 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
843 struct ixgbe_adapter *adapter = q_vector->adapter;
844 struct ixgbe_hw *hw = &adapter->hw;
846 u8 current_itr, ret_itr;
847 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
848 sizeof(struct ixgbe_q_vector);
849 struct ixgbe_ring *rx_ring, *tx_ring;
851 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
852 for (i = 0; i < q_vector->txr_count; i++) {
853 tx_ring = &(adapter->tx_ring[r_idx]);
854 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
856 tx_ring->total_packets,
857 tx_ring->total_bytes);
858 /* if the result for this queue would decrease interrupt
859 * rate for this vector then use that result */
860 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
861 q_vector->tx_itr - 1 : ret_itr);
862 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
866 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
867 for (i = 0; i < q_vector->rxr_count; i++) {
868 rx_ring = &(adapter->rx_ring[r_idx]);
869 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
871 rx_ring->total_packets,
872 rx_ring->total_bytes);
873 /* if the result for this queue would decrease interrupt
874 * rate for this vector then use that result */
875 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
876 q_vector->rx_itr - 1 : ret_itr);
877 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
881 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
883 switch (current_itr) {
884 /* counts and packets in update_itr are dependent on these numbers */
889 new_itr = 20000; /* aka hwitr = ~200 */
897 if (new_itr != q_vector->eitr) {
899 /* do an exponential smoothing */
900 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
901 q_vector->eitr = new_itr;
902 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
903 /* must write high and low 16 bits to reset counter */
904 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
906 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
912 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
914 struct ixgbe_hw *hw = &adapter->hw;
916 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
917 (eicr & IXGBE_EICR_GPI_SDP1)) {
918 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
919 /* write to clear the interrupt */
920 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
924 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
926 struct ixgbe_hw *hw = &adapter->hw;
929 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
930 adapter->link_check_timeout = jiffies;
931 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
932 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
933 schedule_work(&adapter->watchdog_task);
937 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
939 struct net_device *netdev = data;
940 struct ixgbe_adapter *adapter = netdev_priv(netdev);
941 struct ixgbe_hw *hw = &adapter->hw;
942 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
944 if (eicr & IXGBE_EICR_LSC)
945 ixgbe_check_lsc(adapter);
947 ixgbe_check_fan_failure(adapter, eicr);
949 if (!test_bit(__IXGBE_DOWN, &adapter->state))
950 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
955 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
957 struct ixgbe_q_vector *q_vector = data;
958 struct ixgbe_adapter *adapter = q_vector->adapter;
959 struct ixgbe_ring *tx_ring;
962 if (!q_vector->txr_count)
965 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
966 for (i = 0; i < q_vector->txr_count; i++) {
967 tx_ring = &(adapter->tx_ring[r_idx]);
968 #ifdef CONFIG_IXGBE_DCA
969 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
970 ixgbe_update_tx_dca(adapter, tx_ring);
972 tx_ring->total_bytes = 0;
973 tx_ring->total_packets = 0;
974 ixgbe_clean_tx_irq(adapter, tx_ring);
975 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
983 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
985 * @data: pointer to our q_vector struct for this interrupt vector
987 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
989 struct ixgbe_q_vector *q_vector = data;
990 struct ixgbe_adapter *adapter = q_vector->adapter;
991 struct ixgbe_ring *rx_ring;
995 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
996 for (i = 0; i < q_vector->rxr_count; i++) {
997 rx_ring = &(adapter->rx_ring[r_idx]);
998 rx_ring->total_bytes = 0;
999 rx_ring->total_packets = 0;
1000 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1004 if (!q_vector->rxr_count)
1007 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1008 rx_ring = &(adapter->rx_ring[r_idx]);
1009 /* disable interrupts on this vector only */
1010 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
1011 napi_schedule(&q_vector->napi);
1016 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1018 ixgbe_msix_clean_rx(irq, data);
1019 ixgbe_msix_clean_tx(irq, data);
1025 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1026 * @napi: napi struct with our devices info in it
1027 * @budget: amount of work driver is allowed to do this pass, in packets
1029 * This function is optimized for cleaning one queue only on a single
1032 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1034 struct ixgbe_q_vector *q_vector =
1035 container_of(napi, struct ixgbe_q_vector, napi);
1036 struct ixgbe_adapter *adapter = q_vector->adapter;
1037 struct ixgbe_ring *rx_ring = NULL;
1041 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1042 rx_ring = &(adapter->rx_ring[r_idx]);
1043 #ifdef CONFIG_IXGBE_DCA
1044 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1045 ixgbe_update_rx_dca(adapter, rx_ring);
1048 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
1050 /* If all Rx work done, exit the polling mode */
1051 if (work_done < budget) {
1052 napi_complete(napi);
1053 if (adapter->itr_setting & 3)
1054 ixgbe_set_itr_msix(q_vector);
1055 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1056 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
1063 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1064 * @napi: napi struct with our devices info in it
1065 * @budget: amount of work driver is allowed to do this pass, in packets
1067 * This function will clean more than one rx queue associated with a
1070 static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1072 struct ixgbe_q_vector *q_vector =
1073 container_of(napi, struct ixgbe_q_vector, napi);
1074 struct ixgbe_adapter *adapter = q_vector->adapter;
1075 struct ixgbe_ring *rx_ring = NULL;
1076 int work_done = 0, i;
1078 u16 enable_mask = 0;
1080 /* attempt to distribute budget to each queue fairly, but don't allow
1081 * the budget to go below 1 because we'll exit polling */
1082 budget /= (q_vector->rxr_count ?: 1);
1083 budget = max(budget, 1);
1084 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1085 for (i = 0; i < q_vector->rxr_count; i++) {
1086 rx_ring = &(adapter->rx_ring[r_idx]);
1087 #ifdef CONFIG_IXGBE_DCA
1088 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1089 ixgbe_update_rx_dca(adapter, rx_ring);
1091 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
1092 enable_mask |= rx_ring->v_idx;
1093 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1097 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1098 rx_ring = &(adapter->rx_ring[r_idx]);
1099 /* If all Rx work done, exit the polling mode */
1100 if (work_done < budget) {
1101 napi_complete(napi);
1102 if (adapter->itr_setting & 3)
1103 ixgbe_set_itr_msix(q_vector);
1104 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1105 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1111 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
1114 a->q_vector[v_idx].adapter = a;
1115 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1116 a->q_vector[v_idx].rxr_count++;
1117 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1120 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
1123 a->q_vector[v_idx].adapter = a;
1124 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1125 a->q_vector[v_idx].txr_count++;
1126 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1130 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1131 * @adapter: board private structure to initialize
1132 * @vectors: allotted vector count for descriptor rings
1134 * This function maps descriptor rings to the queue-specific vectors
1135 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1136 * one vector per ring/queue, but on a constrained vector budget, we
1137 * group the rings as "efficiently" as possible. You would add new
1138 * mapping configurations in here.
1140 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
1144 int rxr_idx = 0, txr_idx = 0;
1145 int rxr_remaining = adapter->num_rx_queues;
1146 int txr_remaining = adapter->num_tx_queues;
1151 /* No mapping required if MSI-X is disabled. */
1152 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1156 * The ideal configuration...
1157 * We have enough vectors to map one per queue.
1159 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1160 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1161 map_vector_to_rxq(adapter, v_start, rxr_idx);
1163 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1164 map_vector_to_txq(adapter, v_start, txr_idx);
1170 * If we don't have enough vectors for a 1-to-1
1171 * mapping, we'll have to group them so there are
1172 * multiple queues per vector.
1174 /* Re-adjusting *qpv takes care of the remainder. */
1175 for (i = v_start; i < vectors; i++) {
1176 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1177 for (j = 0; j < rqpv; j++) {
1178 map_vector_to_rxq(adapter, i, rxr_idx);
1183 for (i = v_start; i < vectors; i++) {
1184 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1185 for (j = 0; j < tqpv; j++) {
1186 map_vector_to_txq(adapter, i, txr_idx);
1197 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1198 * @adapter: board private structure
1200 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1201 * interrupts from the kernel.
1203 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1205 struct net_device *netdev = adapter->netdev;
1206 irqreturn_t (*handler)(int, void *);
1207 int i, vector, q_vectors, err;
1210 /* Decrement for Other and TCP Timer vectors */
1211 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1213 /* Map the Tx/Rx rings to the vectors we were allotted. */
1214 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1218 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1219 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1220 &ixgbe_msix_clean_many)
1221 for (vector = 0; vector < q_vectors; vector++) {
1222 handler = SET_HANDLER(&adapter->q_vector[vector]);
1224 if(handler == &ixgbe_msix_clean_rx) {
1225 sprintf(adapter->name[vector], "%s-%s-%d",
1226 netdev->name, "rx", ri++);
1228 else if(handler == &ixgbe_msix_clean_tx) {
1229 sprintf(adapter->name[vector], "%s-%s-%d",
1230 netdev->name, "tx", ti++);
1233 sprintf(adapter->name[vector], "%s-%s-%d",
1234 netdev->name, "TxRx", vector);
1236 err = request_irq(adapter->msix_entries[vector].vector,
1237 handler, 0, adapter->name[vector],
1238 &(adapter->q_vector[vector]));
1241 "request_irq failed for MSIX interrupt "
1242 "Error: %d\n", err);
1243 goto free_queue_irqs;
1247 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1248 err = request_irq(adapter->msix_entries[vector].vector,
1249 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
1252 "request_irq for msix_lsc failed: %d\n", err);
1253 goto free_queue_irqs;
1259 for (i = vector - 1; i >= 0; i--)
1260 free_irq(adapter->msix_entries[--vector].vector,
1261 &(adapter->q_vector[i]));
1262 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1263 pci_disable_msix(adapter->pdev);
1264 kfree(adapter->msix_entries);
1265 adapter->msix_entries = NULL;
1270 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1272 struct ixgbe_hw *hw = &adapter->hw;
1273 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1275 u32 new_itr = q_vector->eitr;
1276 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1277 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1279 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
1281 tx_ring->total_packets,
1282 tx_ring->total_bytes);
1283 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
1285 rx_ring->total_packets,
1286 rx_ring->total_bytes);
1288 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1290 switch (current_itr) {
1291 /* counts and packets in update_itr are dependent on these numbers */
1292 case lowest_latency:
1296 new_itr = 20000; /* aka hwitr = ~200 */
1305 if (new_itr != q_vector->eitr) {
1307 /* do an exponential smoothing */
1308 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1309 q_vector->eitr = new_itr;
1310 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1311 /* must write high and low 16 bits to reset counter */
1312 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1319 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1320 * @adapter: board private structure
1322 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1324 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1325 IXGBE_WRITE_FLUSH(&adapter->hw);
1326 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1328 for (i = 0; i < adapter->num_msix_vectors; i++)
1329 synchronize_irq(adapter->msix_entries[i].vector);
1331 synchronize_irq(adapter->pdev->irq);
1336 * ixgbe_irq_enable - Enable default interrupt generation settings
1337 * @adapter: board private structure
1339 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1342 mask = IXGBE_EIMS_ENABLE_MASK;
1343 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1344 mask |= IXGBE_EIMS_GPI_SDP1;
1345 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1346 IXGBE_WRITE_FLUSH(&adapter->hw);
1350 * ixgbe_intr - legacy mode Interrupt Handler
1351 * @irq: interrupt number
1352 * @data: pointer to a network interface device structure
1354 static irqreturn_t ixgbe_intr(int irq, void *data)
1356 struct net_device *netdev = data;
1357 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1358 struct ixgbe_hw *hw = &adapter->hw;
1361 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1362 * therefore no explict interrupt disable is necessary */
1363 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1365 /* shared interrupt alert!
1366 * make sure interrupts are enabled because the read will
1367 * have disabled interrupts due to EIAM */
1368 ixgbe_irq_enable(adapter);
1369 return IRQ_NONE; /* Not our interrupt */
1372 if (eicr & IXGBE_EICR_LSC)
1373 ixgbe_check_lsc(adapter);
1375 ixgbe_check_fan_failure(adapter, eicr);
1377 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
1378 adapter->tx_ring[0].total_packets = 0;
1379 adapter->tx_ring[0].total_bytes = 0;
1380 adapter->rx_ring[0].total_packets = 0;
1381 adapter->rx_ring[0].total_bytes = 0;
1382 /* would disable interrupts here but EIAM disabled it */
1383 __napi_schedule(&adapter->q_vector[0].napi);
1389 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1391 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1393 for (i = 0; i < q_vectors; i++) {
1394 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1395 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1396 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1397 q_vector->rxr_count = 0;
1398 q_vector->txr_count = 0;
1403 * ixgbe_request_irq - initialize interrupts
1404 * @adapter: board private structure
1406 * Attempts to configure interrupts using the best available
1407 * capabilities of the hardware and kernel.
1409 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
1411 struct net_device *netdev = adapter->netdev;
1414 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1415 err = ixgbe_request_msix_irqs(adapter);
1416 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1417 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
1418 netdev->name, netdev);
1420 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
1421 netdev->name, netdev);
1425 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1430 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1432 struct net_device *netdev = adapter->netdev;
1434 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1437 q_vectors = adapter->num_msix_vectors;
1440 free_irq(adapter->msix_entries[i].vector, netdev);
1443 for (; i >= 0; i--) {
1444 free_irq(adapter->msix_entries[i].vector,
1445 &(adapter->q_vector[i]));
1448 ixgbe_reset_q_vectors(adapter);
1450 free_irq(adapter->pdev->irq, netdev);
1455 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1458 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1460 struct ixgbe_hw *hw = &adapter->hw;
1462 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
1463 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
1465 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
1466 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1468 map_vector_to_rxq(adapter, 0, 0);
1469 map_vector_to_txq(adapter, 0, 0);
1471 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
1475 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1476 * @adapter: board private structure
1478 * Configure the Tx unit of the MAC after a reset.
1480 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1483 struct ixgbe_hw *hw = &adapter->hw;
1484 u32 i, j, tdlen, txctrl;
1486 /* Setup the HW Tx Head and Tail descriptor pointers */
1487 for (i = 0; i < adapter->num_tx_queues; i++) {
1488 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1491 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1492 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
1493 (tdba & DMA_32BIT_MASK));
1494 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1496 (ring->count * sizeof(union ixgbe_adv_tx_desc));
1497 tdwba |= IXGBE_TDWBAL_HEAD_WB_ENABLE;
1498 IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(j), tdwba & DMA_32BIT_MASK);
1499 IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(j), (tdwba >> 32));
1500 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1501 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1502 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1503 adapter->tx_ring[i].head = IXGBE_TDH(j);
1504 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1505 /* Disable Tx Head Writeback RO bit, since this hoses
1506 * bookkeeping if things aren't delivered in order.
1508 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1509 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1510 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1514 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1516 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1518 struct ixgbe_ring *rx_ring;
1523 /* program one srrctl register per VMDq index */
1524 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1526 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1527 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1528 shift = find_first_bit(&mask, len);
1529 queue0 = index & mask;
1530 index = (index & mask) >> shift;
1531 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
1533 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1534 queue0 = index & mask;
1535 index = index & mask;
1538 rx_ring = &adapter->rx_ring[queue0];
1540 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1542 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1543 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1545 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1546 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1547 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1548 srrctl |= ((IXGBE_RX_HDR_SIZE <<
1549 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1550 IXGBE_SRRCTL_BSIZEHDR_MASK);
1552 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1554 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1555 srrctl |= IXGBE_RXBUFFER_2048 >>
1556 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1558 srrctl |= rx_ring->rx_buf_len >>
1559 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1561 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1564 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1565 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1568 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
1569 * @adapter: board private structure
1571 * Configure the Rx unit of the MAC after a reset.
1573 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1576 struct ixgbe_hw *hw = &adapter->hw;
1577 struct net_device *netdev = adapter->netdev;
1578 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1580 u32 rdlen, rxctrl, rxcsum;
1581 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1582 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1583 0x6A3E67EA, 0x14364D17, 0x3BED200D};
1590 /* Decide whether to use packet split mode or not */
1591 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1593 /* Set the RX buffer length according to the mode */
1594 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1595 rx_buf_len = IXGBE_RX_HDR_SIZE;
1597 if (netdev->mtu <= ETH_DATA_LEN)
1598 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1600 rx_buf_len = ALIGN(max_frame, 1024);
1603 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1604 fctrl |= IXGBE_FCTRL_BAM;
1605 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
1606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1608 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1609 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1610 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1612 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1613 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1615 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1617 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1618 /* disable receives while setting up the descriptors */
1619 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1620 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1622 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1623 * the Base and Length of the Rx Descriptor Ring */
1624 for (i = 0; i < adapter->num_rx_queues; i++) {
1625 rdba = adapter->rx_ring[i].dma;
1626 j = adapter->rx_ring[i].reg_idx;
1627 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1628 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1629 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1630 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1631 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1632 adapter->rx_ring[i].head = IXGBE_RDH(j);
1633 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1634 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
1636 ixgbe_configure_srrctl(adapter, j);
1640 * For VMDq support of different descriptor types or
1641 * buffer sizes through the use of multiple SRRCTL
1642 * registers, RDRXCTL.MVMEN must be set to 1
1644 * also, the manual doesn't mention it clearly but DCA hints
1645 * will only use queue 0's tags unless this bit is set. Side
1646 * effects of setting this bit are only that SRRCTL must be
1647 * fully programmed [0..15]
1649 if (adapter->flags &
1650 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1651 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1652 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1653 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1656 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
1657 /* Fill out redirection table */
1658 for (i = 0, j = 0; i < 128; i++, j++) {
1659 if (j == adapter->ring_feature[RING_F_RSS].indices)
1661 /* reta = 4-byte sliding window of
1662 * 0x00..(indices-1)(indices-1)00..etc. */
1663 reta = (reta << 8) | (j * 0x11);
1665 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
1668 /* Fill out hash function seeds */
1669 for (i = 0; i < 10; i++)
1670 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
1672 mrqc = IXGBE_MRQC_RSSEN
1673 /* Perform hash on these packet types */
1674 | IXGBE_MRQC_RSS_FIELD_IPV4
1675 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1676 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1677 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1678 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1679 | IXGBE_MRQC_RSS_FIELD_IPV6
1680 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1681 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1682 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
1683 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
1686 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1688 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1689 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1690 /* Disable indicating checksum in descriptor, enables
1692 rxcsum |= IXGBE_RXCSUM_PCSD;
1694 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1695 /* Enable IPv4 payload checksum for UDP fragments
1696 * if PCSD is not set */
1697 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1700 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1703 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1705 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1706 struct ixgbe_hw *hw = &adapter->hw;
1708 /* add VID to filter table */
1709 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
1712 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1714 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1715 struct ixgbe_hw *hw = &adapter->hw;
1717 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1718 ixgbe_irq_disable(adapter);
1720 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1722 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1723 ixgbe_irq_enable(adapter);
1725 /* remove VID from filter table */
1726 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
1729 static void ixgbe_vlan_rx_register(struct net_device *netdev,
1730 struct vlan_group *grp)
1732 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1735 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1736 ixgbe_irq_disable(adapter);
1737 adapter->vlgrp = grp;
1740 * For a DCB driver, always enable VLAN tag stripping so we can
1741 * still receive traffic from a DCB-enabled host even if we're
1744 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1745 ctrl |= IXGBE_VLNCTRL_VME;
1746 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1747 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1748 ixgbe_vlan_rx_add_vid(netdev, 0);
1751 /* enable VLAN tag insert/strip */
1752 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1753 ctrl |= IXGBE_VLNCTRL_VME;
1754 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1755 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1758 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1759 ixgbe_irq_enable(adapter);
1762 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1764 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1766 if (adapter->vlgrp) {
1768 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1769 if (!vlan_group_get_device(adapter->vlgrp, vid))
1771 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1776 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1778 struct dev_mc_list *mc_ptr;
1779 u8 *addr = *mc_addr_ptr;
1782 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1784 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1786 *mc_addr_ptr = NULL;
1792 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
1793 * @netdev: network interface device structure
1795 * The set_rx_method entry point is called whenever the unicast/multicast
1796 * address list or the network interface flags are updated. This routine is
1797 * responsible for configuring the hardware for proper unicast, multicast and
1800 static void ixgbe_set_rx_mode(struct net_device *netdev)
1802 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1803 struct ixgbe_hw *hw = &adapter->hw;
1805 u8 *addr_list = NULL;
1808 /* Check for Promiscuous and All Multicast modes */
1810 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1811 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1813 if (netdev->flags & IFF_PROMISC) {
1814 hw->addr_ctrl.user_set_promisc = 1;
1815 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1816 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1818 if (netdev->flags & IFF_ALLMULTI) {
1819 fctrl |= IXGBE_FCTRL_MPE;
1820 fctrl &= ~IXGBE_FCTRL_UPE;
1822 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1824 vlnctrl |= IXGBE_VLNCTRL_VFE;
1825 hw->addr_ctrl.user_set_promisc = 0;
1828 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1829 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1831 /* reprogram secondary unicast list */
1832 addr_count = netdev->uc_count;
1834 addr_list = netdev->uc_list->dmi_addr;
1835 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1836 ixgbe_addr_list_itr);
1838 /* reprogram multicast list */
1839 addr_count = netdev->mc_count;
1841 addr_list = netdev->mc_list->dmi_addr;
1842 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1843 ixgbe_addr_list_itr);
1846 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1849 struct ixgbe_q_vector *q_vector;
1850 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1852 /* legacy and MSI only use one vector */
1853 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1856 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1857 struct napi_struct *napi;
1858 q_vector = &adapter->q_vector[q_idx];
1859 if (!q_vector->rxr_count)
1861 napi = &q_vector->napi;
1862 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1863 (q_vector->rxr_count > 1))
1864 napi->poll = &ixgbe_clean_rxonly_many;
1870 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1873 struct ixgbe_q_vector *q_vector;
1874 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1876 /* legacy and MSI only use one vector */
1877 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1880 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1881 q_vector = &adapter->q_vector[q_idx];
1882 if (!q_vector->rxr_count)
1884 napi_disable(&q_vector->napi);
1888 #ifdef CONFIG_IXGBE_DCB
1890 * ixgbe_configure_dcb - Configure DCB hardware
1891 * @adapter: ixgbe adapter struct
1893 * This is called by the driver on open to configure the DCB hardware.
1894 * This is also called by the gennetlink interface when reconfiguring
1897 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1899 struct ixgbe_hw *hw = &adapter->hw;
1900 u32 txdctl, vlnctrl;
1903 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1904 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1905 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1907 /* reconfigure the hardware */
1908 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1910 for (i = 0; i < adapter->num_tx_queues; i++) {
1911 j = adapter->tx_ring[i].reg_idx;
1912 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1913 /* PThresh workaround for Tx hang with DFP enabled. */
1915 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1917 /* Enable VLAN tag insert/strip */
1918 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1919 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1920 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1921 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1922 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1926 static void ixgbe_configure(struct ixgbe_adapter *adapter)
1928 struct net_device *netdev = adapter->netdev;
1931 ixgbe_set_rx_mode(netdev);
1933 ixgbe_restore_vlan(adapter);
1934 #ifdef CONFIG_IXGBE_DCB
1935 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1936 netif_set_gso_max_size(netdev, 32768);
1937 ixgbe_configure_dcb(adapter);
1939 netif_set_gso_max_size(netdev, 65536);
1942 netif_set_gso_max_size(netdev, 65536);
1945 ixgbe_configure_tx(adapter);
1946 ixgbe_configure_rx(adapter);
1947 for (i = 0; i < adapter->num_rx_queues; i++)
1948 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
1949 (adapter->rx_ring[i].count - 1));
1952 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1954 struct net_device *netdev = adapter->netdev;
1955 struct ixgbe_hw *hw = &adapter->hw;
1957 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1958 u32 txdctl, rxdctl, mhadd;
1961 ixgbe_get_hw_control(adapter);
1963 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
1964 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
1965 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1966 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
1967 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
1972 /* XXX: to interrupt immediately for EICS writes, enable this */
1973 /* gpie |= IXGBE_GPIE_EIMEN; */
1974 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1977 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
1978 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
1979 * specifically only auto mask tx and rx interrupts */
1980 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1983 /* Enable fan failure interrupt if media type is copper */
1984 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
1985 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
1986 gpie |= IXGBE_SDP1_GPIEN;
1987 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1990 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1991 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
1992 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1993 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
1995 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1998 for (i = 0; i < adapter->num_tx_queues; i++) {
1999 j = adapter->tx_ring[i].reg_idx;
2000 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2001 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2002 txdctl |= (8 << 16);
2003 txdctl |= IXGBE_TXDCTL_ENABLE;
2004 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2007 for (i = 0; i < adapter->num_rx_queues; i++) {
2008 j = adapter->rx_ring[i].reg_idx;
2009 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2010 /* enable PTHRESH=32 descriptors (half the internal cache)
2011 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2012 * this also removes a pesky rx_no_buffer_count increment */
2014 rxdctl |= IXGBE_RXDCTL_ENABLE;
2015 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
2017 /* enable all receives */
2018 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2019 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2020 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2022 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2023 ixgbe_configure_msix(adapter);
2025 ixgbe_configure_msi_and_legacy(adapter);
2027 ixgbe_napi_add_all(adapter);
2029 clear_bit(__IXGBE_DOWN, &adapter->state);
2030 ixgbe_napi_enable_all(adapter);
2032 /* clear any pending interrupts, may auto mask */
2033 IXGBE_READ_REG(hw, IXGBE_EICR);
2035 ixgbe_irq_enable(adapter);
2037 /* enable transmits */
2038 netif_tx_start_all_queues(netdev);
2040 /* bring the link up in the watchdog, this could race with our first
2041 * link up interrupt but shouldn't be a problem */
2042 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2043 adapter->link_check_timeout = jiffies;
2044 mod_timer(&adapter->watchdog_timer, jiffies);
2048 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2050 WARN_ON(in_interrupt());
2051 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2053 ixgbe_down(adapter);
2055 clear_bit(__IXGBE_RESETTING, &adapter->state);
2058 int ixgbe_up(struct ixgbe_adapter *adapter)
2060 /* hardware has been reset, we need to reload some things */
2061 ixgbe_configure(adapter);
2063 return ixgbe_up_complete(adapter);
2066 void ixgbe_reset(struct ixgbe_adapter *adapter)
2068 struct ixgbe_hw *hw = &adapter->hw;
2069 if (hw->mac.ops.init_hw(hw))
2070 dev_err(&adapter->pdev->dev, "Hardware Error\n");
2072 /* reprogram the RAR[0] in case user changed it. */
2073 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2078 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2079 * @adapter: board private structure
2080 * @rx_ring: ring to free buffers from
2082 static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
2083 struct ixgbe_ring *rx_ring)
2085 struct pci_dev *pdev = adapter->pdev;
2089 /* Free all the Rx ring sk_buffs */
2091 for (i = 0; i < rx_ring->count; i++) {
2092 struct ixgbe_rx_buffer *rx_buffer_info;
2094 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2095 if (rx_buffer_info->dma) {
2096 pci_unmap_single(pdev, rx_buffer_info->dma,
2097 rx_ring->rx_buf_len,
2098 PCI_DMA_FROMDEVICE);
2099 rx_buffer_info->dma = 0;
2101 if (rx_buffer_info->skb) {
2102 dev_kfree_skb(rx_buffer_info->skb);
2103 rx_buffer_info->skb = NULL;
2105 if (!rx_buffer_info->page)
2107 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2108 PCI_DMA_FROMDEVICE);
2109 rx_buffer_info->page_dma = 0;
2110 put_page(rx_buffer_info->page);
2111 rx_buffer_info->page = NULL;
2112 rx_buffer_info->page_offset = 0;
2115 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2116 memset(rx_ring->rx_buffer_info, 0, size);
2118 /* Zero out the descriptor ring */
2119 memset(rx_ring->desc, 0, rx_ring->size);
2121 rx_ring->next_to_clean = 0;
2122 rx_ring->next_to_use = 0;
2124 writel(0, adapter->hw.hw_addr + rx_ring->head);
2125 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2129 * ixgbe_clean_tx_ring - Free Tx Buffers
2130 * @adapter: board private structure
2131 * @tx_ring: ring to be cleaned
2133 static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
2134 struct ixgbe_ring *tx_ring)
2136 struct ixgbe_tx_buffer *tx_buffer_info;
2140 /* Free all the Tx ring sk_buffs */
2142 for (i = 0; i < tx_ring->count; i++) {
2143 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2144 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2147 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2148 memset(tx_ring->tx_buffer_info, 0, size);
2150 /* Zero out the descriptor ring */
2151 memset(tx_ring->desc, 0, tx_ring->size);
2153 tx_ring->next_to_use = 0;
2154 tx_ring->next_to_clean = 0;
2156 writel(0, adapter->hw.hw_addr + tx_ring->head);
2157 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2161 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2162 * @adapter: board private structure
2164 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2168 for (i = 0; i < adapter->num_rx_queues; i++)
2169 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2173 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2174 * @adapter: board private structure
2176 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2180 for (i = 0; i < adapter->num_tx_queues; i++)
2181 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2184 void ixgbe_down(struct ixgbe_adapter *adapter)
2186 struct net_device *netdev = adapter->netdev;
2187 struct ixgbe_hw *hw = &adapter->hw;
2192 /* signal that we are down to the interrupt handler */
2193 set_bit(__IXGBE_DOWN, &adapter->state);
2195 /* disable receives */
2196 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2197 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2199 netif_tx_disable(netdev);
2201 IXGBE_WRITE_FLUSH(hw);
2204 netif_tx_stop_all_queues(netdev);
2206 ixgbe_irq_disable(adapter);
2208 ixgbe_napi_disable_all(adapter);
2210 del_timer_sync(&adapter->watchdog_timer);
2211 cancel_work_sync(&adapter->watchdog_task);
2213 /* disable transmits in the hardware now that interrupts are off */
2214 for (i = 0; i < adapter->num_tx_queues; i++) {
2215 j = adapter->tx_ring[i].reg_idx;
2216 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2217 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2218 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2221 netif_carrier_off(netdev);
2223 #ifdef CONFIG_IXGBE_DCA
2224 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2225 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2226 dca_remove_requester(&adapter->pdev->dev);
2230 if (!pci_channel_offline(adapter->pdev))
2231 ixgbe_reset(adapter);
2232 ixgbe_clean_all_tx_rings(adapter);
2233 ixgbe_clean_all_rx_rings(adapter);
2235 #ifdef CONFIG_IXGBE_DCA
2236 /* since we reset the hardware DCA settings were cleared */
2237 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2238 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2239 /* always use CB2 mode, difference is masked
2240 * in the CB driver */
2241 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
2242 ixgbe_setup_dca(adapter);
2248 * ixgbe_poll - NAPI Rx polling callback
2249 * @napi: structure for representing this polling device
2250 * @budget: how many packets driver is allowed to clean
2252 * This function is used for legacy and MSI, NAPI mode
2254 static int ixgbe_poll(struct napi_struct *napi, int budget)
2256 struct ixgbe_q_vector *q_vector = container_of(napi,
2257 struct ixgbe_q_vector, napi);
2258 struct ixgbe_adapter *adapter = q_vector->adapter;
2259 int tx_cleaned, work_done = 0;
2261 #ifdef CONFIG_IXGBE_DCA
2262 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2263 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2264 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2268 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
2269 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
2274 /* If budget not fully consumed, exit the polling mode */
2275 if (work_done < budget) {
2276 napi_complete(napi);
2277 if (adapter->itr_setting & 3)
2278 ixgbe_set_itr(adapter);
2279 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2280 ixgbe_irq_enable(adapter);
2286 * ixgbe_tx_timeout - Respond to a Tx Hang
2287 * @netdev: network interface device structure
2289 static void ixgbe_tx_timeout(struct net_device *netdev)
2291 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2293 /* Do the reset outside of interrupt context */
2294 schedule_work(&adapter->reset_task);
2297 static void ixgbe_reset_task(struct work_struct *work)
2299 struct ixgbe_adapter *adapter;
2300 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2302 /* If we're already down or resetting, just bail */
2303 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2304 test_bit(__IXGBE_RESETTING, &adapter->state))
2307 adapter->tx_timeout_count++;
2309 ixgbe_reinit_locked(adapter);
2312 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2314 int nrq = 1, ntq = 1;
2315 int feature_mask = 0, rss_i, rss_m;
2318 /* Number of supported queues */
2319 switch (adapter->hw.mac.type) {
2320 case ixgbe_mac_82598EB:
2321 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2323 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2325 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2326 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
2328 switch (adapter->flags & feature_mask) {
2329 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2331 rss_i = min(8, rss_i);
2333 nrq = dcb_i * rss_i;
2334 ntq = min(MAX_TX_QUEUES, dcb_i * rss_i);
2336 case (IXGBE_FLAG_DCB_ENABLED):
2341 case (IXGBE_FLAG_RSS_ENABLED):
2357 /* Sanity check, we should never have zero queues */
2361 adapter->ring_feature[RING_F_DCB].indices = dcb_i;
2362 adapter->ring_feature[RING_F_DCB].mask = dcb_m;
2363 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2364 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2372 adapter->num_rx_queues = nrq;
2373 adapter->num_tx_queues = ntq;
2376 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
2379 int err, vector_threshold;
2381 /* We'll want at least 3 (vector_threshold):
2384 * 3) Other (Link Status Change, etc.)
2385 * 4) TCP Timer (optional)
2387 vector_threshold = MIN_MSIX_COUNT;
2389 /* The more we get, the more we will assign to Tx/Rx Cleanup
2390 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2391 * Right now, we simply care about how many we'll get; we'll
2392 * set them up later while requesting irq's.
2394 while (vectors >= vector_threshold) {
2395 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2397 if (!err) /* Success in acquiring all requested vectors. */
2400 vectors = 0; /* Nasty failure, quit now */
2401 else /* err == number of vectors we should try again with */
2405 if (vectors < vector_threshold) {
2406 /* Can't allocate enough MSI-X interrupts? Oh well.
2407 * This just means we'll go with either a single MSI
2408 * vector or fall back to legacy interrupts.
2410 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2411 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2412 kfree(adapter->msix_entries);
2413 adapter->msix_entries = NULL;
2414 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2415 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2416 ixgbe_set_num_queues(adapter);
2418 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2419 adapter->num_msix_vectors = vectors;
2424 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2425 * @adapter: board private structure to initialize
2427 * Once we know the feature-set enabled for the device, we'll cache
2428 * the register offset the descriptor ring is assigned to.
2430 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2432 int feature_mask = 0, rss_i;
2433 int i, txr_idx, rxr_idx;
2436 /* Number of supported queues */
2437 switch (adapter->hw.mac.type) {
2438 case ixgbe_mac_82598EB:
2439 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2440 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2443 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
2444 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2445 switch (adapter->flags & feature_mask) {
2446 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2447 for (i = 0; i < dcb_i; i++) {
2450 for (j = 0; j < adapter->num_rx_queues; j++) {
2451 adapter->rx_ring[rxr_idx].reg_idx =
2456 for (j = 0; j < adapter->num_tx_queues; j++) {
2457 adapter->tx_ring[txr_idx].reg_idx =
2463 case (IXGBE_FLAG_DCB_ENABLED):
2464 /* the number of queues is assumed to be symmetric */
2465 for (i = 0; i < dcb_i; i++) {
2466 adapter->rx_ring[i].reg_idx = i << 3;
2467 adapter->tx_ring[i].reg_idx = i << 2;
2470 case (IXGBE_FLAG_RSS_ENABLED):
2471 for (i = 0; i < adapter->num_rx_queues; i++)
2472 adapter->rx_ring[i].reg_idx = i;
2473 for (i = 0; i < adapter->num_tx_queues; i++)
2474 adapter->tx_ring[i].reg_idx = i;
2487 * ixgbe_alloc_queues - Allocate memory for all rings
2488 * @adapter: board private structure to initialize
2490 * We allocate one ring per queue at run-time since we don't know the
2491 * number of queues at compile-time.
2493 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
2497 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
2498 sizeof(struct ixgbe_ring), GFP_KERNEL);
2499 if (!adapter->tx_ring)
2500 goto err_tx_ring_allocation;
2502 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
2503 sizeof(struct ixgbe_ring), GFP_KERNEL);
2504 if (!adapter->rx_ring)
2505 goto err_rx_ring_allocation;
2507 for (i = 0; i < adapter->num_tx_queues; i++) {
2508 adapter->tx_ring[i].count = adapter->tx_ring_count;
2509 adapter->tx_ring[i].queue_index = i;
2512 for (i = 0; i < adapter->num_rx_queues; i++) {
2513 adapter->rx_ring[i].count = adapter->rx_ring_count;
2514 adapter->rx_ring[i].queue_index = i;
2517 ixgbe_cache_ring_register(adapter);
2521 err_rx_ring_allocation:
2522 kfree(adapter->tx_ring);
2523 err_tx_ring_allocation:
2528 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2529 * @adapter: board private structure to initialize
2531 * Attempt to configure the interrupts using the best available
2532 * capabilities of the hardware and the kernel.
2534 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
2537 int vector, v_budget;
2540 * It's easy to be greedy for MSI-X vectors, but it really
2541 * doesn't do us much good if we have a lot more vectors
2542 * than CPU's. So let's be conservative and only ask for
2543 * (roughly) twice the number of vectors as there are CPU's.
2545 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2546 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2549 * At the same time, hardware can only support a maximum of
2550 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2551 * we can easily reach upwards of 64 Rx descriptor queues and
2552 * 32 Tx queues. Thus, we cap it off in those rare cases where
2553 * the cpu count also exceeds our vector limit.
2555 v_budget = min(v_budget, MAX_MSIX_COUNT);
2557 /* A failure in MSI-X entry allocation isn't fatal, but it does
2558 * mean we disable MSI-X capabilities of the adapter. */
2559 adapter->msix_entries = kcalloc(v_budget,
2560 sizeof(struct msix_entry), GFP_KERNEL);
2561 if (!adapter->msix_entries) {
2562 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2563 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2564 ixgbe_set_num_queues(adapter);
2565 kfree(adapter->tx_ring);
2566 kfree(adapter->rx_ring);
2567 err = ixgbe_alloc_queues(adapter);
2569 DPRINTK(PROBE, ERR, "Unable to allocate memory "
2577 for (vector = 0; vector < v_budget; vector++)
2578 adapter->msix_entries[vector].entry = vector;
2580 ixgbe_acquire_msix_vectors(adapter, v_budget);
2582 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2586 err = pci_enable_msi(adapter->pdev);
2588 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2590 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
2591 "falling back to legacy. Error: %d\n", err);
2597 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2598 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
2603 void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
2605 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2606 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2607 pci_disable_msix(adapter->pdev);
2608 kfree(adapter->msix_entries);
2609 adapter->msix_entries = NULL;
2610 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2611 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2612 pci_disable_msi(adapter->pdev);
2618 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2619 * @adapter: board private structure to initialize
2621 * We determine which interrupt scheme to use based on...
2622 * - Kernel support (MSI, MSI-X)
2623 * - which can be user-defined (via MODULE_PARAM)
2624 * - Hardware queue count (num_*_queues)
2625 * - defined by miscellaneous hardware support/features (RSS, etc.)
2627 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
2631 /* Number of supported queues */
2632 ixgbe_set_num_queues(adapter);
2634 err = ixgbe_alloc_queues(adapter);
2636 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2637 goto err_alloc_queues;
2640 err = ixgbe_set_interrupt_capability(adapter);
2642 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2643 goto err_set_interrupt;
2646 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
2647 "Tx Queue count = %u\n",
2648 (adapter->num_rx_queues > 1) ? "Enabled" :
2649 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2651 set_bit(__IXGBE_DOWN, &adapter->state);
2656 kfree(adapter->tx_ring);
2657 kfree(adapter->rx_ring);
2663 * ixgbe_sfp_timer - worker thread to find a missing module
2664 * @data: pointer to our adapter struct
2666 static void ixgbe_sfp_timer(unsigned long data)
2668 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2670 /* Do the sfp_timer outside of interrupt context due to the
2671 * delays that sfp+ detection requires
2673 schedule_work(&adapter->sfp_task);
2677 * ixgbe_sfp_task - worker thread to find a missing module
2678 * @work: pointer to work_struct containing our data
2680 static void ixgbe_sfp_task(struct work_struct *work)
2682 struct ixgbe_adapter *adapter = container_of(work,
2683 struct ixgbe_adapter,
2685 struct ixgbe_hw *hw = &adapter->hw;
2687 if ((hw->phy.type == ixgbe_phy_nl) &&
2688 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2689 s32 ret = hw->phy.ops.identify_sfp(hw);
2692 ret = hw->phy.ops.reset(hw);
2693 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2694 DPRINTK(PROBE, ERR, "failed to initialize because an "
2695 "unsupported SFP+ module type was detected.\n"
2696 "Reload the driver after installing a "
2697 "supported module.\n");
2698 unregister_netdev(adapter->netdev);
2700 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2703 /* don't need this routine any more */
2704 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2708 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2709 mod_timer(&adapter->sfp_timer,
2710 round_jiffies(jiffies + (2 * HZ)));
2714 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2715 * @adapter: board private structure to initialize
2717 * ixgbe_sw_init initializes the Adapter private data structure.
2718 * Fields are initialized based on PCI device information and
2719 * OS network device settings (MTU size).
2721 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2723 struct ixgbe_hw *hw = &adapter->hw;
2724 struct pci_dev *pdev = adapter->pdev;
2726 #ifdef CONFIG_IXGBE_DCB
2728 struct tc_configuration *tc;
2731 /* PCI config space info */
2733 hw->vendor_id = pdev->vendor;
2734 hw->device_id = pdev->device;
2735 hw->revision_id = pdev->revision;
2736 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2737 hw->subsystem_device_id = pdev->subsystem_device;
2739 /* Set capability flags */
2740 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2741 adapter->ring_feature[RING_F_RSS].indices = rss;
2742 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
2743 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
2745 #ifdef CONFIG_IXGBE_DCB
2746 /* Configure DCB traffic classes */
2747 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2748 tc = &adapter->dcb_cfg.tc_config[j];
2749 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2750 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2751 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2752 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2753 tc->dcb_pfc = pfc_disabled;
2755 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2756 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2757 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2758 adapter->dcb_cfg.round_robin_enable = false;
2759 adapter->dcb_set_bitmap = 0x00;
2760 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2761 adapter->ring_feature[RING_F_DCB].indices);
2764 if (hw->mac.ops.get_media_type &&
2765 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2766 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
2768 /* default flow control settings */
2769 hw->fc.original_type = ixgbe_fc_none;
2770 hw->fc.type = ixgbe_fc_none;
2771 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2772 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2773 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2774 hw->fc.send_xon = true;
2776 /* select 10G link by default */
2777 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2779 /* enable itr by default in dynamic mode */
2780 adapter->itr_setting = 1;
2781 adapter->eitr_param = 20000;
2783 /* set defaults for eitr in MegaBytes */
2784 adapter->eitr_low = 10;
2785 adapter->eitr_high = 20;
2787 /* set default ring sizes */
2788 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2789 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2791 /* initialize eeprom parameters */
2792 if (ixgbe_init_eeprom_params_generic(hw)) {
2793 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2797 /* enable rx csum by default */
2798 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2800 set_bit(__IXGBE_DOWN, &adapter->state);
2806 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2807 * @adapter: board private structure
2808 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2810 * Return 0 on success, negative on failure
2812 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
2813 struct ixgbe_ring *tx_ring)
2815 struct pci_dev *pdev = adapter->pdev;
2818 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2819 tx_ring->tx_buffer_info = vmalloc(size);
2820 if (!tx_ring->tx_buffer_info)
2822 memset(tx_ring->tx_buffer_info, 0, size);
2824 /* round up to nearest 4K */
2825 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc) +
2827 tx_ring->size = ALIGN(tx_ring->size, 4096);
2829 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2834 tx_ring->next_to_use = 0;
2835 tx_ring->next_to_clean = 0;
2836 tx_ring->work_limit = tx_ring->count;
2840 vfree(tx_ring->tx_buffer_info);
2841 tx_ring->tx_buffer_info = NULL;
2842 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2843 "descriptor ring\n");
2848 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2849 * @adapter: board private structure
2851 * If this function returns with an error, then it's possible one or
2852 * more of the rings is populated (while the rest are not). It is the
2853 * callers duty to clean those orphaned rings.
2855 * Return 0 on success, negative on failure
2857 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2861 for (i = 0; i < adapter->num_tx_queues; i++) {
2862 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2865 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2873 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2874 * @adapter: board private structure
2875 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2877 * Returns 0 on success, negative on failure
2879 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
2880 struct ixgbe_ring *rx_ring)
2882 struct pci_dev *pdev = adapter->pdev;
2885 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2886 rx_ring->rx_buffer_info = vmalloc(size);
2887 if (!rx_ring->rx_buffer_info) {
2889 "vmalloc allocation failed for the rx desc ring\n");
2892 memset(rx_ring->rx_buffer_info, 0, size);
2894 /* Round up to nearest 4K */
2895 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2896 rx_ring->size = ALIGN(rx_ring->size, 4096);
2898 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
2900 if (!rx_ring->desc) {
2902 "Memory allocation failed for the rx desc ring\n");
2903 vfree(rx_ring->rx_buffer_info);
2907 rx_ring->next_to_clean = 0;
2908 rx_ring->next_to_use = 0;
2917 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2918 * @adapter: board private structure
2920 * If this function returns with an error, then it's possible one or
2921 * more of the rings is populated (while the rest are not). It is the
2922 * callers duty to clean those orphaned rings.
2924 * Return 0 on success, negative on failure
2927 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2931 for (i = 0; i < adapter->num_rx_queues; i++) {
2932 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2935 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2943 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2944 * @adapter: board private structure
2945 * @tx_ring: Tx descriptor ring for a specific queue
2947 * Free all transmit software resources
2949 void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2950 struct ixgbe_ring *tx_ring)
2952 struct pci_dev *pdev = adapter->pdev;
2954 ixgbe_clean_tx_ring(adapter, tx_ring);
2956 vfree(tx_ring->tx_buffer_info);
2957 tx_ring->tx_buffer_info = NULL;
2959 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2961 tx_ring->desc = NULL;
2965 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
2966 * @adapter: board private structure
2968 * Free all transmit software resources
2970 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
2974 for (i = 0; i < adapter->num_tx_queues; i++)
2975 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
2979 * ixgbe_free_rx_resources - Free Rx Resources
2980 * @adapter: board private structure
2981 * @rx_ring: ring to clean the resources from
2983 * Free all receive software resources
2985 void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
2986 struct ixgbe_ring *rx_ring)
2988 struct pci_dev *pdev = adapter->pdev;
2990 ixgbe_clean_rx_ring(adapter, rx_ring);
2992 vfree(rx_ring->rx_buffer_info);
2993 rx_ring->rx_buffer_info = NULL;
2995 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2997 rx_ring->desc = NULL;
3001 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3002 * @adapter: board private structure
3004 * Free all receive software resources
3006 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3010 for (i = 0; i < adapter->num_rx_queues; i++)
3011 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3015 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3016 * @netdev: network interface device structure
3017 * @new_mtu: new value for maximum frame size
3019 * Returns 0 on success, negative on failure
3021 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3023 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3024 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3026 /* MTU < 68 is an error and causes problems on some kernels */
3027 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
3030 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
3031 netdev->mtu, new_mtu);
3032 /* must set new MTU before calling down or up */
3033 netdev->mtu = new_mtu;
3035 if (netif_running(netdev))
3036 ixgbe_reinit_locked(adapter);
3042 * ixgbe_open - Called when a network interface is made active
3043 * @netdev: network interface device structure
3045 * Returns 0 on success, negative value on failure
3047 * The open entry point is called when a network interface is made
3048 * active by the system (IFF_UP). At this point all resources needed
3049 * for transmit and receive operations are allocated, the interrupt
3050 * handler is registered with the OS, the watchdog timer is started,
3051 * and the stack is notified that the interface is ready.
3053 static int ixgbe_open(struct net_device *netdev)
3055 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3058 /* disallow open during test */
3059 if (test_bit(__IXGBE_TESTING, &adapter->state))
3062 /* allocate transmit descriptors */
3063 err = ixgbe_setup_all_tx_resources(adapter);
3067 /* allocate receive descriptors */
3068 err = ixgbe_setup_all_rx_resources(adapter);
3072 ixgbe_configure(adapter);
3074 err = ixgbe_request_irq(adapter);
3078 err = ixgbe_up_complete(adapter);
3082 netif_tx_start_all_queues(netdev);
3087 ixgbe_release_hw_control(adapter);
3088 ixgbe_free_irq(adapter);
3090 ixgbe_free_all_rx_resources(adapter);
3092 ixgbe_free_all_tx_resources(adapter);
3094 ixgbe_reset(adapter);
3100 * ixgbe_close - Disables a network interface
3101 * @netdev: network interface device structure
3103 * Returns 0, this is not allowed to fail
3105 * The close entry point is called when an interface is de-activated
3106 * by the OS. The hardware is still under the drivers control, but
3107 * needs to be disabled. A global MAC reset is issued to stop the
3108 * hardware, and all transmit and receive resources are freed.
3110 static int ixgbe_close(struct net_device *netdev)
3112 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3114 ixgbe_down(adapter);
3115 ixgbe_free_irq(adapter);
3117 ixgbe_free_all_tx_resources(adapter);
3118 ixgbe_free_all_rx_resources(adapter);
3120 ixgbe_release_hw_control(adapter);
3126 * ixgbe_napi_add_all - prep napi structs for use
3127 * @adapter: private struct
3128 * helper function to napi_add each possible q_vector->napi
3130 void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
3132 int q_idx, q_vectors;
3133 struct net_device *netdev = adapter->netdev;
3134 int (*poll)(struct napi_struct *, int);
3136 /* check if we already have our netdev->napi_list populated */
3137 if (&netdev->napi_list != netdev->napi_list.next)
3140 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3141 poll = &ixgbe_clean_rxonly;
3142 /* Only enable as many vectors as we have rx queues. */
3143 q_vectors = adapter->num_rx_queues;
3146 /* only one q_vector for legacy modes */
3150 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3151 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3152 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3156 void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
3159 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3161 /* legacy and MSI only use one vector */
3162 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3165 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3166 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3167 if (!q_vector->rxr_count)
3169 netif_napi_del(&q_vector->napi);
3174 static int ixgbe_resume(struct pci_dev *pdev)
3176 struct net_device *netdev = pci_get_drvdata(pdev);
3177 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3180 pci_set_power_state(pdev, PCI_D0);
3181 pci_restore_state(pdev);
3182 err = pci_enable_device(pdev);
3184 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
3188 pci_set_master(pdev);
3190 pci_enable_wake(pdev, PCI_D3hot, 0);
3191 pci_enable_wake(pdev, PCI_D3cold, 0);
3193 err = ixgbe_init_interrupt_scheme(adapter);
3195 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3200 ixgbe_napi_add_all(adapter);
3201 ixgbe_reset(adapter);
3203 if (netif_running(netdev)) {
3204 err = ixgbe_open(adapter->netdev);
3209 netif_device_attach(netdev);
3214 #endif /* CONFIG_PM */
3215 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3217 struct net_device *netdev = pci_get_drvdata(pdev);
3218 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3223 netif_device_detach(netdev);
3225 if (netif_running(netdev)) {
3226 ixgbe_down(adapter);
3227 ixgbe_free_irq(adapter);
3228 ixgbe_free_all_tx_resources(adapter);
3229 ixgbe_free_all_rx_resources(adapter);
3231 ixgbe_reset_interrupt_capability(adapter);
3232 ixgbe_napi_del_all(adapter);
3233 INIT_LIST_HEAD(&netdev->napi_list);
3234 kfree(adapter->tx_ring);
3235 kfree(adapter->rx_ring);
3238 retval = pci_save_state(pdev);
3243 pci_enable_wake(pdev, PCI_D3hot, 0);
3244 pci_enable_wake(pdev, PCI_D3cold, 0);
3246 ixgbe_release_hw_control(adapter);
3248 pci_disable_device(pdev);
3250 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3255 static void ixgbe_shutdown(struct pci_dev *pdev)
3257 ixgbe_suspend(pdev, PMSG_SUSPEND);
3261 * ixgbe_update_stats - Update the board statistics counters.
3262 * @adapter: board private structure
3264 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3266 struct ixgbe_hw *hw = &adapter->hw;
3268 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
3270 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
3271 for (i = 0; i < 8; i++) {
3272 /* for packet buffers not used, the register should read 0 */
3273 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3275 adapter->stats.mpc[i] += mpc;
3276 total_mpc += adapter->stats.mpc[i];
3277 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
3278 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3279 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3280 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3281 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3282 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3284 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3286 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3288 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3291 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3292 /* work around hardware counting issue */
3293 adapter->stats.gprc -= missed_rx;
3295 /* 82598 hardware only has a 32 bit counter in the high register */
3296 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3297 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3298 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3299 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3300 adapter->stats.bprc += bprc;
3301 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3302 adapter->stats.mprc -= bprc;
3303 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3304 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3305 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3306 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3307 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3308 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3309 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
3310 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3311 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3312 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3313 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3314 adapter->stats.lxontxc += lxon;
3315 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3316 adapter->stats.lxofftxc += lxoff;
3317 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3318 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
3319 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3321 * 82598 errata - tx of flow control packets is included in tx counters
3323 xon_off_tot = lxon + lxoff;
3324 adapter->stats.gptc -= xon_off_tot;
3325 adapter->stats.mptc -= xon_off_tot;
3326 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
3327 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3328 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3329 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
3330 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3331 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
3332 adapter->stats.ptc64 -= xon_off_tot;
3333 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3334 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3335 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3336 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3337 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
3338 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3340 /* Fill out the OS statistics structure */
3341 adapter->net_stats.multicast = adapter->stats.mprc;
3344 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
3345 adapter->stats.rlec;
3346 adapter->net_stats.rx_dropped = 0;
3347 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3348 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3349 adapter->net_stats.rx_missed_errors = total_mpc;
3353 * ixgbe_watchdog - Timer Call-back
3354 * @data: pointer to adapter cast into an unsigned long
3356 static void ixgbe_watchdog(unsigned long data)
3358 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3359 struct ixgbe_hw *hw = &adapter->hw;
3361 /* Do the watchdog outside of interrupt context due to the lovely
3362 * delays that some of the newer hardware requires */
3363 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3364 /* Cause software interrupt to ensure rx rings are cleaned */
3365 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3367 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3368 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3370 /* For legacy and MSI interrupts don't set any bits that
3371 * are enabled for EIAM, because this operation would
3372 * set *both* EIMS and EICS for any bit in EIAM */
3373 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3374 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3376 /* Reset the timer */
3377 mod_timer(&adapter->watchdog_timer,
3378 round_jiffies(jiffies + 2 * HZ));
3381 schedule_work(&adapter->watchdog_task);
3385 * ixgbe_watchdog_task - worker thread to bring link up
3386 * @work: pointer to work_struct containing our data
3388 static void ixgbe_watchdog_task(struct work_struct *work)
3390 struct ixgbe_adapter *adapter = container_of(work,
3391 struct ixgbe_adapter,
3393 struct net_device *netdev = adapter->netdev;
3394 struct ixgbe_hw *hw = &adapter->hw;
3395 u32 link_speed = adapter->link_speed;
3396 bool link_up = adapter->link_up;
3398 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3400 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3401 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3403 time_after(jiffies, (adapter->link_check_timeout +
3404 IXGBE_TRY_LINK_TIMEOUT))) {
3405 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3406 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3408 adapter->link_up = link_up;
3409 adapter->link_speed = link_speed;
3413 if (!netif_carrier_ok(netdev)) {
3414 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3415 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
3416 #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3417 #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
3418 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3419 "Flow Control: %s\n",
3421 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3423 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3424 "1 Gbps" : "unknown speed")),
3425 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3427 (FLOW_TX ? "TX" : "None"))));
3429 netif_carrier_on(netdev);
3431 /* Force detection of hung controller */
3432 adapter->detect_tx_hung = true;
3435 adapter->link_up = false;
3436 adapter->link_speed = 0;
3437 if (netif_carrier_ok(netdev)) {
3438 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3440 netif_carrier_off(netdev);
3444 ixgbe_update_stats(adapter);
3445 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
3448 static int ixgbe_tso(struct ixgbe_adapter *adapter,
3449 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3450 u32 tx_flags, u8 *hdr_len)
3452 struct ixgbe_adv_tx_context_desc *context_desc;
3455 struct ixgbe_tx_buffer *tx_buffer_info;
3456 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3457 u32 mss_l4len_idx, l4len;
3459 if (skb_is_gso(skb)) {
3460 if (skb_header_cloned(skb)) {
3461 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3465 l4len = tcp_hdrlen(skb);
3468 if (skb->protocol == htons(ETH_P_IP)) {
3469 struct iphdr *iph = ip_hdr(skb);
3472 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3476 adapter->hw_tso_ctxt++;
3477 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3478 ipv6_hdr(skb)->payload_len = 0;
3479 tcp_hdr(skb)->check =
3480 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3481 &ipv6_hdr(skb)->daddr,
3483 adapter->hw_tso6_ctxt++;
3486 i = tx_ring->next_to_use;
3488 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3489 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3491 /* VLAN MACLEN IPLEN */
3492 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3494 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3495 vlan_macip_lens |= ((skb_network_offset(skb)) <<
3496 IXGBE_ADVTXD_MACLEN_SHIFT);
3497 *hdr_len += skb_network_offset(skb);
3499 (skb_transport_header(skb) - skb_network_header(skb));
3501 (skb_transport_header(skb) - skb_network_header(skb));
3502 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3503 context_desc->seqnum_seed = 0;
3505 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
3506 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
3507 IXGBE_ADVTXD_DTYP_CTXT);
3509 if (skb->protocol == htons(ETH_P_IP))
3510 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3511 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3512 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3516 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3517 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
3518 /* use index 1 for TSO */
3519 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3520 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3522 tx_buffer_info->time_stamp = jiffies;
3523 tx_buffer_info->next_to_watch = i;
3526 if (i == tx_ring->count)
3528 tx_ring->next_to_use = i;
3535 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
3536 struct ixgbe_ring *tx_ring,
3537 struct sk_buff *skb, u32 tx_flags)
3539 struct ixgbe_adv_tx_context_desc *context_desc;
3541 struct ixgbe_tx_buffer *tx_buffer_info;
3542 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3544 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3545 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3546 i = tx_ring->next_to_use;
3547 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3548 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3550 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3552 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3553 vlan_macip_lens |= (skb_network_offset(skb) <<
3554 IXGBE_ADVTXD_MACLEN_SHIFT);
3555 if (skb->ip_summed == CHECKSUM_PARTIAL)
3556 vlan_macip_lens |= (skb_transport_header(skb) -
3557 skb_network_header(skb));
3559 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3560 context_desc->seqnum_seed = 0;
3562 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
3563 IXGBE_ADVTXD_DTYP_CTXT);
3565 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3566 switch (skb->protocol) {
3567 case __constant_htons(ETH_P_IP):
3568 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3569 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3571 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3573 case __constant_htons(ETH_P_IPV6):
3574 /* XXX what about other V6 headers?? */
3575 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3577 IXGBE_ADVTXD_TUCMD_L4T_TCP;
3580 if (unlikely(net_ratelimit())) {
3581 DPRINTK(PROBE, WARNING,
3582 "partial checksum but proto=%x!\n",
3589 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3590 /* use index zero for tx checksum offload */
3591 context_desc->mss_l4len_idx = 0;
3593 tx_buffer_info->time_stamp = jiffies;
3594 tx_buffer_info->next_to_watch = i;
3596 adapter->hw_csum_tx_good++;
3598 if (i == tx_ring->count)
3600 tx_ring->next_to_use = i;
3608 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
3609 struct ixgbe_ring *tx_ring,
3610 struct sk_buff *skb, unsigned int first)
3612 struct ixgbe_tx_buffer *tx_buffer_info;
3613 unsigned int len = skb->len;
3614 unsigned int offset = 0, size, count = 0, i;
3615 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3618 len -= skb->data_len;
3620 i = tx_ring->next_to_use;
3623 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3624 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3626 tx_buffer_info->length = size;
3627 tx_buffer_info->dma = pci_map_single(adapter->pdev,
3629 size, PCI_DMA_TODEVICE);
3630 tx_buffer_info->time_stamp = jiffies;
3631 tx_buffer_info->next_to_watch = i;
3637 if (i == tx_ring->count)
3641 for (f = 0; f < nr_frags; f++) {
3642 struct skb_frag_struct *frag;
3644 frag = &skb_shinfo(skb)->frags[f];
3646 offset = frag->page_offset;
3649 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3650 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3652 tx_buffer_info->length = size;
3653 tx_buffer_info->dma = pci_map_page(adapter->pdev,
3658 tx_buffer_info->time_stamp = jiffies;
3659 tx_buffer_info->next_to_watch = i;
3665 if (i == tx_ring->count)
3670 i = tx_ring->count - 1;
3673 tx_ring->tx_buffer_info[i].skb = skb;
3674 tx_ring->tx_buffer_info[first].next_to_watch = i;
3679 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
3680 struct ixgbe_ring *tx_ring,
3681 int tx_flags, int count, u32 paylen, u8 hdr_len)
3683 union ixgbe_adv_tx_desc *tx_desc = NULL;
3684 struct ixgbe_tx_buffer *tx_buffer_info;
3685 u32 olinfo_status = 0, cmd_type_len = 0;
3687 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3689 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3691 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3693 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3694 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3696 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3697 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3699 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3700 IXGBE_ADVTXD_POPTS_SHIFT;
3702 /* use index 1 context for tso */
3703 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3704 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3705 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
3706 IXGBE_ADVTXD_POPTS_SHIFT;
3708 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3709 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3710 IXGBE_ADVTXD_POPTS_SHIFT;
3712 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3714 i = tx_ring->next_to_use;
3716 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3717 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3718 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3719 tx_desc->read.cmd_type_len =
3720 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3721 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3723 if (i == tx_ring->count)
3727 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3730 * Force memory writes to complete before letting h/w
3731 * know there are new descriptors to fetch. (Only
3732 * applicable for weak-ordered memory model archs,
3737 tx_ring->next_to_use = i;
3738 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3741 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
3742 struct ixgbe_ring *tx_ring, int size)
3744 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3746 netif_stop_subqueue(netdev, tx_ring->queue_index);
3747 /* Herbert's original patch had:
3748 * smp_mb__after_netif_stop_queue();
3749 * but since that doesn't exist yet, just open code it. */
3752 /* We need to check again in a case another CPU has just
3753 * made room available. */
3754 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3757 /* A reprieve! - use start_queue because it doesn't call schedule */
3758 netif_start_subqueue(netdev, tx_ring->queue_index);
3759 ++adapter->restart_queue;
3763 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
3764 struct ixgbe_ring *tx_ring, int size)
3766 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3768 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3771 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3773 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3774 struct ixgbe_ring *tx_ring;
3776 unsigned int tx_flags = 0;
3782 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
3783 tx_ring = &adapter->tx_ring[r_idx];
3785 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3786 tx_flags |= vlan_tx_tag_get(skb);
3787 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3788 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3789 tx_flags |= (skb->queue_mapping << 13);
3791 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3792 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3793 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3794 tx_flags |= (skb->queue_mapping << 13);
3795 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3796 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3798 /* three things can cause us to need a context descriptor */
3799 if (skb_is_gso(skb) ||
3800 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3801 (tx_flags & IXGBE_TX_FLAGS_VLAN))
3804 count += TXD_USE_COUNT(skb_headlen(skb));
3805 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
3806 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3808 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
3810 return NETDEV_TX_BUSY;
3813 if (skb->protocol == htons(ETH_P_IP))
3814 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3815 first = tx_ring->next_to_use;
3816 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3818 dev_kfree_skb_any(skb);
3819 return NETDEV_TX_OK;
3823 tx_flags |= IXGBE_TX_FLAGS_TSO;
3824 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
3825 (skb->ip_summed == CHECKSUM_PARTIAL))
3826 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3828 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
3829 ixgbe_tx_map(adapter, tx_ring, skb, first),
3832 netdev->trans_start = jiffies;
3834 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
3836 return NETDEV_TX_OK;
3840 * ixgbe_get_stats - Get System Network Statistics
3841 * @netdev: network interface device structure
3843 * Returns the address of the device statistics structure.
3844 * The statistics are actually updated from the timer callback.
3846 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3848 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3850 /* only return the current stats */
3851 return &adapter->net_stats;
3855 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3856 * @netdev: network interface device structure
3857 * @p: pointer to an address structure
3859 * Returns 0 on success, negative on failure
3861 static int ixgbe_set_mac(struct net_device *netdev, void *p)
3863 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3864 struct ixgbe_hw *hw = &adapter->hw;
3865 struct sockaddr *addr = p;
3867 if (!is_valid_ether_addr(addr->sa_data))
3868 return -EADDRNOTAVAIL;
3870 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3871 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
3873 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
3878 #ifdef CONFIG_NET_POLL_CONTROLLER
3880 * Polling 'interrupt' - used by things like netconsole to send skbs
3881 * without having to re-enable interrupts. It's not called while
3882 * the interrupt routine is executing.
3884 static void ixgbe_netpoll(struct net_device *netdev)
3886 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3888 disable_irq(adapter->pdev->irq);
3889 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3890 ixgbe_intr(adapter->pdev->irq, netdev);
3891 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3892 enable_irq(adapter->pdev->irq);
3897 * ixgbe_link_config - set up initial link with default speed and duplex
3898 * @hw: pointer to private hardware struct
3900 * Returns 0 on success, negative on failure
3902 static int ixgbe_link_config(struct ixgbe_hw *hw)
3904 u32 autoneg = IXGBE_LINK_SPEED_10GB_FULL;
3906 /* must always autoneg for both 1G and 10G link */
3907 hw->mac.autoneg = true;
3909 if ((hw->mac.type == ixgbe_mac_82598EB) &&
3910 (hw->phy.media_type == ixgbe_media_type_copper))
3911 autoneg = IXGBE_LINK_SPEED_82598_AUTONEG;
3913 return hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3916 static const struct net_device_ops ixgbe_netdev_ops = {
3917 .ndo_open = ixgbe_open,
3918 .ndo_stop = ixgbe_close,
3919 .ndo_start_xmit = ixgbe_xmit_frame,
3920 .ndo_get_stats = ixgbe_get_stats,
3921 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3922 .ndo_validate_addr = eth_validate_addr,
3923 .ndo_set_mac_address = ixgbe_set_mac,
3924 .ndo_change_mtu = ixgbe_change_mtu,
3925 .ndo_tx_timeout = ixgbe_tx_timeout,
3926 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3927 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3928 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3929 #ifdef CONFIG_NET_POLL_CONTROLLER
3930 .ndo_poll_controller = ixgbe_netpoll,
3935 * ixgbe_probe - Device Initialization Routine
3936 * @pdev: PCI device information struct
3937 * @ent: entry in ixgbe_pci_tbl
3939 * Returns 0 on success, negative on failure
3941 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3942 * The OS initialization, configuring of the adapter private structure,
3943 * and a hardware reset occur.
3945 static int __devinit ixgbe_probe(struct pci_dev *pdev,
3946 const struct pci_device_id *ent)
3948 struct net_device *netdev;
3949 struct ixgbe_adapter *adapter = NULL;
3950 struct ixgbe_hw *hw;
3951 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
3952 static int cards_found;
3953 int i, err, pci_using_dac;
3954 u16 link_status, link_speed, link_width;
3957 err = pci_enable_device(pdev);
3961 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3962 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3965 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3967 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3969 dev_err(&pdev->dev, "No usable DMA "
3970 "configuration, aborting\n");
3977 err = pci_request_regions(pdev, ixgbe_driver_name);
3979 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
3983 err = pci_enable_pcie_error_reporting(pdev);
3985 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
3987 /* non-fatal, continue */
3990 pci_set_master(pdev);
3991 pci_save_state(pdev);
3993 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
3996 goto err_alloc_etherdev;
3999 SET_NETDEV_DEV(netdev, &pdev->dev);
4001 pci_set_drvdata(pdev, netdev);
4002 adapter = netdev_priv(netdev);
4004 adapter->netdev = netdev;
4005 adapter->pdev = pdev;
4008 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4010 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4011 pci_resource_len(pdev, 0));
4017 for (i = 1; i <= 5; i++) {
4018 if (pci_resource_len(pdev, i) == 0)
4022 netdev->netdev_ops = &ixgbe_netdev_ops;
4023 ixgbe_set_ethtool_ops(netdev);
4024 netdev->watchdog_timeo = 5 * HZ;
4025 strcpy(netdev->name, pci_name(pdev));
4027 adapter->bd_number = cards_found;
4030 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
4031 hw->mac.type = ii->mac;
4034 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4035 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4036 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4037 if (!(eec & (1 << 8)))
4038 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4041 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
4042 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4044 /* set up this timer and work struct before calling get_invariants
4045 * which might start the timer
4047 init_timer(&adapter->sfp_timer);
4048 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4049 adapter->sfp_timer.data = (unsigned long) adapter;
4051 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
4053 err = ii->get_invariants(hw);
4054 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4055 /* start a kernel thread to watch for a module to arrive */
4056 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4057 mod_timer(&adapter->sfp_timer,
4058 round_jiffies(jiffies + (2 * HZ)));
4060 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4061 DPRINTK(PROBE, ERR, "failed to load because an "
4062 "unsupported SFP+ module type was detected.\n");
4068 /* setup the private structure */
4069 err = ixgbe_sw_init(adapter);
4073 /* reset_hw fills in the perm_addr as well */
4074 err = hw->mac.ops.reset_hw(hw);
4076 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4080 netdev->features = NETIF_F_SG |
4082 NETIF_F_HW_VLAN_TX |
4083 NETIF_F_HW_VLAN_RX |
4084 NETIF_F_HW_VLAN_FILTER;
4086 netdev->features |= NETIF_F_IPV6_CSUM;
4087 netdev->features |= NETIF_F_TSO;
4088 netdev->features |= NETIF_F_TSO6;
4089 netdev->features |= NETIF_F_GRO;
4091 netdev->vlan_features |= NETIF_F_TSO;
4092 netdev->vlan_features |= NETIF_F_TSO6;
4093 netdev->vlan_features |= NETIF_F_IP_CSUM;
4094 netdev->vlan_features |= NETIF_F_SG;
4096 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4097 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4099 #ifdef CONFIG_IXGBE_DCB
4100 netdev->dcbnl_ops = &dcbnl_ops;
4104 netdev->features |= NETIF_F_HIGHDMA;
4106 /* make sure the EEPROM is good */
4107 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
4108 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4113 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4114 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4116 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4117 dev_err(&pdev->dev, "invalid MAC address\n");
4122 init_timer(&adapter->watchdog_timer);
4123 adapter->watchdog_timer.function = &ixgbe_watchdog;
4124 adapter->watchdog_timer.data = (unsigned long)adapter;
4126 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
4127 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
4129 err = ixgbe_init_interrupt_scheme(adapter);
4133 /* print bus type/speed/width info */
4134 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4135 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4136 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
4137 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
4138 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4139 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4141 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4142 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4143 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4144 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4147 ixgbe_read_pba_num_generic(hw, &part_num);
4148 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4149 hw->mac.type, hw->phy.type,
4150 (part_num >> 8), (part_num & 0xff));
4152 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4153 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
4154 "this card is not sufficient for optimal "
4156 dev_warn(&pdev->dev, "For optimal performance a x8 "
4157 "PCI-Express slot is required.\n");
4160 /* reset the hardware with the new settings */
4161 hw->mac.ops.start_hw(hw);
4163 /* link_config depends on start_hw being called at least once */
4164 err = ixgbe_link_config(hw);
4166 dev_err(&pdev->dev, "setup_link_speed FAILED %d\n", err);
4170 netif_carrier_off(netdev);
4172 strcpy(netdev->name, "eth%d");
4173 err = register_netdev(netdev);
4177 #ifdef CONFIG_IXGBE_DCA
4178 if (dca_add_requester(&pdev->dev) == 0) {
4179 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4180 /* always use CB2 mode, difference is masked
4181 * in the CB driver */
4182 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4183 ixgbe_setup_dca(adapter);
4187 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4192 ixgbe_release_hw_control(adapter);
4195 ixgbe_reset_interrupt_capability(adapter);
4197 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4198 del_timer_sync(&adapter->sfp_timer);
4199 cancel_work_sync(&adapter->sfp_task);
4200 iounmap(hw->hw_addr);
4202 free_netdev(netdev);
4204 pci_release_regions(pdev);
4207 pci_disable_device(pdev);
4212 * ixgbe_remove - Device Removal Routine
4213 * @pdev: PCI device information struct
4215 * ixgbe_remove is called by the PCI subsystem to alert the driver
4216 * that it should release a PCI device. The could be caused by a
4217 * Hot-Plug event, or because the driver is going to be removed from
4220 static void __devexit ixgbe_remove(struct pci_dev *pdev)
4222 struct net_device *netdev = pci_get_drvdata(pdev);
4223 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4226 set_bit(__IXGBE_DOWN, &adapter->state);
4227 /* clear the module not found bit to make sure the worker won't
4230 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4231 del_timer_sync(&adapter->watchdog_timer);
4233 del_timer_sync(&adapter->sfp_timer);
4234 cancel_work_sync(&adapter->watchdog_task);
4235 cancel_work_sync(&adapter->sfp_task);
4236 flush_scheduled_work();
4238 #ifdef CONFIG_IXGBE_DCA
4239 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4240 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4241 dca_remove_requester(&pdev->dev);
4242 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4246 if (netdev->reg_state == NETREG_REGISTERED)
4247 unregister_netdev(netdev);
4249 ixgbe_reset_interrupt_capability(adapter);
4251 ixgbe_release_hw_control(adapter);
4253 iounmap(adapter->hw.hw_addr);
4254 pci_release_regions(pdev);
4256 DPRINTK(PROBE, INFO, "complete\n");
4257 kfree(adapter->tx_ring);
4258 kfree(adapter->rx_ring);
4260 free_netdev(netdev);
4262 err = pci_disable_pcie_error_reporting(pdev);
4265 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4267 pci_disable_device(pdev);
4271 * ixgbe_io_error_detected - called when PCI error is detected
4272 * @pdev: Pointer to PCI device
4273 * @state: The current pci connection state
4275 * This function is called after a PCI bus error affecting
4276 * this device has been detected.
4278 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
4279 pci_channel_state_t state)
4281 struct net_device *netdev = pci_get_drvdata(pdev);
4282 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4284 netif_device_detach(netdev);
4286 if (netif_running(netdev))
4287 ixgbe_down(adapter);
4288 pci_disable_device(pdev);
4290 /* Request a slot reset. */
4291 return PCI_ERS_RESULT_NEED_RESET;
4295 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4296 * @pdev: Pointer to PCI device
4298 * Restart the card from scratch, as if from a cold-boot.
4300 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4302 struct net_device *netdev = pci_get_drvdata(pdev);
4303 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4304 pci_ers_result_t result;
4307 if (pci_enable_device(pdev)) {
4309 "Cannot re-enable PCI device after reset.\n");
4310 result = PCI_ERS_RESULT_DISCONNECT;
4312 pci_set_master(pdev);
4313 pci_restore_state(pdev);
4315 pci_enable_wake(pdev, PCI_D3hot, 0);
4316 pci_enable_wake(pdev, PCI_D3cold, 0);
4318 ixgbe_reset(adapter);
4320 result = PCI_ERS_RESULT_RECOVERED;
4323 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4326 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4327 /* non-fatal, continue */
4334 * ixgbe_io_resume - called when traffic can start flowing again.
4335 * @pdev: Pointer to PCI device
4337 * This callback is called when the error recovery driver tells us that
4338 * its OK to resume normal operation.
4340 static void ixgbe_io_resume(struct pci_dev *pdev)
4342 struct net_device *netdev = pci_get_drvdata(pdev);
4343 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4345 if (netif_running(netdev)) {
4346 if (ixgbe_up(adapter)) {
4347 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4352 netif_device_attach(netdev);
4355 static struct pci_error_handlers ixgbe_err_handler = {
4356 .error_detected = ixgbe_io_error_detected,
4357 .slot_reset = ixgbe_io_slot_reset,
4358 .resume = ixgbe_io_resume,
4361 static struct pci_driver ixgbe_driver = {
4362 .name = ixgbe_driver_name,
4363 .id_table = ixgbe_pci_tbl,
4364 .probe = ixgbe_probe,
4365 .remove = __devexit_p(ixgbe_remove),
4367 .suspend = ixgbe_suspend,
4368 .resume = ixgbe_resume,
4370 .shutdown = ixgbe_shutdown,
4371 .err_handler = &ixgbe_err_handler
4375 * ixgbe_init_module - Driver Registration Routine
4377 * ixgbe_init_module is the first routine called when the driver is
4378 * loaded. All it does is register with the PCI subsystem.
4380 static int __init ixgbe_init_module(void)
4383 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4384 ixgbe_driver_string, ixgbe_driver_version);
4386 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4388 #ifdef CONFIG_IXGBE_DCA
4389 dca_register_notify(&dca_notifier);
4392 ret = pci_register_driver(&ixgbe_driver);
4396 module_init(ixgbe_init_module);
4399 * ixgbe_exit_module - Driver Exit Cleanup Routine
4401 * ixgbe_exit_module is called just before the driver is removed
4404 static void __exit ixgbe_exit_module(void)
4406 #ifdef CONFIG_IXGBE_DCA
4407 dca_unregister_notify(&dca_notifier);
4409 pci_unregister_driver(&ixgbe_driver);
4412 #ifdef CONFIG_IXGBE_DCA
4413 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
4418 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
4419 __ixgbe_notify_dca);
4421 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4423 #endif /* CONFIG_IXGBE_DCA */
4425 module_exit(ixgbe_exit_module);