ixgbe: Use the instance of net_device_stats from net_device.
[linux-2.6/kvm.git] / drivers / net / ixgbe / ixgbe_main.c
blobc91d50e54427ac429b0acd7827df0b5c4d67ff6c
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
13 more details.
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".
22 Contact Information:
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>
34 #include <linux/in.h>
35 #include <linux/ip.h>
36 #include <linux/tcp.h>
37 #include <linux/pkt_sched.h>
38 #include <linux/ipv6.h>
39 #include <net/checksum.h>
40 #include <net/ip6_checksum.h>
41 #include <linux/ethtool.h>
42 #include <linux/if_vlan.h>
43 #include <scsi/fc/fc_fcoe.h>
45 #include "ixgbe.h"
46 #include "ixgbe_common.h"
48 char ixgbe_driver_name[] = "ixgbe";
49 static const char ixgbe_driver_string[] =
50 "Intel(R) 10 Gigabit PCI Express Network Driver";
52 #define DRV_VERSION "2.0.44-k2"
53 const char ixgbe_driver_version[] = DRV_VERSION;
54 static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
56 static const struct ixgbe_info *ixgbe_info_tbl[] = {
57 [board_82598] = &ixgbe_82598_info,
58 [board_82599] = &ixgbe_82599_info,
61 /* ixgbe_pci_tbl - PCI Device ID Table
63 * Wildcard entries (PCI_ANY_ID) should come last
64 * Last entry must be all 0s
66 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
67 * Class, Class Mask, private data (not used) }
69 static struct pci_device_id ixgbe_pci_tbl[] = {
70 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
71 board_82598 },
72 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
73 board_82598 },
74 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
75 board_82598 },
76 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
77 board_82598 },
78 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
79 board_82598 },
80 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
81 board_82598 },
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
83 board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
85 board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
87 board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
89 board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
91 board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
93 board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
95 board_82599 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
97 board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
99 board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
101 board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
103 board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
105 board_82599 },
107 /* required last entry */
108 {0, }
110 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
112 #ifdef CONFIG_IXGBE_DCA
113 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
114 void *p);
115 static struct notifier_block dca_notifier = {
116 .notifier_call = ixgbe_notify_dca,
117 .next = NULL,
118 .priority = 0
120 #endif
122 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
123 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
124 MODULE_LICENSE("GPL");
125 MODULE_VERSION(DRV_VERSION);
127 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
129 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
131 u32 ctrl_ext;
133 /* Let firmware take over control of h/w */
134 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
135 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
136 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
139 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
141 u32 ctrl_ext;
143 /* Let firmware know the driver has taken over */
144 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
145 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
146 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
150 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
151 * @adapter: pointer to adapter struct
152 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
153 * @queue: queue to map the corresponding interrupt to
154 * @msix_vector: the vector to map to the corresponding queue
157 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
158 u8 queue, u8 msix_vector)
160 u32 ivar, index;
161 struct ixgbe_hw *hw = &adapter->hw;
162 switch (hw->mac.type) {
163 case ixgbe_mac_82598EB:
164 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
165 if (direction == -1)
166 direction = 0;
167 index = (((direction * 64) + queue) >> 2) & 0x1F;
168 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
169 ivar &= ~(0xFF << (8 * (queue & 0x3)));
170 ivar |= (msix_vector << (8 * (queue & 0x3)));
171 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
172 break;
173 case ixgbe_mac_82599EB:
174 if (direction == -1) {
175 /* other causes */
176 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
177 index = ((queue & 1) * 8);
178 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
179 ivar &= ~(0xFF << index);
180 ivar |= (msix_vector << index);
181 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
182 break;
183 } else {
184 /* tx or rx causes */
185 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
186 index = ((16 * (queue & 1)) + (8 * direction));
187 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
188 ivar &= ~(0xFF << index);
189 ivar |= (msix_vector << index);
190 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
191 break;
193 default:
194 break;
198 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
199 u64 qmask)
201 u32 mask;
203 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
204 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
205 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
206 } else {
207 mask = (qmask & 0xFFFFFFFF);
208 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
209 mask = (qmask >> 32);
210 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
214 static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
215 struct ixgbe_tx_buffer
216 *tx_buffer_info)
218 tx_buffer_info->dma = 0;
219 if (tx_buffer_info->skb) {
220 skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb,
221 DMA_TO_DEVICE);
222 dev_kfree_skb_any(tx_buffer_info->skb);
223 tx_buffer_info->skb = NULL;
225 tx_buffer_info->time_stamp = 0;
226 /* tx_buffer_info must be completely set up in the transmit path */
229 static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
230 struct ixgbe_ring *tx_ring,
231 unsigned int eop)
233 struct ixgbe_hw *hw = &adapter->hw;
235 /* Detect a transmit hang in hardware, this serializes the
236 * check with the clearing of time_stamp and movement of eop */
237 adapter->detect_tx_hung = false;
238 if (tx_ring->tx_buffer_info[eop].time_stamp &&
239 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
240 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
241 /* detected Tx unit hang */
242 union ixgbe_adv_tx_desc *tx_desc;
243 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
244 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
245 " Tx Queue <%d>\n"
246 " TDH, TDT <%x>, <%x>\n"
247 " next_to_use <%x>\n"
248 " next_to_clean <%x>\n"
249 "tx_buffer_info[next_to_clean]\n"
250 " time_stamp <%lx>\n"
251 " jiffies <%lx>\n",
252 tx_ring->queue_index,
253 IXGBE_READ_REG(hw, tx_ring->head),
254 IXGBE_READ_REG(hw, tx_ring->tail),
255 tx_ring->next_to_use, eop,
256 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
257 return true;
260 return false;
263 #define IXGBE_MAX_TXD_PWR 14
264 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
266 /* Tx Descriptors needed, worst case */
267 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
268 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
269 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
270 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
272 static void ixgbe_tx_timeout(struct net_device *netdev);
275 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
276 * @q_vector: structure containing interrupt and ring information
277 * @tx_ring: tx ring to clean
279 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
280 struct ixgbe_ring *tx_ring)
282 struct ixgbe_adapter *adapter = q_vector->adapter;
283 struct net_device *netdev = adapter->netdev;
284 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
285 struct ixgbe_tx_buffer *tx_buffer_info;
286 unsigned int i, eop, count = 0;
287 unsigned int total_bytes = 0, total_packets = 0;
289 i = tx_ring->next_to_clean;
290 eop = tx_ring->tx_buffer_info[i].next_to_watch;
291 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
293 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
294 (count < tx_ring->work_limit)) {
295 bool cleaned = false;
296 for ( ; !cleaned; count++) {
297 struct sk_buff *skb;
298 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
299 tx_buffer_info = &tx_ring->tx_buffer_info[i];
300 cleaned = (i == eop);
301 skb = tx_buffer_info->skb;
303 if (cleaned && skb) {
304 unsigned int segs, bytecount;
305 unsigned int hlen = skb_headlen(skb);
307 /* gso_segs is currently only valid for tcp */
308 segs = skb_shinfo(skb)->gso_segs ?: 1;
309 #ifdef IXGBE_FCOE
310 /* adjust for FCoE Sequence Offload */
311 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
312 && (skb->protocol == htons(ETH_P_FCOE)) &&
313 skb_is_gso(skb)) {
314 hlen = skb_transport_offset(skb) +
315 sizeof(struct fc_frame_header) +
316 sizeof(struct fcoe_crc_eof);
317 segs = DIV_ROUND_UP(skb->len - hlen,
318 skb_shinfo(skb)->gso_size);
320 #endif /* IXGBE_FCOE */
321 /* multiply data chunks by size of headers */
322 bytecount = ((segs - 1) * hlen) + skb->len;
323 total_packets += segs;
324 total_bytes += bytecount;
327 ixgbe_unmap_and_free_tx_resource(adapter,
328 tx_buffer_info);
330 tx_desc->wb.status = 0;
332 i++;
333 if (i == tx_ring->count)
334 i = 0;
337 eop = tx_ring->tx_buffer_info[i].next_to_watch;
338 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
341 tx_ring->next_to_clean = i;
343 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
344 if (unlikely(count && netif_carrier_ok(netdev) &&
345 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
346 /* Make sure that anybody stopping the queue after this
347 * sees the new next_to_clean.
349 smp_mb();
350 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
351 !test_bit(__IXGBE_DOWN, &adapter->state)) {
352 netif_wake_subqueue(netdev, tx_ring->queue_index);
353 ++adapter->restart_queue;
357 if (adapter->detect_tx_hung) {
358 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
359 /* schedule immediate reset if we believe we hung */
360 DPRINTK(PROBE, INFO,
361 "tx hang %d detected, resetting adapter\n",
362 adapter->tx_timeout_count + 1);
363 ixgbe_tx_timeout(adapter->netdev);
367 /* re-arm the interrupt */
368 if (count >= tx_ring->work_limit)
369 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
371 tx_ring->total_bytes += total_bytes;
372 tx_ring->total_packets += total_packets;
373 tx_ring->stats.packets += total_packets;
374 tx_ring->stats.bytes += total_bytes;
375 netdev->stats.tx_bytes += total_bytes;
376 netdev->stats.tx_packets += total_packets;
377 return (count < tx_ring->work_limit);
380 #ifdef CONFIG_IXGBE_DCA
381 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
382 struct ixgbe_ring *rx_ring)
384 u32 rxctrl;
385 int cpu = get_cpu();
386 int q = rx_ring - adapter->rx_ring;
388 if (rx_ring->cpu != cpu) {
389 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
390 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
391 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
392 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
393 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
394 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
395 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
396 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
398 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
399 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
400 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
401 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
402 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
403 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
404 rx_ring->cpu = cpu;
406 put_cpu();
409 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
410 struct ixgbe_ring *tx_ring)
412 u32 txctrl;
413 int cpu = get_cpu();
414 int q = tx_ring - adapter->tx_ring;
416 if (tx_ring->cpu != cpu) {
417 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
418 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
419 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
420 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
421 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
422 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
423 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
424 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
426 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
427 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
428 tx_ring->cpu = cpu;
430 put_cpu();
433 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
435 int i;
437 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
438 return;
440 /* always use CB2 mode, difference is masked in the CB driver */
441 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
443 for (i = 0; i < adapter->num_tx_queues; i++) {
444 adapter->tx_ring[i].cpu = -1;
445 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
447 for (i = 0; i < adapter->num_rx_queues; i++) {
448 adapter->rx_ring[i].cpu = -1;
449 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
453 static int __ixgbe_notify_dca(struct device *dev, void *data)
455 struct net_device *netdev = dev_get_drvdata(dev);
456 struct ixgbe_adapter *adapter = netdev_priv(netdev);
457 unsigned long event = *(unsigned long *)data;
459 switch (event) {
460 case DCA_PROVIDER_ADD:
461 /* if we're already enabled, don't do it again */
462 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
463 break;
464 if (dca_add_requester(dev) == 0) {
465 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
466 ixgbe_setup_dca(adapter);
467 break;
469 /* Fall Through since DCA is disabled. */
470 case DCA_PROVIDER_REMOVE:
471 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
472 dca_remove_requester(dev);
473 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
474 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
476 break;
479 return 0;
482 #endif /* CONFIG_IXGBE_DCA */
484 * ixgbe_receive_skb - Send a completed packet up the stack
485 * @adapter: board private structure
486 * @skb: packet to send up
487 * @status: hardware indication of status of receive
488 * @rx_ring: rx descriptor ring (for a specific queue) to setup
489 * @rx_desc: rx descriptor
491 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
492 struct sk_buff *skb, u8 status,
493 struct ixgbe_ring *ring,
494 union ixgbe_adv_rx_desc *rx_desc)
496 struct ixgbe_adapter *adapter = q_vector->adapter;
497 struct napi_struct *napi = &q_vector->napi;
498 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
499 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
501 skb_record_rx_queue(skb, ring->queue_index);
502 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
503 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
504 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
505 else
506 napi_gro_receive(napi, skb);
507 } else {
508 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
509 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
510 else
511 netif_rx(skb);
516 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
517 * @adapter: address of board private structure
518 * @status_err: hardware indication of status of receive
519 * @skb: skb currently being received and modified
521 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
522 union ixgbe_adv_rx_desc *rx_desc,
523 struct sk_buff *skb)
525 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
527 skb->ip_summed = CHECKSUM_NONE;
529 /* Rx csum disabled */
530 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
531 return;
533 /* if IP and error */
534 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
535 (status_err & IXGBE_RXDADV_ERR_IPE)) {
536 adapter->hw_csum_rx_error++;
537 return;
540 if (!(status_err & IXGBE_RXD_STAT_L4CS))
541 return;
543 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
544 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
547 * 82599 errata, UDP frames with a 0 checksum can be marked as
548 * checksum errors.
550 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
551 (adapter->hw.mac.type == ixgbe_mac_82599EB))
552 return;
554 adapter->hw_csum_rx_error++;
555 return;
558 /* It must be a TCP or UDP packet with a valid checksum */
559 skb->ip_summed = CHECKSUM_UNNECESSARY;
560 adapter->hw_csum_rx_good++;
563 static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
564 struct ixgbe_ring *rx_ring, u32 val)
567 * Force memory writes to complete before letting h/w
568 * know there are new descriptors to fetch. (Only
569 * applicable for weak-ordered memory model archs,
570 * such as IA-64).
572 wmb();
573 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
577 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
578 * @adapter: address of board private structure
580 static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
581 struct ixgbe_ring *rx_ring,
582 int cleaned_count)
584 struct pci_dev *pdev = adapter->pdev;
585 union ixgbe_adv_rx_desc *rx_desc;
586 struct ixgbe_rx_buffer *bi;
587 unsigned int i;
589 i = rx_ring->next_to_use;
590 bi = &rx_ring->rx_buffer_info[i];
592 while (cleaned_count--) {
593 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
595 if (!bi->page_dma &&
596 (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
597 if (!bi->page) {
598 bi->page = alloc_page(GFP_ATOMIC);
599 if (!bi->page) {
600 adapter->alloc_rx_page_failed++;
601 goto no_buffers;
603 bi->page_offset = 0;
604 } else {
605 /* use a half page if we're re-using */
606 bi->page_offset ^= (PAGE_SIZE / 2);
609 bi->page_dma = pci_map_page(pdev, bi->page,
610 bi->page_offset,
611 (PAGE_SIZE / 2),
612 PCI_DMA_FROMDEVICE);
615 if (!bi->skb) {
616 struct sk_buff *skb;
617 skb = netdev_alloc_skb(adapter->netdev,
618 (rx_ring->rx_buf_len +
619 NET_IP_ALIGN));
621 if (!skb) {
622 adapter->alloc_rx_buff_failed++;
623 goto no_buffers;
627 * Make buffer alignment 2 beyond a 16 byte boundary
628 * this will result in a 16 byte aligned IP header after
629 * the 14 byte MAC header is removed
631 skb_reserve(skb, NET_IP_ALIGN);
633 bi->skb = skb;
634 bi->dma = pci_map_single(pdev, skb->data,
635 rx_ring->rx_buf_len,
636 PCI_DMA_FROMDEVICE);
638 /* Refresh the desc even if buffer_addrs didn't change because
639 * each write-back erases this info. */
640 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
641 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
642 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
643 } else {
644 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
647 i++;
648 if (i == rx_ring->count)
649 i = 0;
650 bi = &rx_ring->rx_buffer_info[i];
653 no_buffers:
654 if (rx_ring->next_to_use != i) {
655 rx_ring->next_to_use = i;
656 if (i-- == 0)
657 i = (rx_ring->count - 1);
659 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
663 static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
665 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
668 static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
670 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
673 static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
675 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
676 IXGBE_RXDADV_RSCCNT_MASK) >>
677 IXGBE_RXDADV_RSCCNT_SHIFT;
681 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
682 * @skb: pointer to the last skb in the rsc queue
684 * This function changes a queue full of hw rsc buffers into a completed
685 * packet. It uses the ->prev pointers to find the first packet and then
686 * turns it into the frag list owner.
688 static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
690 unsigned int frag_list_size = 0;
692 while (skb->prev) {
693 struct sk_buff *prev = skb->prev;
694 frag_list_size += skb->len;
695 skb->prev = NULL;
696 skb = prev;
699 skb_shinfo(skb)->frag_list = skb->next;
700 skb->next = NULL;
701 skb->len += frag_list_size;
702 skb->data_len += frag_list_size;
703 skb->truesize += frag_list_size;
704 return skb;
707 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
708 struct ixgbe_ring *rx_ring,
709 int *work_done, int work_to_do)
711 struct ixgbe_adapter *adapter = q_vector->adapter;
712 struct net_device *netdev = adapter->netdev;
713 struct pci_dev *pdev = adapter->pdev;
714 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
715 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
716 struct sk_buff *skb;
717 unsigned int i, rsc_count = 0;
718 u32 len, staterr;
719 u16 hdr_info;
720 bool cleaned = false;
721 int cleaned_count = 0;
722 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
723 #ifdef IXGBE_FCOE
724 int ddp_bytes = 0;
725 #endif /* IXGBE_FCOE */
727 i = rx_ring->next_to_clean;
728 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
729 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
730 rx_buffer_info = &rx_ring->rx_buffer_info[i];
732 while (staterr & IXGBE_RXD_STAT_DD) {
733 u32 upper_len = 0;
734 if (*work_done >= work_to_do)
735 break;
736 (*work_done)++;
738 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
739 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
740 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
741 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
742 if (hdr_info & IXGBE_RXDADV_SPH)
743 adapter->rx_hdr_split++;
744 if (len > IXGBE_RX_HDR_SIZE)
745 len = IXGBE_RX_HDR_SIZE;
746 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
747 } else {
748 len = le16_to_cpu(rx_desc->wb.upper.length);
751 cleaned = true;
752 skb = rx_buffer_info->skb;
753 prefetch(skb->data - NET_IP_ALIGN);
754 rx_buffer_info->skb = NULL;
756 if (rx_buffer_info->dma) {
757 pci_unmap_single(pdev, rx_buffer_info->dma,
758 rx_ring->rx_buf_len,
759 PCI_DMA_FROMDEVICE);
760 rx_buffer_info->dma = 0;
761 skb_put(skb, len);
764 if (upper_len) {
765 pci_unmap_page(pdev, rx_buffer_info->page_dma,
766 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
767 rx_buffer_info->page_dma = 0;
768 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
769 rx_buffer_info->page,
770 rx_buffer_info->page_offset,
771 upper_len);
773 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
774 (page_count(rx_buffer_info->page) != 1))
775 rx_buffer_info->page = NULL;
776 else
777 get_page(rx_buffer_info->page);
779 skb->len += upper_len;
780 skb->data_len += upper_len;
781 skb->truesize += upper_len;
784 i++;
785 if (i == rx_ring->count)
786 i = 0;
788 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
789 prefetch(next_rxd);
790 cleaned_count++;
792 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
793 rsc_count = ixgbe_get_rsc_count(rx_desc);
795 if (rsc_count) {
796 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
797 IXGBE_RXDADV_NEXTP_SHIFT;
798 next_buffer = &rx_ring->rx_buffer_info[nextp];
799 rx_ring->rsc_count += (rsc_count - 1);
800 } else {
801 next_buffer = &rx_ring->rx_buffer_info[i];
804 if (staterr & IXGBE_RXD_STAT_EOP) {
805 if (skb->prev)
806 skb = ixgbe_transform_rsc_queue(skb);
807 rx_ring->stats.packets++;
808 rx_ring->stats.bytes += skb->len;
809 } else {
810 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
811 rx_buffer_info->skb = next_buffer->skb;
812 rx_buffer_info->dma = next_buffer->dma;
813 next_buffer->skb = skb;
814 next_buffer->dma = 0;
815 } else {
816 skb->next = next_buffer->skb;
817 skb->next->prev = skb;
819 adapter->non_eop_descs++;
820 goto next_desc;
823 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
824 dev_kfree_skb_irq(skb);
825 goto next_desc;
828 ixgbe_rx_checksum(adapter, rx_desc, skb);
830 /* probably a little skewed due to removing CRC */
831 total_rx_bytes += skb->len;
832 total_rx_packets++;
834 skb->protocol = eth_type_trans(skb, adapter->netdev);
835 #ifdef IXGBE_FCOE
836 /* if ddp, not passing to ULD unless for FCP_RSP or error */
837 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
838 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
839 if (!ddp_bytes)
840 goto next_desc;
842 #endif /* IXGBE_FCOE */
843 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
845 next_desc:
846 rx_desc->wb.upper.status_error = 0;
848 /* return some buffers to hardware, one at a time is too slow */
849 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
850 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
851 cleaned_count = 0;
854 /* use prefetched values */
855 rx_desc = next_rxd;
856 rx_buffer_info = &rx_ring->rx_buffer_info[i];
858 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
861 rx_ring->next_to_clean = i;
862 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
864 if (cleaned_count)
865 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
867 #ifdef IXGBE_FCOE
868 /* include DDPed FCoE data */
869 if (ddp_bytes > 0) {
870 unsigned int mss;
872 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
873 sizeof(struct fc_frame_header) -
874 sizeof(struct fcoe_crc_eof);
875 if (mss > 512)
876 mss &= ~511;
877 total_rx_bytes += ddp_bytes;
878 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
880 #endif /* IXGBE_FCOE */
882 rx_ring->total_packets += total_rx_packets;
883 rx_ring->total_bytes += total_rx_bytes;
884 netdev->stats.rx_bytes += total_rx_bytes;
885 netdev->stats.rx_packets += total_rx_packets;
887 return cleaned;
890 static int ixgbe_clean_rxonly(struct napi_struct *, int);
892 * ixgbe_configure_msix - Configure MSI-X hardware
893 * @adapter: board private structure
895 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
896 * interrupts.
898 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
900 struct ixgbe_q_vector *q_vector;
901 int i, j, q_vectors, v_idx, r_idx;
902 u32 mask;
904 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
907 * Populate the IVAR table and set the ITR values to the
908 * corresponding register.
910 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
911 q_vector = adapter->q_vector[v_idx];
912 /* XXX for_each_bit(...) */
913 r_idx = find_first_bit(q_vector->rxr_idx,
914 adapter->num_rx_queues);
916 for (i = 0; i < q_vector->rxr_count; i++) {
917 j = adapter->rx_ring[r_idx].reg_idx;
918 ixgbe_set_ivar(adapter, 0, j, v_idx);
919 r_idx = find_next_bit(q_vector->rxr_idx,
920 adapter->num_rx_queues,
921 r_idx + 1);
923 r_idx = find_first_bit(q_vector->txr_idx,
924 adapter->num_tx_queues);
926 for (i = 0; i < q_vector->txr_count; i++) {
927 j = adapter->tx_ring[r_idx].reg_idx;
928 ixgbe_set_ivar(adapter, 1, j, v_idx);
929 r_idx = find_next_bit(q_vector->txr_idx,
930 adapter->num_tx_queues,
931 r_idx + 1);
934 if (q_vector->txr_count && !q_vector->rxr_count)
935 /* tx only */
936 q_vector->eitr = adapter->tx_eitr_param;
937 else if (q_vector->rxr_count)
938 /* rx or mixed */
939 q_vector->eitr = adapter->rx_eitr_param;
941 ixgbe_write_eitr(q_vector);
944 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
945 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
946 v_idx);
947 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
948 ixgbe_set_ivar(adapter, -1, 1, v_idx);
949 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
951 /* set up to autoclear timer, and the vectors */
952 mask = IXGBE_EIMS_ENABLE_MASK;
953 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
954 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
957 enum latency_range {
958 lowest_latency = 0,
959 low_latency = 1,
960 bulk_latency = 2,
961 latency_invalid = 255
965 * ixgbe_update_itr - update the dynamic ITR value based on statistics
966 * @adapter: pointer to adapter
967 * @eitr: eitr setting (ints per sec) to give last timeslice
968 * @itr_setting: current throttle rate in ints/second
969 * @packets: the number of packets during this measurement interval
970 * @bytes: the number of bytes during this measurement interval
972 * Stores a new ITR value based on packets and byte
973 * counts during the last interrupt. The advantage of per interrupt
974 * computation is faster updates and more accurate ITR for the current
975 * traffic pattern. Constants in this function were computed
976 * based on theoretical maximum wire speed and thresholds were set based
977 * on testing data as well as attempting to minimize response time
978 * while increasing bulk throughput.
979 * this functionality is controlled by the InterruptThrottleRate module
980 * parameter (see ixgbe_param.c)
982 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
983 u32 eitr, u8 itr_setting,
984 int packets, int bytes)
986 unsigned int retval = itr_setting;
987 u32 timepassed_us;
988 u64 bytes_perint;
990 if (packets == 0)
991 goto update_itr_done;
994 /* simple throttlerate management
995 * 0-20MB/s lowest (100000 ints/s)
996 * 20-100MB/s low (20000 ints/s)
997 * 100-1249MB/s bulk (8000 ints/s)
999 /* what was last interrupt timeslice? */
1000 timepassed_us = 1000000/eitr;
1001 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1003 switch (itr_setting) {
1004 case lowest_latency:
1005 if (bytes_perint > adapter->eitr_low)
1006 retval = low_latency;
1007 break;
1008 case low_latency:
1009 if (bytes_perint > adapter->eitr_high)
1010 retval = bulk_latency;
1011 else if (bytes_perint <= adapter->eitr_low)
1012 retval = lowest_latency;
1013 break;
1014 case bulk_latency:
1015 if (bytes_perint <= adapter->eitr_high)
1016 retval = low_latency;
1017 break;
1020 update_itr_done:
1021 return retval;
1025 * ixgbe_write_eitr - write EITR register in hardware specific way
1026 * @q_vector: structure containing interrupt and ring information
1028 * This function is made to be called by ethtool and by the driver
1029 * when it needs to update EITR registers at runtime. Hardware
1030 * specific quirks/differences are taken care of here.
1032 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
1034 struct ixgbe_adapter *adapter = q_vector->adapter;
1035 struct ixgbe_hw *hw = &adapter->hw;
1036 int v_idx = q_vector->v_idx;
1037 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1039 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1040 /* must write high and low 16 bits to reset counter */
1041 itr_reg |= (itr_reg << 16);
1042 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1044 * set the WDIS bit to not clear the timer bits and cause an
1045 * immediate assertion of the interrupt
1047 itr_reg |= IXGBE_EITR_CNT_WDIS;
1049 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1052 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1054 struct ixgbe_adapter *adapter = q_vector->adapter;
1055 u32 new_itr;
1056 u8 current_itr, ret_itr;
1057 int i, r_idx;
1058 struct ixgbe_ring *rx_ring, *tx_ring;
1060 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1061 for (i = 0; i < q_vector->txr_count; i++) {
1062 tx_ring = &(adapter->tx_ring[r_idx]);
1063 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
1064 q_vector->tx_itr,
1065 tx_ring->total_packets,
1066 tx_ring->total_bytes);
1067 /* if the result for this queue would decrease interrupt
1068 * rate for this vector then use that result */
1069 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
1070 q_vector->tx_itr - 1 : ret_itr);
1071 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1072 r_idx + 1);
1075 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1076 for (i = 0; i < q_vector->rxr_count; i++) {
1077 rx_ring = &(adapter->rx_ring[r_idx]);
1078 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
1079 q_vector->rx_itr,
1080 rx_ring->total_packets,
1081 rx_ring->total_bytes);
1082 /* if the result for this queue would decrease interrupt
1083 * rate for this vector then use that result */
1084 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
1085 q_vector->rx_itr - 1 : ret_itr);
1086 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1087 r_idx + 1);
1090 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1092 switch (current_itr) {
1093 /* counts and packets in update_itr are dependent on these numbers */
1094 case lowest_latency:
1095 new_itr = 100000;
1096 break;
1097 case low_latency:
1098 new_itr = 20000; /* aka hwitr = ~200 */
1099 break;
1100 case bulk_latency:
1101 default:
1102 new_itr = 8000;
1103 break;
1106 if (new_itr != q_vector->eitr) {
1107 /* do an exponential smoothing */
1108 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1110 /* save the algorithm value here, not the smoothed one */
1111 q_vector->eitr = new_itr;
1113 ixgbe_write_eitr(q_vector);
1116 return;
1119 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1121 struct ixgbe_hw *hw = &adapter->hw;
1123 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1124 (eicr & IXGBE_EICR_GPI_SDP1)) {
1125 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1126 /* write to clear the interrupt */
1127 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1131 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1133 struct ixgbe_hw *hw = &adapter->hw;
1135 if (eicr & IXGBE_EICR_GPI_SDP1) {
1136 /* Clear the interrupt */
1137 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1138 schedule_work(&adapter->multispeed_fiber_task);
1139 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1140 /* Clear the interrupt */
1141 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1142 schedule_work(&adapter->sfp_config_module_task);
1143 } else {
1144 /* Interrupt isn't for us... */
1145 return;
1149 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1151 struct ixgbe_hw *hw = &adapter->hw;
1153 adapter->lsc_int++;
1154 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1155 adapter->link_check_timeout = jiffies;
1156 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1157 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1158 schedule_work(&adapter->watchdog_task);
1162 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1164 struct net_device *netdev = data;
1165 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1166 struct ixgbe_hw *hw = &adapter->hw;
1167 u32 eicr;
1170 * Workaround for Silicon errata. Use clear-by-write instead
1171 * of clear-by-read. Reading with EICS will return the
1172 * interrupt causes without clearing, which later be done
1173 * with the write to EICR.
1175 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1176 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1178 if (eicr & IXGBE_EICR_LSC)
1179 ixgbe_check_lsc(adapter);
1181 if (hw->mac.type == ixgbe_mac_82598EB)
1182 ixgbe_check_fan_failure(adapter, eicr);
1184 if (hw->mac.type == ixgbe_mac_82599EB) {
1185 ixgbe_check_sfp_event(adapter, eicr);
1187 /* Handle Flow Director Full threshold interrupt */
1188 if (eicr & IXGBE_EICR_FLOW_DIR) {
1189 int i;
1190 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1191 /* Disable transmits before FDIR Re-initialization */
1192 netif_tx_stop_all_queues(netdev);
1193 for (i = 0; i < adapter->num_tx_queues; i++) {
1194 struct ixgbe_ring *tx_ring =
1195 &adapter->tx_ring[i];
1196 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1197 &tx_ring->reinit_state))
1198 schedule_work(&adapter->fdir_reinit_task);
1202 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1203 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1205 return IRQ_HANDLED;
1208 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1209 u64 qmask)
1211 u32 mask;
1213 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1214 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1215 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1216 } else {
1217 mask = (qmask & 0xFFFFFFFF);
1218 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1219 mask = (qmask >> 32);
1220 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1222 /* skip the flush */
1225 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1226 u64 qmask)
1228 u32 mask;
1230 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1231 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1232 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1233 } else {
1234 mask = (qmask & 0xFFFFFFFF);
1235 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1236 mask = (qmask >> 32);
1237 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1239 /* skip the flush */
1242 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1244 struct ixgbe_q_vector *q_vector = data;
1245 struct ixgbe_adapter *adapter = q_vector->adapter;
1246 struct ixgbe_ring *tx_ring;
1247 int i, r_idx;
1249 if (!q_vector->txr_count)
1250 return IRQ_HANDLED;
1252 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1253 for (i = 0; i < q_vector->txr_count; i++) {
1254 tx_ring = &(adapter->tx_ring[r_idx]);
1255 tx_ring->total_bytes = 0;
1256 tx_ring->total_packets = 0;
1257 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1258 r_idx + 1);
1261 /* disable interrupts on this vector only */
1262 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1263 napi_schedule(&q_vector->napi);
1265 return IRQ_HANDLED;
1269 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1270 * @irq: unused
1271 * @data: pointer to our q_vector struct for this interrupt vector
1273 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1275 struct ixgbe_q_vector *q_vector = data;
1276 struct ixgbe_adapter *adapter = q_vector->adapter;
1277 struct ixgbe_ring *rx_ring;
1278 int r_idx;
1279 int i;
1281 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1282 for (i = 0; i < q_vector->rxr_count; i++) {
1283 rx_ring = &(adapter->rx_ring[r_idx]);
1284 rx_ring->total_bytes = 0;
1285 rx_ring->total_packets = 0;
1286 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1287 r_idx + 1);
1290 if (!q_vector->rxr_count)
1291 return IRQ_HANDLED;
1293 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1294 rx_ring = &(adapter->rx_ring[r_idx]);
1295 /* disable interrupts on this vector only */
1296 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1297 napi_schedule(&q_vector->napi);
1299 return IRQ_HANDLED;
1302 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1304 struct ixgbe_q_vector *q_vector = data;
1305 struct ixgbe_adapter *adapter = q_vector->adapter;
1306 struct ixgbe_ring *ring;
1307 int r_idx;
1308 int i;
1310 if (!q_vector->txr_count && !q_vector->rxr_count)
1311 return IRQ_HANDLED;
1313 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1314 for (i = 0; i < q_vector->txr_count; i++) {
1315 ring = &(adapter->tx_ring[r_idx]);
1316 ring->total_bytes = 0;
1317 ring->total_packets = 0;
1318 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1319 r_idx + 1);
1322 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1323 for (i = 0; i < q_vector->rxr_count; i++) {
1324 ring = &(adapter->rx_ring[r_idx]);
1325 ring->total_bytes = 0;
1326 ring->total_packets = 0;
1327 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1328 r_idx + 1);
1331 /* disable interrupts on this vector only */
1332 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1333 napi_schedule(&q_vector->napi);
1335 return IRQ_HANDLED;
1339 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1340 * @napi: napi struct with our devices info in it
1341 * @budget: amount of work driver is allowed to do this pass, in packets
1343 * This function is optimized for cleaning one queue only on a single
1344 * q_vector!!!
1346 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1348 struct ixgbe_q_vector *q_vector =
1349 container_of(napi, struct ixgbe_q_vector, napi);
1350 struct ixgbe_adapter *adapter = q_vector->adapter;
1351 struct ixgbe_ring *rx_ring = NULL;
1352 int work_done = 0;
1353 long r_idx;
1355 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1356 rx_ring = &(adapter->rx_ring[r_idx]);
1357 #ifdef CONFIG_IXGBE_DCA
1358 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1359 ixgbe_update_rx_dca(adapter, rx_ring);
1360 #endif
1362 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
1364 /* If all Rx work done, exit the polling mode */
1365 if (work_done < budget) {
1366 napi_complete(napi);
1367 if (adapter->rx_itr_setting & 1)
1368 ixgbe_set_itr_msix(q_vector);
1369 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1370 ixgbe_irq_enable_queues(adapter,
1371 ((u64)1 << q_vector->v_idx));
1374 return work_done;
1378 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
1379 * @napi: napi struct with our devices info in it
1380 * @budget: amount of work driver is allowed to do this pass, in packets
1382 * This function will clean more than one rx queue associated with a
1383 * q_vector.
1385 static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
1387 struct ixgbe_q_vector *q_vector =
1388 container_of(napi, struct ixgbe_q_vector, napi);
1389 struct ixgbe_adapter *adapter = q_vector->adapter;
1390 struct ixgbe_ring *ring = NULL;
1391 int work_done = 0, i;
1392 long r_idx;
1393 bool tx_clean_complete = true;
1395 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1396 for (i = 0; i < q_vector->txr_count; i++) {
1397 ring = &(adapter->tx_ring[r_idx]);
1398 #ifdef CONFIG_IXGBE_DCA
1399 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1400 ixgbe_update_tx_dca(adapter, ring);
1401 #endif
1402 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1403 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1404 r_idx + 1);
1407 /* attempt to distribute budget to each queue fairly, but don't allow
1408 * the budget to go below 1 because we'll exit polling */
1409 budget /= (q_vector->rxr_count ?: 1);
1410 budget = max(budget, 1);
1411 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1412 for (i = 0; i < q_vector->rxr_count; i++) {
1413 ring = &(adapter->rx_ring[r_idx]);
1414 #ifdef CONFIG_IXGBE_DCA
1415 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1416 ixgbe_update_rx_dca(adapter, ring);
1417 #endif
1418 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
1419 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1420 r_idx + 1);
1423 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1424 ring = &(adapter->rx_ring[r_idx]);
1425 /* If all Rx work done, exit the polling mode */
1426 if (work_done < budget) {
1427 napi_complete(napi);
1428 if (adapter->rx_itr_setting & 1)
1429 ixgbe_set_itr_msix(q_vector);
1430 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1431 ixgbe_irq_enable_queues(adapter,
1432 ((u64)1 << q_vector->v_idx));
1433 return 0;
1436 return work_done;
1440 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1441 * @napi: napi struct with our devices info in it
1442 * @budget: amount of work driver is allowed to do this pass, in packets
1444 * This function is optimized for cleaning one queue only on a single
1445 * q_vector!!!
1447 static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1449 struct ixgbe_q_vector *q_vector =
1450 container_of(napi, struct ixgbe_q_vector, napi);
1451 struct ixgbe_adapter *adapter = q_vector->adapter;
1452 struct ixgbe_ring *tx_ring = NULL;
1453 int work_done = 0;
1454 long r_idx;
1456 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1457 tx_ring = &(adapter->tx_ring[r_idx]);
1458 #ifdef CONFIG_IXGBE_DCA
1459 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1460 ixgbe_update_tx_dca(adapter, tx_ring);
1461 #endif
1463 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1464 work_done = budget;
1466 /* If all Tx work done, exit the polling mode */
1467 if (work_done < budget) {
1468 napi_complete(napi);
1469 if (adapter->tx_itr_setting & 1)
1470 ixgbe_set_itr_msix(q_vector);
1471 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1472 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1475 return work_done;
1478 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
1479 int r_idx)
1481 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1483 set_bit(r_idx, q_vector->rxr_idx);
1484 q_vector->rxr_count++;
1487 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
1488 int t_idx)
1490 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1492 set_bit(t_idx, q_vector->txr_idx);
1493 q_vector->txr_count++;
1497 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1498 * @adapter: board private structure to initialize
1499 * @vectors: allotted vector count for descriptor rings
1501 * This function maps descriptor rings to the queue-specific vectors
1502 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1503 * one vector per ring/queue, but on a constrained vector budget, we
1504 * group the rings as "efficiently" as possible. You would add new
1505 * mapping configurations in here.
1507 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
1508 int vectors)
1510 int v_start = 0;
1511 int rxr_idx = 0, txr_idx = 0;
1512 int rxr_remaining = adapter->num_rx_queues;
1513 int txr_remaining = adapter->num_tx_queues;
1514 int i, j;
1515 int rqpv, tqpv;
1516 int err = 0;
1518 /* No mapping required if MSI-X is disabled. */
1519 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1520 goto out;
1523 * The ideal configuration...
1524 * We have enough vectors to map one per queue.
1526 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1527 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1528 map_vector_to_rxq(adapter, v_start, rxr_idx);
1530 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1531 map_vector_to_txq(adapter, v_start, txr_idx);
1533 goto out;
1537 * If we don't have enough vectors for a 1-to-1
1538 * mapping, we'll have to group them so there are
1539 * multiple queues per vector.
1541 /* Re-adjusting *qpv takes care of the remainder. */
1542 for (i = v_start; i < vectors; i++) {
1543 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1544 for (j = 0; j < rqpv; j++) {
1545 map_vector_to_rxq(adapter, i, rxr_idx);
1546 rxr_idx++;
1547 rxr_remaining--;
1550 for (i = v_start; i < vectors; i++) {
1551 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1552 for (j = 0; j < tqpv; j++) {
1553 map_vector_to_txq(adapter, i, txr_idx);
1554 txr_idx++;
1555 txr_remaining--;
1559 out:
1560 return err;
1564 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1565 * @adapter: board private structure
1567 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1568 * interrupts from the kernel.
1570 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1572 struct net_device *netdev = adapter->netdev;
1573 irqreturn_t (*handler)(int, void *);
1574 int i, vector, q_vectors, err;
1575 int ri=0, ti=0;
1577 /* Decrement for Other and TCP Timer vectors */
1578 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1580 /* Map the Tx/Rx rings to the vectors we were allotted. */
1581 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1582 if (err)
1583 goto out;
1585 #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
1586 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1587 &ixgbe_msix_clean_many)
1588 for (vector = 0; vector < q_vectors; vector++) {
1589 handler = SET_HANDLER(adapter->q_vector[vector]);
1591 if(handler == &ixgbe_msix_clean_rx) {
1592 sprintf(adapter->name[vector], "%s-%s-%d",
1593 netdev->name, "rx", ri++);
1595 else if(handler == &ixgbe_msix_clean_tx) {
1596 sprintf(adapter->name[vector], "%s-%s-%d",
1597 netdev->name, "tx", ti++);
1599 else
1600 sprintf(adapter->name[vector], "%s-%s-%d",
1601 netdev->name, "TxRx", vector);
1603 err = request_irq(adapter->msix_entries[vector].vector,
1604 handler, 0, adapter->name[vector],
1605 adapter->q_vector[vector]);
1606 if (err) {
1607 DPRINTK(PROBE, ERR,
1608 "request_irq failed for MSIX interrupt "
1609 "Error: %d\n", err);
1610 goto free_queue_irqs;
1614 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1615 err = request_irq(adapter->msix_entries[vector].vector,
1616 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
1617 if (err) {
1618 DPRINTK(PROBE, ERR,
1619 "request_irq for msix_lsc failed: %d\n", err);
1620 goto free_queue_irqs;
1623 return 0;
1625 free_queue_irqs:
1626 for (i = vector - 1; i >= 0; i--)
1627 free_irq(adapter->msix_entries[--vector].vector,
1628 adapter->q_vector[i]);
1629 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1630 pci_disable_msix(adapter->pdev);
1631 kfree(adapter->msix_entries);
1632 adapter->msix_entries = NULL;
1633 out:
1634 return err;
1637 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1639 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
1640 u8 current_itr;
1641 u32 new_itr = q_vector->eitr;
1642 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1643 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1645 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
1646 q_vector->tx_itr,
1647 tx_ring->total_packets,
1648 tx_ring->total_bytes);
1649 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
1650 q_vector->rx_itr,
1651 rx_ring->total_packets,
1652 rx_ring->total_bytes);
1654 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1656 switch (current_itr) {
1657 /* counts and packets in update_itr are dependent on these numbers */
1658 case lowest_latency:
1659 new_itr = 100000;
1660 break;
1661 case low_latency:
1662 new_itr = 20000; /* aka hwitr = ~200 */
1663 break;
1664 case bulk_latency:
1665 new_itr = 8000;
1666 break;
1667 default:
1668 break;
1671 if (new_itr != q_vector->eitr) {
1672 /* do an exponential smoothing */
1673 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1675 /* save the algorithm value here, not the smoothed one */
1676 q_vector->eitr = new_itr;
1678 ixgbe_write_eitr(q_vector);
1681 return;
1685 * ixgbe_irq_enable - Enable default interrupt generation settings
1686 * @adapter: board private structure
1688 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1690 u32 mask;
1692 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1693 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1694 mask |= IXGBE_EIMS_GPI_SDP1;
1695 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1696 mask |= IXGBE_EIMS_ECC;
1697 mask |= IXGBE_EIMS_GPI_SDP1;
1698 mask |= IXGBE_EIMS_GPI_SDP2;
1700 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1701 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1702 mask |= IXGBE_EIMS_FLOW_DIR;
1704 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1705 ixgbe_irq_enable_queues(adapter, ~0);
1706 IXGBE_WRITE_FLUSH(&adapter->hw);
1710 * ixgbe_intr - legacy mode Interrupt Handler
1711 * @irq: interrupt number
1712 * @data: pointer to a network interface device structure
1714 static irqreturn_t ixgbe_intr(int irq, void *data)
1716 struct net_device *netdev = data;
1717 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1718 struct ixgbe_hw *hw = &adapter->hw;
1719 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
1720 u32 eicr;
1723 * Workaround for silicon errata. Mask the interrupts
1724 * before the read of EICR.
1726 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1728 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1729 * therefore no explict interrupt disable is necessary */
1730 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1731 if (!eicr) {
1732 /* shared interrupt alert!
1733 * make sure interrupts are enabled because the read will
1734 * have disabled interrupts due to EIAM */
1735 ixgbe_irq_enable(adapter);
1736 return IRQ_NONE; /* Not our interrupt */
1739 if (eicr & IXGBE_EICR_LSC)
1740 ixgbe_check_lsc(adapter);
1742 if (hw->mac.type == ixgbe_mac_82599EB)
1743 ixgbe_check_sfp_event(adapter, eicr);
1745 ixgbe_check_fan_failure(adapter, eicr);
1747 if (napi_schedule_prep(&(q_vector->napi))) {
1748 adapter->tx_ring[0].total_packets = 0;
1749 adapter->tx_ring[0].total_bytes = 0;
1750 adapter->rx_ring[0].total_packets = 0;
1751 adapter->rx_ring[0].total_bytes = 0;
1752 /* would disable interrupts here but EIAM disabled it */
1753 __napi_schedule(&(q_vector->napi));
1756 return IRQ_HANDLED;
1759 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1761 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1763 for (i = 0; i < q_vectors; i++) {
1764 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
1765 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1766 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1767 q_vector->rxr_count = 0;
1768 q_vector->txr_count = 0;
1773 * ixgbe_request_irq - initialize interrupts
1774 * @adapter: board private structure
1776 * Attempts to configure interrupts using the best available
1777 * capabilities of the hardware and kernel.
1779 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
1781 struct net_device *netdev = adapter->netdev;
1782 int err;
1784 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1785 err = ixgbe_request_msix_irqs(adapter);
1786 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1787 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
1788 netdev->name, netdev);
1789 } else {
1790 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
1791 netdev->name, netdev);
1794 if (err)
1795 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1797 return err;
1800 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1802 struct net_device *netdev = adapter->netdev;
1804 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1805 int i, q_vectors;
1807 q_vectors = adapter->num_msix_vectors;
1809 i = q_vectors - 1;
1810 free_irq(adapter->msix_entries[i].vector, netdev);
1812 i--;
1813 for (; i >= 0; i--) {
1814 free_irq(adapter->msix_entries[i].vector,
1815 adapter->q_vector[i]);
1818 ixgbe_reset_q_vectors(adapter);
1819 } else {
1820 free_irq(adapter->pdev->irq, netdev);
1825 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1826 * @adapter: board private structure
1828 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1830 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1831 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1832 } else {
1833 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1834 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
1835 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
1837 IXGBE_WRITE_FLUSH(&adapter->hw);
1838 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1839 int i;
1840 for (i = 0; i < adapter->num_msix_vectors; i++)
1841 synchronize_irq(adapter->msix_entries[i].vector);
1842 } else {
1843 synchronize_irq(adapter->pdev->irq);
1848 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1851 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1853 struct ixgbe_hw *hw = &adapter->hw;
1855 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
1856 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
1858 ixgbe_set_ivar(adapter, 0, 0, 0);
1859 ixgbe_set_ivar(adapter, 1, 0, 0);
1861 map_vector_to_rxq(adapter, 0, 0);
1862 map_vector_to_txq(adapter, 0, 0);
1864 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
1868 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
1869 * @adapter: board private structure
1871 * Configure the Tx unit of the MAC after a reset.
1873 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1875 u64 tdba;
1876 struct ixgbe_hw *hw = &adapter->hw;
1877 u32 i, j, tdlen, txctrl;
1879 /* Setup the HW Tx Head and Tail descriptor pointers */
1880 for (i = 0; i < adapter->num_tx_queues; i++) {
1881 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1882 j = ring->reg_idx;
1883 tdba = ring->dma;
1884 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1885 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
1886 (tdba & DMA_BIT_MASK(32)));
1887 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1888 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1889 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1890 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1891 adapter->tx_ring[i].head = IXGBE_TDH(j);
1892 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1894 * Disable Tx Head Writeback RO bit, since this hoses
1895 * bookkeeping if things aren't delivered in order.
1897 switch (hw->mac.type) {
1898 case ixgbe_mac_82598EB:
1899 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1900 break;
1901 case ixgbe_mac_82599EB:
1902 default:
1903 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
1904 break;
1906 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1907 switch (hw->mac.type) {
1908 case ixgbe_mac_82598EB:
1909 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1910 break;
1911 case ixgbe_mac_82599EB:
1912 default:
1913 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
1914 break;
1917 if (hw->mac.type == ixgbe_mac_82599EB) {
1918 /* We enable 8 traffic classes, DCB only */
1919 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1920 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1921 IXGBE_MTQC_8TC_8TQ));
1925 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1927 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
1928 struct ixgbe_ring *rx_ring)
1930 u32 srrctl;
1931 int index;
1932 struct ixgbe_ring_feature *feature = adapter->ring_feature;
1934 index = rx_ring->reg_idx;
1935 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1936 unsigned long mask;
1937 mask = (unsigned long) feature[RING_F_RSS].mask;
1938 index = index & mask;
1940 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1942 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1943 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1945 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1946 IXGBE_SRRCTL_BSIZEHDR_MASK;
1948 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
1949 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1950 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1951 #else
1952 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1953 #endif
1954 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1955 } else {
1956 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1957 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1958 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1961 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1964 static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1966 u32 mrqc = 0;
1967 int mask;
1969 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1970 return mrqc;
1972 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1973 #ifdef CONFIG_IXGBE_DCB
1974 | IXGBE_FLAG_DCB_ENABLED
1975 #endif
1978 switch (mask) {
1979 case (IXGBE_FLAG_RSS_ENABLED):
1980 mrqc = IXGBE_MRQC_RSSEN;
1981 break;
1982 #ifdef CONFIG_IXGBE_DCB
1983 case (IXGBE_FLAG_DCB_ENABLED):
1984 mrqc = IXGBE_MRQC_RT8TCEN;
1985 break;
1986 #endif /* CONFIG_IXGBE_DCB */
1987 default:
1988 break;
1991 return mrqc;
1995 * ixgbe_configure_rscctl - enable RSC for the indicated ring
1996 * @adapter: address of board private structure
1997 * @index: index of ring to set
1998 * @rx_buf_len: rx buffer length
2000 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index,
2001 int rx_buf_len)
2003 struct ixgbe_ring *rx_ring;
2004 struct ixgbe_hw *hw = &adapter->hw;
2005 int j;
2006 u32 rscctrl;
2008 rx_ring = &adapter->rx_ring[index];
2009 j = rx_ring->reg_idx;
2010 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2011 rscctrl |= IXGBE_RSCCTL_RSCEN;
2013 * we must limit the number of descriptors so that the
2014 * total size of max desc * buf_len is not greater
2015 * than 65535
2017 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
2018 #if (MAX_SKB_FRAGS > 16)
2019 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2020 #elif (MAX_SKB_FRAGS > 8)
2021 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2022 #elif (MAX_SKB_FRAGS > 4)
2023 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2024 #else
2025 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2026 #endif
2027 } else {
2028 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2029 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2030 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2031 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2032 else
2033 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2035 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2039 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
2040 * @adapter: board private structure
2042 * Configure the Rx unit of the MAC after a reset.
2044 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
2046 u64 rdba;
2047 struct ixgbe_hw *hw = &adapter->hw;
2048 struct ixgbe_ring *rx_ring;
2049 struct net_device *netdev = adapter->netdev;
2050 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2051 int i, j;
2052 u32 rdlen, rxctrl, rxcsum;
2053 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2054 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2055 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2056 u32 fctrl, hlreg0;
2057 u32 reta = 0, mrqc = 0;
2058 u32 rdrxctl;
2059 int rx_buf_len;
2061 /* Decide whether to use packet split mode or not */
2062 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2064 /* Set the RX buffer length according to the mode */
2065 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2066 rx_buf_len = IXGBE_RX_HDR_SIZE;
2067 if (hw->mac.type == ixgbe_mac_82599EB) {
2068 /* PSRTYPE must be initialized in 82599 */
2069 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2070 IXGBE_PSRTYPE_UDPHDR |
2071 IXGBE_PSRTYPE_IPV4HDR |
2072 IXGBE_PSRTYPE_IPV6HDR |
2073 IXGBE_PSRTYPE_L2HDR;
2074 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2076 } else {
2077 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
2078 (netdev->mtu <= ETH_DATA_LEN))
2079 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
2080 else
2081 rx_buf_len = ALIGN(max_frame, 1024);
2084 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2085 fctrl |= IXGBE_FCTRL_BAM;
2086 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
2087 fctrl |= IXGBE_FCTRL_PMCF;
2088 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2090 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2091 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2092 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2093 else
2094 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2095 #ifdef IXGBE_FCOE
2096 if (netdev->features & NETIF_F_FCOE_MTU)
2097 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2098 #endif
2099 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2101 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2102 /* disable receives while setting up the descriptors */
2103 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2104 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2107 * Setup the HW Rx Head and Tail Descriptor Pointers and
2108 * the Base and Length of the Rx Descriptor Ring
2110 for (i = 0; i < adapter->num_rx_queues; i++) {
2111 rx_ring = &adapter->rx_ring[i];
2112 rdba = rx_ring->dma;
2113 j = rx_ring->reg_idx;
2114 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
2115 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2116 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2117 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2118 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
2119 rx_ring->head = IXGBE_RDH(j);
2120 rx_ring->tail = IXGBE_RDT(j);
2121 rx_ring->rx_buf_len = rx_buf_len;
2123 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2124 rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
2125 else
2126 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2128 #ifdef IXGBE_FCOE
2129 if (netdev->features & NETIF_F_FCOE_MTU) {
2130 struct ixgbe_ring_feature *f;
2131 f = &adapter->ring_feature[RING_F_FCOE];
2132 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2133 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2134 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2135 rx_ring->rx_buf_len =
2136 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2140 #endif /* IXGBE_FCOE */
2141 ixgbe_configure_srrctl(adapter, rx_ring);
2144 if (hw->mac.type == ixgbe_mac_82598EB) {
2146 * For VMDq support of different descriptor types or
2147 * buffer sizes through the use of multiple SRRCTL
2148 * registers, RDRXCTL.MVMEN must be set to 1
2150 * also, the manual doesn't mention it clearly but DCA hints
2151 * will only use queue 0's tags unless this bit is set. Side
2152 * effects of setting this bit are only that SRRCTL must be
2153 * fully programmed [0..15]
2155 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2156 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2157 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2160 /* Program MRQC for the distribution of queues */
2161 mrqc = ixgbe_setup_mrqc(adapter);
2163 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2164 /* Fill out redirection table */
2165 for (i = 0, j = 0; i < 128; i++, j++) {
2166 if (j == adapter->ring_feature[RING_F_RSS].indices)
2167 j = 0;
2168 /* reta = 4-byte sliding window of
2169 * 0x00..(indices-1)(indices-1)00..etc. */
2170 reta = (reta << 8) | (j * 0x11);
2171 if ((i & 3) == 3)
2172 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2175 /* Fill out hash function seeds */
2176 for (i = 0; i < 10; i++)
2177 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2179 if (hw->mac.type == ixgbe_mac_82598EB)
2180 mrqc |= IXGBE_MRQC_RSSEN;
2181 /* Perform hash on these packet types */
2182 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2183 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2184 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2185 | IXGBE_MRQC_RSS_FIELD_IPV6
2186 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2187 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2189 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2191 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2193 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2194 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2195 /* Disable indicating checksum in descriptor, enables
2196 * RSS hash */
2197 rxcsum |= IXGBE_RXCSUM_PCSD;
2199 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2200 /* Enable IPv4 payload checksum for UDP fragments
2201 * if PCSD is not set */
2202 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2205 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2207 if (hw->mac.type == ixgbe_mac_82599EB) {
2208 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2209 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
2210 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
2211 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2214 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
2215 /* Enable 82599 HW-RSC */
2216 for (i = 0; i < adapter->num_rx_queues; i++)
2217 ixgbe_configure_rscctl(adapter, i, rx_buf_len);
2219 /* Disable RSC for ACK packets */
2220 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2221 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2225 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2227 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2228 struct ixgbe_hw *hw = &adapter->hw;
2230 /* add VID to filter table */
2231 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
2234 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2236 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2237 struct ixgbe_hw *hw = &adapter->hw;
2239 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2240 ixgbe_irq_disable(adapter);
2242 vlan_group_set_device(adapter->vlgrp, vid, NULL);
2244 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2245 ixgbe_irq_enable(adapter);
2247 /* remove VID from filter table */
2248 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
2251 static void ixgbe_vlan_rx_register(struct net_device *netdev,
2252 struct vlan_group *grp)
2254 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2255 u32 ctrl;
2256 int i, j;
2258 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2259 ixgbe_irq_disable(adapter);
2260 adapter->vlgrp = grp;
2263 * For a DCB driver, always enable VLAN tag stripping so we can
2264 * still receive traffic from a DCB-enabled host even if we're
2265 * not in DCB mode.
2267 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2268 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2269 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2270 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2271 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2272 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2273 ctrl |= IXGBE_VLNCTRL_VFE;
2274 /* enable VLAN tag insert/strip */
2275 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2276 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2277 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2278 for (i = 0; i < adapter->num_rx_queues; i++) {
2279 j = adapter->rx_ring[i].reg_idx;
2280 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2281 ctrl |= IXGBE_RXDCTL_VME;
2282 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2285 ixgbe_vlan_rx_add_vid(netdev, 0);
2287 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2288 ixgbe_irq_enable(adapter);
2291 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2293 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2295 if (adapter->vlgrp) {
2296 u16 vid;
2297 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2298 if (!vlan_group_get_device(adapter->vlgrp, vid))
2299 continue;
2300 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2305 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2307 struct dev_mc_list *mc_ptr;
2308 u8 *addr = *mc_addr_ptr;
2309 *vmdq = 0;
2311 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2312 if (mc_ptr->next)
2313 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2314 else
2315 *mc_addr_ptr = NULL;
2317 return addr;
2321 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
2322 * @netdev: network interface device structure
2324 * The set_rx_method entry point is called whenever the unicast/multicast
2325 * address list or the network interface flags are updated. This routine is
2326 * responsible for configuring the hardware for proper unicast, multicast and
2327 * promiscuous mode.
2329 static void ixgbe_set_rx_mode(struct net_device *netdev)
2331 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2332 struct ixgbe_hw *hw = &adapter->hw;
2333 u32 fctrl, vlnctrl;
2334 u8 *addr_list = NULL;
2335 int addr_count = 0;
2337 /* Check for Promiscuous and All Multicast modes */
2339 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2340 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2342 if (netdev->flags & IFF_PROMISC) {
2343 hw->addr_ctrl.user_set_promisc = 1;
2344 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2345 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
2346 } else {
2347 if (netdev->flags & IFF_ALLMULTI) {
2348 fctrl |= IXGBE_FCTRL_MPE;
2349 fctrl &= ~IXGBE_FCTRL_UPE;
2350 } else {
2351 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2353 vlnctrl |= IXGBE_VLNCTRL_VFE;
2354 hw->addr_ctrl.user_set_promisc = 0;
2357 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2358 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2360 /* reprogram secondary unicast list */
2361 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
2363 /* reprogram multicast list */
2364 addr_count = netdev->mc_count;
2365 if (addr_count)
2366 addr_list = netdev->mc_list->dmi_addr;
2367 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2368 ixgbe_addr_list_itr);
2371 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2373 int q_idx;
2374 struct ixgbe_q_vector *q_vector;
2375 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2377 /* legacy and MSI only use one vector */
2378 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2379 q_vectors = 1;
2381 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2382 struct napi_struct *napi;
2383 q_vector = adapter->q_vector[q_idx];
2384 napi = &q_vector->napi;
2385 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2386 if (!q_vector->rxr_count || !q_vector->txr_count) {
2387 if (q_vector->txr_count == 1)
2388 napi->poll = &ixgbe_clean_txonly;
2389 else if (q_vector->rxr_count == 1)
2390 napi->poll = &ixgbe_clean_rxonly;
2394 napi_enable(napi);
2398 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2400 int q_idx;
2401 struct ixgbe_q_vector *q_vector;
2402 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2404 /* legacy and MSI only use one vector */
2405 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2406 q_vectors = 1;
2408 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2409 q_vector = adapter->q_vector[q_idx];
2410 napi_disable(&q_vector->napi);
2414 #ifdef CONFIG_IXGBE_DCB
2416 * ixgbe_configure_dcb - Configure DCB hardware
2417 * @adapter: ixgbe adapter struct
2419 * This is called by the driver on open to configure the DCB hardware.
2420 * This is also called by the gennetlink interface when reconfiguring
2421 * the DCB state.
2423 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2425 struct ixgbe_hw *hw = &adapter->hw;
2426 u32 txdctl, vlnctrl;
2427 int i, j;
2429 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2430 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2431 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2433 /* reconfigure the hardware */
2434 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2436 for (i = 0; i < adapter->num_tx_queues; i++) {
2437 j = adapter->tx_ring[i].reg_idx;
2438 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2439 /* PThresh workaround for Tx hang with DFP enabled. */
2440 txdctl |= 32;
2441 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2443 /* Enable VLAN tag insert/strip */
2444 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2445 if (hw->mac.type == ixgbe_mac_82598EB) {
2446 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2447 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2448 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2449 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2450 vlnctrl |= IXGBE_VLNCTRL_VFE;
2451 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2452 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2453 for (i = 0; i < adapter->num_rx_queues; i++) {
2454 j = adapter->rx_ring[i].reg_idx;
2455 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2456 vlnctrl |= IXGBE_RXDCTL_VME;
2457 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2460 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2463 #endif
2464 static void ixgbe_configure(struct ixgbe_adapter *adapter)
2466 struct net_device *netdev = adapter->netdev;
2467 struct ixgbe_hw *hw = &adapter->hw;
2468 int i;
2470 ixgbe_set_rx_mode(netdev);
2472 ixgbe_restore_vlan(adapter);
2473 #ifdef CONFIG_IXGBE_DCB
2474 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2475 netif_set_gso_max_size(netdev, 32768);
2476 ixgbe_configure_dcb(adapter);
2477 } else {
2478 netif_set_gso_max_size(netdev, 65536);
2480 #else
2481 netif_set_gso_max_size(netdev, 65536);
2482 #endif
2484 #ifdef IXGBE_FCOE
2485 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2486 ixgbe_configure_fcoe(adapter);
2488 #endif /* IXGBE_FCOE */
2489 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2490 for (i = 0; i < adapter->num_tx_queues; i++)
2491 adapter->tx_ring[i].atr_sample_rate =
2492 adapter->atr_sample_rate;
2493 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2494 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2495 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2498 ixgbe_configure_tx(adapter);
2499 ixgbe_configure_rx(adapter);
2500 for (i = 0; i < adapter->num_rx_queues; i++)
2501 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
2502 (adapter->rx_ring[i].count - 1));
2505 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2507 switch (hw->phy.type) {
2508 case ixgbe_phy_sfp_avago:
2509 case ixgbe_phy_sfp_ftl:
2510 case ixgbe_phy_sfp_intel:
2511 case ixgbe_phy_sfp_unknown:
2512 case ixgbe_phy_tw_tyco:
2513 case ixgbe_phy_tw_unknown:
2514 return true;
2515 default:
2516 return false;
2521 * ixgbe_sfp_link_config - set up SFP+ link
2522 * @adapter: pointer to private adapter struct
2524 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2526 struct ixgbe_hw *hw = &adapter->hw;
2528 if (hw->phy.multispeed_fiber) {
2530 * In multispeed fiber setups, the device may not have
2531 * had a physical connection when the driver loaded.
2532 * If that's the case, the initial link configuration
2533 * couldn't get the MAC into 10G or 1G mode, so we'll
2534 * never have a link status change interrupt fire.
2535 * We need to try and force an autonegotiation
2536 * session, then bring up link.
2538 hw->mac.ops.setup_sfp(hw);
2539 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2540 schedule_work(&adapter->multispeed_fiber_task);
2541 } else {
2543 * Direct Attach Cu and non-multispeed fiber modules
2544 * still need to be configured properly prior to
2545 * attempting link.
2547 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2548 schedule_work(&adapter->sfp_config_module_task);
2553 * ixgbe_non_sfp_link_config - set up non-SFP+ link
2554 * @hw: pointer to private hardware struct
2556 * Returns 0 on success, negative on failure
2558 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
2560 u32 autoneg;
2561 bool negotiation, link_up = false;
2562 u32 ret = IXGBE_ERR_LINK_SETUP;
2564 if (hw->mac.ops.check_link)
2565 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2567 if (ret)
2568 goto link_cfg_out;
2570 if (hw->mac.ops.get_link_capabilities)
2571 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
2572 if (ret)
2573 goto link_cfg_out;
2575 if (hw->mac.ops.setup_link)
2576 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
2577 link_cfg_out:
2578 return ret;
2581 #define IXGBE_MAX_RX_DESC_POLL 10
2582 static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2583 int rxr)
2585 int j = adapter->rx_ring[rxr].reg_idx;
2586 int k;
2588 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2589 if (IXGBE_READ_REG(&adapter->hw,
2590 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2591 break;
2592 else
2593 msleep(1);
2595 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2596 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2597 "not set within the polling period\n", rxr);
2599 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2600 (adapter->rx_ring[rxr].count - 1));
2603 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2605 struct net_device *netdev = adapter->netdev;
2606 struct ixgbe_hw *hw = &adapter->hw;
2607 int i, j = 0;
2608 int num_rx_rings = adapter->num_rx_queues;
2609 int err;
2610 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2611 u32 txdctl, rxdctl, mhadd;
2612 u32 dmatxctl;
2613 u32 gpie;
2615 ixgbe_get_hw_control(adapter);
2617 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2618 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
2619 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2620 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
2621 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
2622 } else {
2623 /* MSI only */
2624 gpie = 0;
2626 /* XXX: to interrupt immediately for EICS writes, enable this */
2627 /* gpie |= IXGBE_GPIE_EIMEN; */
2628 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2631 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2632 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2633 * specifically only auto mask tx and rx interrupts */
2634 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
2637 /* Enable fan failure interrupt if media type is copper */
2638 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2639 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2640 gpie |= IXGBE_SDP1_GPIEN;
2641 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2644 if (hw->mac.type == ixgbe_mac_82599EB) {
2645 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2646 gpie |= IXGBE_SDP1_GPIEN;
2647 gpie |= IXGBE_SDP2_GPIEN;
2648 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2651 #ifdef IXGBE_FCOE
2652 /* adjust max frame to be able to do baby jumbo for FCoE */
2653 if ((netdev->features & NETIF_F_FCOE_MTU) &&
2654 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2655 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2657 #endif /* IXGBE_FCOE */
2658 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2659 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2660 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2661 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2663 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2666 for (i = 0; i < adapter->num_tx_queues; i++) {
2667 j = adapter->tx_ring[i].reg_idx;
2668 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2669 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2670 txdctl |= (8 << 16);
2671 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2674 if (hw->mac.type == ixgbe_mac_82599EB) {
2675 /* DMATXCTL.EN must be set after all Tx queue config is done */
2676 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2677 dmatxctl |= IXGBE_DMATXCTL_TE;
2678 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2680 for (i = 0; i < adapter->num_tx_queues; i++) {
2681 j = adapter->tx_ring[i].reg_idx;
2682 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2683 txdctl |= IXGBE_TXDCTL_ENABLE;
2684 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2687 for (i = 0; i < num_rx_rings; i++) {
2688 j = adapter->rx_ring[i].reg_idx;
2689 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2690 /* enable PTHRESH=32 descriptors (half the internal cache)
2691 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2692 * this also removes a pesky rx_no_buffer_count increment */
2693 rxdctl |= 0x0020;
2694 rxdctl |= IXGBE_RXDCTL_ENABLE;
2695 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
2696 if (hw->mac.type == ixgbe_mac_82599EB)
2697 ixgbe_rx_desc_queue_enable(adapter, i);
2699 /* enable all receives */
2700 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2701 if (hw->mac.type == ixgbe_mac_82598EB)
2702 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2703 else
2704 rxdctl |= IXGBE_RXCTRL_RXEN;
2705 hw->mac.ops.enable_rx_dma(hw, rxdctl);
2707 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2708 ixgbe_configure_msix(adapter);
2709 else
2710 ixgbe_configure_msi_and_legacy(adapter);
2712 clear_bit(__IXGBE_DOWN, &adapter->state);
2713 ixgbe_napi_enable_all(adapter);
2715 /* clear any pending interrupts, may auto mask */
2716 IXGBE_READ_REG(hw, IXGBE_EICR);
2718 ixgbe_irq_enable(adapter);
2721 * If this adapter has a fan, check to see if we had a failure
2722 * before we enabled the interrupt.
2724 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2725 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2726 if (esdp & IXGBE_ESDP_SDP1)
2727 DPRINTK(DRV, CRIT,
2728 "Fan has stopped, replace the adapter\n");
2732 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2733 * arrived before interrupts were enabled but after probe. Such
2734 * devices wouldn't have their type identified yet. We need to
2735 * kick off the SFP+ module setup first, then try to bring up link.
2736 * If we're not hot-pluggable SFP+, we just need to configure link
2737 * and bring it up.
2739 if (hw->phy.type == ixgbe_phy_unknown) {
2740 err = hw->phy.ops.identify(hw);
2741 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2743 * Take the device down and schedule the sfp tasklet
2744 * which will unregister_netdev and log it.
2746 ixgbe_down(adapter);
2747 schedule_work(&adapter->sfp_config_module_task);
2748 return err;
2752 if (ixgbe_is_sfp(hw)) {
2753 ixgbe_sfp_link_config(adapter);
2754 } else {
2755 err = ixgbe_non_sfp_link_config(hw);
2756 if (err)
2757 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2760 for (i = 0; i < adapter->num_tx_queues; i++)
2761 set_bit(__IXGBE_FDIR_INIT_DONE,
2762 &(adapter->tx_ring[i].reinit_state));
2764 /* enable transmits */
2765 netif_tx_start_all_queues(netdev);
2767 /* bring the link up in the watchdog, this could race with our first
2768 * link up interrupt but shouldn't be a problem */
2769 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2770 adapter->link_check_timeout = jiffies;
2771 mod_timer(&adapter->watchdog_timer, jiffies);
2772 return 0;
2775 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2777 WARN_ON(in_interrupt());
2778 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2779 msleep(1);
2780 ixgbe_down(adapter);
2781 ixgbe_up(adapter);
2782 clear_bit(__IXGBE_RESETTING, &adapter->state);
2785 int ixgbe_up(struct ixgbe_adapter *adapter)
2787 /* hardware has been reset, we need to reload some things */
2788 ixgbe_configure(adapter);
2790 return ixgbe_up_complete(adapter);
2793 void ixgbe_reset(struct ixgbe_adapter *adapter)
2795 struct ixgbe_hw *hw = &adapter->hw;
2796 int err;
2798 err = hw->mac.ops.init_hw(hw);
2799 switch (err) {
2800 case 0:
2801 case IXGBE_ERR_SFP_NOT_PRESENT:
2802 break;
2803 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2804 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2805 break;
2806 case IXGBE_ERR_EEPROM_VERSION:
2807 /* We are running on a pre-production device, log a warning */
2808 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2809 "adapter/LOM. Please be aware there may be issues "
2810 "associated with your hardware. If you are "
2811 "experiencing problems please contact your Intel or "
2812 "hardware representative who provided you with this "
2813 "hardware.\n");
2814 break;
2815 default:
2816 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2819 /* reprogram the RAR[0] in case user changed it. */
2820 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2824 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2825 * @adapter: board private structure
2826 * @rx_ring: ring to free buffers from
2828 static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
2829 struct ixgbe_ring *rx_ring)
2831 struct pci_dev *pdev = adapter->pdev;
2832 unsigned long size;
2833 unsigned int i;
2835 /* Free all the Rx ring sk_buffs */
2837 for (i = 0; i < rx_ring->count; i++) {
2838 struct ixgbe_rx_buffer *rx_buffer_info;
2840 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2841 if (rx_buffer_info->dma) {
2842 pci_unmap_single(pdev, rx_buffer_info->dma,
2843 rx_ring->rx_buf_len,
2844 PCI_DMA_FROMDEVICE);
2845 rx_buffer_info->dma = 0;
2847 if (rx_buffer_info->skb) {
2848 struct sk_buff *skb = rx_buffer_info->skb;
2849 rx_buffer_info->skb = NULL;
2850 do {
2851 struct sk_buff *this = skb;
2852 skb = skb->prev;
2853 dev_kfree_skb(this);
2854 } while (skb);
2856 if (!rx_buffer_info->page)
2857 continue;
2858 if (rx_buffer_info->page_dma) {
2859 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2860 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2861 rx_buffer_info->page_dma = 0;
2863 put_page(rx_buffer_info->page);
2864 rx_buffer_info->page = NULL;
2865 rx_buffer_info->page_offset = 0;
2868 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2869 memset(rx_ring->rx_buffer_info, 0, size);
2871 /* Zero out the descriptor ring */
2872 memset(rx_ring->desc, 0, rx_ring->size);
2874 rx_ring->next_to_clean = 0;
2875 rx_ring->next_to_use = 0;
2877 if (rx_ring->head)
2878 writel(0, adapter->hw.hw_addr + rx_ring->head);
2879 if (rx_ring->tail)
2880 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2884 * ixgbe_clean_tx_ring - Free Tx Buffers
2885 * @adapter: board private structure
2886 * @tx_ring: ring to be cleaned
2888 static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
2889 struct ixgbe_ring *tx_ring)
2891 struct ixgbe_tx_buffer *tx_buffer_info;
2892 unsigned long size;
2893 unsigned int i;
2895 /* Free all the Tx ring sk_buffs */
2897 for (i = 0; i < tx_ring->count; i++) {
2898 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2899 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2902 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2903 memset(tx_ring->tx_buffer_info, 0, size);
2905 /* Zero out the descriptor ring */
2906 memset(tx_ring->desc, 0, tx_ring->size);
2908 tx_ring->next_to_use = 0;
2909 tx_ring->next_to_clean = 0;
2911 if (tx_ring->head)
2912 writel(0, adapter->hw.hw_addr + tx_ring->head);
2913 if (tx_ring->tail)
2914 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2918 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2919 * @adapter: board private structure
2921 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2923 int i;
2925 for (i = 0; i < adapter->num_rx_queues; i++)
2926 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2930 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2931 * @adapter: board private structure
2933 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2935 int i;
2937 for (i = 0; i < adapter->num_tx_queues; i++)
2938 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2941 void ixgbe_down(struct ixgbe_adapter *adapter)
2943 struct net_device *netdev = adapter->netdev;
2944 struct ixgbe_hw *hw = &adapter->hw;
2945 u32 rxctrl;
2946 u32 txdctl;
2947 int i, j;
2949 /* signal that we are down to the interrupt handler */
2950 set_bit(__IXGBE_DOWN, &adapter->state);
2952 /* disable receives */
2953 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2954 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2956 netif_tx_disable(netdev);
2958 IXGBE_WRITE_FLUSH(hw);
2959 msleep(10);
2961 netif_tx_stop_all_queues(netdev);
2963 ixgbe_irq_disable(adapter);
2965 ixgbe_napi_disable_all(adapter);
2967 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2968 del_timer_sync(&adapter->sfp_timer);
2969 del_timer_sync(&adapter->watchdog_timer);
2970 cancel_work_sync(&adapter->watchdog_task);
2972 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2973 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2974 cancel_work_sync(&adapter->fdir_reinit_task);
2976 /* disable transmits in the hardware now that interrupts are off */
2977 for (i = 0; i < adapter->num_tx_queues; i++) {
2978 j = adapter->tx_ring[i].reg_idx;
2979 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2980 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2981 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2983 /* Disable the Tx DMA engine on 82599 */
2984 if (hw->mac.type == ixgbe_mac_82599EB)
2985 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2986 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2987 ~IXGBE_DMATXCTL_TE));
2989 netif_carrier_off(netdev);
2991 if (!pci_channel_offline(adapter->pdev))
2992 ixgbe_reset(adapter);
2993 ixgbe_clean_all_tx_rings(adapter);
2994 ixgbe_clean_all_rx_rings(adapter);
2996 #ifdef CONFIG_IXGBE_DCA
2997 /* since we reset the hardware DCA settings were cleared */
2998 ixgbe_setup_dca(adapter);
2999 #endif
3003 * ixgbe_poll - NAPI Rx polling callback
3004 * @napi: structure for representing this polling device
3005 * @budget: how many packets driver is allowed to clean
3007 * This function is used for legacy and MSI, NAPI mode
3009 static int ixgbe_poll(struct napi_struct *napi, int budget)
3011 struct ixgbe_q_vector *q_vector =
3012 container_of(napi, struct ixgbe_q_vector, napi);
3013 struct ixgbe_adapter *adapter = q_vector->adapter;
3014 int tx_clean_complete, work_done = 0;
3016 #ifdef CONFIG_IXGBE_DCA
3017 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3018 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
3019 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
3021 #endif
3023 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
3024 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
3026 if (!tx_clean_complete)
3027 work_done = budget;
3029 /* If budget not fully consumed, exit the polling mode */
3030 if (work_done < budget) {
3031 napi_complete(napi);
3032 if (adapter->rx_itr_setting & 1)
3033 ixgbe_set_itr(adapter);
3034 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3035 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
3037 return work_done;
3041 * ixgbe_tx_timeout - Respond to a Tx Hang
3042 * @netdev: network interface device structure
3044 static void ixgbe_tx_timeout(struct net_device *netdev)
3046 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3048 /* Do the reset outside of interrupt context */
3049 schedule_work(&adapter->reset_task);
3052 static void ixgbe_reset_task(struct work_struct *work)
3054 struct ixgbe_adapter *adapter;
3055 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3057 /* If we're already down or resetting, just bail */
3058 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3059 test_bit(__IXGBE_RESETTING, &adapter->state))
3060 return;
3062 adapter->tx_timeout_count++;
3064 ixgbe_reinit_locked(adapter);
3067 #ifdef CONFIG_IXGBE_DCB
3068 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
3070 bool ret = false;
3071 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
3073 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3074 return ret;
3076 f->mask = 0x7 << 3;
3077 adapter->num_rx_queues = f->indices;
3078 adapter->num_tx_queues = f->indices;
3079 ret = true;
3081 return ret;
3083 #endif
3086 * ixgbe_set_rss_queues: Allocate queues for RSS
3087 * @adapter: board private structure to initialize
3089 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3090 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3093 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3095 bool ret = false;
3096 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
3098 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3099 f->mask = 0xF;
3100 adapter->num_rx_queues = f->indices;
3101 adapter->num_tx_queues = f->indices;
3102 ret = true;
3103 } else {
3104 ret = false;
3107 return ret;
3111 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3112 * @adapter: board private structure to initialize
3114 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3115 * to the original CPU that initiated the Tx session. This runs in addition
3116 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3117 * Rx load across CPUs using RSS.
3120 static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3122 bool ret = false;
3123 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3125 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3126 f_fdir->mask = 0;
3128 /* Flow Director must have RSS enabled */
3129 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3130 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3131 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3132 adapter->num_tx_queues = f_fdir->indices;
3133 adapter->num_rx_queues = f_fdir->indices;
3134 ret = true;
3135 } else {
3136 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3137 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3139 return ret;
3142 #ifdef IXGBE_FCOE
3144 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3145 * @adapter: board private structure to initialize
3147 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3148 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3149 * rx queues out of the max number of rx queues, instead, it is used as the
3150 * index of the first rx queue used by FCoE.
3153 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3155 bool ret = false;
3156 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3158 f->indices = min((int)num_online_cpus(), f->indices);
3159 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3160 adapter->num_rx_queues = 1;
3161 adapter->num_tx_queues = 1;
3162 #ifdef CONFIG_IXGBE_DCB
3163 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3164 DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
3165 ixgbe_set_dcb_queues(adapter);
3167 #endif
3168 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3169 DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
3170 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3171 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3172 ixgbe_set_fdir_queues(adapter);
3173 else
3174 ixgbe_set_rss_queues(adapter);
3176 /* adding FCoE rx rings to the end */
3177 f->mask = adapter->num_rx_queues;
3178 adapter->num_rx_queues += f->indices;
3179 adapter->num_tx_queues += f->indices;
3181 ret = true;
3184 return ret;
3187 #endif /* IXGBE_FCOE */
3189 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3190 * @adapter: board private structure to initialize
3192 * This is the top level queue allocation routine. The order here is very
3193 * important, starting with the "most" number of features turned on at once,
3194 * and ending with the smallest set of features. This way large combinations
3195 * can be allocated if they're turned on, and smaller combinations are the
3196 * fallthrough conditions.
3199 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3201 #ifdef IXGBE_FCOE
3202 if (ixgbe_set_fcoe_queues(adapter))
3203 goto done;
3205 #endif /* IXGBE_FCOE */
3206 #ifdef CONFIG_IXGBE_DCB
3207 if (ixgbe_set_dcb_queues(adapter))
3208 goto done;
3210 #endif
3211 if (ixgbe_set_fdir_queues(adapter))
3212 goto done;
3214 if (ixgbe_set_rss_queues(adapter))
3215 goto done;
3217 /* fallback to base case */
3218 adapter->num_rx_queues = 1;
3219 adapter->num_tx_queues = 1;
3221 done:
3222 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3223 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
3226 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
3227 int vectors)
3229 int err, vector_threshold;
3231 /* We'll want at least 3 (vector_threshold):
3232 * 1) TxQ[0] Cleanup
3233 * 2) RxQ[0] Cleanup
3234 * 3) Other (Link Status Change, etc.)
3235 * 4) TCP Timer (optional)
3237 vector_threshold = MIN_MSIX_COUNT;
3239 /* The more we get, the more we will assign to Tx/Rx Cleanup
3240 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3241 * Right now, we simply care about how many we'll get; we'll
3242 * set them up later while requesting irq's.
3244 while (vectors >= vector_threshold) {
3245 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
3246 vectors);
3247 if (!err) /* Success in acquiring all requested vectors. */
3248 break;
3249 else if (err < 0)
3250 vectors = 0; /* Nasty failure, quit now */
3251 else /* err == number of vectors we should try again with */
3252 vectors = err;
3255 if (vectors < vector_threshold) {
3256 /* Can't allocate enough MSI-X interrupts? Oh well.
3257 * This just means we'll go with either a single MSI
3258 * vector or fall back to legacy interrupts.
3260 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3261 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3262 kfree(adapter->msix_entries);
3263 adapter->msix_entries = NULL;
3264 } else {
3265 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
3267 * Adjust for only the vectors we'll use, which is minimum
3268 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3269 * vectors we were allocated.
3271 adapter->num_msix_vectors = min(vectors,
3272 adapter->max_msix_q_vectors + NON_Q_VECTORS);
3277 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
3278 * @adapter: board private structure to initialize
3280 * Cache the descriptor ring offsets for RSS to the assigned rings.
3283 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
3285 int i;
3286 bool ret = false;
3288 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3289 for (i = 0; i < adapter->num_rx_queues; i++)
3290 adapter->rx_ring[i].reg_idx = i;
3291 for (i = 0; i < adapter->num_tx_queues; i++)
3292 adapter->tx_ring[i].reg_idx = i;
3293 ret = true;
3294 } else {
3295 ret = false;
3298 return ret;
3301 #ifdef CONFIG_IXGBE_DCB
3303 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3304 * @adapter: board private structure to initialize
3306 * Cache the descriptor ring offsets for DCB to the assigned rings.
3309 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3311 int i;
3312 bool ret = false;
3313 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3315 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3316 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
3317 /* the number of queues is assumed to be symmetric */
3318 for (i = 0; i < dcb_i; i++) {
3319 adapter->rx_ring[i].reg_idx = i << 3;
3320 adapter->tx_ring[i].reg_idx = i << 2;
3322 ret = true;
3323 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
3324 if (dcb_i == 8) {
3326 * Tx TC0 starts at: descriptor queue 0
3327 * Tx TC1 starts at: descriptor queue 32
3328 * Tx TC2 starts at: descriptor queue 64
3329 * Tx TC3 starts at: descriptor queue 80
3330 * Tx TC4 starts at: descriptor queue 96
3331 * Tx TC5 starts at: descriptor queue 104
3332 * Tx TC6 starts at: descriptor queue 112
3333 * Tx TC7 starts at: descriptor queue 120
3335 * Rx TC0-TC7 are offset by 16 queues each
3337 for (i = 0; i < 3; i++) {
3338 adapter->tx_ring[i].reg_idx = i << 5;
3339 adapter->rx_ring[i].reg_idx = i << 4;
3341 for ( ; i < 5; i++) {
3342 adapter->tx_ring[i].reg_idx =
3343 ((i + 2) << 4);
3344 adapter->rx_ring[i].reg_idx = i << 4;
3346 for ( ; i < dcb_i; i++) {
3347 adapter->tx_ring[i].reg_idx =
3348 ((i + 8) << 3);
3349 adapter->rx_ring[i].reg_idx = i << 4;
3352 ret = true;
3353 } else if (dcb_i == 4) {
3355 * Tx TC0 starts at: descriptor queue 0
3356 * Tx TC1 starts at: descriptor queue 64
3357 * Tx TC2 starts at: descriptor queue 96
3358 * Tx TC3 starts at: descriptor queue 112
3360 * Rx TC0-TC3 are offset by 32 queues each
3362 adapter->tx_ring[0].reg_idx = 0;
3363 adapter->tx_ring[1].reg_idx = 64;
3364 adapter->tx_ring[2].reg_idx = 96;
3365 adapter->tx_ring[3].reg_idx = 112;
3366 for (i = 0 ; i < dcb_i; i++)
3367 adapter->rx_ring[i].reg_idx = i << 5;
3369 ret = true;
3370 } else {
3371 ret = false;
3373 } else {
3374 ret = false;
3376 } else {
3377 ret = false;
3380 return ret;
3382 #endif
3385 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3386 * @adapter: board private structure to initialize
3388 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3391 static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3393 int i;
3394 bool ret = false;
3396 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3397 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3398 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3399 for (i = 0; i < adapter->num_rx_queues; i++)
3400 adapter->rx_ring[i].reg_idx = i;
3401 for (i = 0; i < adapter->num_tx_queues; i++)
3402 adapter->tx_ring[i].reg_idx = i;
3403 ret = true;
3406 return ret;
3409 #ifdef IXGBE_FCOE
3411 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3412 * @adapter: board private structure to initialize
3414 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3417 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3419 int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
3420 bool ret = false;
3421 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3423 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3424 #ifdef CONFIG_IXGBE_DCB
3425 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3426 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
3428 ixgbe_cache_ring_dcb(adapter);
3429 /* find out queues in TC for FCoE */
3430 fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
3431 fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
3433 * In 82599, the number of Tx queues for each traffic
3434 * class for both 8-TC and 4-TC modes are:
3435 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3436 * 8 TCs: 32 32 16 16 8 8 8 8
3437 * 4 TCs: 64 64 32 32
3438 * We have max 8 queues for FCoE, where 8 the is
3439 * FCoE redirection table size. If TC for FCoE is
3440 * less than or equal to TC3, we have enough queues
3441 * to add max of 8 queues for FCoE, so we start FCoE
3442 * tx descriptor from the next one, i.e., reg_idx + 1.
3443 * If TC for FCoE is above TC3, implying 8 TC mode,
3444 * and we need 8 for FCoE, we have to take all queues
3445 * in that traffic class for FCoE.
3447 if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
3448 fcoe_tx_i--;
3450 #endif /* CONFIG_IXGBE_DCB */
3451 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3452 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3453 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3454 ixgbe_cache_ring_fdir(adapter);
3455 else
3456 ixgbe_cache_ring_rss(adapter);
3458 fcoe_rx_i = f->mask;
3459 fcoe_tx_i = f->mask;
3461 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
3462 adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
3463 adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
3465 ret = true;
3467 return ret;
3470 #endif /* IXGBE_FCOE */
3472 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3473 * @adapter: board private structure to initialize
3475 * Once we know the feature-set enabled for the device, we'll cache
3476 * the register offset the descriptor ring is assigned to.
3478 * Note, the order the various feature calls is important. It must start with
3479 * the "most" features enabled at the same time, then trickle down to the
3480 * least amount of features turned on at once.
3482 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3484 /* start with default case */
3485 adapter->rx_ring[0].reg_idx = 0;
3486 adapter->tx_ring[0].reg_idx = 0;
3488 #ifdef IXGBE_FCOE
3489 if (ixgbe_cache_ring_fcoe(adapter))
3490 return;
3492 #endif /* IXGBE_FCOE */
3493 #ifdef CONFIG_IXGBE_DCB
3494 if (ixgbe_cache_ring_dcb(adapter))
3495 return;
3497 #endif
3498 if (ixgbe_cache_ring_fdir(adapter))
3499 return;
3501 if (ixgbe_cache_ring_rss(adapter))
3502 return;
3506 * ixgbe_alloc_queues - Allocate memory for all rings
3507 * @adapter: board private structure to initialize
3509 * We allocate one ring per queue at run-time since we don't know the
3510 * number of queues at compile-time. The polling_netdev array is
3511 * intended for Multiqueue, but should work fine with a single queue.
3513 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
3515 int i;
3517 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
3518 sizeof(struct ixgbe_ring), GFP_KERNEL);
3519 if (!adapter->tx_ring)
3520 goto err_tx_ring_allocation;
3522 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
3523 sizeof(struct ixgbe_ring), GFP_KERNEL);
3524 if (!adapter->rx_ring)
3525 goto err_rx_ring_allocation;
3527 for (i = 0; i < adapter->num_tx_queues; i++) {
3528 adapter->tx_ring[i].count = adapter->tx_ring_count;
3529 adapter->tx_ring[i].queue_index = i;
3532 for (i = 0; i < adapter->num_rx_queues; i++) {
3533 adapter->rx_ring[i].count = adapter->rx_ring_count;
3534 adapter->rx_ring[i].queue_index = i;
3537 ixgbe_cache_ring_register(adapter);
3539 return 0;
3541 err_rx_ring_allocation:
3542 kfree(adapter->tx_ring);
3543 err_tx_ring_allocation:
3544 return -ENOMEM;
3548 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3549 * @adapter: board private structure to initialize
3551 * Attempt to configure the interrupts using the best available
3552 * capabilities of the hardware and the kernel.
3554 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
3556 struct ixgbe_hw *hw = &adapter->hw;
3557 int err = 0;
3558 int vector, v_budget;
3561 * It's easy to be greedy for MSI-X vectors, but it really
3562 * doesn't do us much good if we have a lot more vectors
3563 * than CPU's. So let's be conservative and only ask for
3564 * (roughly) twice the number of vectors as there are CPU's.
3566 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
3567 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
3570 * At the same time, hardware can only support a maximum of
3571 * hw.mac->max_msix_vectors vectors. With features
3572 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3573 * descriptor queues supported by our device. Thus, we cap it off in
3574 * those rare cases where the cpu count also exceeds our vector limit.
3576 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
3578 /* A failure in MSI-X entry allocation isn't fatal, but it does
3579 * mean we disable MSI-X capabilities of the adapter. */
3580 adapter->msix_entries = kcalloc(v_budget,
3581 sizeof(struct msix_entry), GFP_KERNEL);
3582 if (adapter->msix_entries) {
3583 for (vector = 0; vector < v_budget; vector++)
3584 adapter->msix_entries[vector].entry = vector;
3586 ixgbe_acquire_msix_vectors(adapter, v_budget);
3588 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3589 goto out;
3592 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3593 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
3594 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3595 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3596 adapter->atr_sample_rate = 0;
3597 ixgbe_set_num_queues(adapter);
3599 err = pci_enable_msi(adapter->pdev);
3600 if (!err) {
3601 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3602 } else {
3603 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
3604 "falling back to legacy. Error: %d\n", err);
3605 /* reset err */
3606 err = 0;
3609 out:
3610 return err;
3614 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3615 * @adapter: board private structure to initialize
3617 * We allocate one q_vector per queue interrupt. If allocation fails we
3618 * return -ENOMEM.
3620 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3622 int q_idx, num_q_vectors;
3623 struct ixgbe_q_vector *q_vector;
3624 int napi_vectors;
3625 int (*poll)(struct napi_struct *, int);
3627 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3628 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3629 napi_vectors = adapter->num_rx_queues;
3630 poll = &ixgbe_clean_rxtx_many;
3631 } else {
3632 num_q_vectors = 1;
3633 napi_vectors = 1;
3634 poll = &ixgbe_poll;
3637 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3638 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3639 if (!q_vector)
3640 goto err_out;
3641 q_vector->adapter = adapter;
3642 if (q_vector->txr_count && !q_vector->rxr_count)
3643 q_vector->eitr = adapter->tx_eitr_param;
3644 else
3645 q_vector->eitr = adapter->rx_eitr_param;
3646 q_vector->v_idx = q_idx;
3647 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3648 adapter->q_vector[q_idx] = q_vector;
3651 return 0;
3653 err_out:
3654 while (q_idx) {
3655 q_idx--;
3656 q_vector = adapter->q_vector[q_idx];
3657 netif_napi_del(&q_vector->napi);
3658 kfree(q_vector);
3659 adapter->q_vector[q_idx] = NULL;
3661 return -ENOMEM;
3665 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3666 * @adapter: board private structure to initialize
3668 * This function frees the memory allocated to the q_vectors. In addition if
3669 * NAPI is enabled it will delete any references to the NAPI struct prior
3670 * to freeing the q_vector.
3672 static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3674 int q_idx, num_q_vectors;
3676 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3677 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3678 else
3679 num_q_vectors = 1;
3681 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3682 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
3683 adapter->q_vector[q_idx] = NULL;
3684 netif_napi_del(&q_vector->napi);
3685 kfree(q_vector);
3689 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
3691 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3692 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3693 pci_disable_msix(adapter->pdev);
3694 kfree(adapter->msix_entries);
3695 adapter->msix_entries = NULL;
3696 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3697 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3698 pci_disable_msi(adapter->pdev);
3700 return;
3704 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3705 * @adapter: board private structure to initialize
3707 * We determine which interrupt scheme to use based on...
3708 * - Kernel support (MSI, MSI-X)
3709 * - which can be user-defined (via MODULE_PARAM)
3710 * - Hardware queue count (num_*_queues)
3711 * - defined by miscellaneous hardware support/features (RSS, etc.)
3713 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
3715 int err;
3717 /* Number of supported queues */
3718 ixgbe_set_num_queues(adapter);
3720 err = ixgbe_set_interrupt_capability(adapter);
3721 if (err) {
3722 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3723 goto err_set_interrupt;
3726 err = ixgbe_alloc_q_vectors(adapter);
3727 if (err) {
3728 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3729 "vectors\n");
3730 goto err_alloc_q_vectors;
3733 err = ixgbe_alloc_queues(adapter);
3734 if (err) {
3735 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3736 goto err_alloc_queues;
3739 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
3740 "Tx Queue count = %u\n",
3741 (adapter->num_rx_queues > 1) ? "Enabled" :
3742 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
3744 set_bit(__IXGBE_DOWN, &adapter->state);
3746 return 0;
3748 err_alloc_queues:
3749 ixgbe_free_q_vectors(adapter);
3750 err_alloc_q_vectors:
3751 ixgbe_reset_interrupt_capability(adapter);
3752 err_set_interrupt:
3753 return err;
3757 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3758 * @adapter: board private structure to clear interrupt scheme on
3760 * We go through and clear interrupt specific resources and reset the structure
3761 * to pre-load conditions
3763 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3765 kfree(adapter->tx_ring);
3766 kfree(adapter->rx_ring);
3767 adapter->tx_ring = NULL;
3768 adapter->rx_ring = NULL;
3770 ixgbe_free_q_vectors(adapter);
3771 ixgbe_reset_interrupt_capability(adapter);
3775 * ixgbe_sfp_timer - worker thread to find a missing module
3776 * @data: pointer to our adapter struct
3778 static void ixgbe_sfp_timer(unsigned long data)
3780 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3783 * Do the sfp_timer outside of interrupt context due to the
3784 * delays that sfp+ detection requires
3786 schedule_work(&adapter->sfp_task);
3790 * ixgbe_sfp_task - worker thread to find a missing module
3791 * @work: pointer to work_struct containing our data
3793 static void ixgbe_sfp_task(struct work_struct *work)
3795 struct ixgbe_adapter *adapter = container_of(work,
3796 struct ixgbe_adapter,
3797 sfp_task);
3798 struct ixgbe_hw *hw = &adapter->hw;
3800 if ((hw->phy.type == ixgbe_phy_nl) &&
3801 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3802 s32 ret = hw->phy.ops.identify_sfp(hw);
3803 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
3804 goto reschedule;
3805 ret = hw->phy.ops.reset(hw);
3806 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3807 dev_err(&adapter->pdev->dev, "failed to initialize "
3808 "because an unsupported SFP+ module type "
3809 "was detected.\n"
3810 "Reload the driver after installing a "
3811 "supported module.\n");
3812 unregister_netdev(adapter->netdev);
3813 } else {
3814 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3815 hw->phy.sfp_type);
3817 /* don't need this routine any more */
3818 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3820 return;
3821 reschedule:
3822 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3823 mod_timer(&adapter->sfp_timer,
3824 round_jiffies(jiffies + (2 * HZ)));
3828 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3829 * @adapter: board private structure to initialize
3831 * ixgbe_sw_init initializes the Adapter private data structure.
3832 * Fields are initialized based on PCI device information and
3833 * OS network device settings (MTU size).
3835 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3837 struct ixgbe_hw *hw = &adapter->hw;
3838 struct pci_dev *pdev = adapter->pdev;
3839 unsigned int rss;
3840 #ifdef CONFIG_IXGBE_DCB
3841 int j;
3842 struct tc_configuration *tc;
3843 #endif
3845 /* PCI config space info */
3847 hw->vendor_id = pdev->vendor;
3848 hw->device_id = pdev->device;
3849 hw->revision_id = pdev->revision;
3850 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3851 hw->subsystem_device_id = pdev->subsystem_device;
3853 /* Set capability flags */
3854 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3855 adapter->ring_feature[RING_F_RSS].indices = rss;
3856 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
3857 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
3858 if (hw->mac.type == ixgbe_mac_82598EB) {
3859 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3860 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
3861 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
3862 } else if (hw->mac.type == ixgbe_mac_82599EB) {
3863 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
3864 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
3865 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
3866 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3867 adapter->ring_feature[RING_F_FDIR].indices =
3868 IXGBE_MAX_FDIR_INDICES;
3869 adapter->atr_sample_rate = 20;
3870 adapter->fdir_pballoc = 0;
3871 #ifdef IXGBE_FCOE
3872 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3873 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3874 adapter->ring_feature[RING_F_FCOE].indices = 0;
3875 /* Default traffic class to use for FCoE */
3876 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
3877 #endif /* IXGBE_FCOE */
3880 #ifdef CONFIG_IXGBE_DCB
3881 /* Configure DCB traffic classes */
3882 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3883 tc = &adapter->dcb_cfg.tc_config[j];
3884 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3885 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3886 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3887 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3888 tc->dcb_pfc = pfc_disabled;
3890 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3891 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3892 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
3893 adapter->dcb_cfg.pfc_mode_enable = false;
3894 adapter->dcb_cfg.round_robin_enable = false;
3895 adapter->dcb_set_bitmap = 0x00;
3896 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3897 adapter->ring_feature[RING_F_DCB].indices);
3899 #endif
3901 /* default flow control settings */
3902 hw->fc.requested_mode = ixgbe_fc_full;
3903 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
3904 #ifdef CONFIG_DCB
3905 adapter->last_lfc_mode = hw->fc.current_mode;
3906 #endif
3907 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3908 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3909 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3910 hw->fc.send_xon = true;
3911 hw->fc.disable_fc_autoneg = false;
3913 /* enable itr by default in dynamic mode */
3914 adapter->rx_itr_setting = 1;
3915 adapter->rx_eitr_param = 20000;
3916 adapter->tx_itr_setting = 1;
3917 adapter->tx_eitr_param = 10000;
3919 /* set defaults for eitr in MegaBytes */
3920 adapter->eitr_low = 10;
3921 adapter->eitr_high = 20;
3923 /* set default ring sizes */
3924 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3925 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3927 /* initialize eeprom parameters */
3928 if (ixgbe_init_eeprom_params_generic(hw)) {
3929 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3930 return -EIO;
3933 /* enable rx csum by default */
3934 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3936 set_bit(__IXGBE_DOWN, &adapter->state);
3938 return 0;
3942 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3943 * @adapter: board private structure
3944 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3946 * Return 0 on success, negative on failure
3948 int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
3949 struct ixgbe_ring *tx_ring)
3951 struct pci_dev *pdev = adapter->pdev;
3952 int size;
3954 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3955 tx_ring->tx_buffer_info = vmalloc(size);
3956 if (!tx_ring->tx_buffer_info)
3957 goto err;
3958 memset(tx_ring->tx_buffer_info, 0, size);
3960 /* round up to nearest 4K */
3961 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
3962 tx_ring->size = ALIGN(tx_ring->size, 4096);
3964 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3965 &tx_ring->dma);
3966 if (!tx_ring->desc)
3967 goto err;
3969 tx_ring->next_to_use = 0;
3970 tx_ring->next_to_clean = 0;
3971 tx_ring->work_limit = tx_ring->count;
3972 return 0;
3974 err:
3975 vfree(tx_ring->tx_buffer_info);
3976 tx_ring->tx_buffer_info = NULL;
3977 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3978 "descriptor ring\n");
3979 return -ENOMEM;
3983 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3984 * @adapter: board private structure
3986 * If this function returns with an error, then it's possible one or
3987 * more of the rings is populated (while the rest are not). It is the
3988 * callers duty to clean those orphaned rings.
3990 * Return 0 on success, negative on failure
3992 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3994 int i, err = 0;
3996 for (i = 0; i < adapter->num_tx_queues; i++) {
3997 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3998 if (!err)
3999 continue;
4000 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
4001 break;
4004 return err;
4008 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4009 * @adapter: board private structure
4010 * @rx_ring: rx descriptor ring (for a specific queue) to setup
4012 * Returns 0 on success, negative on failure
4014 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
4015 struct ixgbe_ring *rx_ring)
4017 struct pci_dev *pdev = adapter->pdev;
4018 int size;
4020 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4021 rx_ring->rx_buffer_info = vmalloc(size);
4022 if (!rx_ring->rx_buffer_info) {
4023 DPRINTK(PROBE, ERR,
4024 "vmalloc allocation failed for the rx desc ring\n");
4025 goto alloc_failed;
4027 memset(rx_ring->rx_buffer_info, 0, size);
4029 /* Round up to nearest 4K */
4030 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4031 rx_ring->size = ALIGN(rx_ring->size, 4096);
4033 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
4035 if (!rx_ring->desc) {
4036 DPRINTK(PROBE, ERR,
4037 "Memory allocation failed for the rx desc ring\n");
4038 vfree(rx_ring->rx_buffer_info);
4039 goto alloc_failed;
4042 rx_ring->next_to_clean = 0;
4043 rx_ring->next_to_use = 0;
4045 return 0;
4047 alloc_failed:
4048 return -ENOMEM;
4052 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4053 * @adapter: board private structure
4055 * If this function returns with an error, then it's possible one or
4056 * more of the rings is populated (while the rest are not). It is the
4057 * callers duty to clean those orphaned rings.
4059 * Return 0 on success, negative on failure
4062 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4064 int i, err = 0;
4066 for (i = 0; i < adapter->num_rx_queues; i++) {
4067 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4068 if (!err)
4069 continue;
4070 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4071 break;
4074 return err;
4078 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4079 * @adapter: board private structure
4080 * @tx_ring: Tx descriptor ring for a specific queue
4082 * Free all transmit software resources
4084 void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4085 struct ixgbe_ring *tx_ring)
4087 struct pci_dev *pdev = adapter->pdev;
4089 ixgbe_clean_tx_ring(adapter, tx_ring);
4091 vfree(tx_ring->tx_buffer_info);
4092 tx_ring->tx_buffer_info = NULL;
4094 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4096 tx_ring->desc = NULL;
4100 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4101 * @adapter: board private structure
4103 * Free all transmit software resources
4105 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4107 int i;
4109 for (i = 0; i < adapter->num_tx_queues; i++)
4110 if (adapter->tx_ring[i].desc)
4111 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
4115 * ixgbe_free_rx_resources - Free Rx Resources
4116 * @adapter: board private structure
4117 * @rx_ring: ring to clean the resources from
4119 * Free all receive software resources
4121 void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4122 struct ixgbe_ring *rx_ring)
4124 struct pci_dev *pdev = adapter->pdev;
4126 ixgbe_clean_rx_ring(adapter, rx_ring);
4128 vfree(rx_ring->rx_buffer_info);
4129 rx_ring->rx_buffer_info = NULL;
4131 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4133 rx_ring->desc = NULL;
4137 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4138 * @adapter: board private structure
4140 * Free all receive software resources
4142 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4144 int i;
4146 for (i = 0; i < adapter->num_rx_queues; i++)
4147 if (adapter->rx_ring[i].desc)
4148 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
4152 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4153 * @netdev: network interface device structure
4154 * @new_mtu: new value for maximum frame size
4156 * Returns 0 on success, negative on failure
4158 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4160 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4161 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4163 /* MTU < 68 is an error and causes problems on some kernels */
4164 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4165 return -EINVAL;
4167 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
4168 netdev->mtu, new_mtu);
4169 /* must set new MTU before calling down or up */
4170 netdev->mtu = new_mtu;
4172 if (netif_running(netdev))
4173 ixgbe_reinit_locked(adapter);
4175 return 0;
4179 * ixgbe_open - Called when a network interface is made active
4180 * @netdev: network interface device structure
4182 * Returns 0 on success, negative value on failure
4184 * The open entry point is called when a network interface is made
4185 * active by the system (IFF_UP). At this point all resources needed
4186 * for transmit and receive operations are allocated, the interrupt
4187 * handler is registered with the OS, the watchdog timer is started,
4188 * and the stack is notified that the interface is ready.
4190 static int ixgbe_open(struct net_device *netdev)
4192 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4193 int err;
4195 /* disallow open during test */
4196 if (test_bit(__IXGBE_TESTING, &adapter->state))
4197 return -EBUSY;
4199 netif_carrier_off(netdev);
4201 /* allocate transmit descriptors */
4202 err = ixgbe_setup_all_tx_resources(adapter);
4203 if (err)
4204 goto err_setup_tx;
4206 /* allocate receive descriptors */
4207 err = ixgbe_setup_all_rx_resources(adapter);
4208 if (err)
4209 goto err_setup_rx;
4211 ixgbe_configure(adapter);
4213 err = ixgbe_request_irq(adapter);
4214 if (err)
4215 goto err_req_irq;
4217 err = ixgbe_up_complete(adapter);
4218 if (err)
4219 goto err_up;
4221 netif_tx_start_all_queues(netdev);
4223 return 0;
4225 err_up:
4226 ixgbe_release_hw_control(adapter);
4227 ixgbe_free_irq(adapter);
4228 err_req_irq:
4229 err_setup_rx:
4230 ixgbe_free_all_rx_resources(adapter);
4231 err_setup_tx:
4232 ixgbe_free_all_tx_resources(adapter);
4233 ixgbe_reset(adapter);
4235 return err;
4239 * ixgbe_close - Disables a network interface
4240 * @netdev: network interface device structure
4242 * Returns 0, this is not allowed to fail
4244 * The close entry point is called when an interface is de-activated
4245 * by the OS. The hardware is still under the drivers control, but
4246 * needs to be disabled. A global MAC reset is issued to stop the
4247 * hardware, and all transmit and receive resources are freed.
4249 static int ixgbe_close(struct net_device *netdev)
4251 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4253 ixgbe_down(adapter);
4254 ixgbe_free_irq(adapter);
4256 ixgbe_free_all_tx_resources(adapter);
4257 ixgbe_free_all_rx_resources(adapter);
4259 ixgbe_release_hw_control(adapter);
4261 return 0;
4264 #ifdef CONFIG_PM
4265 static int ixgbe_resume(struct pci_dev *pdev)
4267 struct net_device *netdev = pci_get_drvdata(pdev);
4268 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4269 u32 err;
4271 pci_set_power_state(pdev, PCI_D0);
4272 pci_restore_state(pdev);
4274 err = pci_enable_device_mem(pdev);
4275 if (err) {
4276 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
4277 "suspend\n");
4278 return err;
4280 pci_set_master(pdev);
4282 pci_wake_from_d3(pdev, false);
4284 err = ixgbe_init_interrupt_scheme(adapter);
4285 if (err) {
4286 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4287 "device\n");
4288 return err;
4291 ixgbe_reset(adapter);
4293 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4295 if (netif_running(netdev)) {
4296 err = ixgbe_open(adapter->netdev);
4297 if (err)
4298 return err;
4301 netif_device_attach(netdev);
4303 return 0;
4305 #endif /* CONFIG_PM */
4307 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
4309 struct net_device *netdev = pci_get_drvdata(pdev);
4310 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4311 struct ixgbe_hw *hw = &adapter->hw;
4312 u32 ctrl, fctrl;
4313 u32 wufc = adapter->wol;
4314 #ifdef CONFIG_PM
4315 int retval = 0;
4316 #endif
4318 netif_device_detach(netdev);
4320 if (netif_running(netdev)) {
4321 ixgbe_down(adapter);
4322 ixgbe_free_irq(adapter);
4323 ixgbe_free_all_tx_resources(adapter);
4324 ixgbe_free_all_rx_resources(adapter);
4326 ixgbe_clear_interrupt_scheme(adapter);
4328 #ifdef CONFIG_PM
4329 retval = pci_save_state(pdev);
4330 if (retval)
4331 return retval;
4333 #endif
4334 if (wufc) {
4335 ixgbe_set_rx_mode(netdev);
4337 /* turn on all-multi mode if wake on multicast is enabled */
4338 if (wufc & IXGBE_WUFC_MC) {
4339 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4340 fctrl |= IXGBE_FCTRL_MPE;
4341 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4344 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4345 ctrl |= IXGBE_CTRL_GIO_DIS;
4346 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4348 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4349 } else {
4350 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4351 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4354 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4355 pci_wake_from_d3(pdev, true);
4356 else
4357 pci_wake_from_d3(pdev, false);
4359 *enable_wake = !!wufc;
4361 ixgbe_release_hw_control(adapter);
4363 pci_disable_device(pdev);
4365 return 0;
4368 #ifdef CONFIG_PM
4369 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4371 int retval;
4372 bool wake;
4374 retval = __ixgbe_shutdown(pdev, &wake);
4375 if (retval)
4376 return retval;
4378 if (wake) {
4379 pci_prepare_to_sleep(pdev);
4380 } else {
4381 pci_wake_from_d3(pdev, false);
4382 pci_set_power_state(pdev, PCI_D3hot);
4385 return 0;
4387 #endif /* CONFIG_PM */
4389 static void ixgbe_shutdown(struct pci_dev *pdev)
4391 bool wake;
4393 __ixgbe_shutdown(pdev, &wake);
4395 if (system_state == SYSTEM_POWER_OFF) {
4396 pci_wake_from_d3(pdev, wake);
4397 pci_set_power_state(pdev, PCI_D3hot);
4402 * ixgbe_update_stats - Update the board statistics counters.
4403 * @adapter: board private structure
4405 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4407 struct net_device *netdev = adapter->netdev;
4408 struct ixgbe_hw *hw = &adapter->hw;
4409 u64 total_mpc = 0;
4410 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
4412 if (hw->mac.type == ixgbe_mac_82599EB) {
4413 u64 rsc_count = 0;
4414 for (i = 0; i < 16; i++)
4415 adapter->hw_rx_no_dma_resources +=
4416 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
4417 for (i = 0; i < adapter->num_rx_queues; i++)
4418 rsc_count += adapter->rx_ring[i].rsc_count;
4419 adapter->rsc_count = rsc_count;
4422 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
4423 for (i = 0; i < 8; i++) {
4424 /* for packet buffers not used, the register should read 0 */
4425 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4426 missed_rx += mpc;
4427 adapter->stats.mpc[i] += mpc;
4428 total_mpc += adapter->stats.mpc[i];
4429 if (hw->mac.type == ixgbe_mac_82598EB)
4430 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
4431 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4432 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4433 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4434 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
4435 if (hw->mac.type == ixgbe_mac_82599EB) {
4436 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4437 IXGBE_PXONRXCNT(i));
4438 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4439 IXGBE_PXOFFRXCNT(i));
4440 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
4441 } else {
4442 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4443 IXGBE_PXONRXC(i));
4444 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4445 IXGBE_PXOFFRXC(i));
4447 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4448 IXGBE_PXONTXC(i));
4449 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
4450 IXGBE_PXOFFTXC(i));
4452 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4453 /* work around hardware counting issue */
4454 adapter->stats.gprc -= missed_rx;
4456 /* 82598 hardware only has a 32 bit counter in the high register */
4457 if (hw->mac.type == ixgbe_mac_82599EB) {
4458 u64 tmp;
4459 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4460 tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
4461 adapter->stats.gorc += (tmp << 32);
4462 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4463 tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
4464 adapter->stats.gotc += (tmp << 32);
4465 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4466 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4467 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4468 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
4469 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4470 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
4471 #ifdef IXGBE_FCOE
4472 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4473 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4474 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4475 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4476 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4477 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4478 #endif /* IXGBE_FCOE */
4479 } else {
4480 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4481 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4482 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4483 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4484 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4486 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4487 adapter->stats.bprc += bprc;
4488 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
4489 if (hw->mac.type == ixgbe_mac_82598EB)
4490 adapter->stats.mprc -= bprc;
4491 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4492 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4493 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4494 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4495 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4496 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4497 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
4498 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
4499 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4500 adapter->stats.lxontxc += lxon;
4501 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4502 adapter->stats.lxofftxc += lxoff;
4503 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4504 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
4505 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4507 * 82598 errata - tx of flow control packets is included in tx counters
4509 xon_off_tot = lxon + lxoff;
4510 adapter->stats.gptc -= xon_off_tot;
4511 adapter->stats.mptc -= xon_off_tot;
4512 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
4513 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4514 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4515 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
4516 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4517 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
4518 adapter->stats.ptc64 -= xon_off_tot;
4519 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4520 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4521 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4522 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4523 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
4524 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4526 /* Fill out the OS statistics structure */
4527 netdev->stats.multicast = adapter->stats.mprc;
4529 /* Rx Errors */
4530 netdev->stats.rx_errors = adapter->stats.crcerrs +
4531 adapter->stats.rlec;
4532 netdev->stats.rx_dropped = 0;
4533 netdev->stats.rx_length_errors = adapter->stats.rlec;
4534 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4535 netdev->stats.rx_missed_errors = total_mpc;
4539 * ixgbe_watchdog - Timer Call-back
4540 * @data: pointer to adapter cast into an unsigned long
4542 static void ixgbe_watchdog(unsigned long data)
4544 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
4545 struct ixgbe_hw *hw = &adapter->hw;
4546 u64 eics = 0;
4547 int i;
4550 * Do the watchdog outside of interrupt context due to the lovely
4551 * delays that some of the newer hardware requires
4554 if (test_bit(__IXGBE_DOWN, &adapter->state))
4555 goto watchdog_short_circuit;
4557 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4559 * for legacy and MSI interrupts don't set any bits
4560 * that are enabled for EIAM, because this operation
4561 * would set *both* EIMS and EICS for any bit in EIAM
4563 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4564 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4565 goto watchdog_reschedule;
4568 /* get one bit for every active tx/rx interrupt vector */
4569 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4570 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4571 if (qv->rxr_count || qv->txr_count)
4572 eics |= ((u64)1 << i);
4575 /* Cause software interrupt to ensure rx rings are cleaned */
4576 ixgbe_irq_rearm_queues(adapter, eics);
4578 watchdog_reschedule:
4579 /* Reset the timer */
4580 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4582 watchdog_short_circuit:
4583 schedule_work(&adapter->watchdog_task);
4587 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4588 * @work: pointer to work_struct containing our data
4590 static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4592 struct ixgbe_adapter *adapter = container_of(work,
4593 struct ixgbe_adapter,
4594 multispeed_fiber_task);
4595 struct ixgbe_hw *hw = &adapter->hw;
4596 u32 autoneg;
4597 bool negotiation;
4599 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
4600 autoneg = hw->phy.autoneg_advertised;
4601 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
4602 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
4603 if (hw->mac.ops.setup_link)
4604 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
4605 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4606 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4610 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4611 * @work: pointer to work_struct containing our data
4613 static void ixgbe_sfp_config_module_task(struct work_struct *work)
4615 struct ixgbe_adapter *adapter = container_of(work,
4616 struct ixgbe_adapter,
4617 sfp_config_module_task);
4618 struct ixgbe_hw *hw = &adapter->hw;
4619 u32 err;
4621 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
4623 /* Time for electrical oscillations to settle down */
4624 msleep(100);
4625 err = hw->phy.ops.identify_sfp(hw);
4627 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4628 dev_err(&adapter->pdev->dev, "failed to initialize because "
4629 "an unsupported SFP+ module type was detected.\n"
4630 "Reload the driver after installing a supported "
4631 "module.\n");
4632 unregister_netdev(adapter->netdev);
4633 return;
4635 hw->mac.ops.setup_sfp(hw);
4637 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
4638 /* This will also work for DA Twinax connections */
4639 schedule_work(&adapter->multispeed_fiber_task);
4640 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4644 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4645 * @work: pointer to work_struct containing our data
4647 static void ixgbe_fdir_reinit_task(struct work_struct *work)
4649 struct ixgbe_adapter *adapter = container_of(work,
4650 struct ixgbe_adapter,
4651 fdir_reinit_task);
4652 struct ixgbe_hw *hw = &adapter->hw;
4653 int i;
4655 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4656 for (i = 0; i < adapter->num_tx_queues; i++)
4657 set_bit(__IXGBE_FDIR_INIT_DONE,
4658 &(adapter->tx_ring[i].reinit_state));
4659 } else {
4660 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4661 "ignored adding FDIR ATR filters \n");
4663 /* Done FDIR Re-initialization, enable transmits */
4664 netif_tx_start_all_queues(adapter->netdev);
4668 * ixgbe_watchdog_task - worker thread to bring link up
4669 * @work: pointer to work_struct containing our data
4671 static void ixgbe_watchdog_task(struct work_struct *work)
4673 struct ixgbe_adapter *adapter = container_of(work,
4674 struct ixgbe_adapter,
4675 watchdog_task);
4676 struct net_device *netdev = adapter->netdev;
4677 struct ixgbe_hw *hw = &adapter->hw;
4678 u32 link_speed = adapter->link_speed;
4679 bool link_up = adapter->link_up;
4680 int i;
4681 struct ixgbe_ring *tx_ring;
4682 int some_tx_pending = 0;
4684 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4686 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4687 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
4688 if (link_up) {
4689 #ifdef CONFIG_DCB
4690 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4691 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
4692 hw->mac.ops.fc_enable(hw, i);
4693 } else {
4694 hw->mac.ops.fc_enable(hw, 0);
4696 #else
4697 hw->mac.ops.fc_enable(hw, 0);
4698 #endif
4701 if (link_up ||
4702 time_after(jiffies, (adapter->link_check_timeout +
4703 IXGBE_TRY_LINK_TIMEOUT))) {
4704 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4705 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
4707 adapter->link_up = link_up;
4708 adapter->link_speed = link_speed;
4711 if (link_up) {
4712 if (!netif_carrier_ok(netdev)) {
4713 bool flow_rx, flow_tx;
4715 if (hw->mac.type == ixgbe_mac_82599EB) {
4716 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4717 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4718 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
4719 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
4720 } else {
4721 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4722 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4723 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
4724 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
4727 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4728 "Flow Control: %s\n",
4729 netdev->name,
4730 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4731 "10 Gbps" :
4732 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4733 "1 Gbps" : "unknown speed")),
4734 ((flow_rx && flow_tx) ? "RX/TX" :
4735 (flow_rx ? "RX" :
4736 (flow_tx ? "TX" : "None"))));
4738 netif_carrier_on(netdev);
4739 } else {
4740 /* Force detection of hung controller */
4741 adapter->detect_tx_hung = true;
4743 } else {
4744 adapter->link_up = false;
4745 adapter->link_speed = 0;
4746 if (netif_carrier_ok(netdev)) {
4747 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4748 netdev->name);
4749 netif_carrier_off(netdev);
4753 if (!netif_carrier_ok(netdev)) {
4754 for (i = 0; i < adapter->num_tx_queues; i++) {
4755 tx_ring = &adapter->tx_ring[i];
4756 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4757 some_tx_pending = 1;
4758 break;
4762 if (some_tx_pending) {
4763 /* We've lost link, so the controller stops DMA,
4764 * but we've got queued Tx work that's never going
4765 * to get done, so reset controller to flush Tx.
4766 * (Do the reset outside of interrupt context).
4768 schedule_work(&adapter->reset_task);
4772 ixgbe_update_stats(adapter);
4773 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
4776 static int ixgbe_tso(struct ixgbe_adapter *adapter,
4777 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4778 u32 tx_flags, u8 *hdr_len)
4780 struct ixgbe_adv_tx_context_desc *context_desc;
4781 unsigned int i;
4782 int err;
4783 struct ixgbe_tx_buffer *tx_buffer_info;
4784 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4785 u32 mss_l4len_idx, l4len;
4787 if (skb_is_gso(skb)) {
4788 if (skb_header_cloned(skb)) {
4789 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4790 if (err)
4791 return err;
4793 l4len = tcp_hdrlen(skb);
4794 *hdr_len += l4len;
4796 if (skb->protocol == htons(ETH_P_IP)) {
4797 struct iphdr *iph = ip_hdr(skb);
4798 iph->tot_len = 0;
4799 iph->check = 0;
4800 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
4801 iph->daddr, 0,
4802 IPPROTO_TCP,
4804 adapter->hw_tso_ctxt++;
4805 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4806 ipv6_hdr(skb)->payload_len = 0;
4807 tcp_hdr(skb)->check =
4808 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4809 &ipv6_hdr(skb)->daddr,
4810 0, IPPROTO_TCP, 0);
4811 adapter->hw_tso6_ctxt++;
4814 i = tx_ring->next_to_use;
4816 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4817 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4819 /* VLAN MACLEN IPLEN */
4820 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4821 vlan_macip_lens |=
4822 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4823 vlan_macip_lens |= ((skb_network_offset(skb)) <<
4824 IXGBE_ADVTXD_MACLEN_SHIFT);
4825 *hdr_len += skb_network_offset(skb);
4826 vlan_macip_lens |=
4827 (skb_transport_header(skb) - skb_network_header(skb));
4828 *hdr_len +=
4829 (skb_transport_header(skb) - skb_network_header(skb));
4830 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4831 context_desc->seqnum_seed = 0;
4833 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
4834 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
4835 IXGBE_ADVTXD_DTYP_CTXT);
4837 if (skb->protocol == htons(ETH_P_IP))
4838 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4839 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4840 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4842 /* MSS L4LEN IDX */
4843 mss_l4len_idx =
4844 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4845 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
4846 /* use index 1 for TSO */
4847 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4848 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4850 tx_buffer_info->time_stamp = jiffies;
4851 tx_buffer_info->next_to_watch = i;
4853 i++;
4854 if (i == tx_ring->count)
4855 i = 0;
4856 tx_ring->next_to_use = i;
4858 return true;
4860 return false;
4863 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
4864 struct ixgbe_ring *tx_ring,
4865 struct sk_buff *skb, u32 tx_flags)
4867 struct ixgbe_adv_tx_context_desc *context_desc;
4868 unsigned int i;
4869 struct ixgbe_tx_buffer *tx_buffer_info;
4870 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4872 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4873 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4874 i = tx_ring->next_to_use;
4875 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4876 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4878 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4879 vlan_macip_lens |=
4880 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4881 vlan_macip_lens |= (skb_network_offset(skb) <<
4882 IXGBE_ADVTXD_MACLEN_SHIFT);
4883 if (skb->ip_summed == CHECKSUM_PARTIAL)
4884 vlan_macip_lens |= (skb_transport_header(skb) -
4885 skb_network_header(skb));
4887 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4888 context_desc->seqnum_seed = 0;
4890 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
4891 IXGBE_ADVTXD_DTYP_CTXT);
4893 if (skb->ip_summed == CHECKSUM_PARTIAL) {
4894 switch (skb->protocol) {
4895 case cpu_to_be16(ETH_P_IP):
4896 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4897 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4898 type_tucmd_mlhl |=
4899 IXGBE_ADVTXD_TUCMD_L4T_TCP;
4900 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4901 type_tucmd_mlhl |=
4902 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
4903 break;
4904 case cpu_to_be16(ETH_P_IPV6):
4905 /* XXX what about other V6 headers?? */
4906 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4907 type_tucmd_mlhl |=
4908 IXGBE_ADVTXD_TUCMD_L4T_TCP;
4909 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4910 type_tucmd_mlhl |=
4911 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
4912 break;
4913 default:
4914 if (unlikely(net_ratelimit())) {
4915 DPRINTK(PROBE, WARNING,
4916 "partial checksum but proto=%x!\n",
4917 skb->protocol);
4919 break;
4923 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4924 /* use index zero for tx checksum offload */
4925 context_desc->mss_l4len_idx = 0;
4927 tx_buffer_info->time_stamp = jiffies;
4928 tx_buffer_info->next_to_watch = i;
4930 adapter->hw_csum_tx_good++;
4931 i++;
4932 if (i == tx_ring->count)
4933 i = 0;
4934 tx_ring->next_to_use = i;
4936 return true;
4939 return false;
4942 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
4943 struct ixgbe_ring *tx_ring,
4944 struct sk_buff *skb, u32 tx_flags,
4945 unsigned int first)
4947 struct ixgbe_tx_buffer *tx_buffer_info;
4948 unsigned int len;
4949 unsigned int total = skb->len;
4950 unsigned int offset = 0, size, count = 0, i;
4951 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4952 unsigned int f;
4953 dma_addr_t *map;
4955 i = tx_ring->next_to_use;
4957 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4958 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4959 return 0;
4962 map = skb_shinfo(skb)->dma_maps;
4964 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4965 /* excluding fcoe_crc_eof for FCoE */
4966 total -= sizeof(struct fcoe_crc_eof);
4968 len = min(skb_headlen(skb), total);
4969 while (len) {
4970 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4971 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4973 tx_buffer_info->length = size;
4974 tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
4975 tx_buffer_info->time_stamp = jiffies;
4976 tx_buffer_info->next_to_watch = i;
4978 len -= size;
4979 total -= size;
4980 offset += size;
4981 count++;
4983 if (len) {
4984 i++;
4985 if (i == tx_ring->count)
4986 i = 0;
4990 for (f = 0; f < nr_frags; f++) {
4991 struct skb_frag_struct *frag;
4993 frag = &skb_shinfo(skb)->frags[f];
4994 len = min((unsigned int)frag->size, total);
4995 offset = 0;
4997 while (len) {
4998 i++;
4999 if (i == tx_ring->count)
5000 i = 0;
5002 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5003 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5005 tx_buffer_info->length = size;
5006 tx_buffer_info->dma = map[f] + offset;
5007 tx_buffer_info->time_stamp = jiffies;
5008 tx_buffer_info->next_to_watch = i;
5010 len -= size;
5011 total -= size;
5012 offset += size;
5013 count++;
5015 if (total == 0)
5016 break;
5019 tx_ring->tx_buffer_info[i].skb = skb;
5020 tx_ring->tx_buffer_info[first].next_to_watch = i;
5022 return count;
5025 static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
5026 struct ixgbe_ring *tx_ring,
5027 int tx_flags, int count, u32 paylen, u8 hdr_len)
5029 union ixgbe_adv_tx_desc *tx_desc = NULL;
5030 struct ixgbe_tx_buffer *tx_buffer_info;
5031 u32 olinfo_status = 0, cmd_type_len = 0;
5032 unsigned int i;
5033 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
5035 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
5037 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
5039 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
5040 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
5042 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
5043 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5045 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
5046 IXGBE_ADVTXD_POPTS_SHIFT;
5048 /* use index 1 context for tso */
5049 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5050 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5051 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
5052 IXGBE_ADVTXD_POPTS_SHIFT;
5054 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5055 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
5056 IXGBE_ADVTXD_POPTS_SHIFT;
5058 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5059 olinfo_status |= IXGBE_ADVTXD_CC;
5060 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5061 if (tx_flags & IXGBE_TX_FLAGS_FSO)
5062 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5065 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
5067 i = tx_ring->next_to_use;
5068 while (count--) {
5069 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5070 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5071 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5072 tx_desc->read.cmd_type_len =
5073 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
5074 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5075 i++;
5076 if (i == tx_ring->count)
5077 i = 0;
5080 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5083 * Force memory writes to complete before letting h/w
5084 * know there are new descriptors to fetch. (Only
5085 * applicable for weak-ordered memory model archs,
5086 * such as IA-64).
5088 wmb();
5090 tx_ring->next_to_use = i;
5091 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5094 static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5095 int queue, u32 tx_flags)
5097 /* Right now, we support IPv4 only */
5098 struct ixgbe_atr_input atr_input;
5099 struct tcphdr *th;
5100 struct iphdr *iph = ip_hdr(skb);
5101 struct ethhdr *eth = (struct ethhdr *)skb->data;
5102 u16 vlan_id, src_port, dst_port, flex_bytes;
5103 u32 src_ipv4_addr, dst_ipv4_addr;
5104 u8 l4type = 0;
5106 /* check if we're UDP or TCP */
5107 if (iph->protocol == IPPROTO_TCP) {
5108 th = tcp_hdr(skb);
5109 src_port = th->source;
5110 dst_port = th->dest;
5111 l4type |= IXGBE_ATR_L4TYPE_TCP;
5112 /* l4type IPv4 type is 0, no need to assign */
5113 } else {
5114 /* Unsupported L4 header, just bail here */
5115 return;
5118 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5120 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5121 IXGBE_TX_FLAGS_VLAN_SHIFT;
5122 src_ipv4_addr = iph->saddr;
5123 dst_ipv4_addr = iph->daddr;
5124 flex_bytes = eth->h_proto;
5126 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5127 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5128 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5129 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5130 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5131 /* src and dst are inverted, think how the receiver sees them */
5132 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5133 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5135 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5136 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5139 static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
5140 struct ixgbe_ring *tx_ring, int size)
5142 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5144 netif_stop_subqueue(netdev, tx_ring->queue_index);
5145 /* Herbert's original patch had:
5146 * smp_mb__after_netif_stop_queue();
5147 * but since that doesn't exist yet, just open code it. */
5148 smp_mb();
5150 /* We need to check again in a case another CPU has just
5151 * made room available. */
5152 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5153 return -EBUSY;
5155 /* A reprieve! - use start_queue because it doesn't call schedule */
5156 netif_start_subqueue(netdev, tx_ring->queue_index);
5157 ++adapter->restart_queue;
5158 return 0;
5161 static int ixgbe_maybe_stop_tx(struct net_device *netdev,
5162 struct ixgbe_ring *tx_ring, int size)
5164 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5165 return 0;
5166 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5169 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5171 struct ixgbe_adapter *adapter = netdev_priv(dev);
5173 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5174 return smp_processor_id();
5176 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5177 return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
5179 return skb_tx_hash(dev, skb);
5182 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
5183 struct net_device *netdev)
5185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5186 struct ixgbe_ring *tx_ring;
5187 unsigned int first;
5188 unsigned int tx_flags = 0;
5189 u8 hdr_len = 0;
5190 int r_idx = 0, tso;
5191 int count = 0;
5192 unsigned int f;
5194 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5195 tx_flags |= vlan_tx_tag_get(skb);
5196 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5197 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5198 tx_flags |= (skb->queue_mapping << 13);
5200 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5201 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5202 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5203 if (skb->priority != TC_PRIO_CONTROL) {
5204 tx_flags |= (skb->queue_mapping << 13);
5205 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5206 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5207 } else {
5208 skb->queue_mapping =
5209 adapter->ring_feature[RING_F_DCB].indices-1;
5213 r_idx = skb->queue_mapping;
5214 tx_ring = &adapter->tx_ring[r_idx];
5216 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5217 (skb->protocol == htons(ETH_P_FCOE))) {
5218 tx_flags |= IXGBE_TX_FLAGS_FCOE;
5219 #ifdef IXGBE_FCOE
5220 r_idx = smp_processor_id();
5221 r_idx &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
5222 r_idx += adapter->ring_feature[RING_F_FCOE].mask;
5223 tx_ring = &adapter->tx_ring[r_idx];
5224 #endif
5226 /* four things can cause us to need a context descriptor */
5227 if (skb_is_gso(skb) ||
5228 (skb->ip_summed == CHECKSUM_PARTIAL) ||
5229 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5230 (tx_flags & IXGBE_TX_FLAGS_FCOE))
5231 count++;
5233 count += TXD_USE_COUNT(skb_headlen(skb));
5234 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
5235 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5237 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
5238 adapter->tx_busy++;
5239 return NETDEV_TX_BUSY;
5242 first = tx_ring->next_to_use;
5243 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5244 #ifdef IXGBE_FCOE
5245 /* setup tx offload for FCoE */
5246 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5247 if (tso < 0) {
5248 dev_kfree_skb_any(skb);
5249 return NETDEV_TX_OK;
5251 if (tso)
5252 tx_flags |= IXGBE_TX_FLAGS_FSO;
5253 #endif /* IXGBE_FCOE */
5254 } else {
5255 if (skb->protocol == htons(ETH_P_IP))
5256 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5257 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5258 if (tso < 0) {
5259 dev_kfree_skb_any(skb);
5260 return NETDEV_TX_OK;
5263 if (tso)
5264 tx_flags |= IXGBE_TX_FLAGS_TSO;
5265 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5266 (skb->ip_summed == CHECKSUM_PARTIAL))
5267 tx_flags |= IXGBE_TX_FLAGS_CSUM;
5270 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
5271 if (count) {
5272 /* add the ATR filter if ATR is on */
5273 if (tx_ring->atr_sample_rate) {
5274 ++tx_ring->atr_count;
5275 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5276 test_bit(__IXGBE_FDIR_INIT_DONE,
5277 &tx_ring->reinit_state)) {
5278 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5279 tx_flags);
5280 tx_ring->atr_count = 0;
5283 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5284 hdr_len);
5285 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
5287 } else {
5288 dev_kfree_skb_any(skb);
5289 tx_ring->tx_buffer_info[first].time_stamp = 0;
5290 tx_ring->next_to_use = first;
5293 return NETDEV_TX_OK;
5297 * ixgbe_get_stats - Get System Network Statistics
5298 * @netdev: network interface device structure
5300 * Returns the address of the device statistics structure.
5301 * The statistics are actually updated from the timer callback.
5303 static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5305 /* only return the current stats */
5306 return &netdev->stats;
5310 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5311 * @netdev: network interface device structure
5312 * @p: pointer to an address structure
5314 * Returns 0 on success, negative on failure
5316 static int ixgbe_set_mac(struct net_device *netdev, void *p)
5318 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5319 struct ixgbe_hw *hw = &adapter->hw;
5320 struct sockaddr *addr = p;
5322 if (!is_valid_ether_addr(addr->sa_data))
5323 return -EADDRNOTAVAIL;
5325 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
5326 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
5328 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
5330 return 0;
5333 static int
5334 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5336 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5337 struct ixgbe_hw *hw = &adapter->hw;
5338 u16 value;
5339 int rc;
5341 if (prtad != hw->phy.mdio.prtad)
5342 return -EINVAL;
5343 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5344 if (!rc)
5345 rc = value;
5346 return rc;
5349 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5350 u16 addr, u16 value)
5352 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5353 struct ixgbe_hw *hw = &adapter->hw;
5355 if (prtad != hw->phy.mdio.prtad)
5356 return -EINVAL;
5357 return hw->phy.ops.write_reg(hw, addr, devad, value);
5360 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5362 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5364 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5368 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5369 * netdev->dev_addrs
5370 * @netdev: network interface device structure
5372 * Returns non-zero on failure
5374 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5376 int err = 0;
5377 struct ixgbe_adapter *adapter = netdev_priv(dev);
5378 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5380 if (is_valid_ether_addr(mac->san_addr)) {
5381 rtnl_lock();
5382 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5383 rtnl_unlock();
5385 return err;
5389 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5390 * netdev->dev_addrs
5391 * @netdev: network interface device structure
5393 * Returns non-zero on failure
5395 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5397 int err = 0;
5398 struct ixgbe_adapter *adapter = netdev_priv(dev);
5399 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5401 if (is_valid_ether_addr(mac->san_addr)) {
5402 rtnl_lock();
5403 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5404 rtnl_unlock();
5406 return err;
5409 #ifdef CONFIG_NET_POLL_CONTROLLER
5411 * Polling 'interrupt' - used by things like netconsole to send skbs
5412 * without having to re-enable interrupts. It's not called while
5413 * the interrupt routine is executing.
5415 static void ixgbe_netpoll(struct net_device *netdev)
5417 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5418 int i;
5420 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
5421 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5422 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5423 for (i = 0; i < num_q_vectors; i++) {
5424 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
5425 ixgbe_msix_clean_many(0, q_vector);
5427 } else {
5428 ixgbe_intr(adapter->pdev->irq, netdev);
5430 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
5432 #endif
5434 static const struct net_device_ops ixgbe_netdev_ops = {
5435 .ndo_open = ixgbe_open,
5436 .ndo_stop = ixgbe_close,
5437 .ndo_start_xmit = ixgbe_xmit_frame,
5438 .ndo_select_queue = ixgbe_select_queue,
5439 .ndo_get_stats = ixgbe_get_stats,
5440 .ndo_set_rx_mode = ixgbe_set_rx_mode,
5441 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5442 .ndo_validate_addr = eth_validate_addr,
5443 .ndo_set_mac_address = ixgbe_set_mac,
5444 .ndo_change_mtu = ixgbe_change_mtu,
5445 .ndo_tx_timeout = ixgbe_tx_timeout,
5446 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5447 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5448 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
5449 .ndo_do_ioctl = ixgbe_ioctl,
5450 #ifdef CONFIG_NET_POLL_CONTROLLER
5451 .ndo_poll_controller = ixgbe_netpoll,
5452 #endif
5453 #ifdef IXGBE_FCOE
5454 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5455 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
5456 .ndo_fcoe_enable = ixgbe_fcoe_enable,
5457 .ndo_fcoe_disable = ixgbe_fcoe_disable,
5458 #endif /* IXGBE_FCOE */
5462 * ixgbe_probe - Device Initialization Routine
5463 * @pdev: PCI device information struct
5464 * @ent: entry in ixgbe_pci_tbl
5466 * Returns 0 on success, negative on failure
5468 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5469 * The OS initialization, configuring of the adapter private structure,
5470 * and a hardware reset occur.
5472 static int __devinit ixgbe_probe(struct pci_dev *pdev,
5473 const struct pci_device_id *ent)
5475 struct net_device *netdev;
5476 struct ixgbe_adapter *adapter = NULL;
5477 struct ixgbe_hw *hw;
5478 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
5479 static int cards_found;
5480 int i, err, pci_using_dac;
5481 #ifdef IXGBE_FCOE
5482 u16 device_caps;
5483 #endif
5484 u32 part_num, eec;
5486 err = pci_enable_device_mem(pdev);
5487 if (err)
5488 return err;
5490 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5491 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
5492 pci_using_dac = 1;
5493 } else {
5494 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
5495 if (err) {
5496 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
5497 if (err) {
5498 dev_err(&pdev->dev, "No usable DMA "
5499 "configuration, aborting\n");
5500 goto err_dma;
5503 pci_using_dac = 0;
5506 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5507 IORESOURCE_MEM), ixgbe_driver_name);
5508 if (err) {
5509 dev_err(&pdev->dev,
5510 "pci_request_selected_regions failed 0x%x\n", err);
5511 goto err_pci_reg;
5514 pci_enable_pcie_error_reporting(pdev);
5516 pci_set_master(pdev);
5517 pci_save_state(pdev);
5519 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
5520 if (!netdev) {
5521 err = -ENOMEM;
5522 goto err_alloc_etherdev;
5525 SET_NETDEV_DEV(netdev, &pdev->dev);
5527 pci_set_drvdata(pdev, netdev);
5528 adapter = netdev_priv(netdev);
5530 adapter->netdev = netdev;
5531 adapter->pdev = pdev;
5532 hw = &adapter->hw;
5533 hw->back = adapter;
5534 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5536 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5537 pci_resource_len(pdev, 0));
5538 if (!hw->hw_addr) {
5539 err = -EIO;
5540 goto err_ioremap;
5543 for (i = 1; i <= 5; i++) {
5544 if (pci_resource_len(pdev, i) == 0)
5545 continue;
5548 netdev->netdev_ops = &ixgbe_netdev_ops;
5549 ixgbe_set_ethtool_ops(netdev);
5550 netdev->watchdog_timeo = 5 * HZ;
5551 strcpy(netdev->name, pci_name(pdev));
5553 adapter->bd_number = cards_found;
5555 /* Setup hw api */
5556 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
5557 hw->mac.type = ii->mac;
5559 /* EEPROM */
5560 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5561 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5562 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5563 if (!(eec & (1 << 8)))
5564 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5566 /* PHY */
5567 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
5568 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
5569 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5570 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5571 hw->phy.mdio.mmds = 0;
5572 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5573 hw->phy.mdio.dev = netdev;
5574 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5575 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
5577 /* set up this timer and work struct before calling get_invariants
5578 * which might start the timer
5580 init_timer(&adapter->sfp_timer);
5581 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5582 adapter->sfp_timer.data = (unsigned long) adapter;
5584 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
5586 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5587 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5589 /* a new SFP+ module arrival, called from GPI SDP2 context */
5590 INIT_WORK(&adapter->sfp_config_module_task,
5591 ixgbe_sfp_config_module_task);
5593 ii->get_invariants(hw);
5595 /* setup the private structure */
5596 err = ixgbe_sw_init(adapter);
5597 if (err)
5598 goto err_sw_init;
5601 * If there is a fan on this device and it has failed log the
5602 * failure.
5604 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5605 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5606 if (esdp & IXGBE_ESDP_SDP1)
5607 DPRINTK(PROBE, CRIT,
5608 "Fan has stopped, replace the adapter\n");
5611 /* reset_hw fills in the perm_addr as well */
5612 err = hw->mac.ops.reset_hw(hw);
5613 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5614 hw->mac.type == ixgbe_mac_82598EB) {
5616 * Start a kernel thread to watch for a module to arrive.
5617 * Only do this for 82598, since 82599 will generate
5618 * interrupts on module arrival.
5620 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5621 mod_timer(&adapter->sfp_timer,
5622 round_jiffies(jiffies + (2 * HZ)));
5623 err = 0;
5624 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5625 dev_err(&adapter->pdev->dev, "failed to initialize because "
5626 "an unsupported SFP+ module type was detected.\n"
5627 "Reload the driver after installing a supported "
5628 "module.\n");
5629 goto err_sw_init;
5630 } else if (err) {
5631 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5632 goto err_sw_init;
5635 netdev->features = NETIF_F_SG |
5636 NETIF_F_IP_CSUM |
5637 NETIF_F_HW_VLAN_TX |
5638 NETIF_F_HW_VLAN_RX |
5639 NETIF_F_HW_VLAN_FILTER;
5641 netdev->features |= NETIF_F_IPV6_CSUM;
5642 netdev->features |= NETIF_F_TSO;
5643 netdev->features |= NETIF_F_TSO6;
5644 netdev->features |= NETIF_F_GRO;
5646 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5647 netdev->features |= NETIF_F_SCTP_CSUM;
5649 netdev->vlan_features |= NETIF_F_TSO;
5650 netdev->vlan_features |= NETIF_F_TSO6;
5651 netdev->vlan_features |= NETIF_F_IP_CSUM;
5652 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
5653 netdev->vlan_features |= NETIF_F_SG;
5655 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5656 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5658 #ifdef CONFIG_IXGBE_DCB
5659 netdev->dcbnl_ops = &dcbnl_ops;
5660 #endif
5662 #ifdef IXGBE_FCOE
5663 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
5664 if (hw->mac.ops.get_device_caps) {
5665 hw->mac.ops.get_device_caps(hw, &device_caps);
5666 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5667 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5670 #endif /* IXGBE_FCOE */
5671 if (pci_using_dac)
5672 netdev->features |= NETIF_F_HIGHDMA;
5674 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
5675 netdev->features |= NETIF_F_LRO;
5677 /* make sure the EEPROM is good */
5678 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
5679 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5680 err = -EIO;
5681 goto err_eeprom;
5684 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5685 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5687 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5688 dev_err(&pdev->dev, "invalid MAC address\n");
5689 err = -EIO;
5690 goto err_eeprom;
5693 init_timer(&adapter->watchdog_timer);
5694 adapter->watchdog_timer.function = &ixgbe_watchdog;
5695 adapter->watchdog_timer.data = (unsigned long)adapter;
5697 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
5698 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
5700 err = ixgbe_init_interrupt_scheme(adapter);
5701 if (err)
5702 goto err_sw_init;
5704 switch (pdev->device) {
5705 case IXGBE_DEV_ID_82599_KX4:
5706 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5707 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
5708 /* Enable ACPI wakeup in GRC */
5709 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5710 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
5711 break;
5712 default:
5713 adapter->wol = 0;
5714 break;
5716 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5718 /* pick up the PCI bus settings for reporting later */
5719 hw->mac.ops.get_bus_info(hw);
5721 /* print bus type/speed/width info */
5722 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
5723 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5724 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5725 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5726 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5727 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
5728 "Unknown"),
5729 netdev->dev_addr);
5730 ixgbe_read_pba_num_generic(hw, &part_num);
5731 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5732 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5733 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5734 (part_num >> 8), (part_num & 0xff));
5735 else
5736 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5737 hw->mac.type, hw->phy.type,
5738 (part_num >> 8), (part_num & 0xff));
5740 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
5741 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
5742 "this card is not sufficient for optimal "
5743 "performance.\n");
5744 dev_warn(&pdev->dev, "For optimal performance a x8 "
5745 "PCI-Express slot is required.\n");
5748 /* save off EEPROM version number */
5749 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5751 /* reset the hardware with the new settings */
5752 err = hw->mac.ops.start_hw(hw);
5754 if (err == IXGBE_ERR_EEPROM_VERSION) {
5755 /* We are running on a pre-production device, log a warning */
5756 dev_warn(&pdev->dev, "This device is a pre-production "
5757 "adapter/LOM. Please be aware there may be issues "
5758 "associated with your hardware. If you are "
5759 "experiencing problems please contact your Intel or "
5760 "hardware representative who provided you with this "
5761 "hardware.\n");
5763 strcpy(netdev->name, "eth%d");
5764 err = register_netdev(netdev);
5765 if (err)
5766 goto err_register;
5768 /* carrier off reporting is important to ethtool even BEFORE open */
5769 netif_carrier_off(netdev);
5771 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5772 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5773 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5775 #ifdef CONFIG_IXGBE_DCA
5776 if (dca_add_requester(&pdev->dev) == 0) {
5777 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
5778 ixgbe_setup_dca(adapter);
5780 #endif
5781 /* add san mac addr to netdev */
5782 ixgbe_add_sanmac_netdev(netdev);
5784 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5785 cards_found++;
5786 return 0;
5788 err_register:
5789 ixgbe_release_hw_control(adapter);
5790 ixgbe_clear_interrupt_scheme(adapter);
5791 err_sw_init:
5792 err_eeprom:
5793 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5794 del_timer_sync(&adapter->sfp_timer);
5795 cancel_work_sync(&adapter->sfp_task);
5796 cancel_work_sync(&adapter->multispeed_fiber_task);
5797 cancel_work_sync(&adapter->sfp_config_module_task);
5798 iounmap(hw->hw_addr);
5799 err_ioremap:
5800 free_netdev(netdev);
5801 err_alloc_etherdev:
5802 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5803 IORESOURCE_MEM));
5804 err_pci_reg:
5805 err_dma:
5806 pci_disable_device(pdev);
5807 return err;
5811 * ixgbe_remove - Device Removal Routine
5812 * @pdev: PCI device information struct
5814 * ixgbe_remove is called by the PCI subsystem to alert the driver
5815 * that it should release a PCI device. The could be caused by a
5816 * Hot-Plug event, or because the driver is going to be removed from
5817 * memory.
5819 static void __devexit ixgbe_remove(struct pci_dev *pdev)
5821 struct net_device *netdev = pci_get_drvdata(pdev);
5822 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5824 set_bit(__IXGBE_DOWN, &adapter->state);
5825 /* clear the module not found bit to make sure the worker won't
5826 * reschedule
5828 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5829 del_timer_sync(&adapter->watchdog_timer);
5831 del_timer_sync(&adapter->sfp_timer);
5832 cancel_work_sync(&adapter->watchdog_task);
5833 cancel_work_sync(&adapter->sfp_task);
5834 cancel_work_sync(&adapter->multispeed_fiber_task);
5835 cancel_work_sync(&adapter->sfp_config_module_task);
5836 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5837 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5838 cancel_work_sync(&adapter->fdir_reinit_task);
5839 flush_scheduled_work();
5841 #ifdef CONFIG_IXGBE_DCA
5842 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5843 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5844 dca_remove_requester(&pdev->dev);
5845 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5848 #endif
5849 #ifdef IXGBE_FCOE
5850 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5851 ixgbe_cleanup_fcoe(adapter);
5853 #endif /* IXGBE_FCOE */
5855 /* remove the added san mac */
5856 ixgbe_del_sanmac_netdev(netdev);
5858 if (netdev->reg_state == NETREG_REGISTERED)
5859 unregister_netdev(netdev);
5861 ixgbe_clear_interrupt_scheme(adapter);
5863 ixgbe_release_hw_control(adapter);
5865 iounmap(adapter->hw.hw_addr);
5866 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5867 IORESOURCE_MEM));
5869 DPRINTK(PROBE, INFO, "complete\n");
5871 free_netdev(netdev);
5873 pci_disable_pcie_error_reporting(pdev);
5875 pci_disable_device(pdev);
5879 * ixgbe_io_error_detected - called when PCI error is detected
5880 * @pdev: Pointer to PCI device
5881 * @state: The current pci connection state
5883 * This function is called after a PCI bus error affecting
5884 * this device has been detected.
5886 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
5887 pci_channel_state_t state)
5889 struct net_device *netdev = pci_get_drvdata(pdev);
5890 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5892 netif_device_detach(netdev);
5894 if (state == pci_channel_io_perm_failure)
5895 return PCI_ERS_RESULT_DISCONNECT;
5897 if (netif_running(netdev))
5898 ixgbe_down(adapter);
5899 pci_disable_device(pdev);
5901 /* Request a slot reset. */
5902 return PCI_ERS_RESULT_NEED_RESET;
5906 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5907 * @pdev: Pointer to PCI device
5909 * Restart the card from scratch, as if from a cold-boot.
5911 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5913 struct net_device *netdev = pci_get_drvdata(pdev);
5914 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5915 pci_ers_result_t result;
5916 int err;
5918 if (pci_enable_device_mem(pdev)) {
5919 DPRINTK(PROBE, ERR,
5920 "Cannot re-enable PCI device after reset.\n");
5921 result = PCI_ERS_RESULT_DISCONNECT;
5922 } else {
5923 pci_set_master(pdev);
5924 pci_restore_state(pdev);
5926 pci_wake_from_d3(pdev, false);
5928 ixgbe_reset(adapter);
5929 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5930 result = PCI_ERS_RESULT_RECOVERED;
5933 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5934 if (err) {
5935 dev_err(&pdev->dev,
5936 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5937 /* non-fatal, continue */
5940 return result;
5944 * ixgbe_io_resume - called when traffic can start flowing again.
5945 * @pdev: Pointer to PCI device
5947 * This callback is called when the error recovery driver tells us that
5948 * its OK to resume normal operation.
5950 static void ixgbe_io_resume(struct pci_dev *pdev)
5952 struct net_device *netdev = pci_get_drvdata(pdev);
5953 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5955 if (netif_running(netdev)) {
5956 if (ixgbe_up(adapter)) {
5957 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5958 return;
5962 netif_device_attach(netdev);
5965 static struct pci_error_handlers ixgbe_err_handler = {
5966 .error_detected = ixgbe_io_error_detected,
5967 .slot_reset = ixgbe_io_slot_reset,
5968 .resume = ixgbe_io_resume,
5971 static struct pci_driver ixgbe_driver = {
5972 .name = ixgbe_driver_name,
5973 .id_table = ixgbe_pci_tbl,
5974 .probe = ixgbe_probe,
5975 .remove = __devexit_p(ixgbe_remove),
5976 #ifdef CONFIG_PM
5977 .suspend = ixgbe_suspend,
5978 .resume = ixgbe_resume,
5979 #endif
5980 .shutdown = ixgbe_shutdown,
5981 .err_handler = &ixgbe_err_handler
5985 * ixgbe_init_module - Driver Registration Routine
5987 * ixgbe_init_module is the first routine called when the driver is
5988 * loaded. All it does is register with the PCI subsystem.
5990 static int __init ixgbe_init_module(void)
5992 int ret;
5993 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5994 ixgbe_driver_string, ixgbe_driver_version);
5996 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5998 #ifdef CONFIG_IXGBE_DCA
5999 dca_register_notify(&dca_notifier);
6000 #endif
6002 ret = pci_register_driver(&ixgbe_driver);
6003 return ret;
6006 module_init(ixgbe_init_module);
6009 * ixgbe_exit_module - Driver Exit Cleanup Routine
6011 * ixgbe_exit_module is called just before the driver is removed
6012 * from memory.
6014 static void __exit ixgbe_exit_module(void)
6016 #ifdef CONFIG_IXGBE_DCA
6017 dca_unregister_notify(&dca_notifier);
6018 #endif
6019 pci_unregister_driver(&ixgbe_driver);
6022 #ifdef CONFIG_IXGBE_DCA
6023 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
6024 void *p)
6026 int ret_val;
6028 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
6029 __ixgbe_notify_dca);
6031 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6034 #endif /* CONFIG_IXGBE_DCA */
6035 #ifdef DEBUG
6037 * ixgbe_get_hw_dev_name - return device name string
6038 * used by hardware layer to print debugging information
6040 char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
6042 struct ixgbe_adapter *adapter = hw->back;
6043 return adapter->netdev->name;
6046 #endif
6047 module_exit(ixgbe_exit_module);
6049 /* ixgbe_main.c */