1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 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/module.h>
29 #include <linux/types.h>
30 #include <linux/init.h>
31 #include <linux/vmalloc.h>
32 #include <linux/pagemap.h>
33 #include <linux/netdevice.h>
34 #include <linux/ipv6.h>
35 #include <net/checksum.h>
36 #include <net/ip6_checksum.h>
37 #include <linux/mii.h>
38 #include <linux/ethtool.h>
39 #include <linux/if_vlan.h>
40 #include <linux/pci.h>
41 #include <linux/delay.h>
42 #include <linux/interrupt.h>
43 #include <linux/if_ether.h>
45 #include <linux/dca.h>
49 #define DRV_VERSION "1.0.8-k2"
50 char igb_driver_name[] = "igb";
51 char igb_driver_version[] = DRV_VERSION;
52 static const char igb_driver_string[] =
53 "Intel(R) Gigabit Ethernet Network Driver";
54 static const char igb_copyright[] = "Copyright (c) 2007 Intel Corporation.";
57 static const struct e1000_info *igb_info_tbl[] = {
58 [board_82575] = &e1000_82575_info,
61 static struct pci_device_id igb_pci_tbl[] = {
62 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
63 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
64 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
65 /* required last entry */
69 MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
71 void igb_reset(struct igb_adapter *);
72 static int igb_setup_all_tx_resources(struct igb_adapter *);
73 static int igb_setup_all_rx_resources(struct igb_adapter *);
74 static void igb_free_all_tx_resources(struct igb_adapter *);
75 static void igb_free_all_rx_resources(struct igb_adapter *);
76 static void igb_free_tx_resources(struct igb_ring *);
77 static void igb_free_rx_resources(struct igb_ring *);
78 void igb_update_stats(struct igb_adapter *);
79 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
80 static void __devexit igb_remove(struct pci_dev *pdev);
81 static int igb_sw_init(struct igb_adapter *);
82 static int igb_open(struct net_device *);
83 static int igb_close(struct net_device *);
84 static void igb_configure_tx(struct igb_adapter *);
85 static void igb_configure_rx(struct igb_adapter *);
86 static void igb_setup_rctl(struct igb_adapter *);
87 static void igb_clean_all_tx_rings(struct igb_adapter *);
88 static void igb_clean_all_rx_rings(struct igb_adapter *);
89 static void igb_clean_tx_ring(struct igb_ring *);
90 static void igb_clean_rx_ring(struct igb_ring *);
91 static void igb_set_multi(struct net_device *);
92 static void igb_update_phy_info(unsigned long);
93 static void igb_watchdog(unsigned long);
94 static void igb_watchdog_task(struct work_struct *);
95 static int igb_xmit_frame_ring_adv(struct sk_buff *, struct net_device *,
97 static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *);
98 static struct net_device_stats *igb_get_stats(struct net_device *);
99 static int igb_change_mtu(struct net_device *, int);
100 static int igb_set_mac(struct net_device *, void *);
101 static irqreturn_t igb_intr(int irq, void *);
102 static irqreturn_t igb_intr_msi(int irq, void *);
103 static irqreturn_t igb_msix_other(int irq, void *);
104 static irqreturn_t igb_msix_rx(int irq, void *);
105 static irqreturn_t igb_msix_tx(int irq, void *);
106 static int igb_clean_rx_ring_msix(struct napi_struct *, int);
108 static void igb_update_rx_dca(struct igb_ring *);
109 static void igb_update_tx_dca(struct igb_ring *);
110 static void igb_setup_dca(struct igb_adapter *);
111 #endif /* CONFIG_DCA */
112 static bool igb_clean_tx_irq(struct igb_ring *);
113 static int igb_poll(struct napi_struct *, int);
114 static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int);
115 static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
116 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
117 static void igb_tx_timeout(struct net_device *);
118 static void igb_reset_task(struct work_struct *);
119 static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
120 static void igb_vlan_rx_add_vid(struct net_device *, u16);
121 static void igb_vlan_rx_kill_vid(struct net_device *, u16);
122 static void igb_restore_vlan(struct igb_adapter *);
124 static int igb_suspend(struct pci_dev *, pm_message_t);
126 static int igb_resume(struct pci_dev *);
128 static void igb_shutdown(struct pci_dev *);
130 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
131 static struct notifier_block dca_notifier = {
132 .notifier_call = igb_notify_dca,
138 #ifdef CONFIG_NET_POLL_CONTROLLER
139 /* for netdump / net console */
140 static void igb_netpoll(struct net_device *);
143 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
144 pci_channel_state_t);
145 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
146 static void igb_io_resume(struct pci_dev *);
148 static struct pci_error_handlers igb_err_handler = {
149 .error_detected = igb_io_error_detected,
150 .slot_reset = igb_io_slot_reset,
151 .resume = igb_io_resume,
155 static struct pci_driver igb_driver = {
156 .name = igb_driver_name,
157 .id_table = igb_pci_tbl,
159 .remove = __devexit_p(igb_remove),
161 /* Power Managment Hooks */
162 .suspend = igb_suspend,
163 .resume = igb_resume,
165 .shutdown = igb_shutdown,
166 .err_handler = &igb_err_handler
169 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
170 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
171 MODULE_LICENSE("GPL");
172 MODULE_VERSION(DRV_VERSION);
176 * igb_get_hw_dev_name - return device name string
177 * used by hardware layer to print debugging information
179 char *igb_get_hw_dev_name(struct e1000_hw *hw)
181 struct igb_adapter *adapter = hw->back;
182 return adapter->netdev->name;
187 * igb_init_module - Driver Registration Routine
189 * igb_init_module is the first routine called when the driver is
190 * loaded. All it does is register with the PCI subsystem.
192 static int __init igb_init_module(void)
195 printk(KERN_INFO "%s - version %s\n",
196 igb_driver_string, igb_driver_version);
198 printk(KERN_INFO "%s\n", igb_copyright);
200 ret = pci_register_driver(&igb_driver);
202 dca_register_notify(&dca_notifier);
207 module_init(igb_init_module);
210 * igb_exit_module - Driver Exit Cleanup Routine
212 * igb_exit_module is called just before the driver is removed
215 static void __exit igb_exit_module(void)
218 dca_unregister_notify(&dca_notifier);
220 pci_unregister_driver(&igb_driver);
223 module_exit(igb_exit_module);
226 * igb_alloc_queues - Allocate memory for all rings
227 * @adapter: board private structure to initialize
229 * We allocate one ring per queue at run-time since we don't know the
230 * number of queues at compile-time.
232 static int igb_alloc_queues(struct igb_adapter *adapter)
236 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
237 sizeof(struct igb_ring), GFP_KERNEL);
238 if (!adapter->tx_ring)
241 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
242 sizeof(struct igb_ring), GFP_KERNEL);
243 if (!adapter->rx_ring) {
244 kfree(adapter->tx_ring);
248 for (i = 0; i < adapter->num_tx_queues; i++) {
249 struct igb_ring *ring = &(adapter->tx_ring[i]);
250 ring->adapter = adapter;
251 ring->queue_index = i;
253 for (i = 0; i < adapter->num_rx_queues; i++) {
254 struct igb_ring *ring = &(adapter->rx_ring[i]);
255 ring->adapter = adapter;
256 ring->queue_index = i;
257 ring->itr_register = E1000_ITR;
259 /* set a default napi handler for each rx_ring */
260 netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
265 #define IGB_N0_QUEUE -1
266 static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue,
267 int tx_queue, int msix_vector)
270 struct e1000_hw *hw = &adapter->hw;
271 /* The 82575 assigns vectors using a bitmask, which matches the
272 bitmask for the EICR/EIMS/EIMC registers. To assign one
273 or more queues to a vector, we write the appropriate bits
274 into the MSIXBM register for that vector. */
275 if (rx_queue > IGB_N0_QUEUE) {
276 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
277 adapter->rx_ring[rx_queue].eims_value = msixbm;
279 if (tx_queue > IGB_N0_QUEUE) {
280 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
281 adapter->tx_ring[tx_queue].eims_value =
282 E1000_EICR_TX_QUEUE0 << tx_queue;
284 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
288 * igb_configure_msix - Configure MSI-X hardware
290 * igb_configure_msix sets up the hardware to properly
291 * generate MSI-X interrupts.
293 static void igb_configure_msix(struct igb_adapter *adapter)
297 struct e1000_hw *hw = &adapter->hw;
299 adapter->eims_enable_mask = 0;
301 for (i = 0; i < adapter->num_tx_queues; i++) {
302 struct igb_ring *tx_ring = &adapter->tx_ring[i];
303 igb_assign_vector(adapter, IGB_N0_QUEUE, i, vector++);
304 adapter->eims_enable_mask |= tx_ring->eims_value;
305 if (tx_ring->itr_val)
306 writel(1000000000 / (tx_ring->itr_val * 256),
307 hw->hw_addr + tx_ring->itr_register);
309 writel(1, hw->hw_addr + tx_ring->itr_register);
312 for (i = 0; i < adapter->num_rx_queues; i++) {
313 struct igb_ring *rx_ring = &adapter->rx_ring[i];
314 igb_assign_vector(adapter, i, IGB_N0_QUEUE, vector++);
315 adapter->eims_enable_mask |= rx_ring->eims_value;
316 if (rx_ring->itr_val)
317 writel(1000000000 / (rx_ring->itr_val * 256),
318 hw->hw_addr + rx_ring->itr_register);
320 writel(1, hw->hw_addr + rx_ring->itr_register);
324 /* set vector for other causes, i.e. link changes */
325 array_wr32(E1000_MSIXBM(0), vector++,
328 tmp = rd32(E1000_CTRL_EXT);
329 /* enable MSI-X PBA support*/
330 tmp |= E1000_CTRL_EXT_PBA_CLR;
332 /* Auto-Mask interrupts upon ICR read. */
333 tmp |= E1000_CTRL_EXT_EIAME;
334 tmp |= E1000_CTRL_EXT_IRCA;
336 wr32(E1000_CTRL_EXT, tmp);
337 adapter->eims_enable_mask |= E1000_EIMS_OTHER;
338 adapter->eims_other = E1000_EIMS_OTHER;
344 * igb_request_msix - Initialize MSI-X interrupts
346 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
349 static int igb_request_msix(struct igb_adapter *adapter)
351 struct net_device *netdev = adapter->netdev;
352 int i, err = 0, vector = 0;
356 for (i = 0; i < adapter->num_tx_queues; i++) {
357 struct igb_ring *ring = &(adapter->tx_ring[i]);
358 sprintf(ring->name, "%s-tx%d", netdev->name, i);
359 err = request_irq(adapter->msix_entries[vector].vector,
360 &igb_msix_tx, 0, ring->name,
361 &(adapter->tx_ring[i]));
364 ring->itr_register = E1000_EITR(0) + (vector << 2);
365 ring->itr_val = adapter->itr;
368 for (i = 0; i < adapter->num_rx_queues; i++) {
369 struct igb_ring *ring = &(adapter->rx_ring[i]);
370 if (strlen(netdev->name) < (IFNAMSIZ - 5))
371 sprintf(ring->name, "%s-rx%d", netdev->name, i);
373 memcpy(ring->name, netdev->name, IFNAMSIZ);
374 err = request_irq(adapter->msix_entries[vector].vector,
375 &igb_msix_rx, 0, ring->name,
376 &(adapter->rx_ring[i]));
379 ring->itr_register = E1000_EITR(0) + (vector << 2);
380 ring->itr_val = adapter->itr;
381 /* overwrite the poll routine for MSIX, we've already done
383 ring->napi.poll = &igb_clean_rx_ring_msix;
387 err = request_irq(adapter->msix_entries[vector].vector,
388 &igb_msix_other, 0, netdev->name, netdev);
392 igb_configure_msix(adapter);
398 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
400 if (adapter->msix_entries) {
401 pci_disable_msix(adapter->pdev);
402 kfree(adapter->msix_entries);
403 adapter->msix_entries = NULL;
404 } else if (adapter->msi_enabled)
405 pci_disable_msi(adapter->pdev);
411 * igb_set_interrupt_capability - set MSI or MSI-X if supported
413 * Attempt to configure interrupts using the best available
414 * capabilities of the hardware and kernel.
416 static void igb_set_interrupt_capability(struct igb_adapter *adapter)
421 numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1;
422 adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
424 if (!adapter->msix_entries)
427 for (i = 0; i < numvecs; i++)
428 adapter->msix_entries[i].entry = i;
430 err = pci_enable_msix(adapter->pdev,
431 adapter->msix_entries,
436 igb_reset_interrupt_capability(adapter);
438 /* If we can't do MSI-X, try MSI */
440 adapter->num_rx_queues = 1;
441 adapter->num_tx_queues = 1;
442 if (!pci_enable_msi(adapter->pdev))
443 adapter->msi_enabled = 1;
445 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
446 /* Notify the stack of the (possibly) reduced Tx Queue count. */
447 adapter->netdev->egress_subqueue_count = adapter->num_tx_queues;
453 * igb_request_irq - initialize interrupts
455 * Attempts to configure interrupts using the best available
456 * capabilities of the hardware and kernel.
458 static int igb_request_irq(struct igb_adapter *adapter)
460 struct net_device *netdev = adapter->netdev;
461 struct e1000_hw *hw = &adapter->hw;
464 if (adapter->msix_entries) {
465 err = igb_request_msix(adapter);
468 /* fall back to MSI */
469 igb_reset_interrupt_capability(adapter);
470 if (!pci_enable_msi(adapter->pdev))
471 adapter->msi_enabled = 1;
472 igb_free_all_tx_resources(adapter);
473 igb_free_all_rx_resources(adapter);
474 adapter->num_rx_queues = 1;
475 igb_alloc_queues(adapter);
477 wr32(E1000_MSIXBM(0), (E1000_EICR_RX_QUEUE0 |
481 if (adapter->msi_enabled) {
482 err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0,
483 netdev->name, netdev);
486 /* fall back to legacy interrupts */
487 igb_reset_interrupt_capability(adapter);
488 adapter->msi_enabled = 0;
491 err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED,
492 netdev->name, netdev);
495 dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
502 static void igb_free_irq(struct igb_adapter *adapter)
504 struct net_device *netdev = adapter->netdev;
506 if (adapter->msix_entries) {
509 for (i = 0; i < adapter->num_tx_queues; i++)
510 free_irq(adapter->msix_entries[vector++].vector,
511 &(adapter->tx_ring[i]));
512 for (i = 0; i < adapter->num_rx_queues; i++)
513 free_irq(adapter->msix_entries[vector++].vector,
514 &(adapter->rx_ring[i]));
516 free_irq(adapter->msix_entries[vector++].vector, netdev);
520 free_irq(adapter->pdev->irq, netdev);
524 * igb_irq_disable - Mask off interrupt generation on the NIC
525 * @adapter: board private structure
527 static void igb_irq_disable(struct igb_adapter *adapter)
529 struct e1000_hw *hw = &adapter->hw;
531 if (adapter->msix_entries) {
533 wr32(E1000_EIMC, ~0);
540 synchronize_irq(adapter->pdev->irq);
544 * igb_irq_enable - Enable default interrupt generation settings
545 * @adapter: board private structure
547 static void igb_irq_enable(struct igb_adapter *adapter)
549 struct e1000_hw *hw = &adapter->hw;
551 if (adapter->msix_entries) {
552 wr32(E1000_EIAC, adapter->eims_enable_mask);
553 wr32(E1000_EIAM, adapter->eims_enable_mask);
554 wr32(E1000_EIMS, adapter->eims_enable_mask);
555 wr32(E1000_IMS, E1000_IMS_LSC);
557 wr32(E1000_IMS, IMS_ENABLE_MASK);
558 wr32(E1000_IAM, IMS_ENABLE_MASK);
562 static void igb_update_mng_vlan(struct igb_adapter *adapter)
564 struct net_device *netdev = adapter->netdev;
565 u16 vid = adapter->hw.mng_cookie.vlan_id;
566 u16 old_vid = adapter->mng_vlan_id;
567 if (adapter->vlgrp) {
568 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
569 if (adapter->hw.mng_cookie.status &
570 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
571 igb_vlan_rx_add_vid(netdev, vid);
572 adapter->mng_vlan_id = vid;
574 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
576 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
578 !vlan_group_get_device(adapter->vlgrp, old_vid))
579 igb_vlan_rx_kill_vid(netdev, old_vid);
581 adapter->mng_vlan_id = vid;
586 * igb_release_hw_control - release control of the h/w to f/w
587 * @adapter: address of board private structure
589 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
590 * For ASF and Pass Through versions of f/w this means that the
591 * driver is no longer loaded.
594 static void igb_release_hw_control(struct igb_adapter *adapter)
596 struct e1000_hw *hw = &adapter->hw;
599 /* Let firmware take over control of h/w */
600 ctrl_ext = rd32(E1000_CTRL_EXT);
602 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
607 * igb_get_hw_control - get control of the h/w from f/w
608 * @adapter: address of board private structure
610 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
611 * For ASF and Pass Through versions of f/w this means that
612 * the driver is loaded.
615 static void igb_get_hw_control(struct igb_adapter *adapter)
617 struct e1000_hw *hw = &adapter->hw;
620 /* Let firmware know the driver has taken over */
621 ctrl_ext = rd32(E1000_CTRL_EXT);
623 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
626 static void igb_init_manageability(struct igb_adapter *adapter)
628 struct e1000_hw *hw = &adapter->hw;
630 if (adapter->en_mng_pt) {
631 u32 manc2h = rd32(E1000_MANC2H);
632 u32 manc = rd32(E1000_MANC);
634 /* enable receiving management packets to the host */
635 /* this will probably generate destination unreachable messages
636 * from the host OS, but the packets will be handled on SMBUS */
637 manc |= E1000_MANC_EN_MNG2HOST;
638 #define E1000_MNG2HOST_PORT_623 (1 << 5)
639 #define E1000_MNG2HOST_PORT_664 (1 << 6)
640 manc2h |= E1000_MNG2HOST_PORT_623;
641 manc2h |= E1000_MNG2HOST_PORT_664;
642 wr32(E1000_MANC2H, manc2h);
644 wr32(E1000_MANC, manc);
649 * igb_configure - configure the hardware for RX and TX
650 * @adapter: private board structure
652 static void igb_configure(struct igb_adapter *adapter)
654 struct net_device *netdev = adapter->netdev;
657 igb_get_hw_control(adapter);
658 igb_set_multi(netdev);
660 igb_restore_vlan(adapter);
661 igb_init_manageability(adapter);
663 igb_configure_tx(adapter);
664 igb_setup_rctl(adapter);
665 igb_configure_rx(adapter);
667 igb_rx_fifo_flush_82575(&adapter->hw);
669 /* call IGB_DESC_UNUSED which always leaves
670 * at least 1 descriptor unused to make sure
671 * next_to_use != next_to_clean */
672 for (i = 0; i < adapter->num_rx_queues; i++) {
673 struct igb_ring *ring = &adapter->rx_ring[i];
674 igb_alloc_rx_buffers_adv(ring, IGB_DESC_UNUSED(ring));
678 adapter->tx_queue_len = netdev->tx_queue_len;
683 * igb_up - Open the interface and prepare it to handle traffic
684 * @adapter: board private structure
687 int igb_up(struct igb_adapter *adapter)
689 struct e1000_hw *hw = &adapter->hw;
692 /* hardware has been reset, we need to reload some things */
693 igb_configure(adapter);
695 clear_bit(__IGB_DOWN, &adapter->state);
697 for (i = 0; i < adapter->num_rx_queues; i++)
698 napi_enable(&adapter->rx_ring[i].napi);
699 if (adapter->msix_entries)
700 igb_configure_msix(adapter);
702 /* Clear any pending interrupts. */
704 igb_irq_enable(adapter);
706 /* Fire a link change interrupt to start the watchdog. */
707 wr32(E1000_ICS, E1000_ICS_LSC);
711 void igb_down(struct igb_adapter *adapter)
713 struct e1000_hw *hw = &adapter->hw;
714 struct net_device *netdev = adapter->netdev;
718 /* signal that we're down so the interrupt handler does not
719 * reschedule our watchdog timer */
720 set_bit(__IGB_DOWN, &adapter->state);
722 /* disable receives in the hardware */
723 rctl = rd32(E1000_RCTL);
724 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
725 /* flush and sleep below */
727 netif_stop_queue(netdev);
728 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
729 for (i = 0; i < adapter->num_tx_queues; i++)
730 netif_stop_subqueue(netdev, i);
733 /* disable transmits in the hardware */
734 tctl = rd32(E1000_TCTL);
735 tctl &= ~E1000_TCTL_EN;
736 wr32(E1000_TCTL, tctl);
737 /* flush both disables and wait for them to finish */
741 for (i = 0; i < adapter->num_rx_queues; i++)
742 napi_disable(&adapter->rx_ring[i].napi);
744 igb_irq_disable(adapter);
746 del_timer_sync(&adapter->watchdog_timer);
747 del_timer_sync(&adapter->phy_info_timer);
749 netdev->tx_queue_len = adapter->tx_queue_len;
750 netif_carrier_off(netdev);
751 adapter->link_speed = 0;
752 adapter->link_duplex = 0;
754 if (!pci_channel_offline(adapter->pdev))
756 igb_clean_all_tx_rings(adapter);
757 igb_clean_all_rx_rings(adapter);
760 void igb_reinit_locked(struct igb_adapter *adapter)
762 WARN_ON(in_interrupt());
763 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
767 clear_bit(__IGB_RESETTING, &adapter->state);
770 void igb_reset(struct igb_adapter *adapter)
772 struct e1000_hw *hw = &adapter->hw;
773 struct e1000_fc_info *fc = &adapter->hw.fc;
774 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
777 /* Repartition Pba for greater than 9k mtu
778 * To take effect CTRL.RST is required.
782 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
783 /* adjust PBA for jumbo frames */
784 wr32(E1000_PBA, pba);
786 /* To maintain wire speed transmits, the Tx FIFO should be
787 * large enough to accommodate two full transmit packets,
788 * rounded up to the next 1KB and expressed in KB. Likewise,
789 * the Rx FIFO should be large enough to accommodate at least
790 * one full receive packet and is similarly rounded up and
791 * expressed in KB. */
792 pba = rd32(E1000_PBA);
793 /* upper 16 bits has Tx packet buffer allocation size in KB */
794 tx_space = pba >> 16;
795 /* lower 16 bits has Rx packet buffer allocation size in KB */
797 /* the tx fifo also stores 16 bytes of information about the tx
798 * but don't include ethernet FCS because hardware appends it */
799 min_tx_space = (adapter->max_frame_size +
800 sizeof(struct e1000_tx_desc) -
802 min_tx_space = ALIGN(min_tx_space, 1024);
804 /* software strips receive CRC, so leave room for it */
805 min_rx_space = adapter->max_frame_size;
806 min_rx_space = ALIGN(min_rx_space, 1024);
809 /* If current Tx allocation is less than the min Tx FIFO size,
810 * and the min Tx FIFO size is less than the current Rx FIFO
811 * allocation, take space away from current Rx allocation */
812 if (tx_space < min_tx_space &&
813 ((min_tx_space - tx_space) < pba)) {
814 pba = pba - (min_tx_space - tx_space);
816 /* if short on rx space, rx wins and must trump tx
818 if (pba < min_rx_space)
822 wr32(E1000_PBA, pba);
824 /* flow control settings */
825 /* The high water mark must be low enough to fit one full frame
826 * (or the size used for early receive) above it in the Rx FIFO.
827 * Set it to the lower of:
828 * - 90% of the Rx FIFO size, or
829 * - the full Rx FIFO size minus one full frame */
830 hwm = min(((pba << 10) * 9 / 10),
831 ((pba << 10) - adapter->max_frame_size));
833 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
834 fc->low_water = fc->high_water - 8;
835 fc->pause_time = 0xFFFF;
837 fc->type = fc->original_type;
839 /* Allow time for pending master requests to run */
840 adapter->hw.mac.ops.reset_hw(&adapter->hw);
843 if (adapter->hw.mac.ops.init_hw(&adapter->hw))
844 dev_err(&adapter->pdev->dev, "Hardware Error\n");
846 igb_update_mng_vlan(adapter);
848 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
849 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
851 igb_reset_adaptive(&adapter->hw);
852 if (adapter->hw.phy.ops.get_phy_info)
853 adapter->hw.phy.ops.get_phy_info(&adapter->hw);
857 * igb_is_need_ioport - determine if an adapter needs ioport resources or not
858 * @pdev: PCI device information struct
860 * Returns true if an adapter needs ioport resources
862 static int igb_is_need_ioport(struct pci_dev *pdev)
864 switch (pdev->device) {
865 /* Currently there are no adapters that need ioport resources */
872 * igb_probe - Device Initialization Routine
873 * @pdev: PCI device information struct
874 * @ent: entry in igb_pci_tbl
876 * Returns 0 on success, negative on failure
878 * igb_probe initializes an adapter identified by a pci_dev structure.
879 * The OS initialization, configuring of the adapter private structure,
880 * and a hardware reset occur.
882 static int __devinit igb_probe(struct pci_dev *pdev,
883 const struct pci_device_id *ent)
885 struct net_device *netdev;
886 struct igb_adapter *adapter;
888 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
889 unsigned long mmio_start, mmio_len;
890 int i, err, pci_using_dac;
892 u16 eeprom_apme_mask = IGB_EEPROM_APME;
894 int bars, need_ioport;
896 /* do not allocate ioport bars when not needed */
897 need_ioport = igb_is_need_ioport(pdev);
899 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
900 err = pci_enable_device(pdev);
902 bars = pci_select_bars(pdev, IORESOURCE_MEM);
903 err = pci_enable_device_mem(pdev);
909 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
911 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
915 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
917 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
919 dev_err(&pdev->dev, "No usable DMA "
920 "configuration, aborting\n");
926 err = pci_request_selected_regions(pdev, bars, igb_driver_name);
930 pci_set_master(pdev);
931 pci_save_state(pdev);
934 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
935 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), IGB_MAX_TX_QUEUES);
937 netdev = alloc_etherdev(sizeof(struct igb_adapter));
938 #endif /* CONFIG_NETDEVICES_MULTIQUEUE */
940 goto err_alloc_etherdev;
942 SET_NETDEV_DEV(netdev, &pdev->dev);
944 pci_set_drvdata(pdev, netdev);
945 adapter = netdev_priv(netdev);
946 adapter->netdev = netdev;
947 adapter->pdev = pdev;
950 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
951 adapter->bars = bars;
952 adapter->need_ioport = need_ioport;
954 mmio_start = pci_resource_start(pdev, 0);
955 mmio_len = pci_resource_len(pdev, 0);
958 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
959 if (!adapter->hw.hw_addr)
962 netdev->open = &igb_open;
963 netdev->stop = &igb_close;
964 netdev->get_stats = &igb_get_stats;
965 netdev->set_multicast_list = &igb_set_multi;
966 netdev->set_mac_address = &igb_set_mac;
967 netdev->change_mtu = &igb_change_mtu;
968 netdev->do_ioctl = &igb_ioctl;
969 igb_set_ethtool_ops(netdev);
970 netdev->tx_timeout = &igb_tx_timeout;
971 netdev->watchdog_timeo = 5 * HZ;
972 netdev->vlan_rx_register = igb_vlan_rx_register;
973 netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
974 netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
975 #ifdef CONFIG_NET_POLL_CONTROLLER
976 netdev->poll_controller = igb_netpoll;
978 netdev->hard_start_xmit = &igb_xmit_frame_adv;
980 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
982 netdev->mem_start = mmio_start;
983 netdev->mem_end = mmio_start + mmio_len;
985 /* PCI config space info */
986 hw->vendor_id = pdev->vendor;
987 hw->device_id = pdev->device;
988 hw->revision_id = pdev->revision;
989 hw->subsystem_vendor_id = pdev->subsystem_vendor;
990 hw->subsystem_device_id = pdev->subsystem_device;
992 /* setup the private structure */
994 /* Copy the default MAC, PHY and NVM function pointers */
995 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
996 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
997 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
998 /* Initialize skew-specific constants */
999 err = ei->get_invariants(hw);
1003 err = igb_sw_init(adapter);
1007 igb_get_bus_info_pcie(hw);
1009 hw->phy.autoneg_wait_to_complete = false;
1010 hw->mac.adaptive_ifs = true;
1012 /* Copper options */
1013 if (hw->phy.media_type == e1000_media_type_copper) {
1014 hw->phy.mdix = AUTO_ALL_MODES;
1015 hw->phy.disable_polarity_correction = false;
1016 hw->phy.ms_type = e1000_ms_hw_default;
1019 if (igb_check_reset_block(hw))
1020 dev_info(&pdev->dev,
1021 "PHY reset is blocked due to SOL/IDER session.\n");
1023 netdev->features = NETIF_F_SG |
1025 NETIF_F_HW_VLAN_TX |
1026 NETIF_F_HW_VLAN_RX |
1027 NETIF_F_HW_VLAN_FILTER;
1029 netdev->features |= NETIF_F_TSO;
1030 netdev->features |= NETIF_F_TSO6;
1032 netdev->vlan_features |= NETIF_F_TSO;
1033 netdev->vlan_features |= NETIF_F_TSO6;
1034 netdev->vlan_features |= NETIF_F_HW_CSUM;
1035 netdev->vlan_features |= NETIF_F_SG;
1038 netdev->features |= NETIF_F_HIGHDMA;
1040 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1041 netdev->features |= NETIF_F_MULTI_QUEUE;
1044 netdev->features |= NETIF_F_LLTX;
1045 adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
1047 /* before reading the NVM, reset the controller to put the device in a
1048 * known good starting state */
1049 hw->mac.ops.reset_hw(hw);
1051 /* make sure the NVM is good */
1052 if (igb_validate_nvm_checksum(hw) < 0) {
1053 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
1058 /* copy the MAC address out of the NVM */
1059 if (hw->mac.ops.read_mac_addr(hw))
1060 dev_err(&pdev->dev, "NVM Read Error\n");
1062 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1063 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1065 if (!is_valid_ether_addr(netdev->perm_addr)) {
1066 dev_err(&pdev->dev, "Invalid MAC Address\n");
1071 init_timer(&adapter->watchdog_timer);
1072 adapter->watchdog_timer.function = &igb_watchdog;
1073 adapter->watchdog_timer.data = (unsigned long) adapter;
1075 init_timer(&adapter->phy_info_timer);
1076 adapter->phy_info_timer.function = &igb_update_phy_info;
1077 adapter->phy_info_timer.data = (unsigned long) adapter;
1079 INIT_WORK(&adapter->reset_task, igb_reset_task);
1080 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
1082 /* Initialize link & ring properties that are user-changeable */
1083 adapter->tx_ring->count = 256;
1084 for (i = 0; i < adapter->num_tx_queues; i++)
1085 adapter->tx_ring[i].count = adapter->tx_ring->count;
1086 adapter->rx_ring->count = 256;
1087 for (i = 0; i < adapter->num_rx_queues; i++)
1088 adapter->rx_ring[i].count = adapter->rx_ring->count;
1090 adapter->fc_autoneg = true;
1091 hw->mac.autoneg = true;
1092 hw->phy.autoneg_advertised = 0x2f;
1094 hw->fc.original_type = e1000_fc_default;
1095 hw->fc.type = e1000_fc_default;
1097 adapter->itr_setting = 3;
1098 adapter->itr = IGB_START_ITR;
1100 igb_validate_mdi_setting(hw);
1102 adapter->rx_csum = 1;
1104 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1105 * enable the ACPI Magic Packet filter
1108 if (hw->bus.func == 0 ||
1109 hw->device_id == E1000_DEV_ID_82575EB_COPPER)
1110 hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1,
1113 if (eeprom_data & eeprom_apme_mask)
1114 adapter->eeprom_wol |= E1000_WUFC_MAG;
1116 /* now that we have the eeprom settings, apply the special cases where
1117 * the eeprom may be wrong or the board simply won't support wake on
1118 * lan on a particular port */
1119 switch (pdev->device) {
1120 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1121 adapter->eeprom_wol = 0;
1123 case E1000_DEV_ID_82575EB_FIBER_SERDES:
1124 /* Wake events only supported on port A for dual fiber
1125 * regardless of eeprom setting */
1126 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
1127 adapter->eeprom_wol = 0;
1131 /* initialize the wol settings based on the eeprom settings */
1132 adapter->wol = adapter->eeprom_wol;
1134 /* reset the hardware with the new settings */
1137 /* let the f/w know that the h/w is now under the control of the
1139 igb_get_hw_control(adapter);
1141 /* tell the stack to leave us alone until igb_open() is called */
1142 netif_carrier_off(netdev);
1143 netif_stop_queue(netdev);
1144 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1145 for (i = 0; i < adapter->num_tx_queues; i++)
1146 netif_stop_subqueue(netdev, i);
1149 strcpy(netdev->name, "eth%d");
1150 err = register_netdev(netdev);
1155 if (dca_add_requester(&pdev->dev) == 0) {
1156 adapter->dca_enabled = true;
1157 dev_info(&pdev->dev, "DCA enabled\n");
1158 /* Always use CB2 mode, difference is masked
1159 * in the CB driver. */
1160 wr32(E1000_DCA_CTRL, 2);
1161 igb_setup_dca(adapter);
1165 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
1166 /* print bus type/speed/width info */
1167 dev_info(&pdev->dev,
1168 "%s: (PCIe:%s:%s) %02x:%02x:%02x:%02x:%02x:%02x\n",
1170 ((hw->bus.speed == e1000_bus_speed_2500)
1171 ? "2.5Gb/s" : "unknown"),
1172 ((hw->bus.width == e1000_bus_width_pcie_x4)
1173 ? "Width x4" : (hw->bus.width == e1000_bus_width_pcie_x1)
1174 ? "Width x1" : "unknown"),
1175 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
1176 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
1178 igb_read_part_num(hw, &part_num);
1179 dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
1180 (part_num >> 8), (part_num & 0xff));
1182 dev_info(&pdev->dev,
1183 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1184 adapter->msix_entries ? "MSI-X" :
1185 adapter->msi_enabled ? "MSI" : "legacy",
1186 adapter->num_rx_queues, adapter->num_tx_queues);
1191 igb_release_hw_control(adapter);
1193 if (!igb_check_reset_block(hw))
1194 hw->phy.ops.reset_phy(hw);
1196 if (hw->flash_address)
1197 iounmap(hw->flash_address);
1199 igb_remove_device(hw);
1200 kfree(adapter->tx_ring);
1201 kfree(adapter->rx_ring);
1204 iounmap(hw->hw_addr);
1206 free_netdev(netdev);
1208 pci_release_selected_regions(pdev, bars);
1211 pci_disable_device(pdev);
1216 * igb_remove - Device Removal Routine
1217 * @pdev: PCI device information struct
1219 * igb_remove is called by the PCI subsystem to alert the driver
1220 * that it should release a PCI device. The could be caused by a
1221 * Hot-Plug event, or because the driver is going to be removed from
1224 static void __devexit igb_remove(struct pci_dev *pdev)
1226 struct net_device *netdev = pci_get_drvdata(pdev);
1227 struct igb_adapter *adapter = netdev_priv(netdev);
1228 struct e1000_hw *hw = &adapter->hw;
1230 /* flush_scheduled work may reschedule our watchdog task, so
1231 * explicitly disable watchdog tasks from being rescheduled */
1232 set_bit(__IGB_DOWN, &adapter->state);
1233 del_timer_sync(&adapter->watchdog_timer);
1234 del_timer_sync(&adapter->phy_info_timer);
1236 flush_scheduled_work();
1239 if (adapter->dca_enabled) {
1240 dev_info(&pdev->dev, "DCA disabled\n");
1241 dca_remove_requester(&pdev->dev);
1242 adapter->dca_enabled = false;
1243 wr32(E1000_DCA_CTRL, 1);
1247 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1248 * would have already happened in close and is redundant. */
1249 igb_release_hw_control(adapter);
1251 unregister_netdev(netdev);
1253 if (!igb_check_reset_block(&adapter->hw))
1254 adapter->hw.phy.ops.reset_phy(&adapter->hw);
1256 igb_remove_device(&adapter->hw);
1257 igb_reset_interrupt_capability(adapter);
1259 kfree(adapter->tx_ring);
1260 kfree(adapter->rx_ring);
1262 iounmap(adapter->hw.hw_addr);
1263 if (adapter->hw.flash_address)
1264 iounmap(adapter->hw.flash_address);
1265 pci_release_selected_regions(pdev, adapter->bars);
1267 free_netdev(netdev);
1269 pci_disable_device(pdev);
1273 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1274 * @adapter: board private structure to initialize
1276 * igb_sw_init initializes the Adapter private data structure.
1277 * Fields are initialized based on PCI device information and
1278 * OS network device settings (MTU size).
1280 static int __devinit igb_sw_init(struct igb_adapter *adapter)
1282 struct e1000_hw *hw = &adapter->hw;
1283 struct net_device *netdev = adapter->netdev;
1284 struct pci_dev *pdev = adapter->pdev;
1286 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
1288 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1289 adapter->rx_ps_hdr_size = 0; /* disable packet split */
1290 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1291 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1293 /* Number of supported queues. */
1294 /* Having more queues than CPUs doesn't make sense. */
1295 adapter->num_rx_queues = min((u32)IGB_MAX_RX_QUEUES, (u32)num_online_cpus());
1296 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1297 adapter->num_tx_queues = min(IGB_MAX_TX_QUEUES, num_online_cpus());
1299 adapter->num_tx_queues = 1;
1300 #endif /* CONFIG_NET_MULTI_QUEUE_DEVICE */
1302 /* This call may decrease the number of queues depending on
1303 * interrupt mode. */
1304 igb_set_interrupt_capability(adapter);
1306 if (igb_alloc_queues(adapter)) {
1307 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
1311 /* Explicitly disable IRQ since the NIC can be in any state. */
1312 igb_irq_disable(adapter);
1314 set_bit(__IGB_DOWN, &adapter->state);
1319 * igb_open - Called when a network interface is made active
1320 * @netdev: network interface device structure
1322 * Returns 0 on success, negative value on failure
1324 * The open entry point is called when a network interface is made
1325 * active by the system (IFF_UP). At this point all resources needed
1326 * for transmit and receive operations are allocated, the interrupt
1327 * handler is registered with the OS, the watchdog timer is started,
1328 * and the stack is notified that the interface is ready.
1330 static int igb_open(struct net_device *netdev)
1332 struct igb_adapter *adapter = netdev_priv(netdev);
1333 struct e1000_hw *hw = &adapter->hw;
1337 /* disallow open during test */
1338 if (test_bit(__IGB_TESTING, &adapter->state))
1341 /* allocate transmit descriptors */
1342 err = igb_setup_all_tx_resources(adapter);
1346 /* allocate receive descriptors */
1347 err = igb_setup_all_rx_resources(adapter);
1351 /* e1000_power_up_phy(adapter); */
1353 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1354 if ((adapter->hw.mng_cookie.status &
1355 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
1356 igb_update_mng_vlan(adapter);
1358 /* before we allocate an interrupt, we must be ready to handle it.
1359 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1360 * as soon as we call pci_request_irq, so we have to setup our
1361 * clean_rx handler before we do so. */
1362 igb_configure(adapter);
1364 err = igb_request_irq(adapter);
1368 /* From here on the code is the same as igb_up() */
1369 clear_bit(__IGB_DOWN, &adapter->state);
1371 for (i = 0; i < adapter->num_rx_queues; i++)
1372 napi_enable(&adapter->rx_ring[i].napi);
1374 /* Clear any pending interrupts. */
1377 igb_irq_enable(adapter);
1379 /* Fire a link status change interrupt to start the watchdog. */
1380 wr32(E1000_ICS, E1000_ICS_LSC);
1385 igb_release_hw_control(adapter);
1386 /* e1000_power_down_phy(adapter); */
1387 igb_free_all_rx_resources(adapter);
1389 igb_free_all_tx_resources(adapter);
1397 * igb_close - Disables a network interface
1398 * @netdev: network interface device structure
1400 * Returns 0, this is not allowed to fail
1402 * The close entry point is called when an interface is de-activated
1403 * by the OS. The hardware is still under the driver's control, but
1404 * needs to be disabled. A global MAC reset is issued to stop the
1405 * hardware, and all transmit and receive resources are freed.
1407 static int igb_close(struct net_device *netdev)
1409 struct igb_adapter *adapter = netdev_priv(netdev);
1411 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
1414 igb_free_irq(adapter);
1416 igb_free_all_tx_resources(adapter);
1417 igb_free_all_rx_resources(adapter);
1419 /* kill manageability vlan ID if supported, but not if a vlan with
1420 * the same ID is registered on the host OS (let 8021q kill it) */
1421 if ((adapter->hw.mng_cookie.status &
1422 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1424 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
1425 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1431 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
1432 * @adapter: board private structure
1433 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1435 * Return 0 on success, negative on failure
1438 int igb_setup_tx_resources(struct igb_adapter *adapter,
1439 struct igb_ring *tx_ring)
1441 struct pci_dev *pdev = adapter->pdev;
1444 size = sizeof(struct igb_buffer) * tx_ring->count;
1445 tx_ring->buffer_info = vmalloc(size);
1446 if (!tx_ring->buffer_info)
1448 memset(tx_ring->buffer_info, 0, size);
1450 /* round up to nearest 4K */
1451 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc)
1453 tx_ring->size = ALIGN(tx_ring->size, 4096);
1455 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
1461 tx_ring->adapter = adapter;
1462 tx_ring->next_to_use = 0;
1463 tx_ring->next_to_clean = 0;
1467 vfree(tx_ring->buffer_info);
1468 dev_err(&adapter->pdev->dev,
1469 "Unable to allocate memory for the transmit descriptor ring\n");
1474 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
1475 * (Descriptors) for all queues
1476 * @adapter: board private structure
1478 * Return 0 on success, negative on failure
1480 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
1483 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1487 for (i = 0; i < adapter->num_tx_queues; i++) {
1488 err = igb_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1490 dev_err(&adapter->pdev->dev,
1491 "Allocation for Tx Queue %u failed\n", i);
1492 for (i--; i >= 0; i--)
1493 igb_free_tx_resources(&adapter->tx_ring[i]);
1498 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1499 for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
1500 r_idx = i % adapter->num_tx_queues;
1501 adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
1508 * igb_configure_tx - Configure transmit Unit after Reset
1509 * @adapter: board private structure
1511 * Configure the Tx unit of the MAC after a reset.
1513 static void igb_configure_tx(struct igb_adapter *adapter)
1516 struct e1000_hw *hw = &adapter->hw;
1521 for (i = 0; i < adapter->num_tx_queues; i++) {
1522 struct igb_ring *ring = &(adapter->tx_ring[i]);
1524 wr32(E1000_TDLEN(i),
1525 ring->count * sizeof(struct e1000_tx_desc));
1527 wr32(E1000_TDBAL(i),
1528 tdba & 0x00000000ffffffffULL);
1529 wr32(E1000_TDBAH(i), tdba >> 32);
1531 tdwba = ring->dma + ring->count * sizeof(struct e1000_tx_desc);
1532 tdwba |= 1; /* enable head wb */
1533 wr32(E1000_TDWBAL(i),
1534 tdwba & 0x00000000ffffffffULL);
1535 wr32(E1000_TDWBAH(i), tdwba >> 32);
1537 ring->head = E1000_TDH(i);
1538 ring->tail = E1000_TDT(i);
1539 writel(0, hw->hw_addr + ring->tail);
1540 writel(0, hw->hw_addr + ring->head);
1541 txdctl = rd32(E1000_TXDCTL(i));
1542 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
1543 wr32(E1000_TXDCTL(i), txdctl);
1545 /* Turn off Relaxed Ordering on head write-backs. The
1546 * writebacks MUST be delivered in order or it will
1547 * completely screw up our bookeeping.
1549 txctrl = rd32(E1000_DCA_TXCTRL(i));
1550 txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
1551 wr32(E1000_DCA_TXCTRL(i), txctrl);
1556 /* Use the default values for the Tx Inter Packet Gap (IPG) timer */
1558 /* Program the Transmit Control Register */
1560 tctl = rd32(E1000_TCTL);
1561 tctl &= ~E1000_TCTL_CT;
1562 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1563 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1565 igb_config_collision_dist(hw);
1567 /* Setup Transmit Descriptor Settings for eop descriptor */
1568 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS;
1570 /* Enable transmits */
1571 tctl |= E1000_TCTL_EN;
1573 wr32(E1000_TCTL, tctl);
1577 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
1578 * @adapter: board private structure
1579 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1581 * Returns 0 on success, negative on failure
1584 int igb_setup_rx_resources(struct igb_adapter *adapter,
1585 struct igb_ring *rx_ring)
1587 struct pci_dev *pdev = adapter->pdev;
1590 size = sizeof(struct igb_buffer) * rx_ring->count;
1591 rx_ring->buffer_info = vmalloc(size);
1592 if (!rx_ring->buffer_info)
1594 memset(rx_ring->buffer_info, 0, size);
1596 desc_len = sizeof(union e1000_adv_rx_desc);
1598 /* Round up to nearest 4K */
1599 rx_ring->size = rx_ring->count * desc_len;
1600 rx_ring->size = ALIGN(rx_ring->size, 4096);
1602 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
1608 rx_ring->next_to_clean = 0;
1609 rx_ring->next_to_use = 0;
1610 rx_ring->pending_skb = NULL;
1612 rx_ring->adapter = adapter;
1617 vfree(rx_ring->buffer_info);
1618 dev_err(&adapter->pdev->dev, "Unable to allocate memory for "
1619 "the receive descriptor ring\n");
1624 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
1625 * (Descriptors) for all queues
1626 * @adapter: board private structure
1628 * Return 0 on success, negative on failure
1630 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
1634 for (i = 0; i < adapter->num_rx_queues; i++) {
1635 err = igb_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1637 dev_err(&adapter->pdev->dev,
1638 "Allocation for Rx Queue %u failed\n", i);
1639 for (i--; i >= 0; i--)
1640 igb_free_rx_resources(&adapter->rx_ring[i]);
1649 * igb_setup_rctl - configure the receive control registers
1650 * @adapter: Board private structure
1652 static void igb_setup_rctl(struct igb_adapter *adapter)
1654 struct e1000_hw *hw = &adapter->hw;
1659 rctl = rd32(E1000_RCTL);
1661 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1663 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1664 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1665 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1667 /* disable the stripping of CRC because it breaks
1668 * BMC firmware connected over SMBUS
1669 rctl |= E1000_RCTL_SECRC;
1672 rctl &= ~E1000_RCTL_SBP;
1674 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1675 rctl &= ~E1000_RCTL_LPE;
1677 rctl |= E1000_RCTL_LPE;
1678 if (adapter->rx_buffer_len <= IGB_RXBUFFER_2048) {
1679 /* Setup buffer sizes */
1680 rctl &= ~E1000_RCTL_SZ_4096;
1681 rctl |= E1000_RCTL_BSEX;
1682 switch (adapter->rx_buffer_len) {
1683 case IGB_RXBUFFER_256:
1684 rctl |= E1000_RCTL_SZ_256;
1685 rctl &= ~E1000_RCTL_BSEX;
1687 case IGB_RXBUFFER_512:
1688 rctl |= E1000_RCTL_SZ_512;
1689 rctl &= ~E1000_RCTL_BSEX;
1691 case IGB_RXBUFFER_1024:
1692 rctl |= E1000_RCTL_SZ_1024;
1693 rctl &= ~E1000_RCTL_BSEX;
1695 case IGB_RXBUFFER_2048:
1697 rctl |= E1000_RCTL_SZ_2048;
1698 rctl &= ~E1000_RCTL_BSEX;
1700 case IGB_RXBUFFER_4096:
1701 rctl |= E1000_RCTL_SZ_4096;
1703 case IGB_RXBUFFER_8192:
1704 rctl |= E1000_RCTL_SZ_8192;
1706 case IGB_RXBUFFER_16384:
1707 rctl |= E1000_RCTL_SZ_16384;
1711 rctl &= ~E1000_RCTL_BSEX;
1712 srrctl = adapter->rx_buffer_len >> E1000_SRRCTL_BSIZEPKT_SHIFT;
1715 /* 82575 and greater support packet-split where the protocol
1716 * header is placed in skb->data and the packet data is
1717 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1718 * In the case of a non-split, skb->data is linearly filled,
1719 * followed by the page buffers. Therefore, skb->data is
1720 * sized to hold the largest protocol header.
1722 /* allocations using alloc_page take too long for regular MTU
1723 * so only enable packet split for jumbo frames */
1724 if (rctl & E1000_RCTL_LPE) {
1725 adapter->rx_ps_hdr_size = IGB_RXBUFFER_128;
1726 srrctl = adapter->rx_ps_hdr_size <<
1727 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
1728 /* buffer size is ALWAYS one page */
1729 srrctl |= PAGE_SIZE >> E1000_SRRCTL_BSIZEPKT_SHIFT;
1730 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1732 adapter->rx_ps_hdr_size = 0;
1733 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
1736 for (i = 0; i < adapter->num_rx_queues; i++)
1737 wr32(E1000_SRRCTL(i), srrctl);
1739 wr32(E1000_RCTL, rctl);
1743 * igb_configure_rx - Configure receive Unit after Reset
1744 * @adapter: board private structure
1746 * Configure the Rx unit of the MAC after a reset.
1748 static void igb_configure_rx(struct igb_adapter *adapter)
1751 struct e1000_hw *hw = &adapter->hw;
1756 /* disable receives while setting up the descriptors */
1757 rctl = rd32(E1000_RCTL);
1758 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1762 if (adapter->itr_setting > 3)
1764 1000000000 / (adapter->itr * 256));
1766 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1767 * the Base and Length of the Rx Descriptor Ring */
1768 for (i = 0; i < adapter->num_rx_queues; i++) {
1769 struct igb_ring *ring = &(adapter->rx_ring[i]);
1771 wr32(E1000_RDBAL(i),
1772 rdba & 0x00000000ffffffffULL);
1773 wr32(E1000_RDBAH(i), rdba >> 32);
1774 wr32(E1000_RDLEN(i),
1775 ring->count * sizeof(union e1000_adv_rx_desc));
1777 ring->head = E1000_RDH(i);
1778 ring->tail = E1000_RDT(i);
1779 writel(0, hw->hw_addr + ring->tail);
1780 writel(0, hw->hw_addr + ring->head);
1782 rxdctl = rd32(E1000_RXDCTL(i));
1783 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
1784 rxdctl &= 0xFFF00000;
1785 rxdctl |= IGB_RX_PTHRESH;
1786 rxdctl |= IGB_RX_HTHRESH << 8;
1787 rxdctl |= IGB_RX_WTHRESH << 16;
1788 wr32(E1000_RXDCTL(i), rxdctl);
1791 if (adapter->num_rx_queues > 1) {
1800 get_random_bytes(&random[0], 40);
1803 for (j = 0; j < (32 * 4); j++) {
1805 (j % adapter->num_rx_queues) << shift;
1808 hw->hw_addr + E1000_RETA(0) + (j & ~3));
1810 mrqc = E1000_MRQC_ENABLE_RSS_4Q;
1812 /* Fill out hash function seeds */
1813 for (j = 0; j < 10; j++)
1814 array_wr32(E1000_RSSRK(0), j, random[j]);
1816 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1817 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1818 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
1819 E1000_MRQC_RSS_FIELD_IPV6_TCP);
1820 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP |
1821 E1000_MRQC_RSS_FIELD_IPV6_UDP);
1822 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
1823 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
1826 wr32(E1000_MRQC, mrqc);
1828 /* Multiqueue and raw packet checksumming are mutually
1829 * exclusive. Note that this not the same as TCP/IP
1830 * checksumming, which works fine. */
1831 rxcsum = rd32(E1000_RXCSUM);
1832 rxcsum |= E1000_RXCSUM_PCSD;
1833 wr32(E1000_RXCSUM, rxcsum);
1835 /* Enable Receive Checksum Offload for TCP and UDP */
1836 rxcsum = rd32(E1000_RXCSUM);
1837 if (adapter->rx_csum) {
1838 rxcsum |= E1000_RXCSUM_TUOFL;
1840 /* Enable IPv4 payload checksum for UDP fragments
1841 * Must be used in conjunction with packet-split. */
1842 if (adapter->rx_ps_hdr_size)
1843 rxcsum |= E1000_RXCSUM_IPPCSE;
1845 rxcsum &= ~E1000_RXCSUM_TUOFL;
1846 /* don't need to clear IPPCSE as it defaults to 0 */
1848 wr32(E1000_RXCSUM, rxcsum);
1853 adapter->max_frame_size + VLAN_TAG_SIZE);
1855 wr32(E1000_RLPML, adapter->max_frame_size);
1857 /* Enable Receives */
1858 wr32(E1000_RCTL, rctl);
1862 * igb_free_tx_resources - Free Tx Resources per Queue
1863 * @adapter: board private structure
1864 * @tx_ring: Tx descriptor ring for a specific queue
1866 * Free all transmit software resources
1868 static void igb_free_tx_resources(struct igb_ring *tx_ring)
1870 struct pci_dev *pdev = tx_ring->adapter->pdev;
1872 igb_clean_tx_ring(tx_ring);
1874 vfree(tx_ring->buffer_info);
1875 tx_ring->buffer_info = NULL;
1877 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1879 tx_ring->desc = NULL;
1883 * igb_free_all_tx_resources - Free Tx Resources for All Queues
1884 * @adapter: board private structure
1886 * Free all transmit software resources
1888 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
1892 for (i = 0; i < adapter->num_tx_queues; i++)
1893 igb_free_tx_resources(&adapter->tx_ring[i]);
1896 static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter,
1897 struct igb_buffer *buffer_info)
1899 if (buffer_info->dma) {
1900 pci_unmap_page(adapter->pdev,
1902 buffer_info->length,
1904 buffer_info->dma = 0;
1906 if (buffer_info->skb) {
1907 dev_kfree_skb_any(buffer_info->skb);
1908 buffer_info->skb = NULL;
1910 buffer_info->time_stamp = 0;
1911 /* buffer_info must be completely set up in the transmit path */
1915 * igb_clean_tx_ring - Free Tx Buffers
1916 * @adapter: board private structure
1917 * @tx_ring: ring to be cleaned
1919 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
1921 struct igb_adapter *adapter = tx_ring->adapter;
1922 struct igb_buffer *buffer_info;
1926 if (!tx_ring->buffer_info)
1928 /* Free all the Tx ring sk_buffs */
1930 for (i = 0; i < tx_ring->count; i++) {
1931 buffer_info = &tx_ring->buffer_info[i];
1932 igb_unmap_and_free_tx_resource(adapter, buffer_info);
1935 size = sizeof(struct igb_buffer) * tx_ring->count;
1936 memset(tx_ring->buffer_info, 0, size);
1938 /* Zero out the descriptor ring */
1940 memset(tx_ring->desc, 0, tx_ring->size);
1942 tx_ring->next_to_use = 0;
1943 tx_ring->next_to_clean = 0;
1945 writel(0, adapter->hw.hw_addr + tx_ring->head);
1946 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1950 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
1951 * @adapter: board private structure
1953 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
1957 for (i = 0; i < adapter->num_tx_queues; i++)
1958 igb_clean_tx_ring(&adapter->tx_ring[i]);
1962 * igb_free_rx_resources - Free Rx Resources
1963 * @adapter: board private structure
1964 * @rx_ring: ring to clean the resources from
1966 * Free all receive software resources
1968 static void igb_free_rx_resources(struct igb_ring *rx_ring)
1970 struct pci_dev *pdev = rx_ring->adapter->pdev;
1972 igb_clean_rx_ring(rx_ring);
1974 vfree(rx_ring->buffer_info);
1975 rx_ring->buffer_info = NULL;
1977 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1979 rx_ring->desc = NULL;
1983 * igb_free_all_rx_resources - Free Rx Resources for All Queues
1984 * @adapter: board private structure
1986 * Free all receive software resources
1988 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
1992 for (i = 0; i < adapter->num_rx_queues; i++)
1993 igb_free_rx_resources(&adapter->rx_ring[i]);
1997 * igb_clean_rx_ring - Free Rx Buffers per Queue
1998 * @adapter: board private structure
1999 * @rx_ring: ring to free buffers from
2001 static void igb_clean_rx_ring(struct igb_ring *rx_ring)
2003 struct igb_adapter *adapter = rx_ring->adapter;
2004 struct igb_buffer *buffer_info;
2005 struct pci_dev *pdev = adapter->pdev;
2009 if (!rx_ring->buffer_info)
2011 /* Free all the Rx ring sk_buffs */
2012 for (i = 0; i < rx_ring->count; i++) {
2013 buffer_info = &rx_ring->buffer_info[i];
2014 if (buffer_info->dma) {
2015 if (adapter->rx_ps_hdr_size)
2016 pci_unmap_single(pdev, buffer_info->dma,
2017 adapter->rx_ps_hdr_size,
2018 PCI_DMA_FROMDEVICE);
2020 pci_unmap_single(pdev, buffer_info->dma,
2021 adapter->rx_buffer_len,
2022 PCI_DMA_FROMDEVICE);
2023 buffer_info->dma = 0;
2026 if (buffer_info->skb) {
2027 dev_kfree_skb(buffer_info->skb);
2028 buffer_info->skb = NULL;
2030 if (buffer_info->page) {
2031 pci_unmap_page(pdev, buffer_info->page_dma,
2032 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2033 put_page(buffer_info->page);
2034 buffer_info->page = NULL;
2035 buffer_info->page_dma = 0;
2039 /* there also may be some cached data from a chained receive */
2040 if (rx_ring->pending_skb) {
2041 dev_kfree_skb(rx_ring->pending_skb);
2042 rx_ring->pending_skb = NULL;
2045 size = sizeof(struct igb_buffer) * rx_ring->count;
2046 memset(rx_ring->buffer_info, 0, size);
2048 /* Zero out the descriptor ring */
2049 memset(rx_ring->desc, 0, rx_ring->size);
2051 rx_ring->next_to_clean = 0;
2052 rx_ring->next_to_use = 0;
2054 writel(0, adapter->hw.hw_addr + rx_ring->head);
2055 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2059 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2060 * @adapter: board private structure
2062 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
2066 for (i = 0; i < adapter->num_rx_queues; i++)
2067 igb_clean_rx_ring(&adapter->rx_ring[i]);
2071 * igb_set_mac - Change the Ethernet Address of the NIC
2072 * @netdev: network interface device structure
2073 * @p: pointer to an address structure
2075 * Returns 0 on success, negative on failure
2077 static int igb_set_mac(struct net_device *netdev, void *p)
2079 struct igb_adapter *adapter = netdev_priv(netdev);
2080 struct sockaddr *addr = p;
2082 if (!is_valid_ether_addr(addr->sa_data))
2083 return -EADDRNOTAVAIL;
2085 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2086 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
2088 adapter->hw.mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2094 * igb_set_multi - Multicast and Promiscuous mode set
2095 * @netdev: network interface device structure
2097 * The set_multi entry point is called whenever the multicast address
2098 * list or the network interface flags are updated. This routine is
2099 * responsible for configuring the hardware for proper multicast,
2100 * promiscuous mode, and all-multi behavior.
2102 static void igb_set_multi(struct net_device *netdev)
2104 struct igb_adapter *adapter = netdev_priv(netdev);
2105 struct e1000_hw *hw = &adapter->hw;
2106 struct e1000_mac_info *mac = &hw->mac;
2107 struct dev_mc_list *mc_ptr;
2112 /* Check for Promiscuous and All Multicast modes */
2114 rctl = rd32(E1000_RCTL);
2116 if (netdev->flags & IFF_PROMISC)
2117 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2118 else if (netdev->flags & IFF_ALLMULTI) {
2119 rctl |= E1000_RCTL_MPE;
2120 rctl &= ~E1000_RCTL_UPE;
2122 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2124 wr32(E1000_RCTL, rctl);
2126 if (!netdev->mc_count) {
2127 /* nothing to program, so clear mc list */
2128 igb_update_mc_addr_list(hw, NULL, 0, 1,
2129 mac->rar_entry_count);
2133 mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC);
2137 /* The shared function expects a packed array of only addresses. */
2138 mc_ptr = netdev->mc_list;
2140 for (i = 0; i < netdev->mc_count; i++) {
2143 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
2144 mc_ptr = mc_ptr->next;
2146 igb_update_mc_addr_list(hw, mta_list, i, 1, mac->rar_entry_count);
2150 /* Need to wait a few seconds after link up to get diagnostic information from
2152 static void igb_update_phy_info(unsigned long data)
2154 struct igb_adapter *adapter = (struct igb_adapter *) data;
2155 if (adapter->hw.phy.ops.get_phy_info)
2156 adapter->hw.phy.ops.get_phy_info(&adapter->hw);
2160 * igb_watchdog - Timer Call-back
2161 * @data: pointer to adapter cast into an unsigned long
2163 static void igb_watchdog(unsigned long data)
2165 struct igb_adapter *adapter = (struct igb_adapter *)data;
2166 /* Do the rest outside of interrupt context */
2167 schedule_work(&adapter->watchdog_task);
2170 static void igb_watchdog_task(struct work_struct *work)
2172 struct igb_adapter *adapter = container_of(work,
2173 struct igb_adapter, watchdog_task);
2174 struct e1000_hw *hw = &adapter->hw;
2176 struct net_device *netdev = adapter->netdev;
2177 struct igb_ring *tx_ring = adapter->tx_ring;
2178 struct e1000_mac_info *mac = &adapter->hw.mac;
2181 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2185 if ((netif_carrier_ok(netdev)) &&
2186 (rd32(E1000_STATUS) & E1000_STATUS_LU))
2189 ret_val = hw->mac.ops.check_for_link(&adapter->hw);
2190 if ((ret_val == E1000_ERR_PHY) &&
2191 (hw->phy.type == e1000_phy_igp_3) &&
2193 E1000_PHY_CTRL_GBE_DISABLE))
2194 dev_info(&adapter->pdev->dev,
2195 "Gigabit has been disabled, downgrading speed\n");
2197 if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
2198 !(rd32(E1000_TXCW) & E1000_TXCW_ANE))
2199 link = mac->serdes_has_link;
2201 link = rd32(E1000_STATUS) &
2205 if (!netif_carrier_ok(netdev)) {
2207 hw->mac.ops.get_speed_and_duplex(&adapter->hw,
2208 &adapter->link_speed,
2209 &adapter->link_duplex);
2211 ctrl = rd32(E1000_CTRL);
2212 dev_info(&adapter->pdev->dev,
2213 "NIC Link is Up %d Mbps %s, "
2214 "Flow Control: %s\n",
2215 adapter->link_speed,
2216 adapter->link_duplex == FULL_DUPLEX ?
2217 "Full Duplex" : "Half Duplex",
2218 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2219 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2220 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2221 E1000_CTRL_TFCE) ? "TX" : "None")));
2223 /* tweak tx_queue_len according to speed/duplex and
2224 * adjust the timeout factor */
2225 netdev->tx_queue_len = adapter->tx_queue_len;
2226 adapter->tx_timeout_factor = 1;
2227 switch (adapter->link_speed) {
2229 netdev->tx_queue_len = 10;
2230 adapter->tx_timeout_factor = 14;
2233 netdev->tx_queue_len = 100;
2234 /* maybe add some timeout factor ? */
2238 netif_carrier_on(netdev);
2239 netif_wake_queue(netdev);
2240 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2241 for (i = 0; i < adapter->num_tx_queues; i++)
2242 netif_wake_subqueue(netdev, i);
2245 if (!test_bit(__IGB_DOWN, &adapter->state))
2246 mod_timer(&adapter->phy_info_timer,
2247 round_jiffies(jiffies + 2 * HZ));
2250 if (netif_carrier_ok(netdev)) {
2251 adapter->link_speed = 0;
2252 adapter->link_duplex = 0;
2253 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
2254 netif_carrier_off(netdev);
2255 netif_stop_queue(netdev);
2256 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2257 for (i = 0; i < adapter->num_tx_queues; i++)
2258 netif_stop_subqueue(netdev, i);
2260 if (!test_bit(__IGB_DOWN, &adapter->state))
2261 mod_timer(&adapter->phy_info_timer,
2262 round_jiffies(jiffies + 2 * HZ));
2267 igb_update_stats(adapter);
2269 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2270 adapter->tpt_old = adapter->stats.tpt;
2271 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
2272 adapter->colc_old = adapter->stats.colc;
2274 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
2275 adapter->gorc_old = adapter->stats.gorc;
2276 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
2277 adapter->gotc_old = adapter->stats.gotc;
2279 igb_update_adaptive(&adapter->hw);
2281 if (!netif_carrier_ok(netdev)) {
2282 if (IGB_DESC_UNUSED(tx_ring) + 1 < tx_ring->count) {
2283 /* We've lost link, so the controller stops DMA,
2284 * but we've got queued Tx work that's never going
2285 * to get done, so reset controller to flush Tx.
2286 * (Do the reset outside of interrupt context). */
2287 adapter->tx_timeout_count++;
2288 schedule_work(&adapter->reset_task);
2292 /* Cause software interrupt to ensure rx ring is cleaned */
2293 wr32(E1000_ICS, E1000_ICS_RXDMT0);
2295 /* Force detection of hung controller every watchdog period */
2296 tx_ring->detect_tx_hung = true;
2298 /* Reset the timer */
2299 if (!test_bit(__IGB_DOWN, &adapter->state))
2300 mod_timer(&adapter->watchdog_timer,
2301 round_jiffies(jiffies + 2 * HZ));
2304 enum latency_range {
2308 latency_invalid = 255
2312 static void igb_lower_rx_eitr(struct igb_adapter *adapter,
2313 struct igb_ring *rx_ring)
2315 struct e1000_hw *hw = &adapter->hw;
2318 new_val = rx_ring->itr_val / 2;
2319 if (new_val < IGB_MIN_DYN_ITR)
2320 new_val = IGB_MIN_DYN_ITR;
2322 if (new_val != rx_ring->itr_val) {
2323 rx_ring->itr_val = new_val;
2324 wr32(rx_ring->itr_register,
2325 1000000000 / (new_val * 256));
2329 static void igb_raise_rx_eitr(struct igb_adapter *adapter,
2330 struct igb_ring *rx_ring)
2332 struct e1000_hw *hw = &adapter->hw;
2335 new_val = rx_ring->itr_val * 2;
2336 if (new_val > IGB_MAX_DYN_ITR)
2337 new_val = IGB_MAX_DYN_ITR;
2339 if (new_val != rx_ring->itr_val) {
2340 rx_ring->itr_val = new_val;
2341 wr32(rx_ring->itr_register,
2342 1000000000 / (new_val * 256));
2347 * igb_update_itr - update the dynamic ITR value based on statistics
2348 * Stores a new ITR value based on packets and byte
2349 * counts during the last interrupt. The advantage of per interrupt
2350 * computation is faster updates and more accurate ITR for the current
2351 * traffic pattern. Constants in this function were computed
2352 * based on theoretical maximum wire speed and thresholds were set based
2353 * on testing data as well as attempting to minimize response time
2354 * while increasing bulk throughput.
2355 * this functionality is controlled by the InterruptThrottleRate module
2356 * parameter (see igb_param.c)
2357 * NOTE: These calculations are only valid when operating in a single-
2358 * queue environment.
2359 * @adapter: pointer to adapter
2360 * @itr_setting: current adapter->itr
2361 * @packets: the number of packets during this measurement interval
2362 * @bytes: the number of bytes during this measurement interval
2364 static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
2365 int packets, int bytes)
2367 unsigned int retval = itr_setting;
2370 goto update_itr_done;
2372 switch (itr_setting) {
2373 case lowest_latency:
2374 /* handle TSO and jumbo frames */
2375 if (bytes/packets > 8000)
2376 retval = bulk_latency;
2377 else if ((packets < 5) && (bytes > 512))
2378 retval = low_latency;
2380 case low_latency: /* 50 usec aka 20000 ints/s */
2381 if (bytes > 10000) {
2382 /* this if handles the TSO accounting */
2383 if (bytes/packets > 8000) {
2384 retval = bulk_latency;
2385 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
2386 retval = bulk_latency;
2387 } else if ((packets > 35)) {
2388 retval = lowest_latency;
2390 } else if (bytes/packets > 2000) {
2391 retval = bulk_latency;
2392 } else if (packets <= 2 && bytes < 512) {
2393 retval = lowest_latency;
2396 case bulk_latency: /* 250 usec aka 4000 ints/s */
2397 if (bytes > 25000) {
2399 retval = low_latency;
2400 } else if (bytes < 6000) {
2401 retval = low_latency;
2410 static void igb_set_itr(struct igb_adapter *adapter, u16 itr_register,
2414 u32 new_itr = adapter->itr;
2416 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2417 if (adapter->link_speed != SPEED_1000) {
2423 adapter->rx_itr = igb_update_itr(adapter,
2425 adapter->rx_ring->total_packets,
2426 adapter->rx_ring->total_bytes);
2427 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2428 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2429 adapter->rx_itr = low_latency;
2432 adapter->tx_itr = igb_update_itr(adapter,
2434 adapter->tx_ring->total_packets,
2435 adapter->tx_ring->total_bytes);
2436 /* conservative mode (itr 3) eliminates the
2437 * lowest_latency setting */
2438 if (adapter->itr_setting == 3 &&
2439 adapter->tx_itr == lowest_latency)
2440 adapter->tx_itr = low_latency;
2442 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2444 current_itr = adapter->rx_itr;
2447 switch (current_itr) {
2448 /* counts and packets in update_itr are dependent on these numbers */
2449 case lowest_latency:
2453 new_itr = 20000; /* aka hwitr = ~200 */
2463 if (new_itr != adapter->itr) {
2464 /* this attempts to bias the interrupt rate towards Bulk
2465 * by adding intermediate steps when interrupt rate is
2467 new_itr = new_itr > adapter->itr ?
2468 min(adapter->itr + (new_itr >> 2), new_itr) :
2470 /* Don't write the value here; it resets the adapter's
2471 * internal timer, and causes us to delay far longer than
2472 * we should between interrupts. Instead, we write the ITR
2473 * value at the beginning of the next interrupt so the timing
2474 * ends up being correct.
2476 adapter->itr = new_itr;
2477 adapter->set_itr = 1;
2484 #define IGB_TX_FLAGS_CSUM 0x00000001
2485 #define IGB_TX_FLAGS_VLAN 0x00000002
2486 #define IGB_TX_FLAGS_TSO 0x00000004
2487 #define IGB_TX_FLAGS_IPV4 0x00000008
2488 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
2489 #define IGB_TX_FLAGS_VLAN_SHIFT 16
2491 static inline int igb_tso_adv(struct igb_adapter *adapter,
2492 struct igb_ring *tx_ring,
2493 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
2495 struct e1000_adv_tx_context_desc *context_desc;
2498 struct igb_buffer *buffer_info;
2499 u32 info = 0, tu_cmd = 0;
2500 u32 mss_l4len_idx, l4len;
2503 if (skb_header_cloned(skb)) {
2504 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2509 l4len = tcp_hdrlen(skb);
2512 if (skb->protocol == htons(ETH_P_IP)) {
2513 struct iphdr *iph = ip_hdr(skb);
2516 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2520 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
2521 ipv6_hdr(skb)->payload_len = 0;
2522 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2523 &ipv6_hdr(skb)->daddr,
2527 i = tx_ring->next_to_use;
2529 buffer_info = &tx_ring->buffer_info[i];
2530 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
2531 /* VLAN MACLEN IPLEN */
2532 if (tx_flags & IGB_TX_FLAGS_VLAN)
2533 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
2534 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
2535 *hdr_len += skb_network_offset(skb);
2536 info |= skb_network_header_len(skb);
2537 *hdr_len += skb_network_header_len(skb);
2538 context_desc->vlan_macip_lens = cpu_to_le32(info);
2540 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2541 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
2543 if (skb->protocol == htons(ETH_P_IP))
2544 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
2545 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2547 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
2550 mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
2551 mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
2553 /* Context index must be unique per ring. Luckily, so is the interrupt
2555 mss_l4len_idx |= tx_ring->eims_value >> 4;
2557 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2558 context_desc->seqnum_seed = 0;
2560 buffer_info->time_stamp = jiffies;
2561 buffer_info->dma = 0;
2563 if (i == tx_ring->count)
2566 tx_ring->next_to_use = i;
2571 static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
2572 struct igb_ring *tx_ring,
2573 struct sk_buff *skb, u32 tx_flags)
2575 struct e1000_adv_tx_context_desc *context_desc;
2577 struct igb_buffer *buffer_info;
2578 u32 info = 0, tu_cmd = 0;
2580 if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
2581 (tx_flags & IGB_TX_FLAGS_VLAN)) {
2582 i = tx_ring->next_to_use;
2583 buffer_info = &tx_ring->buffer_info[i];
2584 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
2586 if (tx_flags & IGB_TX_FLAGS_VLAN)
2587 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
2588 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
2589 if (skb->ip_summed == CHECKSUM_PARTIAL)
2590 info |= skb_network_header_len(skb);
2592 context_desc->vlan_macip_lens = cpu_to_le32(info);
2594 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
2596 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2597 switch (skb->protocol) {
2598 case __constant_htons(ETH_P_IP):
2599 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
2600 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2601 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2603 case __constant_htons(ETH_P_IPV6):
2604 /* XXX what about other V6 headers?? */
2605 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2606 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2609 if (unlikely(net_ratelimit()))
2610 dev_warn(&adapter->pdev->dev,
2611 "partial checksum but proto=%x!\n",
2617 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
2618 context_desc->seqnum_seed = 0;
2619 context_desc->mss_l4len_idx =
2620 cpu_to_le32(tx_ring->queue_index << 4);
2622 buffer_info->time_stamp = jiffies;
2623 buffer_info->dma = 0;
2626 if (i == tx_ring->count)
2628 tx_ring->next_to_use = i;
2637 #define IGB_MAX_TXD_PWR 16
2638 #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
2640 static inline int igb_tx_map_adv(struct igb_adapter *adapter,
2641 struct igb_ring *tx_ring,
2642 struct sk_buff *skb)
2644 struct igb_buffer *buffer_info;
2645 unsigned int len = skb_headlen(skb);
2646 unsigned int count = 0, i;
2649 i = tx_ring->next_to_use;
2651 buffer_info = &tx_ring->buffer_info[i];
2652 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
2653 buffer_info->length = len;
2654 /* set time_stamp *before* dma to help avoid a possible race */
2655 buffer_info->time_stamp = jiffies;
2656 buffer_info->dma = pci_map_single(adapter->pdev, skb->data, len,
2660 if (i == tx_ring->count)
2663 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
2664 struct skb_frag_struct *frag;
2666 frag = &skb_shinfo(skb)->frags[f];
2669 buffer_info = &tx_ring->buffer_info[i];
2670 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
2671 buffer_info->length = len;
2672 buffer_info->time_stamp = jiffies;
2673 buffer_info->dma = pci_map_page(adapter->pdev,
2681 if (i == tx_ring->count)
2685 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2686 tx_ring->buffer_info[i].skb = skb;
2691 static inline void igb_tx_queue_adv(struct igb_adapter *adapter,
2692 struct igb_ring *tx_ring,
2693 int tx_flags, int count, u32 paylen,
2696 union e1000_adv_tx_desc *tx_desc = NULL;
2697 struct igb_buffer *buffer_info;
2698 u32 olinfo_status = 0, cmd_type_len;
2701 cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
2702 E1000_ADVTXD_DCMD_DEXT);
2704 if (tx_flags & IGB_TX_FLAGS_VLAN)
2705 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
2707 if (tx_flags & IGB_TX_FLAGS_TSO) {
2708 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
2710 /* insert tcp checksum */
2711 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2713 /* insert ip checksum */
2714 if (tx_flags & IGB_TX_FLAGS_IPV4)
2715 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
2717 } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
2718 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2721 if (tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_TSO |
2723 olinfo_status |= tx_ring->queue_index << 4;
2725 olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
2727 i = tx_ring->next_to_use;
2729 buffer_info = &tx_ring->buffer_info[i];
2730 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
2731 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
2732 tx_desc->read.cmd_type_len =
2733 cpu_to_le32(cmd_type_len | buffer_info->length);
2734 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
2736 if (i == tx_ring->count)
2740 tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
2741 /* Force memory writes to complete before letting h/w
2742 * know there are new descriptors to fetch. (Only
2743 * applicable for weak-ordered memory model archs,
2744 * such as IA-64). */
2747 tx_ring->next_to_use = i;
2748 writel(i, adapter->hw.hw_addr + tx_ring->tail);
2749 /* we need this if more than one processor can write to our tail
2750 * at a time, it syncronizes IO on IA64/Altix systems */
2754 static int __igb_maybe_stop_tx(struct net_device *netdev,
2755 struct igb_ring *tx_ring, int size)
2757 struct igb_adapter *adapter = netdev_priv(netdev);
2759 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2760 netif_stop_subqueue(netdev, tx_ring->queue_index);
2762 netif_stop_queue(netdev);
2765 /* Herbert's original patch had:
2766 * smp_mb__after_netif_stop_queue();
2767 * but since that doesn't exist yet, just open code it. */
2770 /* We need to check again in a case another CPU has just
2771 * made room available. */
2772 if (IGB_DESC_UNUSED(tx_ring) < size)
2776 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2777 netif_wake_subqueue(netdev, tx_ring->queue_index);
2779 netif_wake_queue(netdev);
2781 ++adapter->restart_queue;
2785 static int igb_maybe_stop_tx(struct net_device *netdev,
2786 struct igb_ring *tx_ring, int size)
2788 if (IGB_DESC_UNUSED(tx_ring) >= size)
2790 return __igb_maybe_stop_tx(netdev, tx_ring, size);
2793 #define TXD_USE_COUNT(S) (((S) >> (IGB_MAX_TXD_PWR)) + 1)
2795 static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
2796 struct net_device *netdev,
2797 struct igb_ring *tx_ring)
2799 struct igb_adapter *adapter = netdev_priv(netdev);
2800 unsigned int tx_flags = 0;
2805 len = skb_headlen(skb);
2807 if (test_bit(__IGB_DOWN, &adapter->state)) {
2808 dev_kfree_skb_any(skb);
2809 return NETDEV_TX_OK;
2812 if (skb->len <= 0) {
2813 dev_kfree_skb_any(skb);
2814 return NETDEV_TX_OK;
2817 /* need: 1 descriptor per page,
2818 * + 2 desc gap to keep tail from touching head,
2819 * + 1 desc for skb->data,
2820 * + 1 desc for context descriptor,
2821 * otherwise try next time */
2822 if (igb_maybe_stop_tx(netdev, tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
2823 /* this is a hard error */
2824 return NETDEV_TX_BUSY;
2827 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
2828 tx_flags |= IGB_TX_FLAGS_VLAN;
2829 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
2832 if (skb->protocol == htons(ETH_P_IP))
2833 tx_flags |= IGB_TX_FLAGS_IPV4;
2835 tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags,
2839 dev_kfree_skb_any(skb);
2840 return NETDEV_TX_OK;
2844 tx_flags |= IGB_TX_FLAGS_TSO;
2845 else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags))
2846 if (skb->ip_summed == CHECKSUM_PARTIAL)
2847 tx_flags |= IGB_TX_FLAGS_CSUM;
2849 igb_tx_queue_adv(adapter, tx_ring, tx_flags,
2850 igb_tx_map_adv(adapter, tx_ring, skb),
2853 netdev->trans_start = jiffies;
2855 /* Make sure there is space in the ring for the next send. */
2856 igb_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 4);
2858 return NETDEV_TX_OK;
2861 static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *netdev)
2863 struct igb_adapter *adapter = netdev_priv(netdev);
2864 struct igb_ring *tx_ring;
2866 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2868 r_idx = skb->queue_mapping & (IGB_MAX_TX_QUEUES - 1);
2869 tx_ring = adapter->multi_tx_table[r_idx];
2871 tx_ring = &adapter->tx_ring[0];
2875 /* This goes back to the question of how to logically map a tx queue
2876 * to a flow. Right now, performance is impacted slightly negatively
2877 * if using multiple tx queues. If the stack breaks away from a
2878 * single qdisc implementation, we can look at this again. */
2879 return (igb_xmit_frame_ring_adv(skb, netdev, tx_ring));
2883 * igb_tx_timeout - Respond to a Tx Hang
2884 * @netdev: network interface device structure
2886 static void igb_tx_timeout(struct net_device *netdev)
2888 struct igb_adapter *adapter = netdev_priv(netdev);
2889 struct e1000_hw *hw = &adapter->hw;
2891 /* Do the reset outside of interrupt context */
2892 adapter->tx_timeout_count++;
2893 schedule_work(&adapter->reset_task);
2894 wr32(E1000_EICS, adapter->eims_enable_mask &
2895 ~(E1000_EIMS_TCP_TIMER | E1000_EIMS_OTHER));
2898 static void igb_reset_task(struct work_struct *work)
2900 struct igb_adapter *adapter;
2901 adapter = container_of(work, struct igb_adapter, reset_task);
2903 igb_reinit_locked(adapter);
2907 * igb_get_stats - Get System Network Statistics
2908 * @netdev: network interface device structure
2910 * Returns the address of the device statistics structure.
2911 * The statistics are actually updated from the timer callback.
2913 static struct net_device_stats *
2914 igb_get_stats(struct net_device *netdev)
2916 struct igb_adapter *adapter = netdev_priv(netdev);
2918 /* only return the current stats */
2919 return &adapter->net_stats;
2923 * igb_change_mtu - Change the Maximum Transfer Unit
2924 * @netdev: network interface device structure
2925 * @new_mtu: new value for maximum frame size
2927 * Returns 0 on success, negative on failure
2929 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
2931 struct igb_adapter *adapter = netdev_priv(netdev);
2932 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2934 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
2935 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2936 dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
2940 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2941 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2942 dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
2946 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
2948 /* igb_down has a dependency on max_frame_size */
2949 adapter->max_frame_size = max_frame;
2950 if (netif_running(netdev))
2953 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
2954 * means we reserve 2 more, this pushes us to allocate from the next
2956 * i.e. RXBUFFER_2048 --> size-4096 slab
2959 if (max_frame <= IGB_RXBUFFER_256)
2960 adapter->rx_buffer_len = IGB_RXBUFFER_256;
2961 else if (max_frame <= IGB_RXBUFFER_512)
2962 adapter->rx_buffer_len = IGB_RXBUFFER_512;
2963 else if (max_frame <= IGB_RXBUFFER_1024)
2964 adapter->rx_buffer_len = IGB_RXBUFFER_1024;
2965 else if (max_frame <= IGB_RXBUFFER_2048)
2966 adapter->rx_buffer_len = IGB_RXBUFFER_2048;
2968 adapter->rx_buffer_len = IGB_RXBUFFER_4096;
2969 /* adjust allocation if LPE protects us, and we aren't using SBP */
2970 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
2971 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))
2972 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
2974 dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
2975 netdev->mtu, new_mtu);
2976 netdev->mtu = new_mtu;
2978 if (netif_running(netdev))
2983 clear_bit(__IGB_RESETTING, &adapter->state);
2989 * igb_update_stats - Update the board statistics counters
2990 * @adapter: board private structure
2993 void igb_update_stats(struct igb_adapter *adapter)
2995 struct e1000_hw *hw = &adapter->hw;
2996 struct pci_dev *pdev = adapter->pdev;
2999 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3002 * Prevent stats update while adapter is being reset, or if the pci
3003 * connection is down.
3005 if (adapter->link_speed == 0)
3007 if (pci_channel_offline(pdev))
3010 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
3011 adapter->stats.gprc += rd32(E1000_GPRC);
3012 adapter->stats.gorc += rd32(E1000_GORCL);
3013 rd32(E1000_GORCH); /* clear GORCL */
3014 adapter->stats.bprc += rd32(E1000_BPRC);
3015 adapter->stats.mprc += rd32(E1000_MPRC);
3016 adapter->stats.roc += rd32(E1000_ROC);
3018 adapter->stats.prc64 += rd32(E1000_PRC64);
3019 adapter->stats.prc127 += rd32(E1000_PRC127);
3020 adapter->stats.prc255 += rd32(E1000_PRC255);
3021 adapter->stats.prc511 += rd32(E1000_PRC511);
3022 adapter->stats.prc1023 += rd32(E1000_PRC1023);
3023 adapter->stats.prc1522 += rd32(E1000_PRC1522);
3024 adapter->stats.symerrs += rd32(E1000_SYMERRS);
3025 adapter->stats.sec += rd32(E1000_SEC);
3027 adapter->stats.mpc += rd32(E1000_MPC);
3028 adapter->stats.scc += rd32(E1000_SCC);
3029 adapter->stats.ecol += rd32(E1000_ECOL);
3030 adapter->stats.mcc += rd32(E1000_MCC);
3031 adapter->stats.latecol += rd32(E1000_LATECOL);
3032 adapter->stats.dc += rd32(E1000_DC);
3033 adapter->stats.rlec += rd32(E1000_RLEC);
3034 adapter->stats.xonrxc += rd32(E1000_XONRXC);
3035 adapter->stats.xontxc += rd32(E1000_XONTXC);
3036 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
3037 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
3038 adapter->stats.fcruc += rd32(E1000_FCRUC);
3039 adapter->stats.gptc += rd32(E1000_GPTC);
3040 adapter->stats.gotc += rd32(E1000_GOTCL);
3041 rd32(E1000_GOTCH); /* clear GOTCL */
3042 adapter->stats.rnbc += rd32(E1000_RNBC);
3043 adapter->stats.ruc += rd32(E1000_RUC);
3044 adapter->stats.rfc += rd32(E1000_RFC);
3045 adapter->stats.rjc += rd32(E1000_RJC);
3046 adapter->stats.tor += rd32(E1000_TORH);
3047 adapter->stats.tot += rd32(E1000_TOTH);
3048 adapter->stats.tpr += rd32(E1000_TPR);
3050 adapter->stats.ptc64 += rd32(E1000_PTC64);
3051 adapter->stats.ptc127 += rd32(E1000_PTC127);
3052 adapter->stats.ptc255 += rd32(E1000_PTC255);
3053 adapter->stats.ptc511 += rd32(E1000_PTC511);
3054 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
3055 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
3057 adapter->stats.mptc += rd32(E1000_MPTC);
3058 adapter->stats.bptc += rd32(E1000_BPTC);
3060 /* used for adaptive IFS */
3062 hw->mac.tx_packet_delta = rd32(E1000_TPT);
3063 adapter->stats.tpt += hw->mac.tx_packet_delta;
3064 hw->mac.collision_delta = rd32(E1000_COLC);
3065 adapter->stats.colc += hw->mac.collision_delta;
3067 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
3068 adapter->stats.rxerrc += rd32(E1000_RXERRC);
3069 adapter->stats.tncrs += rd32(E1000_TNCRS);
3070 adapter->stats.tsctc += rd32(E1000_TSCTC);
3071 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
3073 adapter->stats.iac += rd32(E1000_IAC);
3074 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
3075 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
3076 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
3077 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
3078 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
3079 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
3080 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
3081 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
3083 /* Fill out the OS statistics structure */
3084 adapter->net_stats.multicast = adapter->stats.mprc;
3085 adapter->net_stats.collisions = adapter->stats.colc;
3089 /* RLEC on some newer hardware can be incorrect so build
3090 * our own version based on RUC and ROC */
3091 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3092 adapter->stats.crcerrs + adapter->stats.algnerrc +
3093 adapter->stats.ruc + adapter->stats.roc +
3094 adapter->stats.cexterr;
3095 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3097 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3098 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3099 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3102 adapter->net_stats.tx_errors = adapter->stats.ecol +
3103 adapter->stats.latecol;
3104 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3105 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3106 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3108 /* Tx Dropped needs to be maintained elsewhere */
3111 if (hw->phy.media_type == e1000_media_type_copper) {
3112 if ((adapter->link_speed == SPEED_1000) &&
3113 (!hw->phy.ops.read_phy_reg(hw, PHY_1000T_STATUS,
3115 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3116 adapter->phy_stats.idle_errors += phy_tmp;
3120 /* Management Stats */
3121 adapter->stats.mgptc += rd32(E1000_MGTPTC);
3122 adapter->stats.mgprc += rd32(E1000_MGTPRC);
3123 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
3127 static irqreturn_t igb_msix_other(int irq, void *data)
3129 struct net_device *netdev = data;
3130 struct igb_adapter *adapter = netdev_priv(netdev);
3131 struct e1000_hw *hw = &adapter->hw;
3132 u32 icr = rd32(E1000_ICR);
3134 /* reading ICR causes bit 31 of EICR to be cleared */
3135 if (!(icr & E1000_ICR_LSC))
3136 goto no_link_interrupt;
3137 hw->mac.get_link_status = 1;
3138 /* guard against interrupt when we're going down */
3139 if (!test_bit(__IGB_DOWN, &adapter->state))
3140 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3143 wr32(E1000_IMS, E1000_IMS_LSC);
3144 wr32(E1000_EIMS, adapter->eims_other);
3149 static irqreturn_t igb_msix_tx(int irq, void *data)
3151 struct igb_ring *tx_ring = data;
3152 struct igb_adapter *adapter = tx_ring->adapter;
3153 struct e1000_hw *hw = &adapter->hw;
3155 if (!tx_ring->itr_val)
3156 wr32(E1000_EIMC, tx_ring->eims_value);
3158 if (adapter->dca_enabled)
3159 igb_update_tx_dca(tx_ring);
3161 tx_ring->total_bytes = 0;
3162 tx_ring->total_packets = 0;
3164 /* auto mask will automatically reenable the interrupt when we write
3166 if (!igb_clean_tx_irq(tx_ring))
3167 /* Ring was not completely cleaned, so fire another interrupt */
3168 wr32(E1000_EICS, tx_ring->eims_value);
3170 wr32(E1000_EIMS, tx_ring->eims_value);
3175 static irqreturn_t igb_msix_rx(int irq, void *data)
3177 struct igb_ring *rx_ring = data;
3178 struct igb_adapter *adapter = rx_ring->adapter;
3179 struct e1000_hw *hw = &adapter->hw;
3181 /* Write the ITR value calculated at the end of the
3182 * previous interrupt.
3185 if (adapter->set_itr) {
3186 wr32(rx_ring->itr_register,
3187 1000000000 / (rx_ring->itr_val * 256));
3188 adapter->set_itr = 0;
3191 if (netif_rx_schedule_prep(adapter->netdev, &rx_ring->napi))
3192 __netif_rx_schedule(adapter->netdev, &rx_ring->napi);
3195 if (adapter->dca_enabled)
3196 igb_update_rx_dca(rx_ring);
3202 static void igb_update_rx_dca(struct igb_ring *rx_ring)
3205 struct igb_adapter *adapter = rx_ring->adapter;
3206 struct e1000_hw *hw = &adapter->hw;
3207 int cpu = get_cpu();
3208 int q = rx_ring - adapter->rx_ring;
3210 if (rx_ring->cpu != cpu) {
3211 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
3212 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
3213 dca_rxctrl |= dca_get_tag(cpu);
3214 dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
3215 dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
3216 dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
3217 wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
3223 static void igb_update_tx_dca(struct igb_ring *tx_ring)
3226 struct igb_adapter *adapter = tx_ring->adapter;
3227 struct e1000_hw *hw = &adapter->hw;
3228 int cpu = get_cpu();
3229 int q = tx_ring - adapter->tx_ring;
3231 if (tx_ring->cpu != cpu) {
3232 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
3233 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
3234 dca_txctrl |= dca_get_tag(cpu);
3235 dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
3236 wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
3242 static void igb_setup_dca(struct igb_adapter *adapter)
3246 if (!(adapter->dca_enabled))
3249 for (i = 0; i < adapter->num_tx_queues; i++) {
3250 adapter->tx_ring[i].cpu = -1;
3251 igb_update_tx_dca(&adapter->tx_ring[i]);
3253 for (i = 0; i < adapter->num_rx_queues; i++) {
3254 adapter->rx_ring[i].cpu = -1;
3255 igb_update_rx_dca(&adapter->rx_ring[i]);
3259 static int __igb_notify_dca(struct device *dev, void *data)
3261 struct net_device *netdev = dev_get_drvdata(dev);
3262 struct igb_adapter *adapter = netdev_priv(netdev);
3263 struct e1000_hw *hw = &adapter->hw;
3264 unsigned long event = *(unsigned long *)data;
3267 case DCA_PROVIDER_ADD:
3268 /* if already enabled, don't do it again */
3269 if (adapter->dca_enabled)
3271 adapter->dca_enabled = true;
3272 /* Always use CB2 mode, difference is masked
3273 * in the CB driver. */
3274 wr32(E1000_DCA_CTRL, 2);
3275 if (dca_add_requester(dev) == 0) {
3276 dev_info(&adapter->pdev->dev, "DCA enabled\n");
3277 igb_setup_dca(adapter);
3280 /* Fall Through since DCA is disabled. */
3281 case DCA_PROVIDER_REMOVE:
3282 if (adapter->dca_enabled) {
3283 /* without this a class_device is left
3284 * hanging around in the sysfs model */
3285 dca_remove_requester(dev);
3286 dev_info(&adapter->pdev->dev, "DCA disabled\n");
3287 adapter->dca_enabled = false;
3288 wr32(E1000_DCA_CTRL, 1);
3296 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
3301 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
3304 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
3306 #endif /* CONFIG_DCA */
3309 * igb_intr_msi - Interrupt Handler
3310 * @irq: interrupt number
3311 * @data: pointer to a network interface device structure
3313 static irqreturn_t igb_intr_msi(int irq, void *data)
3315 struct net_device *netdev = data;
3316 struct igb_adapter *adapter = netdev_priv(netdev);
3317 struct e1000_hw *hw = &adapter->hw;
3318 /* read ICR disables interrupts using IAM */
3319 u32 icr = rd32(E1000_ICR);
3321 /* Write the ITR value calculated at the end of the
3322 * previous interrupt.
3324 if (adapter->set_itr) {
3325 wr32(E1000_ITR, 1000000000 / (adapter->itr * 256));
3326 adapter->set_itr = 0;
3329 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3330 hw->mac.get_link_status = 1;
3331 if (!test_bit(__IGB_DOWN, &adapter->state))
3332 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3335 netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
3341 * igb_intr - Interrupt Handler
3342 * @irq: interrupt number
3343 * @data: pointer to a network interface device structure
3345 static irqreturn_t igb_intr(int irq, void *data)
3347 struct net_device *netdev = data;
3348 struct igb_adapter *adapter = netdev_priv(netdev);
3349 struct e1000_hw *hw = &adapter->hw;
3350 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3351 * need for the IMC write */
3352 u32 icr = rd32(E1000_ICR);
3355 return IRQ_NONE; /* Not our interrupt */
3357 /* Write the ITR value calculated at the end of the
3358 * previous interrupt.
3360 if (adapter->set_itr) {
3361 wr32(E1000_ITR, 1000000000 / (adapter->itr * 256));
3362 adapter->set_itr = 0;
3365 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3366 * not set, then the adapter didn't send an interrupt */
3367 if (!(icr & E1000_ICR_INT_ASSERTED))
3370 eicr = rd32(E1000_EICR);
3372 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3373 hw->mac.get_link_status = 1;
3374 /* guard against interrupt when we're going down */
3375 if (!test_bit(__IGB_DOWN, &adapter->state))
3376 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3379 netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
3385 * igb_poll - NAPI Rx polling callback
3386 * @napi: napi polling structure
3387 * @budget: count of how many packets we should handle
3389 static int igb_poll(struct napi_struct *napi, int budget)
3391 struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
3392 struct igb_adapter *adapter = rx_ring->adapter;
3393 struct net_device *netdev = adapter->netdev;
3394 int tx_clean_complete, work_done = 0;
3396 /* this poll routine only supports one tx and one rx queue */
3398 if (adapter->dca_enabled)
3399 igb_update_tx_dca(&adapter->tx_ring[0]);
3401 tx_clean_complete = igb_clean_tx_irq(&adapter->tx_ring[0]);
3404 if (adapter->dca_enabled)
3405 igb_update_rx_dca(&adapter->rx_ring[0]);
3407 igb_clean_rx_irq_adv(&adapter->rx_ring[0], &work_done, budget);
3409 /* If no Tx and not enough Rx work done, exit the polling mode */
3410 if ((tx_clean_complete && (work_done < budget)) ||
3411 !netif_running(netdev)) {
3412 if (adapter->itr_setting & 3)
3413 igb_set_itr(adapter, E1000_ITR, false);
3414 netif_rx_complete(netdev, napi);
3415 if (!test_bit(__IGB_DOWN, &adapter->state))
3416 igb_irq_enable(adapter);
3423 static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
3425 struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
3426 struct igb_adapter *adapter = rx_ring->adapter;
3427 struct e1000_hw *hw = &adapter->hw;
3428 struct net_device *netdev = adapter->netdev;
3431 /* Keep link state information with original netdev */
3432 if (!netif_carrier_ok(netdev))
3436 if (adapter->dca_enabled)
3437 igb_update_rx_dca(rx_ring);
3439 igb_clean_rx_irq_adv(rx_ring, &work_done, budget);
3442 /* If not enough Rx work done, exit the polling mode */
3443 if ((work_done == 0) || !netif_running(netdev)) {
3445 netif_rx_complete(netdev, napi);
3447 wr32(E1000_EIMS, rx_ring->eims_value);
3448 if ((adapter->itr_setting & 3) && !rx_ring->no_itr_adjust &&
3449 (rx_ring->total_packets > IGB_DYN_ITR_PACKET_THRESHOLD)) {
3450 int mean_size = rx_ring->total_bytes /
3451 rx_ring->total_packets;
3452 if (mean_size < IGB_DYN_ITR_LENGTH_LOW)
3453 igb_raise_rx_eitr(adapter, rx_ring);
3454 else if (mean_size > IGB_DYN_ITR_LENGTH_HIGH)
3455 igb_lower_rx_eitr(adapter, rx_ring);
3458 if (!test_bit(__IGB_DOWN, &adapter->state))
3459 wr32(E1000_EIMS, rx_ring->eims_value);
3467 static inline u32 get_head(struct igb_ring *tx_ring)
3469 void *end = (struct e1000_tx_desc *)tx_ring->desc + tx_ring->count;
3470 return le32_to_cpu(*(volatile __le32 *)end);
3474 * igb_clean_tx_irq - Reclaim resources after transmit completes
3475 * @adapter: board private structure
3476 * returns true if ring is completely cleaned
3478 static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
3480 struct igb_adapter *adapter = tx_ring->adapter;
3481 struct e1000_hw *hw = &adapter->hw;
3482 struct net_device *netdev = adapter->netdev;
3483 struct e1000_tx_desc *tx_desc;
3484 struct igb_buffer *buffer_info;
3485 struct sk_buff *skb;
3488 unsigned int count = 0;
3489 bool cleaned = false;
3491 unsigned int total_bytes = 0, total_packets = 0;
3494 head = get_head(tx_ring);
3495 i = tx_ring->next_to_clean;
3499 tx_desc = E1000_TX_DESC(*tx_ring, i);
3500 buffer_info = &tx_ring->buffer_info[i];
3501 skb = buffer_info->skb;
3504 unsigned int segs, bytecount;
3505 /* gso_segs is currently only valid for tcp */
3506 segs = skb_shinfo(skb)->gso_segs ?: 1;
3507 /* multiply data chunks by size of headers */
3508 bytecount = ((segs - 1) * skb_headlen(skb)) +
3510 total_packets += segs;
3511 total_bytes += bytecount;
3514 igb_unmap_and_free_tx_resource(adapter, buffer_info);
3515 tx_desc->upper.data = 0;
3518 if (i == tx_ring->count)
3522 if (count == IGB_MAX_TX_CLEAN) {
3529 head = get_head(tx_ring);
3530 if (head == oldhead)
3535 tx_ring->next_to_clean = i;
3537 if (unlikely(cleaned &&
3538 netif_carrier_ok(netdev) &&
3539 IGB_DESC_UNUSED(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
3540 /* Make sure that anybody stopping the queue after this
3541 * sees the new next_to_clean.
3544 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3545 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
3546 !(test_bit(__IGB_DOWN, &adapter->state))) {
3547 netif_wake_subqueue(netdev, tx_ring->queue_index);
3548 ++adapter->restart_queue;
3551 if (netif_queue_stopped(netdev) &&
3552 !(test_bit(__IGB_DOWN, &adapter->state))) {
3553 netif_wake_queue(netdev);
3554 ++adapter->restart_queue;
3559 if (tx_ring->detect_tx_hung) {
3560 /* Detect a transmit hang in hardware, this serializes the
3561 * check with the clearing of time_stamp and movement of i */
3562 tx_ring->detect_tx_hung = false;
3563 if (tx_ring->buffer_info[i].time_stamp &&
3564 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
3565 (adapter->tx_timeout_factor * HZ))
3566 && !(rd32(E1000_STATUS) &
3567 E1000_STATUS_TXOFF)) {
3569 tx_desc = E1000_TX_DESC(*tx_ring, i);
3570 /* detected Tx unit hang */
3571 dev_err(&adapter->pdev->dev,
3572 "Detected Tx Unit Hang\n"
3576 " next_to_use <%x>\n"
3577 " next_to_clean <%x>\n"
3579 "buffer_info[next_to_clean]\n"
3580 " time_stamp <%lx>\n"
3582 " desc.status <%x>\n",
3583 (unsigned long)((tx_ring - adapter->tx_ring) /
3584 sizeof(struct igb_ring)),
3585 readl(adapter->hw.hw_addr + tx_ring->head),
3586 readl(adapter->hw.hw_addr + tx_ring->tail),
3587 tx_ring->next_to_use,
3588 tx_ring->next_to_clean,
3590 tx_ring->buffer_info[i].time_stamp,
3592 tx_desc->upper.fields.status);
3593 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
3594 netif_stop_subqueue(netdev, tx_ring->queue_index);
3596 netif_stop_queue(netdev);
3600 tx_ring->total_bytes += total_bytes;
3601 tx_ring->total_packets += total_packets;
3602 tx_ring->tx_stats.bytes += total_bytes;
3603 tx_ring->tx_stats.packets += total_packets;
3604 adapter->net_stats.tx_bytes += total_bytes;
3605 adapter->net_stats.tx_packets += total_packets;
3611 * igb_receive_skb - helper function to handle rx indications
3612 * @adapter: board private structure
3613 * @status: descriptor status field as written by hardware
3614 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3615 * @skb: pointer to sk_buff to be indicated to stack
3617 static void igb_receive_skb(struct igb_adapter *adapter, u8 status, __le16 vlan,
3618 struct sk_buff *skb)
3620 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
3621 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3624 netif_receive_skb(skb);
3628 static inline void igb_rx_checksum_adv(struct igb_adapter *adapter,
3629 u32 status_err, struct sk_buff *skb)
3631 skb->ip_summed = CHECKSUM_NONE;
3633 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
3634 if ((status_err & E1000_RXD_STAT_IXSM) || !adapter->rx_csum)
3636 /* TCP/UDP checksum error bit is set */
3638 (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
3639 /* let the stack verify checksum errors */
3640 adapter->hw_csum_err++;
3643 /* It must be a TCP or UDP packet with a valid checksum */
3644 if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
3645 skb->ip_summed = CHECKSUM_UNNECESSARY;
3647 adapter->hw_csum_good++;
3650 static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
3651 int *work_done, int budget)
3653 struct igb_adapter *adapter = rx_ring->adapter;
3654 struct net_device *netdev = adapter->netdev;
3655 struct pci_dev *pdev = adapter->pdev;
3656 union e1000_adv_rx_desc *rx_desc , *next_rxd;
3657 struct igb_buffer *buffer_info , *next_buffer;
3658 struct sk_buff *skb;
3660 u32 length, hlen, staterr;
3661 bool cleaned = false;
3662 int cleaned_count = 0;
3663 unsigned int total_bytes = 0, total_packets = 0;
3665 i = rx_ring->next_to_clean;
3666 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
3667 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
3669 while (staterr & E1000_RXD_STAT_DD) {
3670 if (*work_done >= budget)
3673 buffer_info = &rx_ring->buffer_info[i];
3675 /* HW will not DMA in data larger than the given buffer, even
3676 * if it parses the (NFS, of course) header to be larger. In
3677 * that case, it fills the header buffer and spills the rest
3680 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
3681 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
3682 if (hlen > adapter->rx_ps_hdr_size)
3683 hlen = adapter->rx_ps_hdr_size;
3685 length = le16_to_cpu(rx_desc->wb.upper.length);
3689 if (rx_ring->pending_skb != NULL) {
3690 skb = rx_ring->pending_skb;
3691 rx_ring->pending_skb = NULL;
3692 j = rx_ring->pending_skb_page;
3694 skb = buffer_info->skb;
3695 prefetch(skb->data - NET_IP_ALIGN);
3696 buffer_info->skb = NULL;
3698 pci_unmap_single(pdev, buffer_info->dma,
3699 adapter->rx_ps_hdr_size +
3701 PCI_DMA_FROMDEVICE);
3704 pci_unmap_single(pdev, buffer_info->dma,
3705 adapter->rx_buffer_len +
3707 PCI_DMA_FROMDEVICE);
3708 skb_put(skb, length);
3715 pci_unmap_page(pdev, buffer_info->page_dma,
3716 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3717 buffer_info->page_dma = 0;
3718 skb_fill_page_desc(skb, j, buffer_info->page,
3720 buffer_info->page = NULL;
3723 skb->data_len += length;
3724 skb->truesize += length;
3725 rx_desc->wb.upper.status_error = 0;
3726 if (staterr & E1000_RXD_STAT_EOP)
3732 if (i == rx_ring->count)
3735 buffer_info = &rx_ring->buffer_info[i];
3736 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
3737 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
3738 length = le16_to_cpu(rx_desc->wb.upper.length);
3739 if (!(staterr & E1000_RXD_STAT_DD)) {
3740 rx_ring->pending_skb = skb;
3741 rx_ring->pending_skb_page = j;
3746 pskb_trim(skb, skb->len - 4);
3748 if (i == rx_ring->count)
3750 next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
3752 next_buffer = &rx_ring->buffer_info[i];
3754 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
3755 dev_kfree_skb_irq(skb);
3758 rx_ring->no_itr_adjust |= (staterr & E1000_RXD_STAT_DYNINT);
3760 total_bytes += skb->len;
3763 igb_rx_checksum_adv(adapter, staterr, skb);
3765 skb->protocol = eth_type_trans(skb, netdev);
3767 igb_receive_skb(adapter, staterr, rx_desc->wb.upper.vlan, skb);
3769 netdev->last_rx = jiffies;
3772 rx_desc->wb.upper.status_error = 0;
3774 /* return some buffers to hardware, one at a time is too slow */
3775 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
3776 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
3780 /* use prefetched values */
3782 buffer_info = next_buffer;
3784 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
3787 rx_ring->next_to_clean = i;
3788 cleaned_count = IGB_DESC_UNUSED(rx_ring);
3791 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
3793 rx_ring->total_packets += total_packets;
3794 rx_ring->total_bytes += total_bytes;
3795 rx_ring->rx_stats.packets += total_packets;
3796 rx_ring->rx_stats.bytes += total_bytes;
3797 adapter->net_stats.rx_bytes += total_bytes;
3798 adapter->net_stats.rx_packets += total_packets;
3804 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
3805 * @adapter: address of board private structure
3807 static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
3810 struct igb_adapter *adapter = rx_ring->adapter;
3811 struct net_device *netdev = adapter->netdev;
3812 struct pci_dev *pdev = adapter->pdev;
3813 union e1000_adv_rx_desc *rx_desc;
3814 struct igb_buffer *buffer_info;
3815 struct sk_buff *skb;
3818 i = rx_ring->next_to_use;
3819 buffer_info = &rx_ring->buffer_info[i];
3821 while (cleaned_count--) {
3822 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
3824 if (adapter->rx_ps_hdr_size && !buffer_info->page) {
3825 buffer_info->page = alloc_page(GFP_ATOMIC);
3826 if (!buffer_info->page) {
3827 adapter->alloc_rx_buff_failed++;
3830 buffer_info->page_dma =
3834 PCI_DMA_FROMDEVICE);
3837 if (!buffer_info->skb) {
3840 if (adapter->rx_ps_hdr_size)
3841 bufsz = adapter->rx_ps_hdr_size;
3843 bufsz = adapter->rx_buffer_len;
3844 bufsz += NET_IP_ALIGN;
3845 skb = netdev_alloc_skb(netdev, bufsz);
3848 adapter->alloc_rx_buff_failed++;
3852 /* Make buffer alignment 2 beyond a 16 byte boundary
3853 * this will result in a 16 byte aligned IP header after
3854 * the 14 byte MAC header is removed
3856 skb_reserve(skb, NET_IP_ALIGN);
3858 buffer_info->skb = skb;
3859 buffer_info->dma = pci_map_single(pdev, skb->data,
3861 PCI_DMA_FROMDEVICE);
3864 /* Refresh the desc even if buffer_addrs didn't change because
3865 * each write-back erases this info. */
3866 if (adapter->rx_ps_hdr_size) {
3867 rx_desc->read.pkt_addr =
3868 cpu_to_le64(buffer_info->page_dma);
3869 rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
3871 rx_desc->read.pkt_addr =
3872 cpu_to_le64(buffer_info->dma);
3873 rx_desc->read.hdr_addr = 0;
3877 if (i == rx_ring->count)
3879 buffer_info = &rx_ring->buffer_info[i];
3883 if (rx_ring->next_to_use != i) {
3884 rx_ring->next_to_use = i;
3886 i = (rx_ring->count - 1);
3890 /* Force memory writes to complete before letting h/w
3891 * know there are new descriptors to fetch. (Only
3892 * applicable for weak-ordered memory model archs,
3893 * such as IA-64). */
3895 writel(i, adapter->hw.hw_addr + rx_ring->tail);
3905 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3907 struct igb_adapter *adapter = netdev_priv(netdev);
3908 struct mii_ioctl_data *data = if_mii(ifr);
3910 if (adapter->hw.phy.media_type != e1000_media_type_copper)
3915 data->phy_id = adapter->hw.phy.addr;
3918 if (!capable(CAP_NET_ADMIN))
3920 if (adapter->hw.phy.ops.read_phy_reg(&adapter->hw,
3922 & 0x1F, &data->val_out))
3938 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3944 return igb_mii_ioctl(netdev, ifr, cmd);
3950 static void igb_vlan_rx_register(struct net_device *netdev,
3951 struct vlan_group *grp)
3953 struct igb_adapter *adapter = netdev_priv(netdev);
3954 struct e1000_hw *hw = &adapter->hw;
3957 igb_irq_disable(adapter);
3958 adapter->vlgrp = grp;
3961 /* enable VLAN tag insert/strip */
3962 ctrl = rd32(E1000_CTRL);
3963 ctrl |= E1000_CTRL_VME;
3964 wr32(E1000_CTRL, ctrl);
3966 /* enable VLAN receive filtering */
3967 rctl = rd32(E1000_RCTL);
3968 rctl |= E1000_RCTL_VFE;
3969 rctl &= ~E1000_RCTL_CFIEN;
3970 wr32(E1000_RCTL, rctl);
3971 igb_update_mng_vlan(adapter);
3973 adapter->max_frame_size + VLAN_TAG_SIZE);
3975 /* disable VLAN tag insert/strip */
3976 ctrl = rd32(E1000_CTRL);
3977 ctrl &= ~E1000_CTRL_VME;
3978 wr32(E1000_CTRL, ctrl);
3980 /* disable VLAN filtering */
3981 rctl = rd32(E1000_RCTL);
3982 rctl &= ~E1000_RCTL_VFE;
3983 wr32(E1000_RCTL, rctl);
3984 if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) {
3985 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3986 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
3989 adapter->max_frame_size);
3992 if (!test_bit(__IGB_DOWN, &adapter->state))
3993 igb_irq_enable(adapter);
3996 static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3998 struct igb_adapter *adapter = netdev_priv(netdev);
3999 struct e1000_hw *hw = &adapter->hw;
4002 if ((adapter->hw.mng_cookie.status &
4003 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
4004 (vid == adapter->mng_vlan_id))
4006 /* add VID to filter table */
4007 index = (vid >> 5) & 0x7F;
4008 vfta = array_rd32(E1000_VFTA, index);
4009 vfta |= (1 << (vid & 0x1F));
4010 igb_write_vfta(&adapter->hw, index, vfta);
4013 static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4015 struct igb_adapter *adapter = netdev_priv(netdev);
4016 struct e1000_hw *hw = &adapter->hw;
4019 igb_irq_disable(adapter);
4020 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4022 if (!test_bit(__IGB_DOWN, &adapter->state))
4023 igb_irq_enable(adapter);
4025 if ((adapter->hw.mng_cookie.status &
4026 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
4027 (vid == adapter->mng_vlan_id)) {
4028 /* release control to f/w */
4029 igb_release_hw_control(adapter);
4033 /* remove VID from filter table */
4034 index = (vid >> 5) & 0x7F;
4035 vfta = array_rd32(E1000_VFTA, index);
4036 vfta &= ~(1 << (vid & 0x1F));
4037 igb_write_vfta(&adapter->hw, index, vfta);
4040 static void igb_restore_vlan(struct igb_adapter *adapter)
4042 igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4044 if (adapter->vlgrp) {
4046 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4047 if (!vlan_group_get_device(adapter->vlgrp, vid))
4049 igb_vlan_rx_add_vid(adapter->netdev, vid);
4054 int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
4056 struct e1000_mac_info *mac = &adapter->hw.mac;
4060 /* Fiber NICs only allow 1000 gbps Full duplex */
4061 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
4062 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4063 dev_err(&adapter->pdev->dev,
4064 "Unsupported Speed/Duplex configuration\n");
4069 case SPEED_10 + DUPLEX_HALF:
4070 mac->forced_speed_duplex = ADVERTISE_10_HALF;
4072 case SPEED_10 + DUPLEX_FULL:
4073 mac->forced_speed_duplex = ADVERTISE_10_FULL;
4075 case SPEED_100 + DUPLEX_HALF:
4076 mac->forced_speed_duplex = ADVERTISE_100_HALF;
4078 case SPEED_100 + DUPLEX_FULL:
4079 mac->forced_speed_duplex = ADVERTISE_100_FULL;
4081 case SPEED_1000 + DUPLEX_FULL:
4083 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
4085 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4087 dev_err(&adapter->pdev->dev,
4088 "Unsupported Speed/Duplex configuration\n");
4095 static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
4097 struct net_device *netdev = pci_get_drvdata(pdev);
4098 struct igb_adapter *adapter = netdev_priv(netdev);
4099 struct e1000_hw *hw = &adapter->hw;
4100 u32 ctrl, ctrl_ext, rctl, status;
4101 u32 wufc = adapter->wol;
4106 netif_device_detach(netdev);
4108 if (netif_running(netdev)) {
4109 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
4111 igb_free_irq(adapter);
4115 retval = pci_save_state(pdev);
4120 status = rd32(E1000_STATUS);
4121 if (status & E1000_STATUS_LU)
4122 wufc &= ~E1000_WUFC_LNKC;
4125 igb_setup_rctl(adapter);
4126 igb_set_multi(netdev);
4128 /* turn on all-multi mode if wake on multicast is enabled */
4129 if (wufc & E1000_WUFC_MC) {
4130 rctl = rd32(E1000_RCTL);
4131 rctl |= E1000_RCTL_MPE;
4132 wr32(E1000_RCTL, rctl);
4135 ctrl = rd32(E1000_CTRL);
4136 /* advertise wake from D3Cold */
4137 #define E1000_CTRL_ADVD3WUC 0x00100000
4138 /* phy power management enable */
4139 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4140 ctrl |= E1000_CTRL_ADVD3WUC;
4141 wr32(E1000_CTRL, ctrl);
4143 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
4144 adapter->hw.phy.media_type ==
4145 e1000_media_type_internal_serdes) {
4146 /* keep the laser running in D3 */
4147 ctrl_ext = rd32(E1000_CTRL_EXT);
4148 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4149 wr32(E1000_CTRL_EXT, ctrl_ext);
4152 /* Allow time for pending master requests to run */
4153 igb_disable_pcie_master(&adapter->hw);
4155 wr32(E1000_WUC, E1000_WUC_PME_EN);
4156 wr32(E1000_WUFC, wufc);
4157 pci_enable_wake(pdev, PCI_D3hot, 1);
4158 pci_enable_wake(pdev, PCI_D3cold, 1);
4161 wr32(E1000_WUFC, 0);
4162 pci_enable_wake(pdev, PCI_D3hot, 0);
4163 pci_enable_wake(pdev, PCI_D3cold, 0);
4166 /* make sure adapter isn't asleep if manageability is enabled */
4167 if (adapter->en_mng_pt) {
4168 pci_enable_wake(pdev, PCI_D3hot, 1);
4169 pci_enable_wake(pdev, PCI_D3cold, 1);
4172 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4173 * would have already happened in close and is redundant. */
4174 igb_release_hw_control(adapter);
4176 pci_disable_device(pdev);
4178 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4184 static int igb_resume(struct pci_dev *pdev)
4186 struct net_device *netdev = pci_get_drvdata(pdev);
4187 struct igb_adapter *adapter = netdev_priv(netdev);
4188 struct e1000_hw *hw = &adapter->hw;
4191 pci_set_power_state(pdev, PCI_D0);
4192 pci_restore_state(pdev);
4194 if (adapter->need_ioport)
4195 err = pci_enable_device(pdev);
4197 err = pci_enable_device_mem(pdev);
4200 "igb: Cannot enable PCI device from suspend\n");
4203 pci_set_master(pdev);
4205 pci_enable_wake(pdev, PCI_D3hot, 0);
4206 pci_enable_wake(pdev, PCI_D3cold, 0);
4208 if (netif_running(netdev)) {
4209 err = igb_request_irq(adapter);
4214 /* e1000_power_up_phy(adapter); */
4217 wr32(E1000_WUS, ~0);
4219 igb_init_manageability(adapter);
4221 if (netif_running(netdev))
4224 netif_device_attach(netdev);
4226 /* let the f/w know that the h/w is now under the control of the
4228 igb_get_hw_control(adapter);
4234 static void igb_shutdown(struct pci_dev *pdev)
4236 igb_suspend(pdev, PMSG_SUSPEND);
4239 #ifdef CONFIG_NET_POLL_CONTROLLER
4241 * Polling 'interrupt' - used by things like netconsole to send skbs
4242 * without having to re-enable interrupts. It's not called while
4243 * the interrupt routine is executing.
4245 static void igb_netpoll(struct net_device *netdev)
4247 struct igb_adapter *adapter = netdev_priv(netdev);
4251 igb_irq_disable(adapter);
4252 for (i = 0; i < adapter->num_tx_queues; i++)
4253 igb_clean_tx_irq(&adapter->tx_ring[i]);
4255 for (i = 0; i < adapter->num_rx_queues; i++)
4256 igb_clean_rx_irq_adv(&adapter->rx_ring[i],
4258 adapter->rx_ring[i].napi.weight);
4260 igb_irq_enable(adapter);
4262 #endif /* CONFIG_NET_POLL_CONTROLLER */
4265 * igb_io_error_detected - called when PCI error is detected
4266 * @pdev: Pointer to PCI device
4267 * @state: The current pci connection state
4269 * This function is called after a PCI bus error affecting
4270 * this device has been detected.
4272 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
4273 pci_channel_state_t state)
4275 struct net_device *netdev = pci_get_drvdata(pdev);
4276 struct igb_adapter *adapter = netdev_priv(netdev);
4278 netif_device_detach(netdev);
4280 if (netif_running(netdev))
4282 pci_disable_device(pdev);
4284 /* Request a slot slot reset. */
4285 return PCI_ERS_RESULT_NEED_RESET;
4289 * igb_io_slot_reset - called after the pci bus has been reset.
4290 * @pdev: Pointer to PCI device
4292 * Restart the card from scratch, as if from a cold-boot. Implementation
4293 * resembles the first-half of the igb_resume routine.
4295 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
4297 struct net_device *netdev = pci_get_drvdata(pdev);
4298 struct igb_adapter *adapter = netdev_priv(netdev);
4299 struct e1000_hw *hw = &adapter->hw;
4302 if (adapter->need_ioport)
4303 err = pci_enable_device(pdev);
4305 err = pci_enable_device_mem(pdev);
4308 "Cannot re-enable PCI device after reset.\n");
4309 return PCI_ERS_RESULT_DISCONNECT;
4311 pci_set_master(pdev);
4312 pci_restore_state(pdev);
4314 pci_enable_wake(pdev, PCI_D3hot, 0);
4315 pci_enable_wake(pdev, PCI_D3cold, 0);
4318 wr32(E1000_WUS, ~0);
4320 return PCI_ERS_RESULT_RECOVERED;
4324 * igb_io_resume - called when traffic can start flowing again.
4325 * @pdev: Pointer to PCI device
4327 * This callback is called when the error recovery driver tells us that
4328 * its OK to resume normal operation. Implementation resembles the
4329 * second-half of the igb_resume routine.
4331 static void igb_io_resume(struct pci_dev *pdev)
4333 struct net_device *netdev = pci_get_drvdata(pdev);
4334 struct igb_adapter *adapter = netdev_priv(netdev);
4336 igb_init_manageability(adapter);
4338 if (netif_running(netdev)) {
4339 if (igb_up(adapter)) {
4340 dev_err(&pdev->dev, "igb_up failed after reset\n");
4345 netif_device_attach(netdev);
4347 /* let the f/w know that the h/w is now under the control of the
4349 igb_get_hw_control(adapter);