1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 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 "2.0.8-k2"
51 const char ixgbe_driver_version[] = DRV_VERSION;
52 static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
54 static const struct ixgbe_info *ixgbe_info_tbl[] = {
55 [board_82598] = &ixgbe_82598_info,
56 [board_82599] = &ixgbe_82599_info,
59 /* ixgbe_pci_tbl - PCI Device ID Table
61 * Wildcard entries (PCI_ANY_ID) should come last
62 * Last entry must be all 0s
64 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
65 * Class, Class Mask, private data (not used) }
67 static struct pci_device_id ixgbe_pci_tbl[] = {
68 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
70 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
72 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
74 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
76 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
78 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
80 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
95 /* required last entry */
98 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
100 #ifdef CONFIG_IXGBE_DCA
101 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
103 static struct notifier_block dca_notifier = {
104 .notifier_call = ixgbe_notify_dca,
110 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
111 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
112 MODULE_LICENSE("GPL");
113 MODULE_VERSION(DRV_VERSION);
115 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
117 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
121 /* Let firmware take over control of h/w */
122 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
123 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
124 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
127 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
131 /* Let firmware know the driver has taken over */
132 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
133 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
134 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
138 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
139 * @adapter: pointer to adapter struct
140 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
141 * @queue: queue to map the corresponding interrupt to
142 * @msix_vector: the vector to map to the corresponding queue
145 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
146 u8 queue, u8 msix_vector)
149 struct ixgbe_hw *hw = &adapter->hw;
150 switch (hw->mac.type) {
151 case ixgbe_mac_82598EB:
152 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
155 index = (((direction * 64) + queue) >> 2) & 0x1F;
156 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
157 ivar &= ~(0xFF << (8 * (queue & 0x3)));
158 ivar |= (msix_vector << (8 * (queue & 0x3)));
159 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
161 case ixgbe_mac_82599EB:
162 if (direction == -1) {
164 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
165 index = ((queue & 1) * 8);
166 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
167 ivar &= ~(0xFF << index);
168 ivar |= (msix_vector << index);
169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
172 /* tx or rx causes */
173 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
174 index = ((16 * (queue & 1)) + (8 * direction));
175 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
176 ivar &= ~(0xFF << index);
177 ivar |= (msix_vector << index);
178 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
186 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
187 struct ixgbe_tx_buffer
190 if (tx_buffer_info->dma) {
191 pci_unmap_page(adapter->pdev, tx_buffer_info->dma,
192 tx_buffer_info->length, PCI_DMA_TODEVICE);
193 tx_buffer_info->dma = 0;
195 if (tx_buffer_info->skb) {
196 dev_kfree_skb_any(tx_buffer_info->skb);
197 tx_buffer_info->skb = NULL;
199 /* tx_buffer_info must be completely set up in the transmit path */
202 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
203 struct ixgbe_ring *tx_ring,
206 struct ixgbe_hw *hw = &adapter->hw;
209 /* Detect a transmit hang in hardware, this serializes the
210 * check with the clearing of time_stamp and movement of eop */
211 head = IXGBE_READ_REG(hw, tx_ring->head);
212 tail = IXGBE_READ_REG(hw, tx_ring->tail);
213 adapter->detect_tx_hung = false;
214 if ((head != tail) &&
215 tx_ring->tx_buffer_info[eop].time_stamp &&
216 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
217 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
218 /* detected Tx unit hang */
219 union ixgbe_adv_tx_desc *tx_desc;
220 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
221 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
223 " TDH, TDT <%x>, <%x>\n"
224 " next_to_use <%x>\n"
225 " next_to_clean <%x>\n"
226 "tx_buffer_info[next_to_clean]\n"
227 " time_stamp <%lx>\n"
229 tx_ring->queue_index,
231 tx_ring->next_to_use, eop,
232 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
239 #define IXGBE_MAX_TXD_PWR 14
240 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
242 /* Tx Descriptors needed, worst case */
243 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
244 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
245 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
246 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
248 static void ixgbe_tx_timeout(struct net_device *netdev);
251 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
252 * @adapter: board private structure
253 * @tx_ring: tx ring to clean
255 * returns true if transmit work is done
257 static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
258 struct ixgbe_ring *tx_ring)
260 struct net_device *netdev = adapter->netdev;
261 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
262 struct ixgbe_tx_buffer *tx_buffer_info;
263 unsigned int i, eop, count = 0;
264 unsigned int total_bytes = 0, total_packets = 0;
266 i = tx_ring->next_to_clean;
267 eop = tx_ring->tx_buffer_info[i].next_to_watch;
268 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
270 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
271 (count < tx_ring->work_limit)) {
272 bool cleaned = false;
273 for ( ; !cleaned; count++) {
275 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
276 tx_buffer_info = &tx_ring->tx_buffer_info[i];
277 cleaned = (i == eop);
278 skb = tx_buffer_info->skb;
280 if (cleaned && skb) {
281 unsigned int segs, bytecount;
283 /* gso_segs is currently only valid for tcp */
284 segs = skb_shinfo(skb)->gso_segs ?: 1;
285 /* multiply data chunks by size of headers */
286 bytecount = ((segs - 1) * skb_headlen(skb)) +
288 total_packets += segs;
289 total_bytes += bytecount;
292 ixgbe_unmap_and_free_tx_resource(adapter,
295 tx_desc->wb.status = 0;
298 if (i == tx_ring->count)
302 eop = tx_ring->tx_buffer_info[i].next_to_watch;
303 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
306 tx_ring->next_to_clean = i;
308 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
309 if (unlikely(count && netif_carrier_ok(netdev) &&
310 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
311 /* Make sure that anybody stopping the queue after this
312 * sees the new next_to_clean.
315 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
316 !test_bit(__IXGBE_DOWN, &adapter->state)) {
317 netif_wake_subqueue(netdev, tx_ring->queue_index);
318 ++adapter->restart_queue;
322 if (adapter->detect_tx_hung) {
323 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
324 /* schedule immediate reset if we believe we hung */
326 "tx hang %d detected, resetting adapter\n",
327 adapter->tx_timeout_count + 1);
328 ixgbe_tx_timeout(adapter->netdev);
332 /* re-arm the interrupt */
333 if (count >= tx_ring->work_limit)
334 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
336 tx_ring->total_bytes += total_bytes;
337 tx_ring->total_packets += total_packets;
338 tx_ring->stats.packets += total_packets;
339 tx_ring->stats.bytes += total_bytes;
340 adapter->net_stats.tx_bytes += total_bytes;
341 adapter->net_stats.tx_packets += total_packets;
342 return (count < tx_ring->work_limit);
345 #ifdef CONFIG_IXGBE_DCA
346 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
347 struct ixgbe_ring *rx_ring)
351 int q = rx_ring - adapter->rx_ring;
353 if (rx_ring->cpu != cpu) {
354 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
355 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
356 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
357 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
358 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
359 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
360 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
361 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
363 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
364 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
365 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
366 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
367 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
368 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
374 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
375 struct ixgbe_ring *tx_ring)
379 int q = tx_ring - adapter->tx_ring;
381 if (tx_ring->cpu != cpu) {
382 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
383 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
384 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
385 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
386 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
387 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
388 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
389 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
391 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
392 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
398 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
402 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
405 for (i = 0; i < adapter->num_tx_queues; i++) {
406 adapter->tx_ring[i].cpu = -1;
407 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
409 for (i = 0; i < adapter->num_rx_queues; i++) {
410 adapter->rx_ring[i].cpu = -1;
411 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
415 static int __ixgbe_notify_dca(struct device *dev, void *data)
417 struct net_device *netdev = dev_get_drvdata(dev);
418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
419 unsigned long event = *(unsigned long *)data;
422 case DCA_PROVIDER_ADD:
423 /* if we're already enabled, don't do it again */
424 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
426 /* Always use CB2 mode, difference is masked
427 * in the CB driver. */
428 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
429 if (dca_add_requester(dev) == 0) {
430 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
431 ixgbe_setup_dca(adapter);
434 /* Fall Through since DCA is disabled. */
435 case DCA_PROVIDER_REMOVE:
436 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
437 dca_remove_requester(dev);
438 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
439 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
447 #endif /* CONFIG_IXGBE_DCA */
449 * ixgbe_receive_skb - Send a completed packet up the stack
450 * @adapter: board private structure
451 * @skb: packet to send up
452 * @status: hardware indication of status of receive
453 * @rx_ring: rx descriptor ring (for a specific queue) to setup
454 * @rx_desc: rx descriptor
456 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
457 struct sk_buff *skb, u8 status,
458 union ixgbe_adv_rx_desc *rx_desc)
460 struct ixgbe_adapter *adapter = q_vector->adapter;
461 struct napi_struct *napi = &q_vector->napi;
462 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
463 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
465 skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]);
466 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
467 if (adapter->vlgrp && is_vlan && (tag != 0))
468 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
470 napi_gro_receive(napi, skb);
472 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
473 if (adapter->vlgrp && is_vlan && (tag != 0))
474 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
476 netif_receive_skb(skb);
478 if (adapter->vlgrp && is_vlan && (tag != 0))
479 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
487 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
488 * @adapter: address of board private structure
489 * @status_err: hardware indication of status of receive
490 * @skb: skb currently being received and modified
492 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
493 u32 status_err, struct sk_buff *skb)
495 skb->ip_summed = CHECKSUM_NONE;
497 /* Rx csum disabled */
498 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
501 /* if IP and error */
502 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
503 (status_err & IXGBE_RXDADV_ERR_IPE)) {
504 adapter->hw_csum_rx_error++;
508 if (!(status_err & IXGBE_RXD_STAT_L4CS))
511 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
512 adapter->hw_csum_rx_error++;
516 /* It must be a TCP or UDP packet with a valid checksum */
517 skb->ip_summed = CHECKSUM_UNNECESSARY;
518 adapter->hw_csum_rx_good++;
521 static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
522 struct ixgbe_ring *rx_ring, u32 val)
525 * Force memory writes to complete before letting h/w
526 * know there are new descriptors to fetch. (Only
527 * applicable for weak-ordered memory model archs,
531 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
535 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
536 * @adapter: address of board private structure
538 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
539 struct ixgbe_ring *rx_ring,
542 struct pci_dev *pdev = adapter->pdev;
543 union ixgbe_adv_rx_desc *rx_desc;
544 struct ixgbe_rx_buffer *bi;
546 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
548 i = rx_ring->next_to_use;
549 bi = &rx_ring->rx_buffer_info[i];
551 while (cleaned_count--) {
552 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
555 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
557 bi->page = alloc_page(GFP_ATOMIC);
559 adapter->alloc_rx_page_failed++;
564 /* use a half page if we're re-using */
565 bi->page_offset ^= (PAGE_SIZE / 2);
568 bi->page_dma = pci_map_page(pdev, bi->page,
576 skb = netdev_alloc_skb(adapter->netdev, bufsz);
579 adapter->alloc_rx_buff_failed++;
584 * Make buffer alignment 2 beyond a 16 byte boundary
585 * this will result in a 16 byte aligned IP header after
586 * the 14 byte MAC header is removed
588 skb_reserve(skb, NET_IP_ALIGN);
591 bi->dma = pci_map_single(pdev, skb->data, bufsz,
594 /* Refresh the desc even if buffer_addrs didn't change because
595 * each write-back erases this info. */
596 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
597 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
598 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
600 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
604 if (i == rx_ring->count)
606 bi = &rx_ring->rx_buffer_info[i];
610 if (rx_ring->next_to_use != i) {
611 rx_ring->next_to_use = i;
613 i = (rx_ring->count - 1);
615 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
619 static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
621 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
624 static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
626 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
629 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
630 struct ixgbe_ring *rx_ring,
631 int *work_done, int work_to_do)
633 struct ixgbe_adapter *adapter = q_vector->adapter;
634 struct pci_dev *pdev = adapter->pdev;
635 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
636 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
641 bool cleaned = false;
642 int cleaned_count = 0;
643 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
645 i = rx_ring->next_to_clean;
646 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
647 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
648 rx_buffer_info = &rx_ring->rx_buffer_info[i];
650 while (staterr & IXGBE_RXD_STAT_DD) {
652 if (*work_done >= work_to_do)
656 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
657 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
658 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
659 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
660 if (hdr_info & IXGBE_RXDADV_SPH)
661 adapter->rx_hdr_split++;
662 if (len > IXGBE_RX_HDR_SIZE)
663 len = IXGBE_RX_HDR_SIZE;
664 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
666 len = le16_to_cpu(rx_desc->wb.upper.length);
670 skb = rx_buffer_info->skb;
671 prefetch(skb->data - NET_IP_ALIGN);
672 rx_buffer_info->skb = NULL;
674 if (len && !skb_shinfo(skb)->nr_frags) {
675 pci_unmap_single(pdev, rx_buffer_info->dma,
682 pci_unmap_page(pdev, rx_buffer_info->page_dma,
683 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
684 rx_buffer_info->page_dma = 0;
685 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
686 rx_buffer_info->page,
687 rx_buffer_info->page_offset,
690 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
691 (page_count(rx_buffer_info->page) != 1))
692 rx_buffer_info->page = NULL;
694 get_page(rx_buffer_info->page);
696 skb->len += upper_len;
697 skb->data_len += upper_len;
698 skb->truesize += upper_len;
702 if (i == rx_ring->count)
704 next_buffer = &rx_ring->rx_buffer_info[i];
706 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
710 if (staterr & IXGBE_RXD_STAT_EOP) {
711 rx_ring->stats.packets++;
712 rx_ring->stats.bytes += skb->len;
714 rx_buffer_info->skb = next_buffer->skb;
715 rx_buffer_info->dma = next_buffer->dma;
716 next_buffer->skb = skb;
717 next_buffer->dma = 0;
718 adapter->non_eop_descs++;
722 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
723 dev_kfree_skb_irq(skb);
727 ixgbe_rx_checksum(adapter, staterr, skb);
729 /* probably a little skewed due to removing CRC */
730 total_rx_bytes += skb->len;
733 skb->protocol = eth_type_trans(skb, adapter->netdev);
734 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
737 rx_desc->wb.upper.status_error = 0;
739 /* return some buffers to hardware, one at a time is too slow */
740 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
741 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
745 /* use prefetched values */
747 rx_buffer_info = next_buffer;
749 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
752 rx_ring->next_to_clean = i;
753 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
756 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
758 rx_ring->total_packets += total_rx_packets;
759 rx_ring->total_bytes += total_rx_bytes;
760 adapter->net_stats.rx_bytes += total_rx_bytes;
761 adapter->net_stats.rx_packets += total_rx_packets;
766 static int ixgbe_clean_rxonly(struct napi_struct *, int);
768 * ixgbe_configure_msix - Configure MSI-X hardware
769 * @adapter: board private structure
771 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
774 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
776 struct ixgbe_q_vector *q_vector;
777 int i, j, q_vectors, v_idx, r_idx;
780 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
782 /* Populate the IVAR table and set the ITR values to the
783 * corresponding register.
785 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
786 q_vector = &adapter->q_vector[v_idx];
787 /* XXX for_each_bit(...) */
788 r_idx = find_first_bit(q_vector->rxr_idx,
789 adapter->num_rx_queues);
791 for (i = 0; i < q_vector->rxr_count; i++) {
792 j = adapter->rx_ring[r_idx].reg_idx;
793 ixgbe_set_ivar(adapter, 0, j, v_idx);
794 r_idx = find_next_bit(q_vector->rxr_idx,
795 adapter->num_rx_queues,
798 r_idx = find_first_bit(q_vector->txr_idx,
799 adapter->num_tx_queues);
801 for (i = 0; i < q_vector->txr_count; i++) {
802 j = adapter->tx_ring[r_idx].reg_idx;
803 ixgbe_set_ivar(adapter, 1, j, v_idx);
804 r_idx = find_next_bit(q_vector->txr_idx,
805 adapter->num_tx_queues,
809 /* if this is a tx only vector halve the interrupt rate */
810 if (q_vector->txr_count && !q_vector->rxr_count)
811 q_vector->eitr = (adapter->eitr_param >> 1);
812 else if (q_vector->rxr_count)
814 q_vector->eitr = adapter->eitr_param;
817 * since ths is initial set up don't need to call
818 * ixgbe_write_eitr helper
820 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
821 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
824 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
825 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
827 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
828 ixgbe_set_ivar(adapter, -1, 1, v_idx);
829 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
831 /* set up to autoclear timer, and the vectors */
832 mask = IXGBE_EIMS_ENABLE_MASK;
833 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
834 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
841 latency_invalid = 255
845 * ixgbe_update_itr - update the dynamic ITR value based on statistics
846 * @adapter: pointer to adapter
847 * @eitr: eitr setting (ints per sec) to give last timeslice
848 * @itr_setting: current throttle rate in ints/second
849 * @packets: the number of packets during this measurement interval
850 * @bytes: the number of bytes during this measurement interval
852 * Stores a new ITR value based on packets and byte
853 * counts during the last interrupt. The advantage of per interrupt
854 * computation is faster updates and more accurate ITR for the current
855 * traffic pattern. Constants in this function were computed
856 * based on theoretical maximum wire speed and thresholds were set based
857 * on testing data as well as attempting to minimize response time
858 * while increasing bulk throughput.
859 * this functionality is controlled by the InterruptThrottleRate module
860 * parameter (see ixgbe_param.c)
862 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
863 u32 eitr, u8 itr_setting,
864 int packets, int bytes)
866 unsigned int retval = itr_setting;
871 goto update_itr_done;
874 /* simple throttlerate management
875 * 0-20MB/s lowest (100000 ints/s)
876 * 20-100MB/s low (20000 ints/s)
877 * 100-1249MB/s bulk (8000 ints/s)
879 /* what was last interrupt timeslice? */
880 timepassed_us = 1000000/eitr;
881 bytes_perint = bytes / timepassed_us; /* bytes/usec */
883 switch (itr_setting) {
885 if (bytes_perint > adapter->eitr_low)
886 retval = low_latency;
889 if (bytes_perint > adapter->eitr_high)
890 retval = bulk_latency;
891 else if (bytes_perint <= adapter->eitr_low)
892 retval = lowest_latency;
895 if (bytes_perint <= adapter->eitr_high)
896 retval = low_latency;
905 * ixgbe_write_eitr - write EITR register in hardware specific way
906 * @adapter: pointer to adapter struct
907 * @v_idx: vector index into q_vector array
908 * @itr_reg: new value to be written in *register* format, not ints/s
910 * This function is made to be called by ethtool and by the driver
911 * when it needs to update EITR registers at runtime. Hardware
912 * specific quirks/differences are taken care of here.
914 void ixgbe_write_eitr(struct ixgbe_adapter *adapter, int v_idx, u32 itr_reg)
916 struct ixgbe_hw *hw = &adapter->hw;
917 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
918 /* must write high and low 16 bits to reset counter */
919 itr_reg |= (itr_reg << 16);
920 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
922 * set the WDIS bit to not clear the timer bits and cause an
923 * immediate assertion of the interrupt
925 itr_reg |= IXGBE_EITR_CNT_WDIS;
927 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
930 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
932 struct ixgbe_adapter *adapter = q_vector->adapter;
934 u8 current_itr, ret_itr;
935 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
936 sizeof(struct ixgbe_q_vector);
937 struct ixgbe_ring *rx_ring, *tx_ring;
939 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
940 for (i = 0; i < q_vector->txr_count; i++) {
941 tx_ring = &(adapter->tx_ring[r_idx]);
942 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
944 tx_ring->total_packets,
945 tx_ring->total_bytes);
946 /* if the result for this queue would decrease interrupt
947 * rate for this vector then use that result */
948 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
949 q_vector->tx_itr - 1 : ret_itr);
950 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
954 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
955 for (i = 0; i < q_vector->rxr_count; i++) {
956 rx_ring = &(adapter->rx_ring[r_idx]);
957 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
959 rx_ring->total_packets,
960 rx_ring->total_bytes);
961 /* if the result for this queue would decrease interrupt
962 * rate for this vector then use that result */
963 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
964 q_vector->rx_itr - 1 : ret_itr);
965 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
969 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
971 switch (current_itr) {
972 /* counts and packets in update_itr are dependent on these numbers */
977 new_itr = 20000; /* aka hwitr = ~200 */
985 if (new_itr != q_vector->eitr) {
988 /* save the algorithm value here, not the smoothed one */
989 q_vector->eitr = new_itr;
990 /* do an exponential smoothing */
991 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
992 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
993 ixgbe_write_eitr(adapter, v_idx, itr_reg);
999 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1001 struct ixgbe_hw *hw = &adapter->hw;
1003 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1004 (eicr & IXGBE_EICR_GPI_SDP1)) {
1005 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1006 /* write to clear the interrupt */
1007 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1011 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1013 struct ixgbe_hw *hw = &adapter->hw;
1015 if (eicr & IXGBE_EICR_GPI_SDP1) {
1016 /* Clear the interrupt */
1017 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1018 schedule_work(&adapter->multispeed_fiber_task);
1019 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1020 /* Clear the interrupt */
1021 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1022 schedule_work(&adapter->sfp_config_module_task);
1024 /* Interrupt isn't for us... */
1029 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1031 struct ixgbe_hw *hw = &adapter->hw;
1034 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1035 adapter->link_check_timeout = jiffies;
1036 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1037 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1038 schedule_work(&adapter->watchdog_task);
1042 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1044 struct net_device *netdev = data;
1045 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1046 struct ixgbe_hw *hw = &adapter->hw;
1050 * Workaround for Silicon errata. Use clear-by-write instead
1051 * of clear-by-read. Reading with EICS will return the
1052 * interrupt causes without clearing, which later be done
1053 * with the write to EICR.
1055 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1056 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1058 if (eicr & IXGBE_EICR_LSC)
1059 ixgbe_check_lsc(adapter);
1061 if (hw->mac.type == ixgbe_mac_82598EB)
1062 ixgbe_check_fan_failure(adapter, eicr);
1064 if (hw->mac.type == ixgbe_mac_82599EB)
1065 ixgbe_check_sfp_event(adapter, eicr);
1066 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1067 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1072 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1074 struct ixgbe_q_vector *q_vector = data;
1075 struct ixgbe_adapter *adapter = q_vector->adapter;
1076 struct ixgbe_ring *tx_ring;
1079 if (!q_vector->txr_count)
1082 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1083 for (i = 0; i < q_vector->txr_count; i++) {
1084 tx_ring = &(adapter->tx_ring[r_idx]);
1085 #ifdef CONFIG_IXGBE_DCA
1086 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1087 ixgbe_update_tx_dca(adapter, tx_ring);
1089 tx_ring->total_bytes = 0;
1090 tx_ring->total_packets = 0;
1091 ixgbe_clean_tx_irq(adapter, tx_ring);
1092 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1100 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1102 * @data: pointer to our q_vector struct for this interrupt vector
1104 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1106 struct ixgbe_q_vector *q_vector = data;
1107 struct ixgbe_adapter *adapter = q_vector->adapter;
1108 struct ixgbe_ring *rx_ring;
1112 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1113 for (i = 0; i < q_vector->rxr_count; i++) {
1114 rx_ring = &(adapter->rx_ring[r_idx]);
1115 rx_ring->total_bytes = 0;
1116 rx_ring->total_packets = 0;
1117 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1121 if (!q_vector->rxr_count)
1124 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1125 rx_ring = &(adapter->rx_ring[r_idx]);
1126 /* disable interrupts on this vector only */
1127 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
1128 napi_schedule(&q_vector->napi);
1133 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1135 ixgbe_msix_clean_rx(irq, data);
1136 ixgbe_msix_clean_tx(irq, data);
1142 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1143 * @napi: napi struct with our devices info in it
1144 * @budget: amount of work driver is allowed to do this pass, in packets
1146 * This function is optimized for cleaning one queue only on a single
1149 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1151 struct ixgbe_q_vector *q_vector =
1152 container_of(napi, struct ixgbe_q_vector, napi);
1153 struct ixgbe_adapter *adapter = q_vector->adapter;
1154 struct ixgbe_ring *rx_ring = NULL;
1158 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1159 rx_ring = &(adapter->rx_ring[r_idx]);
1160 #ifdef CONFIG_IXGBE_DCA
1161 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1162 ixgbe_update_rx_dca(adapter, rx_ring);
1165 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
1167 /* If all Rx work done, exit the polling mode */
1168 if (work_done < budget) {
1169 napi_complete(napi);
1170 if (adapter->itr_setting & 1)
1171 ixgbe_set_itr_msix(q_vector);
1172 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1173 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
1180 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1181 * @napi: napi struct with our devices info in it
1182 * @budget: amount of work driver is allowed to do this pass, in packets
1184 * This function will clean more than one rx queue associated with a
1187 static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1189 struct ixgbe_q_vector *q_vector =
1190 container_of(napi, struct ixgbe_q_vector, napi);
1191 struct ixgbe_adapter *adapter = q_vector->adapter;
1192 struct ixgbe_ring *rx_ring = NULL;
1193 int work_done = 0, i;
1195 u16 enable_mask = 0;
1197 /* attempt to distribute budget to each queue fairly, but don't allow
1198 * the budget to go below 1 because we'll exit polling */
1199 budget /= (q_vector->rxr_count ?: 1);
1200 budget = max(budget, 1);
1201 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1202 for (i = 0; i < q_vector->rxr_count; i++) {
1203 rx_ring = &(adapter->rx_ring[r_idx]);
1204 #ifdef CONFIG_IXGBE_DCA
1205 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1206 ixgbe_update_rx_dca(adapter, rx_ring);
1208 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
1209 enable_mask |= rx_ring->v_idx;
1210 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1214 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1215 rx_ring = &(adapter->rx_ring[r_idx]);
1216 /* If all Rx work done, exit the polling mode */
1217 if (work_done < budget) {
1218 napi_complete(napi);
1219 if (adapter->itr_setting & 1)
1220 ixgbe_set_itr_msix(q_vector);
1221 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1222 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1228 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
1231 a->q_vector[v_idx].adapter = a;
1232 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1233 a->q_vector[v_idx].rxr_count++;
1234 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1237 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
1240 a->q_vector[v_idx].adapter = a;
1241 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1242 a->q_vector[v_idx].txr_count++;
1243 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1247 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1248 * @adapter: board private structure to initialize
1249 * @vectors: allotted vector count for descriptor rings
1251 * This function maps descriptor rings to the queue-specific vectors
1252 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1253 * one vector per ring/queue, but on a constrained vector budget, we
1254 * group the rings as "efficiently" as possible. You would add new
1255 * mapping configurations in here.
1257 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
1261 int rxr_idx = 0, txr_idx = 0;
1262 int rxr_remaining = adapter->num_rx_queues;
1263 int txr_remaining = adapter->num_tx_queues;
1268 /* No mapping required if MSI-X is disabled. */
1269 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1273 * The ideal configuration...
1274 * We have enough vectors to map one per queue.
1276 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1277 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1278 map_vector_to_rxq(adapter, v_start, rxr_idx);
1280 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1281 map_vector_to_txq(adapter, v_start, txr_idx);
1287 * If we don't have enough vectors for a 1-to-1
1288 * mapping, we'll have to group them so there are
1289 * multiple queues per vector.
1291 /* Re-adjusting *qpv takes care of the remainder. */
1292 for (i = v_start; i < vectors; i++) {
1293 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1294 for (j = 0; j < rqpv; j++) {
1295 map_vector_to_rxq(adapter, i, rxr_idx);
1300 for (i = v_start; i < vectors; i++) {
1301 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1302 for (j = 0; j < tqpv; j++) {
1303 map_vector_to_txq(adapter, i, txr_idx);
1314 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1315 * @adapter: board private structure
1317 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1318 * interrupts from the kernel.
1320 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1322 struct net_device *netdev = adapter->netdev;
1323 irqreturn_t (*handler)(int, void *);
1324 int i, vector, q_vectors, err;
1327 /* Decrement for Other and TCP Timer vectors */
1328 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1330 /* Map the Tx/Rx rings to the vectors we were allotted. */
1331 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1335 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1336 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1337 &ixgbe_msix_clean_many)
1338 for (vector = 0; vector < q_vectors; vector++) {
1339 handler = SET_HANDLER(&adapter->q_vector[vector]);
1341 if(handler == &ixgbe_msix_clean_rx) {
1342 sprintf(adapter->name[vector], "%s-%s-%d",
1343 netdev->name, "rx", ri++);
1345 else if(handler == &ixgbe_msix_clean_tx) {
1346 sprintf(adapter->name[vector], "%s-%s-%d",
1347 netdev->name, "tx", ti++);
1350 sprintf(adapter->name[vector], "%s-%s-%d",
1351 netdev->name, "TxRx", vector);
1353 err = request_irq(adapter->msix_entries[vector].vector,
1354 handler, 0, adapter->name[vector],
1355 &(adapter->q_vector[vector]));
1358 "request_irq failed for MSIX interrupt "
1359 "Error: %d\n", err);
1360 goto free_queue_irqs;
1364 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1365 err = request_irq(adapter->msix_entries[vector].vector,
1366 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
1369 "request_irq for msix_lsc failed: %d\n", err);
1370 goto free_queue_irqs;
1376 for (i = vector - 1; i >= 0; i--)
1377 free_irq(adapter->msix_entries[--vector].vector,
1378 &(adapter->q_vector[i]));
1379 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1380 pci_disable_msix(adapter->pdev);
1381 kfree(adapter->msix_entries);
1382 adapter->msix_entries = NULL;
1387 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1389 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1391 u32 new_itr = q_vector->eitr;
1392 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1393 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1395 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
1397 tx_ring->total_packets,
1398 tx_ring->total_bytes);
1399 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
1401 rx_ring->total_packets,
1402 rx_ring->total_bytes);
1404 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1406 switch (current_itr) {
1407 /* counts and packets in update_itr are dependent on these numbers */
1408 case lowest_latency:
1412 new_itr = 20000; /* aka hwitr = ~200 */
1421 if (new_itr != q_vector->eitr) {
1424 /* save the algorithm value here, not the smoothed one */
1425 q_vector->eitr = new_itr;
1426 /* do an exponential smoothing */
1427 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1428 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1429 ixgbe_write_eitr(adapter, 0, itr_reg);
1436 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1437 * @adapter: board private structure
1439 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1441 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1442 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1443 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
1444 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(2), ~0);
1446 IXGBE_WRITE_FLUSH(&adapter->hw);
1447 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1449 for (i = 0; i < adapter->num_msix_vectors; i++)
1450 synchronize_irq(adapter->msix_entries[i].vector);
1452 synchronize_irq(adapter->pdev->irq);
1457 * ixgbe_irq_enable - Enable default interrupt generation settings
1458 * @adapter: board private structure
1460 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1463 mask = IXGBE_EIMS_ENABLE_MASK;
1464 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1465 mask |= IXGBE_EIMS_GPI_SDP1;
1466 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1467 mask |= IXGBE_EIMS_ECC;
1468 mask |= IXGBE_EIMS_GPI_SDP1;
1469 mask |= IXGBE_EIMS_GPI_SDP2;
1472 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1473 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1474 /* enable the rest of the queue vectors */
1475 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1),
1476 (IXGBE_EIMS_RTX_QUEUE << 16));
1477 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1478 ((IXGBE_EIMS_RTX_QUEUE << 16) |
1479 IXGBE_EIMS_RTX_QUEUE));
1481 IXGBE_WRITE_FLUSH(&adapter->hw);
1485 * ixgbe_intr - legacy mode Interrupt Handler
1486 * @irq: interrupt number
1487 * @data: pointer to a network interface device structure
1489 static irqreturn_t ixgbe_intr(int irq, void *data)
1491 struct net_device *netdev = data;
1492 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1493 struct ixgbe_hw *hw = &adapter->hw;
1497 * Workaround for silicon errata. Mask the interrupts
1498 * before the read of EICR.
1500 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1502 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1503 * therefore no explict interrupt disable is necessary */
1504 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1506 /* shared interrupt alert!
1507 * make sure interrupts are enabled because the read will
1508 * have disabled interrupts due to EIAM */
1509 ixgbe_irq_enable(adapter);
1510 return IRQ_NONE; /* Not our interrupt */
1513 if (eicr & IXGBE_EICR_LSC)
1514 ixgbe_check_lsc(adapter);
1516 if (hw->mac.type == ixgbe_mac_82599EB)
1517 ixgbe_check_sfp_event(adapter, eicr);
1519 ixgbe_check_fan_failure(adapter, eicr);
1521 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
1522 adapter->tx_ring[0].total_packets = 0;
1523 adapter->tx_ring[0].total_bytes = 0;
1524 adapter->rx_ring[0].total_packets = 0;
1525 adapter->rx_ring[0].total_bytes = 0;
1526 /* would disable interrupts here but EIAM disabled it */
1527 __napi_schedule(&adapter->q_vector[0].napi);
1533 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1535 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1537 for (i = 0; i < q_vectors; i++) {
1538 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1539 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1540 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1541 q_vector->rxr_count = 0;
1542 q_vector->txr_count = 0;
1547 * ixgbe_request_irq - initialize interrupts
1548 * @adapter: board private structure
1550 * Attempts to configure interrupts using the best available
1551 * capabilities of the hardware and kernel.
1553 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
1555 struct net_device *netdev = adapter->netdev;
1558 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1559 err = ixgbe_request_msix_irqs(adapter);
1560 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1561 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
1562 netdev->name, netdev);
1564 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
1565 netdev->name, netdev);
1569 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1574 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1576 struct net_device *netdev = adapter->netdev;
1578 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1581 q_vectors = adapter->num_msix_vectors;
1584 free_irq(adapter->msix_entries[i].vector, netdev);
1587 for (; i >= 0; i--) {
1588 free_irq(adapter->msix_entries[i].vector,
1589 &(adapter->q_vector[i]));
1592 ixgbe_reset_q_vectors(adapter);
1594 free_irq(adapter->pdev->irq, netdev);
1599 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1602 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1604 struct ixgbe_hw *hw = &adapter->hw;
1606 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
1607 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
1609 ixgbe_set_ivar(adapter, 0, 0, 0);
1610 ixgbe_set_ivar(adapter, 1, 0, 0);
1612 map_vector_to_rxq(adapter, 0, 0);
1613 map_vector_to_txq(adapter, 0, 0);
1615 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
1619 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1620 * @adapter: board private structure
1622 * Configure the Tx unit of the MAC after a reset.
1624 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1627 struct ixgbe_hw *hw = &adapter->hw;
1628 u32 i, j, tdlen, txctrl;
1630 /* Setup the HW Tx Head and Tail descriptor pointers */
1631 for (i = 0; i < adapter->num_tx_queues; i++) {
1632 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1635 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1636 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
1637 (tdba & DMA_32BIT_MASK));
1638 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1639 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1640 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1641 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1642 adapter->tx_ring[i].head = IXGBE_TDH(j);
1643 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1644 /* Disable Tx Head Writeback RO bit, since this hoses
1645 * bookkeeping if things aren't delivered in order.
1647 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1648 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1649 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1651 if (hw->mac.type == ixgbe_mac_82599EB) {
1652 /* We enable 8 traffic classes, DCB only */
1653 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1654 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1655 IXGBE_MTQC_8TC_8TQ));
1659 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1661 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1663 struct ixgbe_ring *rx_ring;
1668 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1671 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1672 queue0 = index & mask;
1673 index = index & mask;
1676 rx_ring = &adapter->rx_ring[queue0];
1678 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1680 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1681 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1683 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1684 u16 bufsz = IXGBE_RXBUFFER_2048;
1685 /* grow the amount we can receive on large page machines */
1686 if (bufsz < (PAGE_SIZE / 2))
1687 bufsz = (PAGE_SIZE / 2);
1688 /* cap the bufsz at our largest descriptor size */
1689 bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz);
1691 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1692 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1693 srrctl |= ((IXGBE_RX_HDR_SIZE <<
1694 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1695 IXGBE_SRRCTL_BSIZEHDR_MASK);
1697 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1699 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1700 srrctl |= IXGBE_RXBUFFER_2048 >>
1701 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1703 srrctl |= rx_ring->rx_buf_len >>
1704 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1707 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1711 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
1712 * @adapter: board private structure
1714 * Configure the Rx unit of the MAC after a reset.
1716 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1719 struct ixgbe_hw *hw = &adapter->hw;
1720 struct net_device *netdev = adapter->netdev;
1721 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1723 u32 rdlen, rxctrl, rxcsum;
1724 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1725 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1726 0x6A3E67EA, 0x14364D17, 0x3BED200D};
1728 u32 reta = 0, mrqc = 0;
1732 /* Decide whether to use packet split mode or not */
1733 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1735 /* Set the RX buffer length according to the mode */
1736 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1737 rx_buf_len = IXGBE_RX_HDR_SIZE;
1738 if (hw->mac.type == ixgbe_mac_82599EB) {
1739 /* PSRTYPE must be initialized in 82599 */
1740 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1741 IXGBE_PSRTYPE_UDPHDR |
1742 IXGBE_PSRTYPE_IPV4HDR |
1743 IXGBE_PSRTYPE_IPV6HDR;
1744 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1747 if (netdev->mtu <= ETH_DATA_LEN)
1748 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1750 rx_buf_len = ALIGN(max_frame, 1024);
1753 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1754 fctrl |= IXGBE_FCTRL_BAM;
1755 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
1756 fctrl |= IXGBE_FCTRL_PMCF;
1757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1759 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1760 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1761 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1763 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1764 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1766 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1767 /* disable receives while setting up the descriptors */
1768 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1769 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1771 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1772 * the Base and Length of the Rx Descriptor Ring */
1773 for (i = 0; i < adapter->num_rx_queues; i++) {
1774 rdba = adapter->rx_ring[i].dma;
1775 j = adapter->rx_ring[i].reg_idx;
1776 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1777 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1778 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1779 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1780 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1781 adapter->rx_ring[i].head = IXGBE_RDH(j);
1782 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1783 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
1785 ixgbe_configure_srrctl(adapter, j);
1788 if (hw->mac.type == ixgbe_mac_82598EB) {
1790 * For VMDq support of different descriptor types or
1791 * buffer sizes through the use of multiple SRRCTL
1792 * registers, RDRXCTL.MVMEN must be set to 1
1794 * also, the manual doesn't mention it clearly but DCA hints
1795 * will only use queue 0's tags unless this bit is set. Side
1796 * effects of setting this bit are only that SRRCTL must be
1797 * fully programmed [0..15]
1799 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1800 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1801 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1804 /* Program MRQC for the distribution of queues */
1805 if (hw->mac.type == ixgbe_mac_82599EB) {
1806 int mask = adapter->flags & (
1807 IXGBE_FLAG_RSS_ENABLED
1808 | IXGBE_FLAG_DCB_ENABLED
1812 case (IXGBE_FLAG_RSS_ENABLED):
1813 mrqc = IXGBE_MRQC_RSSEN;
1815 case (IXGBE_FLAG_DCB_ENABLED):
1816 mrqc = IXGBE_MRQC_RT8TCEN;
1822 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
1823 /* Fill out redirection table */
1824 for (i = 0, j = 0; i < 128; i++, j++) {
1825 if (j == adapter->ring_feature[RING_F_RSS].indices)
1827 /* reta = 4-byte sliding window of
1828 * 0x00..(indices-1)(indices-1)00..etc. */
1829 reta = (reta << 8) | (j * 0x11);
1831 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
1834 /* Fill out hash function seeds */
1835 for (i = 0; i < 10; i++)
1836 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
1838 if (hw->mac.type == ixgbe_mac_82598EB)
1839 mrqc |= IXGBE_MRQC_RSSEN;
1840 /* Perform hash on these packet types */
1841 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
1842 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1843 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1844 | IXGBE_MRQC_RSS_FIELD_IPV6
1845 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1846 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
1848 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
1850 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1852 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1853 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1854 /* Disable indicating checksum in descriptor, enables
1856 rxcsum |= IXGBE_RXCSUM_PCSD;
1858 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1859 /* Enable IPv4 payload checksum for UDP fragments
1860 * if PCSD is not set */
1861 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1864 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1866 if (hw->mac.type == ixgbe_mac_82599EB) {
1867 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1868 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
1869 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1873 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1875 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1876 struct ixgbe_hw *hw = &adapter->hw;
1878 /* add VID to filter table */
1879 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
1882 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1884 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1885 struct ixgbe_hw *hw = &adapter->hw;
1887 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1888 ixgbe_irq_disable(adapter);
1890 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1892 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1893 ixgbe_irq_enable(adapter);
1895 /* remove VID from filter table */
1896 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
1899 static void ixgbe_vlan_rx_register(struct net_device *netdev,
1900 struct vlan_group *grp)
1902 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1906 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1907 ixgbe_irq_disable(adapter);
1908 adapter->vlgrp = grp;
1911 * For a DCB driver, always enable VLAN tag stripping so we can
1912 * still receive traffic from a DCB-enabled host even if we're
1915 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1916 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1917 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1918 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1919 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1920 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1921 ctrl |= IXGBE_VLNCTRL_VFE;
1922 /* enable VLAN tag insert/strip */
1923 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1924 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1925 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1926 for (i = 0; i < adapter->num_rx_queues; i++) {
1927 j = adapter->rx_ring[i].reg_idx;
1928 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
1929 ctrl |= IXGBE_RXDCTL_VME;
1930 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
1933 ixgbe_vlan_rx_add_vid(netdev, 0);
1935 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1936 ixgbe_irq_enable(adapter);
1939 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1941 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1943 if (adapter->vlgrp) {
1945 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1946 if (!vlan_group_get_device(adapter->vlgrp, vid))
1948 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1953 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1955 struct dev_mc_list *mc_ptr;
1956 u8 *addr = *mc_addr_ptr;
1959 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1961 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1963 *mc_addr_ptr = NULL;
1969 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
1970 * @netdev: network interface device structure
1972 * The set_rx_method entry point is called whenever the unicast/multicast
1973 * address list or the network interface flags are updated. This routine is
1974 * responsible for configuring the hardware for proper unicast, multicast and
1977 static void ixgbe_set_rx_mode(struct net_device *netdev)
1979 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1980 struct ixgbe_hw *hw = &adapter->hw;
1982 u8 *addr_list = NULL;
1985 /* Check for Promiscuous and All Multicast modes */
1987 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1988 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1990 if (netdev->flags & IFF_PROMISC) {
1991 hw->addr_ctrl.user_set_promisc = 1;
1992 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1993 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1995 if (netdev->flags & IFF_ALLMULTI) {
1996 fctrl |= IXGBE_FCTRL_MPE;
1997 fctrl &= ~IXGBE_FCTRL_UPE;
1999 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2001 vlnctrl |= IXGBE_VLNCTRL_VFE;
2002 hw->addr_ctrl.user_set_promisc = 0;
2005 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2006 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2008 /* reprogram secondary unicast list */
2009 addr_count = netdev->uc_count;
2011 addr_list = netdev->uc_list->dmi_addr;
2012 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
2013 ixgbe_addr_list_itr);
2015 /* reprogram multicast list */
2016 addr_count = netdev->mc_count;
2018 addr_list = netdev->mc_list->dmi_addr;
2019 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2020 ixgbe_addr_list_itr);
2023 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2026 struct ixgbe_q_vector *q_vector;
2027 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2029 /* legacy and MSI only use one vector */
2030 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2033 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2034 struct napi_struct *napi;
2035 q_vector = &adapter->q_vector[q_idx];
2036 if (!q_vector->rxr_count)
2038 napi = &q_vector->napi;
2039 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
2040 (q_vector->rxr_count > 1))
2041 napi->poll = &ixgbe_clean_rxonly_many;
2047 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2050 struct ixgbe_q_vector *q_vector;
2051 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2053 /* legacy and MSI only use one vector */
2054 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2057 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2058 q_vector = &adapter->q_vector[q_idx];
2059 if (!q_vector->rxr_count)
2061 napi_disable(&q_vector->napi);
2065 #ifdef CONFIG_IXGBE_DCB
2067 * ixgbe_configure_dcb - Configure DCB hardware
2068 * @adapter: ixgbe adapter struct
2070 * This is called by the driver on open to configure the DCB hardware.
2071 * This is also called by the gennetlink interface when reconfiguring
2074 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2076 struct ixgbe_hw *hw = &adapter->hw;
2077 u32 txdctl, vlnctrl;
2080 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2081 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2082 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2084 /* reconfigure the hardware */
2085 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2087 for (i = 0; i < adapter->num_tx_queues; i++) {
2088 j = adapter->tx_ring[i].reg_idx;
2089 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2090 /* PThresh workaround for Tx hang with DFP enabled. */
2092 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2094 /* Enable VLAN tag insert/strip */
2095 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2096 if (hw->mac.type == ixgbe_mac_82598EB) {
2097 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2098 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2099 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2100 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2101 vlnctrl |= IXGBE_VLNCTRL_VFE;
2102 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2103 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2104 for (i = 0; i < adapter->num_rx_queues; i++) {
2105 j = adapter->rx_ring[i].reg_idx;
2106 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2107 vlnctrl |= IXGBE_RXDCTL_VME;
2108 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2111 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2115 static void ixgbe_configure(struct ixgbe_adapter *adapter)
2117 struct net_device *netdev = adapter->netdev;
2120 ixgbe_set_rx_mode(netdev);
2122 ixgbe_restore_vlan(adapter);
2123 #ifdef CONFIG_IXGBE_DCB
2124 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2125 netif_set_gso_max_size(netdev, 32768);
2126 ixgbe_configure_dcb(adapter);
2128 netif_set_gso_max_size(netdev, 65536);
2131 netif_set_gso_max_size(netdev, 65536);
2134 ixgbe_configure_tx(adapter);
2135 ixgbe_configure_rx(adapter);
2136 for (i = 0; i < adapter->num_rx_queues; i++)
2137 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
2138 (adapter->rx_ring[i].count - 1));
2141 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2143 switch (hw->phy.type) {
2144 case ixgbe_phy_sfp_avago:
2145 case ixgbe_phy_sfp_ftl:
2146 case ixgbe_phy_sfp_intel:
2147 case ixgbe_phy_sfp_unknown:
2148 case ixgbe_phy_tw_tyco:
2149 case ixgbe_phy_tw_unknown:
2157 * ixgbe_sfp_link_config - set up SFP+ link
2158 * @adapter: pointer to private adapter struct
2160 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2162 struct ixgbe_hw *hw = &adapter->hw;
2164 if (hw->phy.multispeed_fiber) {
2166 * In multispeed fiber setups, the device may not have
2167 * had a physical connection when the driver loaded.
2168 * If that's the case, the initial link configuration
2169 * couldn't get the MAC into 10G or 1G mode, so we'll
2170 * never have a link status change interrupt fire.
2171 * We need to try and force an autonegotiation
2172 * session, then bring up link.
2174 hw->mac.ops.setup_sfp(hw);
2175 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2176 schedule_work(&adapter->multispeed_fiber_task);
2179 * Direct Attach Cu and non-multispeed fiber modules
2180 * still need to be configured properly prior to
2183 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2184 schedule_work(&adapter->sfp_config_module_task);
2189 * ixgbe_non_sfp_link_config - set up non-SFP+ link
2190 * @hw: pointer to private hardware struct
2192 * Returns 0 on success, negative on failure
2194 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
2197 bool link_up = false;
2198 u32 ret = IXGBE_ERR_LINK_SETUP;
2200 if (hw->mac.ops.check_link)
2201 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2206 if (hw->mac.ops.get_link_capabilities)
2207 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2212 if (hw->mac.ops.setup_link_speed)
2213 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
2218 #define IXGBE_MAX_RX_DESC_POLL 10
2219 static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2222 int j = adapter->rx_ring[rxr].reg_idx;
2225 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2226 if (IXGBE_READ_REG(&adapter->hw,
2227 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2232 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2233 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2234 "not set within the polling period\n", rxr);
2236 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2237 (adapter->rx_ring[rxr].count - 1));
2240 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2242 struct net_device *netdev = adapter->netdev;
2243 struct ixgbe_hw *hw = &adapter->hw;
2245 int num_rx_rings = adapter->num_rx_queues;
2247 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2248 u32 txdctl, rxdctl, mhadd;
2252 ixgbe_get_hw_control(adapter);
2254 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2255 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
2256 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2257 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
2258 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
2263 /* XXX: to interrupt immediately for EICS writes, enable this */
2264 /* gpie |= IXGBE_GPIE_EIMEN; */
2265 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2268 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2269 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2270 * specifically only auto mask tx and rx interrupts */
2271 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
2274 /* Enable fan failure interrupt if media type is copper */
2275 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2276 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2277 gpie |= IXGBE_SDP1_GPIEN;
2278 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2281 if (hw->mac.type == ixgbe_mac_82599EB) {
2282 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2283 gpie |= IXGBE_SDP1_GPIEN;
2284 gpie |= IXGBE_SDP2_GPIEN;
2285 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2288 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2289 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2290 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2291 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2293 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2296 for (i = 0; i < adapter->num_tx_queues; i++) {
2297 j = adapter->tx_ring[i].reg_idx;
2298 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2299 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2300 txdctl |= (8 << 16);
2301 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2304 if (hw->mac.type == ixgbe_mac_82599EB) {
2305 /* DMATXCTL.EN must be set after all Tx queue config is done */
2306 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2307 dmatxctl |= IXGBE_DMATXCTL_TE;
2308 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2310 for (i = 0; i < adapter->num_tx_queues; i++) {
2311 j = adapter->tx_ring[i].reg_idx;
2312 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2313 txdctl |= IXGBE_TXDCTL_ENABLE;
2314 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2317 for (i = 0; i < num_rx_rings; i++) {
2318 j = adapter->rx_ring[i].reg_idx;
2319 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2320 /* enable PTHRESH=32 descriptors (half the internal cache)
2321 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2322 * this also removes a pesky rx_no_buffer_count increment */
2324 rxdctl |= IXGBE_RXDCTL_ENABLE;
2325 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
2326 if (hw->mac.type == ixgbe_mac_82599EB)
2327 ixgbe_rx_desc_queue_enable(adapter, i);
2329 /* enable all receives */
2330 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2331 if (hw->mac.type == ixgbe_mac_82598EB)
2332 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2334 rxdctl |= IXGBE_RXCTRL_RXEN;
2335 hw->mac.ops.enable_rx_dma(hw, rxdctl);
2337 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2338 ixgbe_configure_msix(adapter);
2340 ixgbe_configure_msi_and_legacy(adapter);
2342 clear_bit(__IXGBE_DOWN, &adapter->state);
2343 ixgbe_napi_enable_all(adapter);
2345 /* clear any pending interrupts, may auto mask */
2346 IXGBE_READ_REG(hw, IXGBE_EICR);
2348 ixgbe_irq_enable(adapter);
2351 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2352 * arrived before interrupts were enabled. We need to kick off
2353 * the SFP+ module setup first, then try to bring up link.
2354 * If we're not hot-pluggable SFP+, we just need to configure link
2357 err = hw->phy.ops.identify(hw);
2358 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2359 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2360 ixgbe_down(adapter);
2364 if (ixgbe_is_sfp(hw)) {
2365 ixgbe_sfp_link_config(adapter);
2367 err = ixgbe_non_sfp_link_config(hw);
2369 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2372 /* enable transmits */
2373 netif_tx_start_all_queues(netdev);
2375 /* bring the link up in the watchdog, this could race with our first
2376 * link up interrupt but shouldn't be a problem */
2377 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2378 adapter->link_check_timeout = jiffies;
2379 mod_timer(&adapter->watchdog_timer, jiffies);
2383 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2385 WARN_ON(in_interrupt());
2386 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2388 ixgbe_down(adapter);
2390 clear_bit(__IXGBE_RESETTING, &adapter->state);
2393 int ixgbe_up(struct ixgbe_adapter *adapter)
2395 /* hardware has been reset, we need to reload some things */
2396 ixgbe_configure(adapter);
2398 ixgbe_napi_add_all(adapter);
2400 return ixgbe_up_complete(adapter);
2403 void ixgbe_reset(struct ixgbe_adapter *adapter)
2405 struct ixgbe_hw *hw = &adapter->hw;
2406 if (hw->mac.ops.init_hw(hw))
2407 dev_err(&adapter->pdev->dev, "Hardware Error\n");
2409 /* reprogram the RAR[0] in case user changed it. */
2410 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2415 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2416 * @adapter: board private structure
2417 * @rx_ring: ring to free buffers from
2419 static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
2420 struct ixgbe_ring *rx_ring)
2422 struct pci_dev *pdev = adapter->pdev;
2426 /* Free all the Rx ring sk_buffs */
2428 for (i = 0; i < rx_ring->count; i++) {
2429 struct ixgbe_rx_buffer *rx_buffer_info;
2431 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2432 if (rx_buffer_info->dma) {
2433 pci_unmap_single(pdev, rx_buffer_info->dma,
2434 rx_ring->rx_buf_len,
2435 PCI_DMA_FROMDEVICE);
2436 rx_buffer_info->dma = 0;
2438 if (rx_buffer_info->skb) {
2439 dev_kfree_skb(rx_buffer_info->skb);
2440 rx_buffer_info->skb = NULL;
2442 if (!rx_buffer_info->page)
2444 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2445 PCI_DMA_FROMDEVICE);
2446 rx_buffer_info->page_dma = 0;
2447 put_page(rx_buffer_info->page);
2448 rx_buffer_info->page = NULL;
2449 rx_buffer_info->page_offset = 0;
2452 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2453 memset(rx_ring->rx_buffer_info, 0, size);
2455 /* Zero out the descriptor ring */
2456 memset(rx_ring->desc, 0, rx_ring->size);
2458 rx_ring->next_to_clean = 0;
2459 rx_ring->next_to_use = 0;
2462 writel(0, adapter->hw.hw_addr + rx_ring->head);
2464 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2468 * ixgbe_clean_tx_ring - Free Tx Buffers
2469 * @adapter: board private structure
2470 * @tx_ring: ring to be cleaned
2472 static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
2473 struct ixgbe_ring *tx_ring)
2475 struct ixgbe_tx_buffer *tx_buffer_info;
2479 /* Free all the Tx ring sk_buffs */
2481 for (i = 0; i < tx_ring->count; i++) {
2482 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2483 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2486 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2487 memset(tx_ring->tx_buffer_info, 0, size);
2489 /* Zero out the descriptor ring */
2490 memset(tx_ring->desc, 0, tx_ring->size);
2492 tx_ring->next_to_use = 0;
2493 tx_ring->next_to_clean = 0;
2496 writel(0, adapter->hw.hw_addr + tx_ring->head);
2498 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2502 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2503 * @adapter: board private structure
2505 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2509 for (i = 0; i < adapter->num_rx_queues; i++)
2510 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2514 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2515 * @adapter: board private structure
2517 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2521 for (i = 0; i < adapter->num_tx_queues; i++)
2522 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2525 void ixgbe_down(struct ixgbe_adapter *adapter)
2527 struct net_device *netdev = adapter->netdev;
2528 struct ixgbe_hw *hw = &adapter->hw;
2533 /* signal that we are down to the interrupt handler */
2534 set_bit(__IXGBE_DOWN, &adapter->state);
2536 /* disable receives */
2537 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2538 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2540 netif_tx_disable(netdev);
2542 IXGBE_WRITE_FLUSH(hw);
2545 netif_tx_stop_all_queues(netdev);
2547 ixgbe_irq_disable(adapter);
2549 ixgbe_napi_disable_all(adapter);
2551 del_timer_sync(&adapter->watchdog_timer);
2552 cancel_work_sync(&adapter->watchdog_task);
2554 /* disable transmits in the hardware now that interrupts are off */
2555 for (i = 0; i < adapter->num_tx_queues; i++) {
2556 j = adapter->tx_ring[i].reg_idx;
2557 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2558 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2559 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2562 netif_carrier_off(netdev);
2564 #ifdef CONFIG_IXGBE_DCA
2565 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2566 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2567 dca_remove_requester(&adapter->pdev->dev);
2571 if (!pci_channel_offline(adapter->pdev))
2572 ixgbe_reset(adapter);
2573 ixgbe_clean_all_tx_rings(adapter);
2574 ixgbe_clean_all_rx_rings(adapter);
2576 #ifdef CONFIG_IXGBE_DCA
2577 /* since we reset the hardware DCA settings were cleared */
2578 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2579 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2580 /* always use CB2 mode, difference is masked
2581 * in the CB driver */
2582 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
2583 ixgbe_setup_dca(adapter);
2589 * ixgbe_poll - NAPI Rx polling callback
2590 * @napi: structure for representing this polling device
2591 * @budget: how many packets driver is allowed to clean
2593 * This function is used for legacy and MSI, NAPI mode
2595 static int ixgbe_poll(struct napi_struct *napi, int budget)
2597 struct ixgbe_q_vector *q_vector =
2598 container_of(napi, struct ixgbe_q_vector, napi);
2599 struct ixgbe_adapter *adapter = q_vector->adapter;
2600 int tx_clean_complete, work_done = 0;
2602 #ifdef CONFIG_IXGBE_DCA
2603 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2604 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2605 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2609 tx_clean_complete = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
2610 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
2612 if (!tx_clean_complete)
2615 /* If budget not fully consumed, exit the polling mode */
2616 if (work_done < budget) {
2617 napi_complete(napi);
2618 if (adapter->itr_setting & 1)
2619 ixgbe_set_itr(adapter);
2620 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2621 ixgbe_irq_enable(adapter);
2627 * ixgbe_tx_timeout - Respond to a Tx Hang
2628 * @netdev: network interface device structure
2630 static void ixgbe_tx_timeout(struct net_device *netdev)
2632 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2634 /* Do the reset outside of interrupt context */
2635 schedule_work(&adapter->reset_task);
2638 static void ixgbe_reset_task(struct work_struct *work)
2640 struct ixgbe_adapter *adapter;
2641 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2643 /* If we're already down or resetting, just bail */
2644 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2645 test_bit(__IXGBE_RESETTING, &adapter->state))
2648 adapter->tx_timeout_count++;
2650 ixgbe_reinit_locked(adapter);
2653 #ifdef CONFIG_IXGBE_DCB
2654 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
2658 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2659 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2660 adapter->num_rx_queues =
2661 adapter->ring_feature[RING_F_DCB].indices;
2662 adapter->num_tx_queues =
2663 adapter->ring_feature[RING_F_DCB].indices;
2673 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2677 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2678 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2679 adapter->num_rx_queues =
2680 adapter->ring_feature[RING_F_RSS].indices;
2681 adapter->num_tx_queues =
2682 adapter->ring_feature[RING_F_RSS].indices;
2691 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2693 /* Start with base case */
2694 adapter->num_rx_queues = 1;
2695 adapter->num_tx_queues = 1;
2697 #ifdef CONFIG_IXGBE_DCB
2698 if (ixgbe_set_dcb_queues(adapter))
2702 if (ixgbe_set_rss_queues(adapter))
2706 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
2709 int err, vector_threshold;
2711 /* We'll want at least 3 (vector_threshold):
2714 * 3) Other (Link Status Change, etc.)
2715 * 4) TCP Timer (optional)
2717 vector_threshold = MIN_MSIX_COUNT;
2719 /* The more we get, the more we will assign to Tx/Rx Cleanup
2720 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2721 * Right now, we simply care about how many we'll get; we'll
2722 * set them up later while requesting irq's.
2724 while (vectors >= vector_threshold) {
2725 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2727 if (!err) /* Success in acquiring all requested vectors. */
2730 vectors = 0; /* Nasty failure, quit now */
2731 else /* err == number of vectors we should try again with */
2735 if (vectors < vector_threshold) {
2736 /* Can't allocate enough MSI-X interrupts? Oh well.
2737 * This just means we'll go with either a single MSI
2738 * vector or fall back to legacy interrupts.
2740 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2741 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2742 kfree(adapter->msix_entries);
2743 adapter->msix_entries = NULL;
2744 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2745 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2746 ixgbe_set_num_queues(adapter);
2748 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2750 * Adjust for only the vectors we'll use, which is minimum
2751 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2752 * vectors we were allocated.
2754 adapter->num_msix_vectors = min(vectors,
2755 adapter->max_msix_q_vectors + NON_Q_VECTORS);
2760 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
2761 * @adapter: board private structure to initialize
2763 * Cache the descriptor ring offsets for RSS to the assigned rings.
2766 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
2771 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2772 for (i = 0; i < adapter->num_rx_queues; i++)
2773 adapter->rx_ring[i].reg_idx = i;
2774 for (i = 0; i < adapter->num_tx_queues; i++)
2775 adapter->tx_ring[i].reg_idx = i;
2784 #ifdef CONFIG_IXGBE_DCB
2786 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2787 * @adapter: board private structure to initialize
2789 * Cache the descriptor ring offsets for DCB to the assigned rings.
2792 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2796 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2798 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2799 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2800 /* the number of queues is assumed to be symmetric */
2801 for (i = 0; i < dcb_i; i++) {
2802 adapter->rx_ring[i].reg_idx = i << 3;
2803 adapter->tx_ring[i].reg_idx = i << 2;
2806 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2807 for (i = 0; i < dcb_i; i++) {
2808 adapter->rx_ring[i].reg_idx = i << 4;
2809 adapter->tx_ring[i].reg_idx = i << 4;
2824 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2825 * @adapter: board private structure to initialize
2827 * Once we know the feature-set enabled for the device, we'll cache
2828 * the register offset the descriptor ring is assigned to.
2830 * Note, the order the various feature calls is important. It must start with
2831 * the "most" features enabled at the same time, then trickle down to the
2832 * least amount of features turned on at once.
2834 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2836 /* start with default case */
2837 adapter->rx_ring[0].reg_idx = 0;
2838 adapter->tx_ring[0].reg_idx = 0;
2840 #ifdef CONFIG_IXGBE_DCB
2841 if (ixgbe_cache_ring_dcb(adapter))
2845 if (ixgbe_cache_ring_rss(adapter))
2850 * ixgbe_alloc_queues - Allocate memory for all rings
2851 * @adapter: board private structure to initialize
2853 * We allocate one ring per queue at run-time since we don't know the
2854 * number of queues at compile-time.
2856 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
2860 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
2861 sizeof(struct ixgbe_ring), GFP_KERNEL);
2862 if (!adapter->tx_ring)
2863 goto err_tx_ring_allocation;
2865 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
2866 sizeof(struct ixgbe_ring), GFP_KERNEL);
2867 if (!adapter->rx_ring)
2868 goto err_rx_ring_allocation;
2870 for (i = 0; i < adapter->num_tx_queues; i++) {
2871 adapter->tx_ring[i].count = adapter->tx_ring_count;
2872 adapter->tx_ring[i].queue_index = i;
2875 for (i = 0; i < adapter->num_rx_queues; i++) {
2876 adapter->rx_ring[i].count = adapter->rx_ring_count;
2877 adapter->rx_ring[i].queue_index = i;
2880 ixgbe_cache_ring_register(adapter);
2884 err_rx_ring_allocation:
2885 kfree(adapter->tx_ring);
2886 err_tx_ring_allocation:
2891 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2892 * @adapter: board private structure to initialize
2894 * Attempt to configure the interrupts using the best available
2895 * capabilities of the hardware and the kernel.
2897 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
2900 int vector, v_budget;
2903 * It's easy to be greedy for MSI-X vectors, but it really
2904 * doesn't do us much good if we have a lot more vectors
2905 * than CPU's. So let's be conservative and only ask for
2906 * (roughly) twice the number of vectors as there are CPU's.
2908 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2909 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2912 * At the same time, hardware can only support a maximum of
2913 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2914 * we can easily reach upwards of 64 Rx descriptor queues and
2915 * 32 Tx queues. Thus, we cap it off in those rare cases where
2916 * the cpu count also exceeds our vector limit.
2918 v_budget = min(v_budget, MAX_MSIX_COUNT);
2920 /* A failure in MSI-X entry allocation isn't fatal, but it does
2921 * mean we disable MSI-X capabilities of the adapter. */
2922 adapter->msix_entries = kcalloc(v_budget,
2923 sizeof(struct msix_entry), GFP_KERNEL);
2924 if (!adapter->msix_entries) {
2925 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
2926 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2927 ixgbe_set_num_queues(adapter);
2928 kfree(adapter->tx_ring);
2929 kfree(adapter->rx_ring);
2930 err = ixgbe_alloc_queues(adapter);
2932 DPRINTK(PROBE, ERR, "Unable to allocate memory "
2940 for (vector = 0; vector < v_budget; vector++)
2941 adapter->msix_entries[vector].entry = vector;
2943 ixgbe_acquire_msix_vectors(adapter, v_budget);
2945 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2949 err = pci_enable_msi(adapter->pdev);
2951 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2953 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
2954 "falling back to legacy. Error: %d\n", err);
2960 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2961 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
2966 void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
2968 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2969 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2970 pci_disable_msix(adapter->pdev);
2971 kfree(adapter->msix_entries);
2972 adapter->msix_entries = NULL;
2973 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2974 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2975 pci_disable_msi(adapter->pdev);
2981 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2982 * @adapter: board private structure to initialize
2984 * We determine which interrupt scheme to use based on...
2985 * - Kernel support (MSI, MSI-X)
2986 * - which can be user-defined (via MODULE_PARAM)
2987 * - Hardware queue count (num_*_queues)
2988 * - defined by miscellaneous hardware support/features (RSS, etc.)
2990 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
2994 /* Number of supported queues */
2995 ixgbe_set_num_queues(adapter);
2997 err = ixgbe_alloc_queues(adapter);
2999 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3000 goto err_alloc_queues;
3003 err = ixgbe_set_interrupt_capability(adapter);
3005 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3006 goto err_set_interrupt;
3009 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
3010 "Tx Queue count = %u\n",
3011 (adapter->num_rx_queues > 1) ? "Enabled" :
3012 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
3014 set_bit(__IXGBE_DOWN, &adapter->state);
3019 kfree(adapter->tx_ring);
3020 kfree(adapter->rx_ring);
3026 * ixgbe_sfp_timer - worker thread to find a missing module
3027 * @data: pointer to our adapter struct
3029 static void ixgbe_sfp_timer(unsigned long data)
3031 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3033 /* Do the sfp_timer outside of interrupt context due to the
3034 * delays that sfp+ detection requires
3036 schedule_work(&adapter->sfp_task);
3040 * ixgbe_sfp_task - worker thread to find a missing module
3041 * @work: pointer to work_struct containing our data
3043 static void ixgbe_sfp_task(struct work_struct *work)
3045 struct ixgbe_adapter *adapter = container_of(work,
3046 struct ixgbe_adapter,
3048 struct ixgbe_hw *hw = &adapter->hw;
3050 if ((hw->phy.type == ixgbe_phy_nl) &&
3051 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3052 s32 ret = hw->phy.ops.identify_sfp(hw);
3055 ret = hw->phy.ops.reset(hw);
3056 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3057 DPRINTK(PROBE, ERR, "failed to initialize because an "
3058 "unsupported SFP+ module type was detected.\n"
3059 "Reload the driver after installing a "
3060 "supported module.\n");
3061 unregister_netdev(adapter->netdev);
3063 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3066 /* don't need this routine any more */
3067 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3071 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3072 mod_timer(&adapter->sfp_timer,
3073 round_jiffies(jiffies + (2 * HZ)));
3077 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3078 * @adapter: board private structure to initialize
3080 * ixgbe_sw_init initializes the Adapter private data structure.
3081 * Fields are initialized based on PCI device information and
3082 * OS network device settings (MTU size).
3084 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3086 struct ixgbe_hw *hw = &adapter->hw;
3087 struct pci_dev *pdev = adapter->pdev;
3089 #ifdef CONFIG_IXGBE_DCB
3091 struct tc_configuration *tc;
3094 /* PCI config space info */
3096 hw->vendor_id = pdev->vendor;
3097 hw->device_id = pdev->device;
3098 hw->revision_id = pdev->revision;
3099 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3100 hw->subsystem_device_id = pdev->subsystem_device;
3102 /* Set capability flags */
3103 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3104 adapter->ring_feature[RING_F_RSS].indices = rss;
3105 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
3106 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
3107 if (hw->mac.type == ixgbe_mac_82598EB)
3108 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
3109 else if (hw->mac.type == ixgbe_mac_82599EB)
3110 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
3112 #ifdef CONFIG_IXGBE_DCB
3113 /* Configure DCB traffic classes */
3114 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3115 tc = &adapter->dcb_cfg.tc_config[j];
3116 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3117 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3118 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3119 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3120 tc->dcb_pfc = pfc_disabled;
3122 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3123 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3124 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
3125 adapter->dcb_cfg.round_robin_enable = false;
3126 adapter->dcb_set_bitmap = 0x00;
3127 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3128 adapter->ring_feature[RING_F_DCB].indices);
3132 /* default flow control settings */
3133 hw->fc.requested_mode = ixgbe_fc_none;
3134 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3135 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3136 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3137 hw->fc.send_xon = true;
3139 /* enable itr by default in dynamic mode */
3140 adapter->itr_setting = 1;
3141 adapter->eitr_param = 20000;
3143 /* set defaults for eitr in MegaBytes */
3144 adapter->eitr_low = 10;
3145 adapter->eitr_high = 20;
3147 /* set default ring sizes */
3148 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3149 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3151 /* initialize eeprom parameters */
3152 if (ixgbe_init_eeprom_params_generic(hw)) {
3153 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3157 /* enable rx csum by default */
3158 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3160 set_bit(__IXGBE_DOWN, &adapter->state);
3166 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3167 * @adapter: board private structure
3168 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3170 * Return 0 on success, negative on failure
3172 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
3173 struct ixgbe_ring *tx_ring)
3175 struct pci_dev *pdev = adapter->pdev;
3178 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3179 tx_ring->tx_buffer_info = vmalloc(size);
3180 if (!tx_ring->tx_buffer_info)
3182 memset(tx_ring->tx_buffer_info, 0, size);
3184 /* round up to nearest 4K */
3185 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
3186 tx_ring->size = ALIGN(tx_ring->size, 4096);
3188 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3193 tx_ring->next_to_use = 0;
3194 tx_ring->next_to_clean = 0;
3195 tx_ring->work_limit = tx_ring->count;
3199 vfree(tx_ring->tx_buffer_info);
3200 tx_ring->tx_buffer_info = NULL;
3201 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3202 "descriptor ring\n");
3207 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3208 * @adapter: board private structure
3210 * If this function returns with an error, then it's possible one or
3211 * more of the rings is populated (while the rest are not). It is the
3212 * callers duty to clean those orphaned rings.
3214 * Return 0 on success, negative on failure
3216 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3220 for (i = 0; i < adapter->num_tx_queues; i++) {
3221 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3224 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3232 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3233 * @adapter: board private structure
3234 * @rx_ring: rx descriptor ring (for a specific queue) to setup
3236 * Returns 0 on success, negative on failure
3238 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
3239 struct ixgbe_ring *rx_ring)
3241 struct pci_dev *pdev = adapter->pdev;
3244 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3245 rx_ring->rx_buffer_info = vmalloc(size);
3246 if (!rx_ring->rx_buffer_info) {
3248 "vmalloc allocation failed for the rx desc ring\n");
3251 memset(rx_ring->rx_buffer_info, 0, size);
3253 /* Round up to nearest 4K */
3254 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3255 rx_ring->size = ALIGN(rx_ring->size, 4096);
3257 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
3259 if (!rx_ring->desc) {
3261 "Memory allocation failed for the rx desc ring\n");
3262 vfree(rx_ring->rx_buffer_info);
3266 rx_ring->next_to_clean = 0;
3267 rx_ring->next_to_use = 0;
3276 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3277 * @adapter: board private structure
3279 * If this function returns with an error, then it's possible one or
3280 * more of the rings is populated (while the rest are not). It is the
3281 * callers duty to clean those orphaned rings.
3283 * Return 0 on success, negative on failure
3286 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3290 for (i = 0; i < adapter->num_rx_queues; i++) {
3291 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3294 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3302 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3303 * @adapter: board private structure
3304 * @tx_ring: Tx descriptor ring for a specific queue
3306 * Free all transmit software resources
3308 void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3309 struct ixgbe_ring *tx_ring)
3311 struct pci_dev *pdev = adapter->pdev;
3313 ixgbe_clean_tx_ring(adapter, tx_ring);
3315 vfree(tx_ring->tx_buffer_info);
3316 tx_ring->tx_buffer_info = NULL;
3318 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3320 tx_ring->desc = NULL;
3324 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3325 * @adapter: board private structure
3327 * Free all transmit software resources
3329 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3333 for (i = 0; i < adapter->num_tx_queues; i++)
3334 if (adapter->tx_ring[i].desc)
3335 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3339 * ixgbe_free_rx_resources - Free Rx Resources
3340 * @adapter: board private structure
3341 * @rx_ring: ring to clean the resources from
3343 * Free all receive software resources
3345 void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3346 struct ixgbe_ring *rx_ring)
3348 struct pci_dev *pdev = adapter->pdev;
3350 ixgbe_clean_rx_ring(adapter, rx_ring);
3352 vfree(rx_ring->rx_buffer_info);
3353 rx_ring->rx_buffer_info = NULL;
3355 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3357 rx_ring->desc = NULL;
3361 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3362 * @adapter: board private structure
3364 * Free all receive software resources
3366 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3370 for (i = 0; i < adapter->num_rx_queues; i++)
3371 if (adapter->rx_ring[i].desc)
3372 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3376 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3377 * @netdev: network interface device structure
3378 * @new_mtu: new value for maximum frame size
3380 * Returns 0 on success, negative on failure
3382 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3384 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3385 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3387 /* MTU < 68 is an error and causes problems on some kernels */
3388 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
3391 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
3392 netdev->mtu, new_mtu);
3393 /* must set new MTU before calling down or up */
3394 netdev->mtu = new_mtu;
3396 if (netif_running(netdev))
3397 ixgbe_reinit_locked(adapter);
3403 * ixgbe_open - Called when a network interface is made active
3404 * @netdev: network interface device structure
3406 * Returns 0 on success, negative value on failure
3408 * The open entry point is called when a network interface is made
3409 * active by the system (IFF_UP). At this point all resources needed
3410 * for transmit and receive operations are allocated, the interrupt
3411 * handler is registered with the OS, the watchdog timer is started,
3412 * and the stack is notified that the interface is ready.
3414 static int ixgbe_open(struct net_device *netdev)
3416 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3419 /* disallow open during test */
3420 if (test_bit(__IXGBE_TESTING, &adapter->state))
3423 /* allocate transmit descriptors */
3424 err = ixgbe_setup_all_tx_resources(adapter);
3428 /* allocate receive descriptors */
3429 err = ixgbe_setup_all_rx_resources(adapter);
3433 ixgbe_configure(adapter);
3435 ixgbe_napi_add_all(adapter);
3437 err = ixgbe_request_irq(adapter);
3441 err = ixgbe_up_complete(adapter);
3445 netif_tx_start_all_queues(netdev);
3450 ixgbe_release_hw_control(adapter);
3451 ixgbe_free_irq(adapter);
3453 ixgbe_free_all_rx_resources(adapter);
3455 ixgbe_free_all_tx_resources(adapter);
3457 ixgbe_reset(adapter);
3463 * ixgbe_close - Disables a network interface
3464 * @netdev: network interface device structure
3466 * Returns 0, this is not allowed to fail
3468 * The close entry point is called when an interface is de-activated
3469 * by the OS. The hardware is still under the drivers control, but
3470 * needs to be disabled. A global MAC reset is issued to stop the
3471 * hardware, and all transmit and receive resources are freed.
3473 static int ixgbe_close(struct net_device *netdev)
3475 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3477 ixgbe_down(adapter);
3478 ixgbe_free_irq(adapter);
3480 ixgbe_free_all_tx_resources(adapter);
3481 ixgbe_free_all_rx_resources(adapter);
3483 ixgbe_release_hw_control(adapter);
3489 * ixgbe_napi_add_all - prep napi structs for use
3490 * @adapter: private struct
3492 * helper function to napi_add each possible q_vector->napi
3494 void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
3496 int q_idx, q_vectors;
3497 struct net_device *netdev = adapter->netdev;
3498 int (*poll)(struct napi_struct *, int);
3500 /* check if we already have our netdev->napi_list populated */
3501 if (&netdev->napi_list != netdev->napi_list.next)
3504 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3505 poll = &ixgbe_clean_rxonly;
3506 /* Only enable as many vectors as we have rx queues. */
3507 q_vectors = adapter->num_rx_queues;
3510 /* only one q_vector for legacy modes */
3514 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3515 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3516 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3520 void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
3523 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3525 /* legacy and MSI only use one vector */
3526 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3529 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3530 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3531 if (!q_vector->rxr_count)
3533 netif_napi_del(&q_vector->napi);
3538 static int ixgbe_resume(struct pci_dev *pdev)
3540 struct net_device *netdev = pci_get_drvdata(pdev);
3541 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3544 pci_set_power_state(pdev, PCI_D0);
3545 pci_restore_state(pdev);
3546 err = pci_enable_device(pdev);
3548 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
3552 pci_set_master(pdev);
3554 pci_enable_wake(pdev, PCI_D3hot, 0);
3555 pci_enable_wake(pdev, PCI_D3cold, 0);
3557 err = ixgbe_init_interrupt_scheme(adapter);
3559 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3564 ixgbe_reset(adapter);
3566 if (netif_running(netdev)) {
3567 err = ixgbe_open(adapter->netdev);
3572 netif_device_attach(netdev);
3577 #endif /* CONFIG_PM */
3578 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3580 struct net_device *netdev = pci_get_drvdata(pdev);
3581 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3582 struct ixgbe_hw *hw = &adapter->hw;
3584 u32 wufc = adapter->wol;
3589 netif_device_detach(netdev);
3591 if (netif_running(netdev)) {
3592 ixgbe_down(adapter);
3593 ixgbe_free_irq(adapter);
3594 ixgbe_free_all_tx_resources(adapter);
3595 ixgbe_free_all_rx_resources(adapter);
3597 ixgbe_reset_interrupt_capability(adapter);
3598 ixgbe_napi_del_all(adapter);
3599 INIT_LIST_HEAD(&netdev->napi_list);
3600 kfree(adapter->tx_ring);
3601 kfree(adapter->rx_ring);
3604 retval = pci_save_state(pdev);
3609 ixgbe_set_rx_mode(netdev);
3611 /* turn on all-multi mode if wake on multicast is enabled */
3612 if (wufc & IXGBE_WUFC_MC) {
3613 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3614 fctrl |= IXGBE_FCTRL_MPE;
3615 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3618 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3619 ctrl |= IXGBE_CTRL_GIO_DIS;
3620 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3622 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
3624 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
3625 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
3628 if (wufc && hw->mac.type == ixgbe_mac_82599EB) {
3629 pci_enable_wake(pdev, PCI_D3hot, 1);
3630 pci_enable_wake(pdev, PCI_D3cold, 1);
3632 pci_enable_wake(pdev, PCI_D3hot, 0);
3633 pci_enable_wake(pdev, PCI_D3cold, 0);
3636 ixgbe_release_hw_control(adapter);
3638 pci_disable_device(pdev);
3640 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3645 static void ixgbe_shutdown(struct pci_dev *pdev)
3647 ixgbe_suspend(pdev, PMSG_SUSPEND);
3651 * ixgbe_update_stats - Update the board statistics counters.
3652 * @adapter: board private structure
3654 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3656 struct ixgbe_hw *hw = &adapter->hw;
3658 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
3660 if (hw->mac.type == ixgbe_mac_82599EB) {
3661 for (i = 0; i < 16; i++)
3662 adapter->hw_rx_no_dma_resources +=
3663 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
3666 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
3667 for (i = 0; i < 8; i++) {
3668 /* for packet buffers not used, the register should read 0 */
3669 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3671 adapter->stats.mpc[i] += mpc;
3672 total_mpc += adapter->stats.mpc[i];
3673 if (hw->mac.type == ixgbe_mac_82598EB)
3674 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
3675 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3676 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3677 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3678 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3679 if (hw->mac.type == ixgbe_mac_82599EB) {
3680 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3681 IXGBE_PXONRXCNT(i));
3682 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3683 IXGBE_PXOFFRXCNT(i));
3684 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
3686 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3688 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3691 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3693 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3696 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3697 /* work around hardware counting issue */
3698 adapter->stats.gprc -= missed_rx;
3700 /* 82598 hardware only has a 32 bit counter in the high register */
3701 if (hw->mac.type == ixgbe_mac_82599EB) {
3702 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
3703 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
3704 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
3705 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
3706 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
3707 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
3708 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
3709 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
3711 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3712 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3713 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3714 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3715 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3717 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3718 adapter->stats.bprc += bprc;
3719 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3720 if (hw->mac.type == ixgbe_mac_82598EB)
3721 adapter->stats.mprc -= bprc;
3722 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3723 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3724 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3725 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3726 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3727 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3728 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
3729 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3730 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3731 adapter->stats.lxontxc += lxon;
3732 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3733 adapter->stats.lxofftxc += lxoff;
3734 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3735 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
3736 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3738 * 82598 errata - tx of flow control packets is included in tx counters
3740 xon_off_tot = lxon + lxoff;
3741 adapter->stats.gptc -= xon_off_tot;
3742 adapter->stats.mptc -= xon_off_tot;
3743 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
3744 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3745 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3746 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
3747 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3748 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
3749 adapter->stats.ptc64 -= xon_off_tot;
3750 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3751 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3752 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3753 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3754 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
3755 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3757 /* Fill out the OS statistics structure */
3758 adapter->net_stats.multicast = adapter->stats.mprc;
3761 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
3762 adapter->stats.rlec;
3763 adapter->net_stats.rx_dropped = 0;
3764 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3765 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3766 adapter->net_stats.rx_missed_errors = total_mpc;
3770 * ixgbe_watchdog - Timer Call-back
3771 * @data: pointer to adapter cast into an unsigned long
3773 static void ixgbe_watchdog(unsigned long data)
3775 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3776 struct ixgbe_hw *hw = &adapter->hw;
3778 /* Do the watchdog outside of interrupt context due to the lovely
3779 * delays that some of the newer hardware requires */
3780 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3781 /* Cause software interrupt to ensure rx rings are cleaned */
3782 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3784 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3785 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3787 /* For legacy and MSI interrupts don't set any bits that
3788 * are enabled for EIAM, because this operation would
3789 * set *both* EIMS and EICS for any bit in EIAM */
3790 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3791 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3793 /* Reset the timer */
3794 mod_timer(&adapter->watchdog_timer,
3795 round_jiffies(jiffies + 2 * HZ));
3798 schedule_work(&adapter->watchdog_task);
3802 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
3803 * @work: pointer to work_struct containing our data
3805 static void ixgbe_multispeed_fiber_task(struct work_struct *work)
3807 struct ixgbe_adapter *adapter = container_of(work,
3808 struct ixgbe_adapter,
3809 multispeed_fiber_task);
3810 struct ixgbe_hw *hw = &adapter->hw;
3813 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
3814 if (hw->mac.ops.get_link_capabilities)
3815 hw->mac.ops.get_link_capabilities(hw, &autoneg,
3817 if (hw->mac.ops.setup_link_speed)
3818 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3819 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3820 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
3824 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
3825 * @work: pointer to work_struct containing our data
3827 static void ixgbe_sfp_config_module_task(struct work_struct *work)
3829 struct ixgbe_adapter *adapter = container_of(work,
3830 struct ixgbe_adapter,
3831 sfp_config_module_task);
3832 struct ixgbe_hw *hw = &adapter->hw;
3835 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
3836 err = hw->phy.ops.identify_sfp(hw);
3837 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3838 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
3839 ixgbe_down(adapter);
3842 hw->mac.ops.setup_sfp(hw);
3844 if (!adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)
3845 /* This will also work for DA Twinax connections */
3846 schedule_work(&adapter->multispeed_fiber_task);
3847 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
3851 * ixgbe_watchdog_task - worker thread to bring link up
3852 * @work: pointer to work_struct containing our data
3854 static void ixgbe_watchdog_task(struct work_struct *work)
3856 struct ixgbe_adapter *adapter = container_of(work,
3857 struct ixgbe_adapter,
3859 struct net_device *netdev = adapter->netdev;
3860 struct ixgbe_hw *hw = &adapter->hw;
3861 u32 link_speed = adapter->link_speed;
3862 bool link_up = adapter->link_up;
3864 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3866 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3867 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3869 time_after(jiffies, (adapter->link_check_timeout +
3870 IXGBE_TRY_LINK_TIMEOUT))) {
3871 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3872 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3874 adapter->link_up = link_up;
3875 adapter->link_speed = link_speed;
3879 if (!netif_carrier_ok(netdev)) {
3880 bool flow_rx, flow_tx;
3882 if (hw->mac.type == ixgbe_mac_82599EB) {
3883 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3884 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3885 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
3886 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
3888 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3889 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
3890 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
3891 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
3894 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3895 "Flow Control: %s\n",
3897 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3899 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3900 "1 Gbps" : "unknown speed")),
3901 ((flow_rx && flow_tx) ? "RX/TX" :
3903 (flow_tx ? "TX" : "None"))));
3905 netif_carrier_on(netdev);
3907 /* Force detection of hung controller */
3908 adapter->detect_tx_hung = true;
3911 adapter->link_up = false;
3912 adapter->link_speed = 0;
3913 if (netif_carrier_ok(netdev)) {
3914 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3916 netif_carrier_off(netdev);
3920 ixgbe_update_stats(adapter);
3921 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
3924 static int ixgbe_tso(struct ixgbe_adapter *adapter,
3925 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3926 u32 tx_flags, u8 *hdr_len)
3928 struct ixgbe_adv_tx_context_desc *context_desc;
3931 struct ixgbe_tx_buffer *tx_buffer_info;
3932 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3933 u32 mss_l4len_idx, l4len;
3935 if (skb_is_gso(skb)) {
3936 if (skb_header_cloned(skb)) {
3937 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3941 l4len = tcp_hdrlen(skb);
3944 if (skb->protocol == htons(ETH_P_IP)) {
3945 struct iphdr *iph = ip_hdr(skb);
3948 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3952 adapter->hw_tso_ctxt++;
3953 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3954 ipv6_hdr(skb)->payload_len = 0;
3955 tcp_hdr(skb)->check =
3956 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3957 &ipv6_hdr(skb)->daddr,
3959 adapter->hw_tso6_ctxt++;
3962 i = tx_ring->next_to_use;
3964 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3965 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3967 /* VLAN MACLEN IPLEN */
3968 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3970 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3971 vlan_macip_lens |= ((skb_network_offset(skb)) <<
3972 IXGBE_ADVTXD_MACLEN_SHIFT);
3973 *hdr_len += skb_network_offset(skb);
3975 (skb_transport_header(skb) - skb_network_header(skb));
3977 (skb_transport_header(skb) - skb_network_header(skb));
3978 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3979 context_desc->seqnum_seed = 0;
3981 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
3982 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
3983 IXGBE_ADVTXD_DTYP_CTXT);
3985 if (skb->protocol == htons(ETH_P_IP))
3986 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3987 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3988 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3992 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3993 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
3994 /* use index 1 for TSO */
3995 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3996 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3998 tx_buffer_info->time_stamp = jiffies;
3999 tx_buffer_info->next_to_watch = i;
4002 if (i == tx_ring->count)
4004 tx_ring->next_to_use = i;
4011 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
4012 struct ixgbe_ring *tx_ring,
4013 struct sk_buff *skb, u32 tx_flags)
4015 struct ixgbe_adv_tx_context_desc *context_desc;
4017 struct ixgbe_tx_buffer *tx_buffer_info;
4018 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4020 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4021 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4022 i = tx_ring->next_to_use;
4023 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4024 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4026 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4028 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4029 vlan_macip_lens |= (skb_network_offset(skb) <<
4030 IXGBE_ADVTXD_MACLEN_SHIFT);
4031 if (skb->ip_summed == CHECKSUM_PARTIAL)
4032 vlan_macip_lens |= (skb_transport_header(skb) -
4033 skb_network_header(skb));
4035 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4036 context_desc->seqnum_seed = 0;
4038 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
4039 IXGBE_ADVTXD_DTYP_CTXT);
4041 if (skb->ip_summed == CHECKSUM_PARTIAL) {
4042 switch (skb->protocol) {
4043 case cpu_to_be16(ETH_P_IP):
4044 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4045 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4047 IXGBE_ADVTXD_TUCMD_L4T_TCP;
4049 case cpu_to_be16(ETH_P_IPV6):
4050 /* XXX what about other V6 headers?? */
4051 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4053 IXGBE_ADVTXD_TUCMD_L4T_TCP;
4056 if (unlikely(net_ratelimit())) {
4057 DPRINTK(PROBE, WARNING,
4058 "partial checksum but proto=%x!\n",
4065 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4066 /* use index zero for tx checksum offload */
4067 context_desc->mss_l4len_idx = 0;
4069 tx_buffer_info->time_stamp = jiffies;
4070 tx_buffer_info->next_to_watch = i;
4072 adapter->hw_csum_tx_good++;
4074 if (i == tx_ring->count)
4076 tx_ring->next_to_use = i;
4084 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
4085 struct ixgbe_ring *tx_ring,
4086 struct sk_buff *skb, unsigned int first)
4088 struct ixgbe_tx_buffer *tx_buffer_info;
4089 unsigned int len = skb->len;
4090 unsigned int offset = 0, size, count = 0, i;
4091 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4094 len -= skb->data_len;
4096 i = tx_ring->next_to_use;
4099 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4100 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4102 tx_buffer_info->length = size;
4103 tx_buffer_info->dma = pci_map_single(adapter->pdev,
4105 size, PCI_DMA_TODEVICE);
4106 tx_buffer_info->time_stamp = jiffies;
4107 tx_buffer_info->next_to_watch = i;
4113 if (i == tx_ring->count)
4117 for (f = 0; f < nr_frags; f++) {
4118 struct skb_frag_struct *frag;
4120 frag = &skb_shinfo(skb)->frags[f];
4122 offset = frag->page_offset;
4125 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4126 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4128 tx_buffer_info->length = size;
4129 tx_buffer_info->dma = pci_map_page(adapter->pdev,
4134 tx_buffer_info->time_stamp = jiffies;
4135 tx_buffer_info->next_to_watch = i;
4141 if (i == tx_ring->count)
4146 i = tx_ring->count - 1;
4149 tx_ring->tx_buffer_info[i].skb = skb;
4150 tx_ring->tx_buffer_info[first].next_to_watch = i;
4155 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
4156 struct ixgbe_ring *tx_ring,
4157 int tx_flags, int count, u32 paylen, u8 hdr_len)
4159 union ixgbe_adv_tx_desc *tx_desc = NULL;
4160 struct ixgbe_tx_buffer *tx_buffer_info;
4161 u32 olinfo_status = 0, cmd_type_len = 0;
4163 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4165 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4167 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4169 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4170 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4172 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4173 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4175 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
4176 IXGBE_ADVTXD_POPTS_SHIFT;
4178 /* use index 1 context for tso */
4179 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4180 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4181 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
4182 IXGBE_ADVTXD_POPTS_SHIFT;
4184 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4185 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
4186 IXGBE_ADVTXD_POPTS_SHIFT;
4188 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4190 i = tx_ring->next_to_use;
4192 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4193 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4194 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4195 tx_desc->read.cmd_type_len =
4196 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
4197 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
4199 if (i == tx_ring->count)
4203 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4206 * Force memory writes to complete before letting h/w
4207 * know there are new descriptors to fetch. (Only
4208 * applicable for weak-ordered memory model archs,
4213 tx_ring->next_to_use = i;
4214 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4217 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
4218 struct ixgbe_ring *tx_ring, int size)
4220 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4222 netif_stop_subqueue(netdev, tx_ring->queue_index);
4223 /* Herbert's original patch had:
4224 * smp_mb__after_netif_stop_queue();
4225 * but since that doesn't exist yet, just open code it. */
4228 /* We need to check again in a case another CPU has just
4229 * made room available. */
4230 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
4233 /* A reprieve! - use start_queue because it doesn't call schedule */
4234 netif_start_subqueue(netdev, tx_ring->queue_index);
4235 ++adapter->restart_queue;
4239 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
4240 struct ixgbe_ring *tx_ring, int size)
4242 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
4244 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
4247 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4249 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4250 struct ixgbe_ring *tx_ring;
4252 unsigned int tx_flags = 0;
4258 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
4259 tx_ring = &adapter->tx_ring[r_idx];
4261 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4262 tx_flags |= vlan_tx_tag_get(skb);
4263 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4264 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
4265 tx_flags |= (skb->queue_mapping << 13);
4267 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4268 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4269 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4270 tx_flags |= (skb->queue_mapping << 13);
4271 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4272 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4274 /* three things can cause us to need a context descriptor */
4275 if (skb_is_gso(skb) ||
4276 (skb->ip_summed == CHECKSUM_PARTIAL) ||
4277 (tx_flags & IXGBE_TX_FLAGS_VLAN))
4280 count += TXD_USE_COUNT(skb_headlen(skb));
4281 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
4282 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
4284 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
4286 return NETDEV_TX_BUSY;
4289 if (skb->protocol == htons(ETH_P_IP))
4290 tx_flags |= IXGBE_TX_FLAGS_IPV4;
4291 first = tx_ring->next_to_use;
4292 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4294 dev_kfree_skb_any(skb);
4295 return NETDEV_TX_OK;
4299 tx_flags |= IXGBE_TX_FLAGS_TSO;
4300 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
4301 (skb->ip_summed == CHECKSUM_PARTIAL))
4302 tx_flags |= IXGBE_TX_FLAGS_CSUM;
4304 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
4305 ixgbe_tx_map(adapter, tx_ring, skb, first),
4308 netdev->trans_start = jiffies;
4310 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
4312 return NETDEV_TX_OK;
4316 * ixgbe_get_stats - Get System Network Statistics
4317 * @netdev: network interface device structure
4319 * Returns the address of the device statistics structure.
4320 * The statistics are actually updated from the timer callback.
4322 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
4324 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4326 /* only return the current stats */
4327 return &adapter->net_stats;
4331 * ixgbe_set_mac - Change the Ethernet Address of the NIC
4332 * @netdev: network interface device structure
4333 * @p: pointer to an address structure
4335 * Returns 0 on success, negative on failure
4337 static int ixgbe_set_mac(struct net_device *netdev, void *p)
4339 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4340 struct ixgbe_hw *hw = &adapter->hw;
4341 struct sockaddr *addr = p;
4343 if (!is_valid_ether_addr(addr->sa_data))
4344 return -EADDRNOTAVAIL;
4346 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4347 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4349 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
4354 #ifdef CONFIG_NET_POLL_CONTROLLER
4356 * Polling 'interrupt' - used by things like netconsole to send skbs
4357 * without having to re-enable interrupts. It's not called while
4358 * the interrupt routine is executing.
4360 static void ixgbe_netpoll(struct net_device *netdev)
4362 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4364 disable_irq(adapter->pdev->irq);
4365 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
4366 ixgbe_intr(adapter->pdev->irq, netdev);
4367 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
4368 enable_irq(adapter->pdev->irq);
4372 static const struct net_device_ops ixgbe_netdev_ops = {
4373 .ndo_open = ixgbe_open,
4374 .ndo_stop = ixgbe_close,
4375 .ndo_start_xmit = ixgbe_xmit_frame,
4376 .ndo_get_stats = ixgbe_get_stats,
4377 .ndo_set_multicast_list = ixgbe_set_rx_mode,
4378 .ndo_validate_addr = eth_validate_addr,
4379 .ndo_set_mac_address = ixgbe_set_mac,
4380 .ndo_change_mtu = ixgbe_change_mtu,
4381 .ndo_tx_timeout = ixgbe_tx_timeout,
4382 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
4383 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
4384 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
4385 #ifdef CONFIG_NET_POLL_CONTROLLER
4386 .ndo_poll_controller = ixgbe_netpoll,
4391 * ixgbe_probe - Device Initialization Routine
4392 * @pdev: PCI device information struct
4393 * @ent: entry in ixgbe_pci_tbl
4395 * Returns 0 on success, negative on failure
4397 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
4398 * The OS initialization, configuring of the adapter private structure,
4399 * and a hardware reset occur.
4401 static int __devinit ixgbe_probe(struct pci_dev *pdev,
4402 const struct pci_device_id *ent)
4404 struct net_device *netdev;
4405 struct ixgbe_adapter *adapter = NULL;
4406 struct ixgbe_hw *hw;
4407 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
4408 static int cards_found;
4409 int i, err, pci_using_dac;
4413 err = pci_enable_device(pdev);
4417 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4418 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
4421 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4423 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4425 dev_err(&pdev->dev, "No usable DMA "
4426 "configuration, aborting\n");
4433 err = pci_request_regions(pdev, ixgbe_driver_name);
4435 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4439 err = pci_enable_pcie_error_reporting(pdev);
4441 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4443 /* non-fatal, continue */
4446 pci_set_master(pdev);
4447 pci_save_state(pdev);
4449 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
4452 goto err_alloc_etherdev;
4455 SET_NETDEV_DEV(netdev, &pdev->dev);
4457 pci_set_drvdata(pdev, netdev);
4458 adapter = netdev_priv(netdev);
4460 adapter->netdev = netdev;
4461 adapter->pdev = pdev;
4464 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4466 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4467 pci_resource_len(pdev, 0));
4473 for (i = 1; i <= 5; i++) {
4474 if (pci_resource_len(pdev, i) == 0)
4478 netdev->netdev_ops = &ixgbe_netdev_ops;
4479 ixgbe_set_ethtool_ops(netdev);
4480 netdev->watchdog_timeo = 5 * HZ;
4481 strcpy(netdev->name, pci_name(pdev));
4483 adapter->bd_number = cards_found;
4486 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
4487 hw->mac.type = ii->mac;
4490 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4491 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4492 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4493 if (!(eec & (1 << 8)))
4494 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4497 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
4498 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4500 /* set up this timer and work struct before calling get_invariants
4501 * which might start the timer
4503 init_timer(&adapter->sfp_timer);
4504 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4505 adapter->sfp_timer.data = (unsigned long) adapter;
4507 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
4509 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
4510 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
4512 /* a new SFP+ module arrival, called from GPI SDP2 context */
4513 INIT_WORK(&adapter->sfp_config_module_task,
4514 ixgbe_sfp_config_module_task);
4516 err = ii->get_invariants(hw);
4517 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4518 /* start a kernel thread to watch for a module to arrive */
4519 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4520 mod_timer(&adapter->sfp_timer,
4521 round_jiffies(jiffies + (2 * HZ)));
4523 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4524 DPRINTK(PROBE, ERR, "failed to load because an "
4525 "unsupported SFP+ module type was detected.\n");
4531 /* setup the private structure */
4532 err = ixgbe_sw_init(adapter);
4536 /* reset_hw fills in the perm_addr as well */
4537 err = hw->mac.ops.reset_hw(hw);
4539 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4543 netdev->features = NETIF_F_SG |
4545 NETIF_F_HW_VLAN_TX |
4546 NETIF_F_HW_VLAN_RX |
4547 NETIF_F_HW_VLAN_FILTER;
4549 netdev->features |= NETIF_F_IPV6_CSUM;
4550 netdev->features |= NETIF_F_TSO;
4551 netdev->features |= NETIF_F_TSO6;
4552 netdev->features |= NETIF_F_GRO;
4554 netdev->vlan_features |= NETIF_F_TSO;
4555 netdev->vlan_features |= NETIF_F_TSO6;
4556 netdev->vlan_features |= NETIF_F_IP_CSUM;
4557 netdev->vlan_features |= NETIF_F_SG;
4559 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4560 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4562 #ifdef CONFIG_IXGBE_DCB
4563 netdev->dcbnl_ops = &dcbnl_ops;
4567 netdev->features |= NETIF_F_HIGHDMA;
4569 /* make sure the EEPROM is good */
4570 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
4571 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4576 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4577 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4579 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4580 dev_err(&pdev->dev, "invalid MAC address\n");
4585 init_timer(&adapter->watchdog_timer);
4586 adapter->watchdog_timer.function = &ixgbe_watchdog;
4587 adapter->watchdog_timer.data = (unsigned long)adapter;
4589 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
4590 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
4592 err = ixgbe_init_interrupt_scheme(adapter);
4596 switch (pdev->device) {
4597 case IXGBE_DEV_ID_82599_KX4:
4598 #define IXGBE_PCIE_PMCSR 0x44
4599 adapter->wol = IXGBE_WUFC_MAG;
4600 pci_read_config_word(pdev, IXGBE_PCIE_PMCSR, &pm_value);
4601 pci_write_config_word(pdev, IXGBE_PCIE_PMCSR,
4602 (pm_value | (1 << 8)));
4608 device_init_wakeup(&adapter->pdev->dev, true);
4609 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
4611 /* print bus type/speed/width info */
4612 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
4613 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
4614 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
4615 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
4616 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
4617 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
4620 ixgbe_read_pba_num_generic(hw, &part_num);
4621 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
4622 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
4623 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
4624 (part_num >> 8), (part_num & 0xff));
4626 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4627 hw->mac.type, hw->phy.type,
4628 (part_num >> 8), (part_num & 0xff));
4630 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
4631 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
4632 "this card is not sufficient for optimal "
4634 dev_warn(&pdev->dev, "For optimal performance a x8 "
4635 "PCI-Express slot is required.\n");
4638 /* save off EEPROM version number */
4639 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4641 /* reset the hardware with the new settings */
4642 hw->mac.ops.start_hw(hw);
4644 netif_carrier_off(netdev);
4646 strcpy(netdev->name, "eth%d");
4647 err = register_netdev(netdev);
4651 #ifdef CONFIG_IXGBE_DCA
4652 if (dca_add_requester(&pdev->dev) == 0) {
4653 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4654 /* always use CB2 mode, difference is masked
4655 * in the CB driver */
4656 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4657 ixgbe_setup_dca(adapter);
4661 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4666 ixgbe_release_hw_control(adapter);
4669 ixgbe_reset_interrupt_capability(adapter);
4671 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4672 del_timer_sync(&adapter->sfp_timer);
4673 cancel_work_sync(&adapter->sfp_task);
4674 cancel_work_sync(&adapter->multispeed_fiber_task);
4675 cancel_work_sync(&adapter->sfp_config_module_task);
4676 iounmap(hw->hw_addr);
4678 free_netdev(netdev);
4680 pci_release_regions(pdev);
4683 pci_disable_device(pdev);
4688 * ixgbe_remove - Device Removal Routine
4689 * @pdev: PCI device information struct
4691 * ixgbe_remove is called by the PCI subsystem to alert the driver
4692 * that it should release a PCI device. The could be caused by a
4693 * Hot-Plug event, or because the driver is going to be removed from
4696 static void __devexit ixgbe_remove(struct pci_dev *pdev)
4698 struct net_device *netdev = pci_get_drvdata(pdev);
4699 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4702 set_bit(__IXGBE_DOWN, &adapter->state);
4703 /* clear the module not found bit to make sure the worker won't
4706 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4707 del_timer_sync(&adapter->watchdog_timer);
4709 del_timer_sync(&adapter->sfp_timer);
4710 cancel_work_sync(&adapter->watchdog_task);
4711 cancel_work_sync(&adapter->sfp_task);
4712 cancel_work_sync(&adapter->multispeed_fiber_task);
4713 cancel_work_sync(&adapter->sfp_config_module_task);
4714 flush_scheduled_work();
4716 #ifdef CONFIG_IXGBE_DCA
4717 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4718 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4719 dca_remove_requester(&pdev->dev);
4720 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4724 if (netdev->reg_state == NETREG_REGISTERED)
4725 unregister_netdev(netdev);
4727 ixgbe_reset_interrupt_capability(adapter);
4729 ixgbe_release_hw_control(adapter);
4731 iounmap(adapter->hw.hw_addr);
4732 pci_release_regions(pdev);
4734 DPRINTK(PROBE, INFO, "complete\n");
4735 kfree(adapter->tx_ring);
4736 kfree(adapter->rx_ring);
4738 free_netdev(netdev);
4740 err = pci_disable_pcie_error_reporting(pdev);
4743 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4745 pci_disable_device(pdev);
4749 * ixgbe_io_error_detected - called when PCI error is detected
4750 * @pdev: Pointer to PCI device
4751 * @state: The current pci connection state
4753 * This function is called after a PCI bus error affecting
4754 * this device has been detected.
4756 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
4757 pci_channel_state_t state)
4759 struct net_device *netdev = pci_get_drvdata(pdev);
4760 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4762 netif_device_detach(netdev);
4764 if (netif_running(netdev))
4765 ixgbe_down(adapter);
4766 pci_disable_device(pdev);
4768 /* Request a slot reset. */
4769 return PCI_ERS_RESULT_NEED_RESET;
4773 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4774 * @pdev: Pointer to PCI device
4776 * Restart the card from scratch, as if from a cold-boot.
4778 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4780 struct net_device *netdev = pci_get_drvdata(pdev);
4781 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4782 pci_ers_result_t result;
4785 if (pci_enable_device(pdev)) {
4787 "Cannot re-enable PCI device after reset.\n");
4788 result = PCI_ERS_RESULT_DISCONNECT;
4790 pci_set_master(pdev);
4791 pci_restore_state(pdev);
4793 pci_enable_wake(pdev, PCI_D3hot, 0);
4794 pci_enable_wake(pdev, PCI_D3cold, 0);
4796 ixgbe_reset(adapter);
4798 result = PCI_ERS_RESULT_RECOVERED;
4801 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4804 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4805 /* non-fatal, continue */
4812 * ixgbe_io_resume - called when traffic can start flowing again.
4813 * @pdev: Pointer to PCI device
4815 * This callback is called when the error recovery driver tells us that
4816 * its OK to resume normal operation.
4818 static void ixgbe_io_resume(struct pci_dev *pdev)
4820 struct net_device *netdev = pci_get_drvdata(pdev);
4821 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4823 if (netif_running(netdev)) {
4824 if (ixgbe_up(adapter)) {
4825 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4830 netif_device_attach(netdev);
4833 static struct pci_error_handlers ixgbe_err_handler = {
4834 .error_detected = ixgbe_io_error_detected,
4835 .slot_reset = ixgbe_io_slot_reset,
4836 .resume = ixgbe_io_resume,
4839 static struct pci_driver ixgbe_driver = {
4840 .name = ixgbe_driver_name,
4841 .id_table = ixgbe_pci_tbl,
4842 .probe = ixgbe_probe,
4843 .remove = __devexit_p(ixgbe_remove),
4845 .suspend = ixgbe_suspend,
4846 .resume = ixgbe_resume,
4848 .shutdown = ixgbe_shutdown,
4849 .err_handler = &ixgbe_err_handler
4853 * ixgbe_init_module - Driver Registration Routine
4855 * ixgbe_init_module is the first routine called when the driver is
4856 * loaded. All it does is register with the PCI subsystem.
4858 static int __init ixgbe_init_module(void)
4861 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4862 ixgbe_driver_string, ixgbe_driver_version);
4864 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4866 #ifdef CONFIG_IXGBE_DCA
4867 dca_register_notify(&dca_notifier);
4870 ret = pci_register_driver(&ixgbe_driver);
4874 module_init(ixgbe_init_module);
4877 * ixgbe_exit_module - Driver Exit Cleanup Routine
4879 * ixgbe_exit_module is called just before the driver is removed
4882 static void __exit ixgbe_exit_module(void)
4884 #ifdef CONFIG_IXGBE_DCA
4885 dca_unregister_notify(&dca_notifier);
4887 pci_unregister_driver(&ixgbe_driver);
4890 #ifdef CONFIG_IXGBE_DCA
4891 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
4896 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
4897 __ixgbe_notify_dca);
4899 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4901 #endif /* CONFIG_IXGBE_DCA */
4903 module_exit(ixgbe_exit_module);