1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/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/net_tstamp.h>
38 #include <linux/mii.h>
39 #include <linux/ethtool.h>
40 #include <linux/if_vlan.h>
41 #include <linux/pci.h>
42 #include <linux/pci-aspm.h>
43 #include <linux/delay.h>
44 #include <linux/interrupt.h>
45 #include <linux/if_ether.h>
46 #include <linux/aer.h>
48 #include <linux/dca.h>
52 #define DRV_VERSION "1.3.16-k2"
53 char igb_driver_name[] = "igb";
54 char igb_driver_version[] = DRV_VERSION;
55 static const char igb_driver_string[] =
56 "Intel(R) Gigabit Ethernet Network Driver";
57 static const char igb_copyright[] = "Copyright (c) 2007-2009 Intel Corporation.";
59 static const struct e1000_info *igb_info_tbl[] = {
60 [board_82575] = &e1000_82575_info,
63 static struct pci_device_id igb_pci_tbl[] = {
64 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
65 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
66 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
67 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
68 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
69 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
70 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
71 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
72 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
73 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
74 /* required last entry */
78 MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
80 void igb_reset(struct igb_adapter *);
81 static int igb_setup_all_tx_resources(struct igb_adapter *);
82 static int igb_setup_all_rx_resources(struct igb_adapter *);
83 static void igb_free_all_tx_resources(struct igb_adapter *);
84 static void igb_free_all_rx_resources(struct igb_adapter *);
85 void igb_update_stats(struct igb_adapter *);
86 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
87 static void __devexit igb_remove(struct pci_dev *pdev);
88 static int igb_sw_init(struct igb_adapter *);
89 static int igb_open(struct net_device *);
90 static int igb_close(struct net_device *);
91 static void igb_configure_tx(struct igb_adapter *);
92 static void igb_configure_rx(struct igb_adapter *);
93 static void igb_setup_tctl(struct igb_adapter *);
94 static void igb_setup_rctl(struct igb_adapter *);
95 static void igb_clean_all_tx_rings(struct igb_adapter *);
96 static void igb_clean_all_rx_rings(struct igb_adapter *);
97 static void igb_clean_tx_ring(struct igb_ring *);
98 static void igb_clean_rx_ring(struct igb_ring *);
99 static void igb_set_rx_mode(struct net_device *);
100 static void igb_update_phy_info(unsigned long);
101 static void igb_watchdog(unsigned long);
102 static void igb_watchdog_task(struct work_struct *);
103 static netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *,
105 static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
106 struct net_device *);
107 static struct net_device_stats *igb_get_stats(struct net_device *);
108 static int igb_change_mtu(struct net_device *, int);
109 static int igb_set_mac(struct net_device *, void *);
110 static void igb_set_uta(struct igb_adapter *adapter);
111 static irqreturn_t igb_intr(int irq, void *);
112 static irqreturn_t igb_intr_msi(int irq, void *);
113 static irqreturn_t igb_msix_other(int irq, void *);
114 static irqreturn_t igb_msix_ring(int irq, void *);
115 #ifdef CONFIG_IGB_DCA
116 static void igb_update_dca(struct igb_q_vector *);
117 static void igb_setup_dca(struct igb_adapter *);
118 #endif /* CONFIG_IGB_DCA */
119 static bool igb_clean_tx_irq(struct igb_q_vector *);
120 static int igb_poll(struct napi_struct *, int);
121 static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int);
122 static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
123 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
124 static void igb_tx_timeout(struct net_device *);
125 static void igb_reset_task(struct work_struct *);
126 static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
127 static void igb_vlan_rx_add_vid(struct net_device *, u16);
128 static void igb_vlan_rx_kill_vid(struct net_device *, u16);
129 static void igb_restore_vlan(struct igb_adapter *);
130 static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
131 static void igb_ping_all_vfs(struct igb_adapter *);
132 static void igb_msg_task(struct igb_adapter *);
133 static int igb_rcv_msg_from_vf(struct igb_adapter *, u32);
134 static void igb_vmm_control(struct igb_adapter *);
135 static int igb_set_vf_mac(struct igb_adapter *adapter, int, unsigned char *);
136 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
138 static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn)
142 reg_data = rd32(E1000_VMOLR(vfn));
143 reg_data |= E1000_VMOLR_BAM | /* Accept broadcast */
144 E1000_VMOLR_ROMPE | /* Accept packets matched in MTA */
145 E1000_VMOLR_AUPE | /* Accept untagged packets */
146 E1000_VMOLR_STRVLAN; /* Strip vlan tags */
147 wr32(E1000_VMOLR(vfn), reg_data);
150 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
153 struct e1000_hw *hw = &adapter->hw;
156 /* if it isn't the PF check to see if VFs are enabled and
157 * increase the size to support vlan tags */
158 if (vfn < adapter->vfs_allocated_count &&
159 adapter->vf_data[vfn].vlans_enabled)
160 size += VLAN_TAG_SIZE;
162 vmolr = rd32(E1000_VMOLR(vfn));
163 vmolr &= ~E1000_VMOLR_RLPML_MASK;
164 vmolr |= size | E1000_VMOLR_LPE;
165 wr32(E1000_VMOLR(vfn), vmolr);
171 static int igb_suspend(struct pci_dev *, pm_message_t);
172 static int igb_resume(struct pci_dev *);
174 static void igb_shutdown(struct pci_dev *);
175 #ifdef CONFIG_IGB_DCA
176 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
177 static struct notifier_block dca_notifier = {
178 .notifier_call = igb_notify_dca,
183 #ifdef CONFIG_NET_POLL_CONTROLLER
184 /* for netdump / net console */
185 static void igb_netpoll(struct net_device *);
187 #ifdef CONFIG_PCI_IOV
188 static unsigned int max_vfs = 0;
189 module_param(max_vfs, uint, 0);
190 MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
191 "per physical function");
192 #endif /* CONFIG_PCI_IOV */
194 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
195 pci_channel_state_t);
196 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
197 static void igb_io_resume(struct pci_dev *);
199 static struct pci_error_handlers igb_err_handler = {
200 .error_detected = igb_io_error_detected,
201 .slot_reset = igb_io_slot_reset,
202 .resume = igb_io_resume,
206 static struct pci_driver igb_driver = {
207 .name = igb_driver_name,
208 .id_table = igb_pci_tbl,
210 .remove = __devexit_p(igb_remove),
212 /* Power Managment Hooks */
213 .suspend = igb_suspend,
214 .resume = igb_resume,
216 .shutdown = igb_shutdown,
217 .err_handler = &igb_err_handler
220 static int global_quad_port_a; /* global quad port a indication */
222 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
223 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
224 MODULE_LICENSE("GPL");
225 MODULE_VERSION(DRV_VERSION);
228 * Scale the NIC clock cycle by a large factor so that
229 * relatively small clock corrections can be added or
230 * substracted at each clock tick. The drawbacks of a
231 * large factor are a) that the clock register overflows
232 * more quickly (not such a big deal) and b) that the
233 * increment per tick has to fit into 24 bits.
236 * TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS *
238 * TIMINCA += TIMINCA * adjustment [ppm] / 1e9
240 * The base scale factor is intentionally a power of two
241 * so that the division in %struct timecounter can be done with
244 #define IGB_TSYNC_SHIFT (19)
245 #define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT)
248 * The duration of one clock cycle of the NIC.
250 * @todo This hard-coded value is part of the specification and might change
251 * in future hardware revisions. Add revision check.
253 #define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16
255 #if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24)
256 # error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA
260 * igb_read_clock - read raw cycle counter (to be used by time counter)
262 static cycle_t igb_read_clock(const struct cyclecounter *tc)
264 struct igb_adapter *adapter =
265 container_of(tc, struct igb_adapter, cycles);
266 struct e1000_hw *hw = &adapter->hw;
269 stamp = rd32(E1000_SYSTIML);
270 stamp |= (u64)rd32(E1000_SYSTIMH) << 32ULL;
277 * igb_get_hw_dev_name - return device name string
278 * used by hardware layer to print debugging information
280 char *igb_get_hw_dev_name(struct e1000_hw *hw)
282 struct igb_adapter *adapter = hw->back;
283 return adapter->netdev->name;
287 * igb_get_time_str - format current NIC and system time as string
289 static char *igb_get_time_str(struct igb_adapter *adapter,
292 cycle_t hw = adapter->cycles.read(&adapter->cycles);
293 struct timespec nic = ns_to_timespec(timecounter_read(&adapter->clock));
295 struct timespec delta;
296 getnstimeofday(&sys);
298 delta = timespec_sub(nic, sys);
301 "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns",
303 (long)nic.tv_sec, nic.tv_nsec,
304 (long)sys.tv_sec, sys.tv_nsec,
305 (long)delta.tv_sec, delta.tv_nsec);
312 * igb_desc_unused - calculate if we have unused descriptors
314 static int igb_desc_unused(struct igb_ring *ring)
316 if (ring->next_to_clean > ring->next_to_use)
317 return ring->next_to_clean - ring->next_to_use - 1;
319 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
323 * igb_init_module - Driver Registration Routine
325 * igb_init_module is the first routine called when the driver is
326 * loaded. All it does is register with the PCI subsystem.
328 static int __init igb_init_module(void)
331 printk(KERN_INFO "%s - version %s\n",
332 igb_driver_string, igb_driver_version);
334 printk(KERN_INFO "%s\n", igb_copyright);
336 global_quad_port_a = 0;
338 #ifdef CONFIG_IGB_DCA
339 dca_register_notify(&dca_notifier);
342 ret = pci_register_driver(&igb_driver);
346 module_init(igb_init_module);
349 * igb_exit_module - Driver Exit Cleanup Routine
351 * igb_exit_module is called just before the driver is removed
354 static void __exit igb_exit_module(void)
356 #ifdef CONFIG_IGB_DCA
357 dca_unregister_notify(&dca_notifier);
359 pci_unregister_driver(&igb_driver);
362 module_exit(igb_exit_module);
364 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
366 * igb_cache_ring_register - Descriptor ring to register mapping
367 * @adapter: board private structure to initialize
369 * Once we know the feature-set enabled for the device, we'll cache
370 * the register offset the descriptor ring is assigned to.
372 static void igb_cache_ring_register(struct igb_adapter *adapter)
375 u32 rbase_offset = adapter->vfs_allocated_count;
377 switch (adapter->hw.mac.type) {
379 /* The queues are allocated for virtualization such that VF 0
380 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
381 * In order to avoid collision we start at the first free queue
382 * and continue consuming queues in the same sequence
384 for (i = 0; i < adapter->num_rx_queues; i++)
385 adapter->rx_ring[i].reg_idx = rbase_offset +
387 for (i = 0; i < adapter->num_tx_queues; i++)
388 adapter->tx_ring[i].reg_idx = rbase_offset +
393 for (i = 0; i < adapter->num_rx_queues; i++)
394 adapter->rx_ring[i].reg_idx = i;
395 for (i = 0; i < adapter->num_tx_queues; i++)
396 adapter->tx_ring[i].reg_idx = i;
401 static void igb_free_queues(struct igb_adapter *adapter)
403 kfree(adapter->tx_ring);
404 kfree(adapter->rx_ring);
406 adapter->tx_ring = NULL;
407 adapter->rx_ring = NULL;
409 adapter->num_rx_queues = 0;
410 adapter->num_tx_queues = 0;
414 * igb_alloc_queues - Allocate memory for all rings
415 * @adapter: board private structure to initialize
417 * We allocate one ring per queue at run-time since we don't know the
418 * number of queues at compile-time.
420 static int igb_alloc_queues(struct igb_adapter *adapter)
424 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
425 sizeof(struct igb_ring), GFP_KERNEL);
426 if (!adapter->tx_ring)
429 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
430 sizeof(struct igb_ring), GFP_KERNEL);
431 if (!adapter->rx_ring)
434 for (i = 0; i < adapter->num_tx_queues; i++) {
435 struct igb_ring *ring = &(adapter->tx_ring[i]);
436 ring->count = adapter->tx_ring_count;
437 ring->queue_index = i;
438 ring->pdev = adapter->pdev;
439 ring->netdev = adapter->netdev;
440 /* For 82575, context index must be unique per ring. */
441 if (adapter->hw.mac.type == e1000_82575)
442 ring->flags = IGB_RING_FLAG_TX_CTX_IDX;
445 for (i = 0; i < adapter->num_rx_queues; i++) {
446 struct igb_ring *ring = &(adapter->rx_ring[i]);
447 ring->count = adapter->rx_ring_count;
448 ring->queue_index = i;
449 ring->pdev = adapter->pdev;
450 ring->netdev = adapter->netdev;
451 ring->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
452 ring->flags = IGB_RING_FLAG_RX_CSUM; /* enable rx checksum */
453 /* set flag indicating ring supports SCTP checksum offload */
454 if (adapter->hw.mac.type >= e1000_82576)
455 ring->flags |= IGB_RING_FLAG_RX_SCTP_CSUM;
458 igb_cache_ring_register(adapter);
463 igb_free_queues(adapter);
468 #define IGB_N0_QUEUE -1
469 static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
472 struct igb_adapter *adapter = q_vector->adapter;
473 struct e1000_hw *hw = &adapter->hw;
475 int rx_queue = IGB_N0_QUEUE;
476 int tx_queue = IGB_N0_QUEUE;
478 if (q_vector->rx_ring)
479 rx_queue = q_vector->rx_ring->reg_idx;
480 if (q_vector->tx_ring)
481 tx_queue = q_vector->tx_ring->reg_idx;
483 switch (hw->mac.type) {
485 /* The 82575 assigns vectors using a bitmask, which matches the
486 bitmask for the EICR/EIMS/EIMC registers. To assign one
487 or more queues to a vector, we write the appropriate bits
488 into the MSIXBM register for that vector. */
489 if (rx_queue > IGB_N0_QUEUE)
490 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
491 if (tx_queue > IGB_N0_QUEUE)
492 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
493 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
494 q_vector->eims_value = msixbm;
497 /* 82576 uses a table-based method for assigning vectors.
498 Each queue has a single entry in the table to which we write
499 a vector number along with a "valid" bit. Sadly, the layout
500 of the table is somewhat counterintuitive. */
501 if (rx_queue > IGB_N0_QUEUE) {
502 index = (rx_queue & 0x7);
503 ivar = array_rd32(E1000_IVAR0, index);
505 /* vector goes into low byte of register */
506 ivar = ivar & 0xFFFFFF00;
507 ivar |= msix_vector | E1000_IVAR_VALID;
509 /* vector goes into third byte of register */
510 ivar = ivar & 0xFF00FFFF;
511 ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
513 array_wr32(E1000_IVAR0, index, ivar);
515 if (tx_queue > IGB_N0_QUEUE) {
516 index = (tx_queue & 0x7);
517 ivar = array_rd32(E1000_IVAR0, index);
519 /* vector goes into second byte of register */
520 ivar = ivar & 0xFFFF00FF;
521 ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
523 /* vector goes into high byte of register */
524 ivar = ivar & 0x00FFFFFF;
525 ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
527 array_wr32(E1000_IVAR0, index, ivar);
529 q_vector->eims_value = 1 << msix_vector;
538 * igb_configure_msix - Configure MSI-X hardware
540 * igb_configure_msix sets up the hardware to properly
541 * generate MSI-X interrupts.
543 static void igb_configure_msix(struct igb_adapter *adapter)
547 struct e1000_hw *hw = &adapter->hw;
549 adapter->eims_enable_mask = 0;
551 /* set vector for other causes, i.e. link changes */
552 switch (hw->mac.type) {
554 tmp = rd32(E1000_CTRL_EXT);
555 /* enable MSI-X PBA support*/
556 tmp |= E1000_CTRL_EXT_PBA_CLR;
558 /* Auto-Mask interrupts upon ICR read. */
559 tmp |= E1000_CTRL_EXT_EIAME;
560 tmp |= E1000_CTRL_EXT_IRCA;
562 wr32(E1000_CTRL_EXT, tmp);
564 /* enable msix_other interrupt */
565 array_wr32(E1000_MSIXBM(0), vector++,
567 adapter->eims_other = E1000_EIMS_OTHER;
572 /* Turn on MSI-X capability first, or our settings
573 * won't stick. And it will take days to debug. */
574 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
575 E1000_GPIE_PBA | E1000_GPIE_EIAME |
578 /* enable msix_other interrupt */
579 adapter->eims_other = 1 << vector;
580 tmp = (vector++ | E1000_IVAR_VALID) << 8;
582 wr32(E1000_IVAR_MISC, tmp);
585 /* do nothing, since nothing else supports MSI-X */
587 } /* switch (hw->mac.type) */
589 adapter->eims_enable_mask |= adapter->eims_other;
591 for (i = 0; i < adapter->num_q_vectors; i++) {
592 struct igb_q_vector *q_vector = adapter->q_vector[i];
593 igb_assign_vector(q_vector, vector++);
594 adapter->eims_enable_mask |= q_vector->eims_value;
601 * igb_request_msix - Initialize MSI-X interrupts
603 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
606 static int igb_request_msix(struct igb_adapter *adapter)
608 struct net_device *netdev = adapter->netdev;
609 struct e1000_hw *hw = &adapter->hw;
610 int i, err = 0, vector = 0;
612 err = request_irq(adapter->msix_entries[vector].vector,
613 &igb_msix_other, 0, netdev->name, adapter);
618 for (i = 0; i < adapter->num_q_vectors; i++) {
619 struct igb_q_vector *q_vector = adapter->q_vector[i];
621 q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
623 if (q_vector->rx_ring && q_vector->tx_ring)
624 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
625 q_vector->rx_ring->queue_index);
626 else if (q_vector->tx_ring)
627 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
628 q_vector->tx_ring->queue_index);
629 else if (q_vector->rx_ring)
630 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
631 q_vector->rx_ring->queue_index);
633 sprintf(q_vector->name, "%s-unused", netdev->name);
635 err = request_irq(adapter->msix_entries[vector].vector,
636 &igb_msix_ring, 0, q_vector->name,
643 igb_configure_msix(adapter);
649 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
651 if (adapter->msix_entries) {
652 pci_disable_msix(adapter->pdev);
653 kfree(adapter->msix_entries);
654 adapter->msix_entries = NULL;
655 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
656 pci_disable_msi(adapter->pdev);
661 * igb_free_q_vectors - Free memory allocated for interrupt vectors
662 * @adapter: board private structure to initialize
664 * This function frees the memory allocated to the q_vectors. In addition if
665 * NAPI is enabled it will delete any references to the NAPI struct prior
666 * to freeing the q_vector.
668 static void igb_free_q_vectors(struct igb_adapter *adapter)
672 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
673 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
674 adapter->q_vector[v_idx] = NULL;
675 netif_napi_del(&q_vector->napi);
678 adapter->num_q_vectors = 0;
682 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
684 * This function resets the device so that it has 0 rx queues, tx queues, and
685 * MSI-X interrupts allocated.
687 static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
689 igb_free_queues(adapter);
690 igb_free_q_vectors(adapter);
691 igb_reset_interrupt_capability(adapter);
695 * igb_set_interrupt_capability - set MSI or MSI-X if supported
697 * Attempt to configure interrupts using the best available
698 * capabilities of the hardware and kernel.
700 static void igb_set_interrupt_capability(struct igb_adapter *adapter)
705 /* Number of supported queues. */
706 adapter->num_rx_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
707 adapter->num_tx_queues = min_t(u32, IGB_MAX_TX_QUEUES, num_online_cpus());
709 /* start with one vector for every rx queue */
710 numvecs = adapter->num_rx_queues;
712 /* if tx handler is seperate add 1 for every tx queue */
713 numvecs += adapter->num_tx_queues;
715 /* store the number of vectors reserved for queues */
716 adapter->num_q_vectors = numvecs;
718 /* add 1 vector for link status interrupts */
720 adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
722 if (!adapter->msix_entries)
725 for (i = 0; i < numvecs; i++)
726 adapter->msix_entries[i].entry = i;
728 err = pci_enable_msix(adapter->pdev,
729 adapter->msix_entries,
734 igb_reset_interrupt_capability(adapter);
736 /* If we can't do MSI-X, try MSI */
738 #ifdef CONFIG_PCI_IOV
739 /* disable SR-IOV for non MSI-X configurations */
740 if (adapter->vf_data) {
741 struct e1000_hw *hw = &adapter->hw;
742 /* disable iov and allow time for transactions to clear */
743 pci_disable_sriov(adapter->pdev);
746 kfree(adapter->vf_data);
747 adapter->vf_data = NULL;
748 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
750 dev_info(&adapter->pdev->dev, "IOV Disabled\n");
753 adapter->num_rx_queues = 1;
754 adapter->num_tx_queues = 1;
755 adapter->num_q_vectors = 1;
756 if (!pci_enable_msi(adapter->pdev))
757 adapter->flags |= IGB_FLAG_HAS_MSI;
759 /* Notify the stack of the (possibly) reduced Tx Queue count. */
760 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
765 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
766 * @adapter: board private structure to initialize
768 * We allocate one q_vector per queue interrupt. If allocation fails we
771 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
773 struct igb_q_vector *q_vector;
774 struct e1000_hw *hw = &adapter->hw;
777 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
778 q_vector = kzalloc(sizeof(struct igb_q_vector), GFP_KERNEL);
781 q_vector->adapter = adapter;
782 q_vector->itr_shift = (hw->mac.type == e1000_82575) ? 16 : 0;
783 q_vector->itr_register = hw->hw_addr + E1000_EITR(0);
784 q_vector->itr_val = IGB_START_ITR;
785 q_vector->set_itr = 1;
786 netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);
787 adapter->q_vector[v_idx] = q_vector;
794 q_vector = adapter->q_vector[v_idx];
795 netif_napi_del(&q_vector->napi);
797 adapter->q_vector[v_idx] = NULL;
802 static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter,
803 int ring_idx, int v_idx)
805 struct igb_q_vector *q_vector;
807 q_vector = adapter->q_vector[v_idx];
808 q_vector->rx_ring = &adapter->rx_ring[ring_idx];
809 q_vector->rx_ring->q_vector = q_vector;
810 q_vector->itr_val = adapter->itr;
813 static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter,
814 int ring_idx, int v_idx)
816 struct igb_q_vector *q_vector;
818 q_vector = adapter->q_vector[v_idx];
819 q_vector->tx_ring = &adapter->tx_ring[ring_idx];
820 q_vector->tx_ring->q_vector = q_vector;
821 q_vector->itr_val = adapter->itr;
825 * igb_map_ring_to_vector - maps allocated queues to vectors
827 * This function maps the recently allocated queues to vectors.
829 static int igb_map_ring_to_vector(struct igb_adapter *adapter)
834 if ((adapter->num_q_vectors < adapter->num_rx_queues) ||
835 (adapter->num_q_vectors < adapter->num_tx_queues))
838 if (adapter->num_q_vectors >=
839 (adapter->num_rx_queues + adapter->num_tx_queues)) {
840 for (i = 0; i < adapter->num_rx_queues; i++)
841 igb_map_rx_ring_to_vector(adapter, i, v_idx++);
842 for (i = 0; i < adapter->num_tx_queues; i++)
843 igb_map_tx_ring_to_vector(adapter, i, v_idx++);
845 for (i = 0; i < adapter->num_rx_queues; i++) {
846 if (i < adapter->num_tx_queues)
847 igb_map_tx_ring_to_vector(adapter, i, v_idx);
848 igb_map_rx_ring_to_vector(adapter, i, v_idx++);
850 for (; i < adapter->num_tx_queues; i++)
851 igb_map_tx_ring_to_vector(adapter, i, v_idx++);
857 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
859 * This function initializes the interrupts and allocates all of the queues.
861 static int igb_init_interrupt_scheme(struct igb_adapter *adapter)
863 struct pci_dev *pdev = adapter->pdev;
866 igb_set_interrupt_capability(adapter);
868 err = igb_alloc_q_vectors(adapter);
870 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
871 goto err_alloc_q_vectors;
874 err = igb_alloc_queues(adapter);
876 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
877 goto err_alloc_queues;
880 err = igb_map_ring_to_vector(adapter);
882 dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n");
889 igb_free_queues(adapter);
891 igb_free_q_vectors(adapter);
893 igb_reset_interrupt_capability(adapter);
898 * igb_request_irq - initialize interrupts
900 * Attempts to configure interrupts using the best available
901 * capabilities of the hardware and kernel.
903 static int igb_request_irq(struct igb_adapter *adapter)
905 struct net_device *netdev = adapter->netdev;
906 struct pci_dev *pdev = adapter->pdev;
907 struct e1000_hw *hw = &adapter->hw;
910 if (adapter->msix_entries) {
911 err = igb_request_msix(adapter);
914 /* fall back to MSI */
915 igb_clear_interrupt_scheme(adapter);
916 if (!pci_enable_msi(adapter->pdev))
917 adapter->flags |= IGB_FLAG_HAS_MSI;
918 igb_free_all_tx_resources(adapter);
919 igb_free_all_rx_resources(adapter);
920 adapter->num_tx_queues = 1;
921 adapter->num_rx_queues = 1;
922 adapter->num_q_vectors = 1;
923 err = igb_alloc_q_vectors(adapter);
926 "Unable to allocate memory for vectors\n");
929 err = igb_alloc_queues(adapter);
932 "Unable to allocate memory for queues\n");
933 igb_free_q_vectors(adapter);
936 igb_setup_all_tx_resources(adapter);
937 igb_setup_all_rx_resources(adapter);
939 switch (hw->mac.type) {
941 wr32(E1000_MSIXBM(0),
942 (E1000_EICR_RX_QUEUE0 |
943 E1000_EICR_TX_QUEUE0 |
947 wr32(E1000_IVAR0, E1000_IVAR_VALID);
954 if (adapter->flags & IGB_FLAG_HAS_MSI) {
955 err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0,
956 netdev->name, adapter);
960 /* fall back to legacy interrupts */
961 igb_reset_interrupt_capability(adapter);
962 adapter->flags &= ~IGB_FLAG_HAS_MSI;
965 err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED,
966 netdev->name, adapter);
969 dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
976 static void igb_free_irq(struct igb_adapter *adapter)
978 if (adapter->msix_entries) {
981 free_irq(adapter->msix_entries[vector++].vector, adapter);
983 for (i = 0; i < adapter->num_q_vectors; i++) {
984 struct igb_q_vector *q_vector = adapter->q_vector[i];
985 free_irq(adapter->msix_entries[vector++].vector,
989 free_irq(adapter->pdev->irq, adapter);
994 * igb_irq_disable - Mask off interrupt generation on the NIC
995 * @adapter: board private structure
997 static void igb_irq_disable(struct igb_adapter *adapter)
999 struct e1000_hw *hw = &adapter->hw;
1001 if (adapter->msix_entries) {
1002 u32 regval = rd32(E1000_EIAM);
1003 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1004 wr32(E1000_EIMC, adapter->eims_enable_mask);
1005 regval = rd32(E1000_EIAC);
1006 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
1010 wr32(E1000_IMC, ~0);
1012 synchronize_irq(adapter->pdev->irq);
1016 * igb_irq_enable - Enable default interrupt generation settings
1017 * @adapter: board private structure
1019 static void igb_irq_enable(struct igb_adapter *adapter)
1021 struct e1000_hw *hw = &adapter->hw;
1023 if (adapter->msix_entries) {
1024 u32 regval = rd32(E1000_EIAC);
1025 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1026 regval = rd32(E1000_EIAM);
1027 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
1028 wr32(E1000_EIMS, adapter->eims_enable_mask);
1029 if (adapter->vfs_allocated_count)
1030 wr32(E1000_MBVFIMR, 0xFF);
1031 wr32(E1000_IMS, (E1000_IMS_LSC | E1000_IMS_VMMB |
1032 E1000_IMS_DOUTSYNC));
1034 wr32(E1000_IMS, IMS_ENABLE_MASK);
1035 wr32(E1000_IAM, IMS_ENABLE_MASK);
1039 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1041 struct net_device *netdev = adapter->netdev;
1042 u16 vid = adapter->hw.mng_cookie.vlan_id;
1043 u16 old_vid = adapter->mng_vlan_id;
1044 if (adapter->vlgrp) {
1045 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
1046 if (adapter->hw.mng_cookie.status &
1047 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1048 igb_vlan_rx_add_vid(netdev, vid);
1049 adapter->mng_vlan_id = vid;
1051 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1053 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1055 !vlan_group_get_device(adapter->vlgrp, old_vid))
1056 igb_vlan_rx_kill_vid(netdev, old_vid);
1058 adapter->mng_vlan_id = vid;
1063 * igb_release_hw_control - release control of the h/w to f/w
1064 * @adapter: address of board private structure
1066 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1067 * For ASF and Pass Through versions of f/w this means that the
1068 * driver is no longer loaded.
1071 static void igb_release_hw_control(struct igb_adapter *adapter)
1073 struct e1000_hw *hw = &adapter->hw;
1076 /* Let firmware take over control of h/w */
1077 ctrl_ext = rd32(E1000_CTRL_EXT);
1078 wr32(E1000_CTRL_EXT,
1079 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1084 * igb_get_hw_control - get control of the h/w from f/w
1085 * @adapter: address of board private structure
1087 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1088 * For ASF and Pass Through versions of f/w this means that
1089 * the driver is loaded.
1092 static void igb_get_hw_control(struct igb_adapter *adapter)
1094 struct e1000_hw *hw = &adapter->hw;
1097 /* Let firmware know the driver has taken over */
1098 ctrl_ext = rd32(E1000_CTRL_EXT);
1099 wr32(E1000_CTRL_EXT,
1100 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1104 * igb_configure - configure the hardware for RX and TX
1105 * @adapter: private board structure
1107 static void igb_configure(struct igb_adapter *adapter)
1109 struct net_device *netdev = adapter->netdev;
1112 igb_get_hw_control(adapter);
1113 igb_set_rx_mode(netdev);
1115 igb_restore_vlan(adapter);
1117 igb_setup_tctl(adapter);
1118 igb_setup_rctl(adapter);
1120 igb_configure_tx(adapter);
1121 igb_configure_rx(adapter);
1123 igb_rx_fifo_flush_82575(&adapter->hw);
1125 /* call igb_desc_unused which always leaves
1126 * at least 1 descriptor unused to make sure
1127 * next_to_use != next_to_clean */
1128 for (i = 0; i < adapter->num_rx_queues; i++) {
1129 struct igb_ring *ring = &adapter->rx_ring[i];
1130 igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring));
1134 adapter->tx_queue_len = netdev->tx_queue_len;
1139 * igb_up - Open the interface and prepare it to handle traffic
1140 * @adapter: board private structure
1143 int igb_up(struct igb_adapter *adapter)
1145 struct e1000_hw *hw = &adapter->hw;
1148 /* hardware has been reset, we need to reload some things */
1149 igb_configure(adapter);
1151 clear_bit(__IGB_DOWN, &adapter->state);
1153 for (i = 0; i < adapter->num_q_vectors; i++) {
1154 struct igb_q_vector *q_vector = adapter->q_vector[i];
1155 napi_enable(&q_vector->napi);
1157 if (adapter->msix_entries)
1158 igb_configure_msix(adapter);
1160 igb_vmm_control(adapter);
1161 igb_set_vmolr(hw, adapter->vfs_allocated_count);
1163 /* Clear any pending interrupts. */
1165 igb_irq_enable(adapter);
1167 netif_tx_start_all_queues(adapter->netdev);
1169 /* Fire a link change interrupt to start the watchdog. */
1170 wr32(E1000_ICS, E1000_ICS_LSC);
1174 void igb_down(struct igb_adapter *adapter)
1176 struct e1000_hw *hw = &adapter->hw;
1177 struct net_device *netdev = adapter->netdev;
1181 /* signal that we're down so the interrupt handler does not
1182 * reschedule our watchdog timer */
1183 set_bit(__IGB_DOWN, &adapter->state);
1185 /* disable receives in the hardware */
1186 rctl = rd32(E1000_RCTL);
1187 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1188 /* flush and sleep below */
1190 netif_tx_stop_all_queues(netdev);
1192 /* disable transmits in the hardware */
1193 tctl = rd32(E1000_TCTL);
1194 tctl &= ~E1000_TCTL_EN;
1195 wr32(E1000_TCTL, tctl);
1196 /* flush both disables and wait for them to finish */
1200 for (i = 0; i < adapter->num_q_vectors; i++) {
1201 struct igb_q_vector *q_vector = adapter->q_vector[i];
1202 napi_disable(&q_vector->napi);
1205 igb_irq_disable(adapter);
1207 del_timer_sync(&adapter->watchdog_timer);
1208 del_timer_sync(&adapter->phy_info_timer);
1210 netdev->tx_queue_len = adapter->tx_queue_len;
1211 netif_carrier_off(netdev);
1213 /* record the stats before reset*/
1214 igb_update_stats(adapter);
1216 adapter->link_speed = 0;
1217 adapter->link_duplex = 0;
1219 if (!pci_channel_offline(adapter->pdev))
1221 igb_clean_all_tx_rings(adapter);
1222 igb_clean_all_rx_rings(adapter);
1223 #ifdef CONFIG_IGB_DCA
1225 /* since we reset the hardware DCA settings were cleared */
1226 igb_setup_dca(adapter);
1230 void igb_reinit_locked(struct igb_adapter *adapter)
1232 WARN_ON(in_interrupt());
1233 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1237 clear_bit(__IGB_RESETTING, &adapter->state);
1240 void igb_reset(struct igb_adapter *adapter)
1242 struct e1000_hw *hw = &adapter->hw;
1243 struct e1000_mac_info *mac = &hw->mac;
1244 struct e1000_fc_info *fc = &hw->fc;
1245 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
1248 /* Repartition Pba for greater than 9k mtu
1249 * To take effect CTRL.RST is required.
1251 switch (mac->type) {
1253 pba = E1000_PBA_64K;
1257 pba = E1000_PBA_34K;
1261 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
1262 (mac->type < e1000_82576)) {
1263 /* adjust PBA for jumbo frames */
1264 wr32(E1000_PBA, pba);
1266 /* To maintain wire speed transmits, the Tx FIFO should be
1267 * large enough to accommodate two full transmit packets,
1268 * rounded up to the next 1KB and expressed in KB. Likewise,
1269 * the Rx FIFO should be large enough to accommodate at least
1270 * one full receive packet and is similarly rounded up and
1271 * expressed in KB. */
1272 pba = rd32(E1000_PBA);
1273 /* upper 16 bits has Tx packet buffer allocation size in KB */
1274 tx_space = pba >> 16;
1275 /* lower 16 bits has Rx packet buffer allocation size in KB */
1277 /* the tx fifo also stores 16 bytes of information about the tx
1278 * but don't include ethernet FCS because hardware appends it */
1279 min_tx_space = (adapter->max_frame_size +
1280 sizeof(union e1000_adv_tx_desc) -
1282 min_tx_space = ALIGN(min_tx_space, 1024);
1283 min_tx_space >>= 10;
1284 /* software strips receive CRC, so leave room for it */
1285 min_rx_space = adapter->max_frame_size;
1286 min_rx_space = ALIGN(min_rx_space, 1024);
1287 min_rx_space >>= 10;
1289 /* If current Tx allocation is less than the min Tx FIFO size,
1290 * and the min Tx FIFO size is less than the current Rx FIFO
1291 * allocation, take space away from current Rx allocation */
1292 if (tx_space < min_tx_space &&
1293 ((min_tx_space - tx_space) < pba)) {
1294 pba = pba - (min_tx_space - tx_space);
1296 /* if short on rx space, rx wins and must trump tx
1298 if (pba < min_rx_space)
1301 wr32(E1000_PBA, pba);
1304 /* flow control settings */
1305 /* The high water mark must be low enough to fit one full frame
1306 * (or the size used for early receive) above it in the Rx FIFO.
1307 * Set it to the lower of:
1308 * - 90% of the Rx FIFO size, or
1309 * - the full Rx FIFO size minus one full frame */
1310 hwm = min(((pba << 10) * 9 / 10),
1311 ((pba << 10) - 2 * adapter->max_frame_size));
1313 if (mac->type < e1000_82576) {
1314 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
1315 fc->low_water = fc->high_water - 8;
1317 fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
1318 fc->low_water = fc->high_water - 16;
1320 fc->pause_time = 0xFFFF;
1322 fc->current_mode = fc->requested_mode;
1324 /* disable receive for all VFs and wait one second */
1325 if (adapter->vfs_allocated_count) {
1327 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
1328 adapter->vf_data[i].clear_to_send = false;
1330 /* ping all the active vfs to let them know we are going down */
1331 igb_ping_all_vfs(adapter);
1333 /* disable transmits and receives */
1334 wr32(E1000_VFRE, 0);
1335 wr32(E1000_VFTE, 0);
1338 /* Allow time for pending master requests to run */
1339 adapter->hw.mac.ops.reset_hw(&adapter->hw);
1342 if (adapter->hw.mac.ops.init_hw(&adapter->hw))
1343 dev_err(&adapter->pdev->dev, "Hardware Error\n");
1345 igb_update_mng_vlan(adapter);
1347 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
1348 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
1350 igb_reset_adaptive(&adapter->hw);
1351 igb_get_phy_info(&adapter->hw);
1354 static const struct net_device_ops igb_netdev_ops = {
1355 .ndo_open = igb_open,
1356 .ndo_stop = igb_close,
1357 .ndo_start_xmit = igb_xmit_frame_adv,
1358 .ndo_get_stats = igb_get_stats,
1359 .ndo_set_rx_mode = igb_set_rx_mode,
1360 .ndo_set_multicast_list = igb_set_rx_mode,
1361 .ndo_set_mac_address = igb_set_mac,
1362 .ndo_change_mtu = igb_change_mtu,
1363 .ndo_do_ioctl = igb_ioctl,
1364 .ndo_tx_timeout = igb_tx_timeout,
1365 .ndo_validate_addr = eth_validate_addr,
1366 .ndo_vlan_rx_register = igb_vlan_rx_register,
1367 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
1368 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
1369 #ifdef CONFIG_NET_POLL_CONTROLLER
1370 .ndo_poll_controller = igb_netpoll,
1375 * igb_probe - Device Initialization Routine
1376 * @pdev: PCI device information struct
1377 * @ent: entry in igb_pci_tbl
1379 * Returns 0 on success, negative on failure
1381 * igb_probe initializes an adapter identified by a pci_dev structure.
1382 * The OS initialization, configuring of the adapter private structure,
1383 * and a hardware reset occur.
1385 static int __devinit igb_probe(struct pci_dev *pdev,
1386 const struct pci_device_id *ent)
1388 struct net_device *netdev;
1389 struct igb_adapter *adapter;
1390 struct e1000_hw *hw;
1391 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
1392 unsigned long mmio_start, mmio_len;
1393 int err, pci_using_dac;
1394 u16 eeprom_data = 0;
1395 u16 eeprom_apme_mask = IGB_EEPROM_APME;
1398 err = pci_enable_device_mem(pdev);
1403 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
1405 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
1409 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1411 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1413 dev_err(&pdev->dev, "No usable DMA "
1414 "configuration, aborting\n");
1420 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
1426 pci_enable_pcie_error_reporting(pdev);
1428 pci_set_master(pdev);
1429 pci_save_state(pdev);
1432 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
1433 IGB_ABS_MAX_TX_QUEUES);
1435 goto err_alloc_etherdev;
1437 SET_NETDEV_DEV(netdev, &pdev->dev);
1439 pci_set_drvdata(pdev, netdev);
1440 adapter = netdev_priv(netdev);
1441 adapter->netdev = netdev;
1442 adapter->pdev = pdev;
1445 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
1447 mmio_start = pci_resource_start(pdev, 0);
1448 mmio_len = pci_resource_len(pdev, 0);
1451 hw->hw_addr = ioremap(mmio_start, mmio_len);
1455 netdev->netdev_ops = &igb_netdev_ops;
1456 igb_set_ethtool_ops(netdev);
1457 netdev->watchdog_timeo = 5 * HZ;
1459 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1461 netdev->mem_start = mmio_start;
1462 netdev->mem_end = mmio_start + mmio_len;
1464 /* PCI config space info */
1465 hw->vendor_id = pdev->vendor;
1466 hw->device_id = pdev->device;
1467 hw->revision_id = pdev->revision;
1468 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1469 hw->subsystem_device_id = pdev->subsystem_device;
1471 /* setup the private structure */
1473 /* Copy the default MAC, PHY and NVM function pointers */
1474 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
1475 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
1476 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
1477 /* Initialize skew-specific constants */
1478 err = ei->get_invariants(hw);
1482 #ifdef CONFIG_PCI_IOV
1483 /* since iov functionality isn't critical to base device function we
1484 * can accept failure. If it fails we don't allow iov to be enabled */
1485 if (hw->mac.type == e1000_82576) {
1486 /* 82576 supports a maximum of 7 VFs in addition to the PF */
1487 unsigned int num_vfs = (max_vfs > 7) ? 7 : max_vfs;
1489 unsigned char mac_addr[ETH_ALEN];
1492 adapter->vf_data = kcalloc(num_vfs,
1493 sizeof(struct vf_data_storage),
1495 if (!adapter->vf_data) {
1497 "Could not allocate VF private data - "
1498 "IOV enable failed\n");
1500 err = pci_enable_sriov(pdev, num_vfs);
1502 adapter->vfs_allocated_count = num_vfs;
1503 dev_info(&pdev->dev,
1504 "%d vfs allocated\n",
1507 i < adapter->vfs_allocated_count;
1509 random_ether_addr(mac_addr);
1510 igb_set_vf_mac(adapter, i,
1514 kfree(adapter->vf_data);
1515 adapter->vf_data = NULL;
1522 /* setup the private structure */
1523 err = igb_sw_init(adapter);
1527 igb_get_bus_info_pcie(hw);
1529 hw->phy.autoneg_wait_to_complete = false;
1530 hw->mac.adaptive_ifs = true;
1532 /* Copper options */
1533 if (hw->phy.media_type == e1000_media_type_copper) {
1534 hw->phy.mdix = AUTO_ALL_MODES;
1535 hw->phy.disable_polarity_correction = false;
1536 hw->phy.ms_type = e1000_ms_hw_default;
1539 if (igb_check_reset_block(hw))
1540 dev_info(&pdev->dev,
1541 "PHY reset is blocked due to SOL/IDER session.\n");
1543 netdev->features = NETIF_F_SG |
1545 NETIF_F_HW_VLAN_TX |
1546 NETIF_F_HW_VLAN_RX |
1547 NETIF_F_HW_VLAN_FILTER;
1549 netdev->features |= NETIF_F_IPV6_CSUM;
1550 netdev->features |= NETIF_F_TSO;
1551 netdev->features |= NETIF_F_TSO6;
1553 netdev->features |= NETIF_F_GRO;
1555 netdev->vlan_features |= NETIF_F_TSO;
1556 netdev->vlan_features |= NETIF_F_TSO6;
1557 netdev->vlan_features |= NETIF_F_IP_CSUM;
1558 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
1559 netdev->vlan_features |= NETIF_F_SG;
1562 netdev->features |= NETIF_F_HIGHDMA;
1564 if (adapter->hw.mac.type == e1000_82576)
1565 netdev->features |= NETIF_F_SCTP_CSUM;
1567 adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
1569 /* before reading the NVM, reset the controller to put the device in a
1570 * known good starting state */
1571 hw->mac.ops.reset_hw(hw);
1573 /* make sure the NVM is good */
1574 if (igb_validate_nvm_checksum(hw) < 0) {
1575 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
1580 /* copy the MAC address out of the NVM */
1581 if (hw->mac.ops.read_mac_addr(hw))
1582 dev_err(&pdev->dev, "NVM Read Error\n");
1584 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1585 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1587 if (!is_valid_ether_addr(netdev->perm_addr)) {
1588 dev_err(&pdev->dev, "Invalid MAC Address\n");
1593 setup_timer(&adapter->watchdog_timer, &igb_watchdog,
1594 (unsigned long) adapter);
1595 setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
1596 (unsigned long) adapter);
1598 INIT_WORK(&adapter->reset_task, igb_reset_task);
1599 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
1601 /* Initialize link properties that are user-changeable */
1602 adapter->fc_autoneg = true;
1603 hw->mac.autoneg = true;
1604 hw->phy.autoneg_advertised = 0x2f;
1606 hw->fc.requested_mode = e1000_fc_default;
1607 hw->fc.current_mode = e1000_fc_default;
1609 adapter->itr_setting = IGB_DEFAULT_ITR;
1610 adapter->itr = IGB_START_ITR;
1612 igb_validate_mdi_setting(hw);
1614 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1615 * enable the ACPI Magic Packet filter
1618 if (hw->bus.func == 0)
1619 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1620 else if (hw->bus.func == 1)
1621 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1623 if (eeprom_data & eeprom_apme_mask)
1624 adapter->eeprom_wol |= E1000_WUFC_MAG;
1626 /* now that we have the eeprom settings, apply the special cases where
1627 * the eeprom may be wrong or the board simply won't support wake on
1628 * lan on a particular port */
1629 switch (pdev->device) {
1630 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1631 adapter->eeprom_wol = 0;
1633 case E1000_DEV_ID_82575EB_FIBER_SERDES:
1634 case E1000_DEV_ID_82576_FIBER:
1635 case E1000_DEV_ID_82576_SERDES:
1636 /* Wake events only supported on port A for dual fiber
1637 * regardless of eeprom setting */
1638 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
1639 adapter->eeprom_wol = 0;
1641 case E1000_DEV_ID_82576_QUAD_COPPER:
1642 /* if quad port adapter, disable WoL on all but port A */
1643 if (global_quad_port_a != 0)
1644 adapter->eeprom_wol = 0;
1646 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
1647 /* Reset for multiple quad port adapters */
1648 if (++global_quad_port_a == 4)
1649 global_quad_port_a = 0;
1653 /* initialize the wol settings based on the eeprom settings */
1654 adapter->wol = adapter->eeprom_wol;
1655 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1657 /* reset the hardware with the new settings */
1660 /* let the f/w know that the h/w is now under the control of the
1662 igb_get_hw_control(adapter);
1664 strcpy(netdev->name, "eth%d");
1665 err = register_netdev(netdev);
1669 /* carrier off reporting is important to ethtool even BEFORE open */
1670 netif_carrier_off(netdev);
1672 #ifdef CONFIG_IGB_DCA
1673 if (dca_add_requester(&pdev->dev) == 0) {
1674 adapter->flags |= IGB_FLAG_DCA_ENABLED;
1675 dev_info(&pdev->dev, "DCA enabled\n");
1676 igb_setup_dca(adapter);
1681 * Initialize hardware timer: we keep it running just in case
1682 * that some program needs it later on.
1684 memset(&adapter->cycles, 0, sizeof(adapter->cycles));
1685 adapter->cycles.read = igb_read_clock;
1686 adapter->cycles.mask = CLOCKSOURCE_MASK(64);
1687 adapter->cycles.mult = 1;
1688 adapter->cycles.shift = IGB_TSYNC_SHIFT;
1691 IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS * IGB_TSYNC_SCALE);
1694 * Avoid rollover while we initialize by resetting the time counter.
1696 wr32(E1000_SYSTIML, 0x00000000);
1697 wr32(E1000_SYSTIMH, 0x00000000);
1700 * Set registers so that rollover occurs soon to test this.
1702 wr32(E1000_SYSTIML, 0x00000000);
1703 wr32(E1000_SYSTIMH, 0xFF800000);
1706 timecounter_init(&adapter->clock,
1708 ktime_to_ns(ktime_get_real()));
1711 * Synchronize our NIC clock against system wall clock. NIC
1712 * time stamp reading requires ~3us per sample, each sample
1713 * was pretty stable even under load => only require 10
1714 * samples for each offset comparison.
1716 memset(&adapter->compare, 0, sizeof(adapter->compare));
1717 adapter->compare.source = &adapter->clock;
1718 adapter->compare.target = ktime_get_real;
1719 adapter->compare.num_samples = 10;
1720 timecompare_update(&adapter->compare, 0);
1726 "igb: %s: hw %p initialized timer\n",
1727 igb_get_time_str(adapter, buffer),
1732 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
1733 /* print bus type/speed/width info */
1734 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
1736 ((hw->bus.speed == e1000_bus_speed_2500)
1737 ? "2.5Gb/s" : "unknown"),
1738 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
1739 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
1740 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
1744 igb_read_part_num(hw, &part_num);
1745 dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
1746 (part_num >> 8), (part_num & 0xff));
1748 dev_info(&pdev->dev,
1749 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1750 adapter->msix_entries ? "MSI-X" :
1751 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
1752 adapter->num_rx_queues, adapter->num_tx_queues);
1757 igb_release_hw_control(adapter);
1759 if (!igb_check_reset_block(hw))
1762 if (hw->flash_address)
1763 iounmap(hw->flash_address);
1765 igb_clear_interrupt_scheme(adapter);
1766 iounmap(hw->hw_addr);
1768 free_netdev(netdev);
1770 pci_release_selected_regions(pdev, pci_select_bars(pdev,
1774 pci_disable_device(pdev);
1779 * igb_remove - Device Removal Routine
1780 * @pdev: PCI device information struct
1782 * igb_remove is called by the PCI subsystem to alert the driver
1783 * that it should release a PCI device. The could be caused by a
1784 * Hot-Plug event, or because the driver is going to be removed from
1787 static void __devexit igb_remove(struct pci_dev *pdev)
1789 struct net_device *netdev = pci_get_drvdata(pdev);
1790 struct igb_adapter *adapter = netdev_priv(netdev);
1791 struct e1000_hw *hw = &adapter->hw;
1793 /* flush_scheduled work may reschedule our watchdog task, so
1794 * explicitly disable watchdog tasks from being rescheduled */
1795 set_bit(__IGB_DOWN, &adapter->state);
1796 del_timer_sync(&adapter->watchdog_timer);
1797 del_timer_sync(&adapter->phy_info_timer);
1799 flush_scheduled_work();
1801 #ifdef CONFIG_IGB_DCA
1802 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
1803 dev_info(&pdev->dev, "DCA disabled\n");
1804 dca_remove_requester(&pdev->dev);
1805 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
1806 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
1810 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1811 * would have already happened in close and is redundant. */
1812 igb_release_hw_control(adapter);
1814 unregister_netdev(netdev);
1816 if (!igb_check_reset_block(&adapter->hw))
1817 igb_reset_phy(&adapter->hw);
1819 igb_clear_interrupt_scheme(adapter);
1821 #ifdef CONFIG_PCI_IOV
1822 /* reclaim resources allocated to VFs */
1823 if (adapter->vf_data) {
1824 /* disable iov and allow time for transactions to clear */
1825 pci_disable_sriov(pdev);
1828 kfree(adapter->vf_data);
1829 adapter->vf_data = NULL;
1830 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
1832 dev_info(&pdev->dev, "IOV Disabled\n");
1835 iounmap(hw->hw_addr);
1836 if (hw->flash_address)
1837 iounmap(hw->flash_address);
1838 pci_release_selected_regions(pdev, pci_select_bars(pdev,
1841 free_netdev(netdev);
1843 pci_disable_pcie_error_reporting(pdev);
1845 pci_disable_device(pdev);
1849 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1850 * @adapter: board private structure to initialize
1852 * igb_sw_init initializes the Adapter private data structure.
1853 * Fields are initialized based on PCI device information and
1854 * OS network device settings (MTU size).
1856 static int __devinit igb_sw_init(struct igb_adapter *adapter)
1858 struct e1000_hw *hw = &adapter->hw;
1859 struct net_device *netdev = adapter->netdev;
1860 struct pci_dev *pdev = adapter->pdev;
1862 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
1864 adapter->tx_ring_count = IGB_DEFAULT_TXD;
1865 adapter->rx_ring_count = IGB_DEFAULT_RXD;
1866 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1867 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1869 /* This call may decrease the number of queues depending on
1870 * interrupt mode. */
1871 if (igb_init_interrupt_scheme(adapter)) {
1872 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
1876 /* Explicitly disable IRQ since the NIC can be in any state. */
1877 igb_irq_disable(adapter);
1879 set_bit(__IGB_DOWN, &adapter->state);
1884 * igb_open - Called when a network interface is made active
1885 * @netdev: network interface device structure
1887 * Returns 0 on success, negative value on failure
1889 * The open entry point is called when a network interface is made
1890 * active by the system (IFF_UP). At this point all resources needed
1891 * for transmit and receive operations are allocated, the interrupt
1892 * handler is registered with the OS, the watchdog timer is started,
1893 * and the stack is notified that the interface is ready.
1895 static int igb_open(struct net_device *netdev)
1897 struct igb_adapter *adapter = netdev_priv(netdev);
1898 struct e1000_hw *hw = &adapter->hw;
1902 /* disallow open during test */
1903 if (test_bit(__IGB_TESTING, &adapter->state))
1906 netif_carrier_off(netdev);
1908 /* allocate transmit descriptors */
1909 err = igb_setup_all_tx_resources(adapter);
1913 /* allocate receive descriptors */
1914 err = igb_setup_all_rx_resources(adapter);
1918 /* e1000_power_up_phy(adapter); */
1920 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1921 if ((adapter->hw.mng_cookie.status &
1922 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
1923 igb_update_mng_vlan(adapter);
1925 /* before we allocate an interrupt, we must be ready to handle it.
1926 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1927 * as soon as we call pci_request_irq, so we have to setup our
1928 * clean_rx handler before we do so. */
1929 igb_configure(adapter);
1931 igb_vmm_control(adapter);
1932 igb_set_vmolr(hw, adapter->vfs_allocated_count);
1934 err = igb_request_irq(adapter);
1938 /* From here on the code is the same as igb_up() */
1939 clear_bit(__IGB_DOWN, &adapter->state);
1941 for (i = 0; i < adapter->num_q_vectors; i++) {
1942 struct igb_q_vector *q_vector = adapter->q_vector[i];
1943 napi_enable(&q_vector->napi);
1946 /* Clear any pending interrupts. */
1949 igb_irq_enable(adapter);
1951 netif_tx_start_all_queues(netdev);
1953 /* Fire a link status change interrupt to start the watchdog. */
1954 wr32(E1000_ICS, E1000_ICS_LSC);
1959 igb_release_hw_control(adapter);
1960 /* e1000_power_down_phy(adapter); */
1961 igb_free_all_rx_resources(adapter);
1963 igb_free_all_tx_resources(adapter);
1971 * igb_close - Disables a network interface
1972 * @netdev: network interface device structure
1974 * Returns 0, this is not allowed to fail
1976 * The close entry point is called when an interface is de-activated
1977 * by the OS. The hardware is still under the driver's control, but
1978 * needs to be disabled. A global MAC reset is issued to stop the
1979 * hardware, and all transmit and receive resources are freed.
1981 static int igb_close(struct net_device *netdev)
1983 struct igb_adapter *adapter = netdev_priv(netdev);
1985 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
1988 igb_free_irq(adapter);
1990 igb_free_all_tx_resources(adapter);
1991 igb_free_all_rx_resources(adapter);
1993 /* kill manageability vlan ID if supported, but not if a vlan with
1994 * the same ID is registered on the host OS (let 8021q kill it) */
1995 if ((adapter->hw.mng_cookie.status &
1996 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1998 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
1999 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2005 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
2006 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2008 * Return 0 on success, negative on failure
2010 int igb_setup_tx_resources(struct igb_ring *tx_ring)
2012 struct pci_dev *pdev = tx_ring->pdev;
2015 size = sizeof(struct igb_buffer) * tx_ring->count;
2016 tx_ring->buffer_info = vmalloc(size);
2017 if (!tx_ring->buffer_info)
2019 memset(tx_ring->buffer_info, 0, size);
2021 /* round up to nearest 4K */
2022 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
2023 tx_ring->size = ALIGN(tx_ring->size, 4096);
2025 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2031 tx_ring->next_to_use = 0;
2032 tx_ring->next_to_clean = 0;
2036 vfree(tx_ring->buffer_info);
2038 "Unable to allocate memory for the transmit descriptor ring\n");
2043 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
2044 * (Descriptors) for all queues
2045 * @adapter: board private structure
2047 * Return 0 on success, negative on failure
2049 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
2054 for (i = 0; i < adapter->num_tx_queues; i++) {
2055 err = igb_setup_tx_resources(&adapter->tx_ring[i]);
2057 dev_err(&adapter->pdev->dev,
2058 "Allocation for Tx Queue %u failed\n", i);
2059 for (i--; i >= 0; i--)
2060 igb_free_tx_resources(&adapter->tx_ring[i]);
2065 for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
2066 r_idx = i % adapter->num_tx_queues;
2067 adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
2073 * igb_setup_tctl - configure the transmit control registers
2074 * @adapter: Board private structure
2076 static void igb_setup_tctl(struct igb_adapter *adapter)
2078 struct e1000_hw *hw = &adapter->hw;
2081 /* disable queue 0 which is enabled by default on 82575 and 82576 */
2082 wr32(E1000_TXDCTL(0), 0);
2084 /* Program the Transmit Control Register */
2085 tctl = rd32(E1000_TCTL);
2086 tctl &= ~E1000_TCTL_CT;
2087 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2088 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2090 igb_config_collision_dist(hw);
2092 /* Enable transmits */
2093 tctl |= E1000_TCTL_EN;
2095 wr32(E1000_TCTL, tctl);
2099 * igb_configure_tx_ring - Configure transmit ring after Reset
2100 * @adapter: board private structure
2101 * @ring: tx ring to configure
2103 * Configure a transmit ring after a reset.
2105 static void igb_configure_tx_ring(struct igb_adapter *adapter,
2106 struct igb_ring *ring)
2108 struct e1000_hw *hw = &adapter->hw;
2110 u64 tdba = ring->dma;
2111 int reg_idx = ring->reg_idx;
2113 /* disable the queue */
2114 txdctl = rd32(E1000_TXDCTL(reg_idx));
2115 wr32(E1000_TXDCTL(reg_idx),
2116 txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
2120 wr32(E1000_TDLEN(reg_idx),
2121 ring->count * sizeof(union e1000_adv_tx_desc));
2122 wr32(E1000_TDBAL(reg_idx),
2123 tdba & 0x00000000ffffffffULL);
2124 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
2126 ring->head = hw->hw_addr + E1000_TDH(reg_idx);
2127 ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
2128 writel(0, ring->head);
2129 writel(0, ring->tail);
2131 txdctl |= IGB_TX_PTHRESH;
2132 txdctl |= IGB_TX_HTHRESH << 8;
2133 txdctl |= IGB_TX_WTHRESH << 16;
2135 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2136 wr32(E1000_TXDCTL(reg_idx), txdctl);
2140 * igb_configure_tx - Configure transmit Unit after Reset
2141 * @adapter: board private structure
2143 * Configure the Tx unit of the MAC after a reset.
2145 static void igb_configure_tx(struct igb_adapter *adapter)
2149 for (i = 0; i < adapter->num_tx_queues; i++)
2150 igb_configure_tx_ring(adapter, &adapter->tx_ring[i]);
2154 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
2155 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2157 * Returns 0 on success, negative on failure
2159 int igb_setup_rx_resources(struct igb_ring *rx_ring)
2161 struct pci_dev *pdev = rx_ring->pdev;
2164 size = sizeof(struct igb_buffer) * rx_ring->count;
2165 rx_ring->buffer_info = vmalloc(size);
2166 if (!rx_ring->buffer_info)
2168 memset(rx_ring->buffer_info, 0, size);
2170 desc_len = sizeof(union e1000_adv_rx_desc);
2172 /* Round up to nearest 4K */
2173 rx_ring->size = rx_ring->count * desc_len;
2174 rx_ring->size = ALIGN(rx_ring->size, 4096);
2176 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
2182 rx_ring->next_to_clean = 0;
2183 rx_ring->next_to_use = 0;
2188 vfree(rx_ring->buffer_info);
2189 dev_err(&pdev->dev, "Unable to allocate memory for "
2190 "the receive descriptor ring\n");
2195 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
2196 * (Descriptors) for all queues
2197 * @adapter: board private structure
2199 * Return 0 on success, negative on failure
2201 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
2205 for (i = 0; i < adapter->num_rx_queues; i++) {
2206 err = igb_setup_rx_resources(&adapter->rx_ring[i]);
2208 dev_err(&adapter->pdev->dev,
2209 "Allocation for Rx Queue %u failed\n", i);
2210 for (i--; i >= 0; i--)
2211 igb_free_rx_resources(&adapter->rx_ring[i]);
2220 * igb_setup_rctl - configure the receive control registers
2221 * @adapter: Board private structure
2223 static void igb_setup_rctl(struct igb_adapter *adapter)
2225 struct e1000_hw *hw = &adapter->hw;
2228 rctl = rd32(E1000_RCTL);
2230 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2231 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
2233 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
2234 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2237 * enable stripping of CRC. It's unlikely this will break BMC
2238 * redirection as it did with e1000. Newer features require
2239 * that the HW strips the CRC.
2241 rctl |= E1000_RCTL_SECRC;
2244 * disable store bad packets and clear size bits.
2246 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
2248 /* enable LPE to prevent packets larger than max_frame_size */
2249 rctl |= E1000_RCTL_LPE;
2251 /* disable queue 0 to prevent tail write w/o re-config */
2252 wr32(E1000_RXDCTL(0), 0);
2254 /* Attention!!! For SR-IOV PF driver operations you must enable
2255 * queue drop for all VF and PF queues to prevent head of line blocking
2256 * if an un-trusted VF does not provide descriptors to hardware.
2258 if (adapter->vfs_allocated_count) {
2261 /* set all queue drop enable bits */
2262 wr32(E1000_QDE, ALL_QUEUES);
2264 vmolr = rd32(E1000_VMOLR(adapter->vfs_allocated_count));
2265 if (rctl & E1000_RCTL_LPE)
2266 vmolr |= E1000_VMOLR_LPE;
2267 if (adapter->num_rx_queues > 1)
2268 vmolr |= E1000_VMOLR_RSSE;
2269 wr32(E1000_VMOLR(adapter->vfs_allocated_count), vmolr);
2272 wr32(E1000_RCTL, rctl);
2276 * igb_rlpml_set - set maximum receive packet size
2277 * @adapter: board private structure
2279 * Configure maximum receivable packet size.
2281 static void igb_rlpml_set(struct igb_adapter *adapter)
2283 u32 max_frame_size = adapter->max_frame_size;
2284 struct e1000_hw *hw = &adapter->hw;
2285 u16 pf_id = adapter->vfs_allocated_count;
2288 max_frame_size += VLAN_TAG_SIZE;
2290 /* if vfs are enabled we set RLPML to the largest possible request
2291 * size and set the VMOLR RLPML to the size we need */
2293 igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
2294 max_frame_size = MAX_STD_JUMBO_FRAME_SIZE + VLAN_TAG_SIZE;
2297 wr32(E1000_RLPML, max_frame_size);
2301 * igb_configure_vt_default_pool - Configure VT default pool
2302 * @adapter: board private structure
2304 * Configure the default pool
2306 static void igb_configure_vt_default_pool(struct igb_adapter *adapter)
2308 struct e1000_hw *hw = &adapter->hw;
2309 u16 pf_id = adapter->vfs_allocated_count;
2312 /* not in sr-iov mode - do nothing */
2316 vtctl = rd32(E1000_VT_CTL);
2317 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
2318 E1000_VT_CTL_DISABLE_DEF_POOL);
2319 vtctl |= pf_id << E1000_VT_CTL_DEFAULT_POOL_SHIFT;
2320 wr32(E1000_VT_CTL, vtctl);
2324 * igb_configure_rx_ring - Configure a receive ring after Reset
2325 * @adapter: board private structure
2326 * @ring: receive ring to be configured
2328 * Configure the Rx unit of the MAC after a reset.
2330 static void igb_configure_rx_ring(struct igb_adapter *adapter,
2331 struct igb_ring *ring)
2333 struct e1000_hw *hw = &adapter->hw;
2334 u64 rdba = ring->dma;
2335 int reg_idx = ring->reg_idx;
2338 /* disable the queue */
2339 rxdctl = rd32(E1000_RXDCTL(reg_idx));
2340 wr32(E1000_RXDCTL(reg_idx),
2341 rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
2343 /* Set DMA base address registers */
2344 wr32(E1000_RDBAL(reg_idx),
2345 rdba & 0x00000000ffffffffULL);
2346 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
2347 wr32(E1000_RDLEN(reg_idx),
2348 ring->count * sizeof(union e1000_adv_rx_desc));
2350 /* initialize head and tail */
2351 ring->head = hw->hw_addr + E1000_RDH(reg_idx);
2352 ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
2353 writel(0, ring->head);
2354 writel(0, ring->tail);
2356 /* set descriptor configuration */
2357 if (ring->rx_buffer_len < IGB_RXBUFFER_1024) {
2358 srrctl = ALIGN(ring->rx_buffer_len, 64) <<
2359 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
2360 #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
2361 srrctl |= IGB_RXBUFFER_16384 >>
2362 E1000_SRRCTL_BSIZEPKT_SHIFT;
2364 srrctl |= (PAGE_SIZE / 2) >>
2365 E1000_SRRCTL_BSIZEPKT_SHIFT;
2367 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2369 srrctl = ALIGN(ring->rx_buffer_len, 1024) >>
2370 E1000_SRRCTL_BSIZEPKT_SHIFT;
2371 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
2374 wr32(E1000_SRRCTL(reg_idx), srrctl);
2376 /* enable receive descriptor fetching */
2377 rxdctl = rd32(E1000_RXDCTL(reg_idx));
2378 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
2379 rxdctl &= 0xFFF00000;
2380 rxdctl |= IGB_RX_PTHRESH;
2381 rxdctl |= IGB_RX_HTHRESH << 8;
2382 rxdctl |= IGB_RX_WTHRESH << 16;
2383 wr32(E1000_RXDCTL(reg_idx), rxdctl);
2387 * igb_configure_rx - Configure receive Unit after Reset
2388 * @adapter: board private structure
2390 * Configure the Rx unit of the MAC after a reset.
2392 static void igb_configure_rx(struct igb_adapter *adapter)
2394 struct e1000_hw *hw = &adapter->hw;
2398 /* disable receives while setting up the descriptors */
2399 rctl = rd32(E1000_RCTL);
2400 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
2404 if (adapter->itr_setting > 3)
2405 wr32(E1000_ITR, adapter->itr);
2407 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2408 * the Base and Length of the Rx Descriptor Ring */
2409 for (i = 0; i < adapter->num_rx_queues; i++)
2410 igb_configure_rx_ring(adapter, &adapter->rx_ring[i]);
2412 if (adapter->num_rx_queues > 1) {
2421 get_random_bytes(&random[0], 40);
2423 if (hw->mac.type >= e1000_82576)
2427 for (j = 0; j < (32 * 4); j++) {
2429 adapter->rx_ring[(j % adapter->num_rx_queues)].reg_idx << shift;
2432 hw->hw_addr + E1000_RETA(0) + (j & ~3));
2434 if (adapter->vfs_allocated_count)
2435 mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
2437 mrqc = E1000_MRQC_ENABLE_RSS_4Q;
2439 /* Fill out hash function seeds */
2440 for (j = 0; j < 10; j++)
2441 array_wr32(E1000_RSSRK(0), j, random[j]);
2443 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
2444 E1000_MRQC_RSS_FIELD_IPV4_TCP);
2445 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
2446 E1000_MRQC_RSS_FIELD_IPV6_TCP);
2447 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP |
2448 E1000_MRQC_RSS_FIELD_IPV6_UDP);
2449 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
2450 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
2452 wr32(E1000_MRQC, mrqc);
2453 } else if (adapter->vfs_allocated_count) {
2454 /* Enable multi-queue for sr-iov */
2455 wr32(E1000_MRQC, E1000_MRQC_ENABLE_VMDQ);
2458 /* Enable Receive Checksum Offload for TCP and UDP */
2459 rxcsum = rd32(E1000_RXCSUM);
2460 /* Disable raw packet checksumming */
2461 rxcsum |= E1000_RXCSUM_PCSD;
2463 if (adapter->hw.mac.type == e1000_82576)
2464 /* Enable Receive Checksum Offload for SCTP */
2465 rxcsum |= E1000_RXCSUM_CRCOFL;
2467 /* Don't need to set TUOFL or IPOFL, they default to 1 */
2468 wr32(E1000_RXCSUM, rxcsum);
2470 /* Set the default pool for the PF's first queue */
2471 igb_configure_vt_default_pool(adapter);
2473 /* set UTA to appropriate mode */
2474 igb_set_uta(adapter);
2476 /* set the correct pool for the PF default MAC address in entry 0 */
2477 igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
2478 adapter->vfs_allocated_count);
2480 igb_rlpml_set(adapter);
2482 /* Enable Receives */
2483 wr32(E1000_RCTL, rctl);
2487 * igb_free_tx_resources - Free Tx Resources per Queue
2488 * @tx_ring: Tx descriptor ring for a specific queue
2490 * Free all transmit software resources
2492 void igb_free_tx_resources(struct igb_ring *tx_ring)
2494 igb_clean_tx_ring(tx_ring);
2496 vfree(tx_ring->buffer_info);
2497 tx_ring->buffer_info = NULL;
2499 pci_free_consistent(tx_ring->pdev, tx_ring->size,
2500 tx_ring->desc, tx_ring->dma);
2502 tx_ring->desc = NULL;
2506 * igb_free_all_tx_resources - Free Tx Resources for All Queues
2507 * @adapter: board private structure
2509 * Free all transmit software resources
2511 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
2515 for (i = 0; i < adapter->num_tx_queues; i++)
2516 igb_free_tx_resources(&adapter->tx_ring[i]);
2519 static void igb_unmap_and_free_tx_resource(struct igb_ring *tx_ring,
2520 struct igb_buffer *buffer_info)
2522 buffer_info->dma = 0;
2523 if (buffer_info->skb) {
2524 skb_dma_unmap(&tx_ring->pdev->dev,
2527 dev_kfree_skb_any(buffer_info->skb);
2528 buffer_info->skb = NULL;
2530 buffer_info->time_stamp = 0;
2531 /* buffer_info must be completely set up in the transmit path */
2535 * igb_clean_tx_ring - Free Tx Buffers
2536 * @tx_ring: ring to be cleaned
2538 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
2540 struct igb_buffer *buffer_info;
2544 if (!tx_ring->buffer_info)
2546 /* Free all the Tx ring sk_buffs */
2548 for (i = 0; i < tx_ring->count; i++) {
2549 buffer_info = &tx_ring->buffer_info[i];
2550 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
2553 size = sizeof(struct igb_buffer) * tx_ring->count;
2554 memset(tx_ring->buffer_info, 0, size);
2556 /* Zero out the descriptor ring */
2558 memset(tx_ring->desc, 0, tx_ring->size);
2560 tx_ring->next_to_use = 0;
2561 tx_ring->next_to_clean = 0;
2563 writel(0, tx_ring->head);
2564 writel(0, tx_ring->tail);
2568 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
2569 * @adapter: board private structure
2571 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
2575 for (i = 0; i < adapter->num_tx_queues; i++)
2576 igb_clean_tx_ring(&adapter->tx_ring[i]);
2580 * igb_free_rx_resources - Free Rx Resources
2581 * @rx_ring: ring to clean the resources from
2583 * Free all receive software resources
2585 void igb_free_rx_resources(struct igb_ring *rx_ring)
2587 igb_clean_rx_ring(rx_ring);
2589 vfree(rx_ring->buffer_info);
2590 rx_ring->buffer_info = NULL;
2592 pci_free_consistent(rx_ring->pdev, rx_ring->size,
2593 rx_ring->desc, rx_ring->dma);
2595 rx_ring->desc = NULL;
2599 * igb_free_all_rx_resources - Free Rx Resources for All Queues
2600 * @adapter: board private structure
2602 * Free all receive software resources
2604 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
2608 for (i = 0; i < adapter->num_rx_queues; i++)
2609 igb_free_rx_resources(&adapter->rx_ring[i]);
2613 * igb_clean_rx_ring - Free Rx Buffers per Queue
2614 * @rx_ring: ring to free buffers from
2616 static void igb_clean_rx_ring(struct igb_ring *rx_ring)
2618 struct igb_buffer *buffer_info;
2622 if (!rx_ring->buffer_info)
2624 /* Free all the Rx ring sk_buffs */
2625 for (i = 0; i < rx_ring->count; i++) {
2626 buffer_info = &rx_ring->buffer_info[i];
2627 if (buffer_info->dma) {
2628 pci_unmap_single(rx_ring->pdev,
2630 rx_ring->rx_buffer_len,
2631 PCI_DMA_FROMDEVICE);
2632 buffer_info->dma = 0;
2635 if (buffer_info->skb) {
2636 dev_kfree_skb(buffer_info->skb);
2637 buffer_info->skb = NULL;
2639 if (buffer_info->page_dma) {
2640 pci_unmap_page(rx_ring->pdev,
2641 buffer_info->page_dma,
2643 PCI_DMA_FROMDEVICE);
2644 buffer_info->page_dma = 0;
2646 if (buffer_info->page) {
2647 put_page(buffer_info->page);
2648 buffer_info->page = NULL;
2649 buffer_info->page_offset = 0;
2653 size = sizeof(struct igb_buffer) * rx_ring->count;
2654 memset(rx_ring->buffer_info, 0, size);
2656 /* Zero out the descriptor ring */
2657 memset(rx_ring->desc, 0, rx_ring->size);
2659 rx_ring->next_to_clean = 0;
2660 rx_ring->next_to_use = 0;
2662 writel(0, rx_ring->head);
2663 writel(0, rx_ring->tail);
2667 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2668 * @adapter: board private structure
2670 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
2674 for (i = 0; i < adapter->num_rx_queues; i++)
2675 igb_clean_rx_ring(&adapter->rx_ring[i]);
2679 * igb_set_mac - Change the Ethernet Address of the NIC
2680 * @netdev: network interface device structure
2681 * @p: pointer to an address structure
2683 * Returns 0 on success, negative on failure
2685 static int igb_set_mac(struct net_device *netdev, void *p)
2687 struct igb_adapter *adapter = netdev_priv(netdev);
2688 struct e1000_hw *hw = &adapter->hw;
2689 struct sockaddr *addr = p;
2691 if (!is_valid_ether_addr(addr->sa_data))
2692 return -EADDRNOTAVAIL;
2694 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2695 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
2697 /* set the correct pool for the new PF MAC address in entry 0 */
2698 igb_rar_set_qsel(adapter, hw->mac.addr, 0,
2699 adapter->vfs_allocated_count);
2705 * igb_write_mc_addr_list - write multicast addresses to MTA
2706 * @netdev: network interface device structure
2708 * Writes multicast address list to the MTA hash table.
2709 * Returns: -ENOMEM on failure
2710 * 0 on no addresses written
2711 * X on writing X addresses to MTA
2713 static int igb_write_mc_addr_list(struct net_device *netdev)
2715 struct igb_adapter *adapter = netdev_priv(netdev);
2716 struct e1000_hw *hw = &adapter->hw;
2717 struct dev_mc_list *mc_ptr = netdev->mc_list;
2722 if (!netdev->mc_count) {
2723 /* nothing to program, so clear mc list */
2724 igb_update_mc_addr_list(hw, NULL, 0);
2725 igb_restore_vf_multicasts(adapter);
2729 mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC);
2733 /* set vmolr receive overflow multicast bit */
2734 vmolr |= E1000_VMOLR_ROMPE;
2736 /* The shared function expects a packed array of only addresses. */
2737 mc_ptr = netdev->mc_list;
2739 for (i = 0; i < netdev->mc_count; i++) {
2742 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
2743 mc_ptr = mc_ptr->next;
2745 igb_update_mc_addr_list(hw, mta_list, i);
2748 return netdev->mc_count;
2752 * igb_write_uc_addr_list - write unicast addresses to RAR table
2753 * @netdev: network interface device structure
2755 * Writes unicast address list to the RAR table.
2756 * Returns: -ENOMEM on failure/insufficient address space
2757 * 0 on no addresses written
2758 * X on writing X addresses to the RAR table
2760 static int igb_write_uc_addr_list(struct net_device *netdev)
2762 struct igb_adapter *adapter = netdev_priv(netdev);
2763 struct e1000_hw *hw = &adapter->hw;
2764 unsigned int vfn = adapter->vfs_allocated_count;
2765 unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
2768 /* return ENOMEM indicating insufficient memory for addresses */
2769 if (netdev->uc.count > rar_entries)
2772 if (netdev->uc.count && rar_entries) {
2773 struct netdev_hw_addr *ha;
2774 list_for_each_entry(ha, &netdev->uc.list, list) {
2777 igb_rar_set_qsel(adapter, ha->addr,
2783 /* write the addresses in reverse order to avoid write combining */
2784 for (; rar_entries > 0 ; rar_entries--) {
2785 wr32(E1000_RAH(rar_entries), 0);
2786 wr32(E1000_RAL(rar_entries), 0);
2794 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2795 * @netdev: network interface device structure
2797 * The set_rx_mode entry point is called whenever the unicast or multicast
2798 * address lists or the network interface flags are updated. This routine is
2799 * responsible for configuring the hardware for proper unicast, multicast,
2800 * promiscuous mode, and all-multi behavior.
2802 static void igb_set_rx_mode(struct net_device *netdev)
2804 struct igb_adapter *adapter = netdev_priv(netdev);
2805 struct e1000_hw *hw = &adapter->hw;
2806 unsigned int vfn = adapter->vfs_allocated_count;
2807 u32 rctl, vmolr = 0;
2810 /* Check for Promiscuous and All Multicast modes */
2811 rctl = rd32(E1000_RCTL);
2813 /* clear the effected bits */
2814 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
2816 if (netdev->flags & IFF_PROMISC) {
2817 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2818 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
2820 if (netdev->flags & IFF_ALLMULTI) {
2821 rctl |= E1000_RCTL_MPE;
2822 vmolr |= E1000_VMOLR_MPME;
2825 * Write addresses to the MTA, if the attempt fails
2826 * then we should just turn on promiscous mode so
2827 * that we can at least receive multicast traffic
2829 count = igb_write_mc_addr_list(netdev);
2831 rctl |= E1000_RCTL_MPE;
2832 vmolr |= E1000_VMOLR_MPME;
2834 vmolr |= E1000_VMOLR_ROMPE;
2838 * Write addresses to available RAR registers, if there is not
2839 * sufficient space to store all the addresses then enable
2840 * unicast promiscous mode
2842 count = igb_write_uc_addr_list(netdev);
2844 rctl |= E1000_RCTL_UPE;
2845 vmolr |= E1000_VMOLR_ROPE;
2847 rctl |= E1000_RCTL_VFE;
2849 wr32(E1000_RCTL, rctl);
2852 * In order to support SR-IOV and eventually VMDq it is necessary to set
2853 * the VMOLR to enable the appropriate modes. Without this workaround
2854 * we will have issues with VLAN tag stripping not being done for frames
2855 * that are only arriving because we are the default pool
2857 if (hw->mac.type < e1000_82576)
2860 vmolr |= rd32(E1000_VMOLR(vfn)) &
2861 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
2862 wr32(E1000_VMOLR(vfn), vmolr);
2863 igb_restore_vf_multicasts(adapter);
2866 /* Need to wait a few seconds after link up to get diagnostic information from
2868 static void igb_update_phy_info(unsigned long data)
2870 struct igb_adapter *adapter = (struct igb_adapter *) data;
2871 igb_get_phy_info(&adapter->hw);
2875 * igb_has_link - check shared code for link and determine up/down
2876 * @adapter: pointer to driver private info
2878 static bool igb_has_link(struct igb_adapter *adapter)
2880 struct e1000_hw *hw = &adapter->hw;
2881 bool link_active = false;
2884 /* get_link_status is set on LSC (link status) interrupt or
2885 * rx sequence error interrupt. get_link_status will stay
2886 * false until the e1000_check_for_link establishes link
2887 * for copper adapters ONLY
2889 switch (hw->phy.media_type) {
2890 case e1000_media_type_copper:
2891 if (hw->mac.get_link_status) {
2892 ret_val = hw->mac.ops.check_for_link(hw);
2893 link_active = !hw->mac.get_link_status;
2898 case e1000_media_type_internal_serdes:
2899 ret_val = hw->mac.ops.check_for_link(hw);
2900 link_active = hw->mac.serdes_has_link;
2903 case e1000_media_type_unknown:
2911 * igb_watchdog - Timer Call-back
2912 * @data: pointer to adapter cast into an unsigned long
2914 static void igb_watchdog(unsigned long data)
2916 struct igb_adapter *adapter = (struct igb_adapter *)data;
2917 /* Do the rest outside of interrupt context */
2918 schedule_work(&adapter->watchdog_task);
2921 static void igb_watchdog_task(struct work_struct *work)
2923 struct igb_adapter *adapter = container_of(work,
2924 struct igb_adapter, watchdog_task);
2925 struct e1000_hw *hw = &adapter->hw;
2926 struct net_device *netdev = adapter->netdev;
2927 struct igb_ring *tx_ring = adapter->tx_ring;
2931 link = igb_has_link(adapter);
2932 if ((netif_carrier_ok(netdev)) && link)
2936 if (!netif_carrier_ok(netdev)) {
2938 hw->mac.ops.get_speed_and_duplex(&adapter->hw,
2939 &adapter->link_speed,
2940 &adapter->link_duplex);
2942 ctrl = rd32(E1000_CTRL);
2943 /* Links status message must follow this format */
2944 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
2945 "Flow Control: %s\n",
2947 adapter->link_speed,
2948 adapter->link_duplex == FULL_DUPLEX ?
2949 "Full Duplex" : "Half Duplex",
2950 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2951 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2952 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2953 E1000_CTRL_TFCE) ? "TX" : "None")));
2955 /* tweak tx_queue_len according to speed/duplex and
2956 * adjust the timeout factor */
2957 netdev->tx_queue_len = adapter->tx_queue_len;
2958 adapter->tx_timeout_factor = 1;
2959 switch (adapter->link_speed) {
2961 netdev->tx_queue_len = 10;
2962 adapter->tx_timeout_factor = 14;
2965 netdev->tx_queue_len = 100;
2966 /* maybe add some timeout factor ? */
2970 netif_carrier_on(netdev);
2972 igb_ping_all_vfs(adapter);
2974 /* link state has changed, schedule phy info update */
2975 if (!test_bit(__IGB_DOWN, &adapter->state))
2976 mod_timer(&adapter->phy_info_timer,
2977 round_jiffies(jiffies + 2 * HZ));
2980 if (netif_carrier_ok(netdev)) {
2981 adapter->link_speed = 0;
2982 adapter->link_duplex = 0;
2983 /* Links status message must follow this format */
2984 printk(KERN_INFO "igb: %s NIC Link is Down\n",
2986 netif_carrier_off(netdev);
2988 igb_ping_all_vfs(adapter);
2990 /* link state has changed, schedule phy info update */
2991 if (!test_bit(__IGB_DOWN, &adapter->state))
2992 mod_timer(&adapter->phy_info_timer,
2993 round_jiffies(jiffies + 2 * HZ));
2998 igb_update_stats(adapter);
3000 hw->mac.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
3001 adapter->tpt_old = adapter->stats.tpt;
3002 hw->mac.collision_delta = adapter->stats.colc - adapter->colc_old;
3003 adapter->colc_old = adapter->stats.colc;
3005 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
3006 adapter->gorc_old = adapter->stats.gorc;
3007 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
3008 adapter->gotc_old = adapter->stats.gotc;
3010 igb_update_adaptive(&adapter->hw);
3012 if (!netif_carrier_ok(netdev)) {
3013 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
3014 /* We've lost link, so the controller stops DMA,
3015 * but we've got queued Tx work that's never going
3016 * to get done, so reset controller to flush Tx.
3017 * (Do the reset outside of interrupt context). */
3018 adapter->tx_timeout_count++;
3019 schedule_work(&adapter->reset_task);
3020 /* return immediately since reset is imminent */
3025 /* Cause software interrupt to ensure rx ring is cleaned */
3026 if (adapter->msix_entries) {
3028 for (i = 0; i < adapter->num_q_vectors; i++) {
3029 struct igb_q_vector *q_vector = adapter->q_vector[i];
3030 eics |= q_vector->eims_value;
3032 wr32(E1000_EICS, eics);
3034 wr32(E1000_ICS, E1000_ICS_RXDMT0);
3037 /* Force detection of hung controller every watchdog period */
3038 tx_ring->detect_tx_hung = true;
3040 /* Reset the timer */
3041 if (!test_bit(__IGB_DOWN, &adapter->state))
3042 mod_timer(&adapter->watchdog_timer,
3043 round_jiffies(jiffies + 2 * HZ));
3046 enum latency_range {
3050 latency_invalid = 255
3055 * igb_update_ring_itr - update the dynamic ITR value based on packet size
3057 * Stores a new ITR value based on strictly on packet size. This
3058 * algorithm is less sophisticated than that used in igb_update_itr,
3059 * due to the difficulty of synchronizing statistics across multiple
3060 * receive rings. The divisors and thresholds used by this fuction
3061 * were determined based on theoretical maximum wire speed and testing
3062 * data, in order to minimize response time while increasing bulk
3064 * This functionality is controlled by the InterruptThrottleRate module
3065 * parameter (see igb_param.c)
3066 * NOTE: This function is called only when operating in a multiqueue
3067 * receive environment.
3068 * @q_vector: pointer to q_vector
3070 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
3072 int new_val = q_vector->itr_val;
3073 int avg_wire_size = 0;
3074 struct igb_adapter *adapter = q_vector->adapter;
3076 /* For non-gigabit speeds, just fix the interrupt rate at 4000
3077 * ints/sec - ITR timer value of 120 ticks.
3079 if (adapter->link_speed != SPEED_1000) {
3084 if (q_vector->rx_ring && q_vector->rx_ring->total_packets) {
3085 struct igb_ring *ring = q_vector->rx_ring;
3086 avg_wire_size = ring->total_bytes / ring->total_packets;
3089 if (q_vector->tx_ring && q_vector->tx_ring->total_packets) {
3090 struct igb_ring *ring = q_vector->tx_ring;
3091 avg_wire_size = max_t(u32, avg_wire_size,
3092 (ring->total_bytes /
3093 ring->total_packets));
3096 /* if avg_wire_size isn't set no work was done */
3100 /* Add 24 bytes to size to account for CRC, preamble, and gap */
3101 avg_wire_size += 24;
3103 /* Don't starve jumbo frames */
3104 avg_wire_size = min(avg_wire_size, 3000);
3106 /* Give a little boost to mid-size frames */
3107 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
3108 new_val = avg_wire_size / 3;
3110 new_val = avg_wire_size / 2;
3113 if (new_val != q_vector->itr_val) {
3114 q_vector->itr_val = new_val;
3115 q_vector->set_itr = 1;
3118 if (q_vector->rx_ring) {
3119 q_vector->rx_ring->total_bytes = 0;
3120 q_vector->rx_ring->total_packets = 0;
3122 if (q_vector->tx_ring) {
3123 q_vector->tx_ring->total_bytes = 0;
3124 q_vector->tx_ring->total_packets = 0;
3129 * igb_update_itr - update the dynamic ITR value based on statistics
3130 * Stores a new ITR value based on packets and byte
3131 * counts during the last interrupt. The advantage of per interrupt
3132 * computation is faster updates and more accurate ITR for the current
3133 * traffic pattern. Constants in this function were computed
3134 * based on theoretical maximum wire speed and thresholds were set based
3135 * on testing data as well as attempting to minimize response time
3136 * while increasing bulk throughput.
3137 * this functionality is controlled by the InterruptThrottleRate module
3138 * parameter (see igb_param.c)
3139 * NOTE: These calculations are only valid when operating in a single-
3140 * queue environment.
3141 * @adapter: pointer to adapter
3142 * @itr_setting: current q_vector->itr_val
3143 * @packets: the number of packets during this measurement interval
3144 * @bytes: the number of bytes during this measurement interval
3146 static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
3147 int packets, int bytes)
3149 unsigned int retval = itr_setting;
3152 goto update_itr_done;
3154 switch (itr_setting) {
3155 case lowest_latency:
3156 /* handle TSO and jumbo frames */
3157 if (bytes/packets > 8000)
3158 retval = bulk_latency;
3159 else if ((packets < 5) && (bytes > 512))
3160 retval = low_latency;
3162 case low_latency: /* 50 usec aka 20000 ints/s */
3163 if (bytes > 10000) {
3164 /* this if handles the TSO accounting */
3165 if (bytes/packets > 8000) {
3166 retval = bulk_latency;
3167 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
3168 retval = bulk_latency;
3169 } else if ((packets > 35)) {
3170 retval = lowest_latency;
3172 } else if (bytes/packets > 2000) {
3173 retval = bulk_latency;
3174 } else if (packets <= 2 && bytes < 512) {
3175 retval = lowest_latency;
3178 case bulk_latency: /* 250 usec aka 4000 ints/s */
3179 if (bytes > 25000) {
3181 retval = low_latency;
3182 } else if (bytes < 1500) {
3183 retval = low_latency;
3192 static void igb_set_itr(struct igb_adapter *adapter)
3194 struct igb_q_vector *q_vector = adapter->q_vector[0];
3196 u32 new_itr = q_vector->itr_val;
3198 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
3199 if (adapter->link_speed != SPEED_1000) {
3205 adapter->rx_itr = igb_update_itr(adapter,
3207 adapter->rx_ring->total_packets,
3208 adapter->rx_ring->total_bytes);
3210 adapter->tx_itr = igb_update_itr(adapter,
3212 adapter->tx_ring->total_packets,
3213 adapter->tx_ring->total_bytes);
3214 current_itr = max(adapter->rx_itr, adapter->tx_itr);
3216 /* conservative mode (itr 3) eliminates the lowest_latency setting */
3217 if (adapter->itr_setting == 3 && current_itr == lowest_latency)
3218 current_itr = low_latency;
3220 switch (current_itr) {
3221 /* counts and packets in update_itr are dependent on these numbers */
3222 case lowest_latency:
3223 new_itr = 56; /* aka 70,000 ints/sec */
3226 new_itr = 196; /* aka 20,000 ints/sec */
3229 new_itr = 980; /* aka 4,000 ints/sec */
3236 adapter->rx_ring->total_bytes = 0;
3237 adapter->rx_ring->total_packets = 0;
3238 adapter->tx_ring->total_bytes = 0;
3239 adapter->tx_ring->total_packets = 0;
3241 if (new_itr != q_vector->itr_val) {
3242 /* this attempts to bias the interrupt rate towards Bulk
3243 * by adding intermediate steps when interrupt rate is
3245 new_itr = new_itr > q_vector->itr_val ?
3246 max((new_itr * q_vector->itr_val) /
3247 (new_itr + (q_vector->itr_val >> 2)),
3250 /* Don't write the value here; it resets the adapter's
3251 * internal timer, and causes us to delay far longer than
3252 * we should between interrupts. Instead, we write the ITR
3253 * value at the beginning of the next interrupt so the timing
3254 * ends up being correct.
3256 q_vector->itr_val = new_itr;
3257 q_vector->set_itr = 1;
3263 #define IGB_TX_FLAGS_CSUM 0x00000001
3264 #define IGB_TX_FLAGS_VLAN 0x00000002
3265 #define IGB_TX_FLAGS_TSO 0x00000004
3266 #define IGB_TX_FLAGS_IPV4 0x00000008
3267 #define IGB_TX_FLAGS_TSTAMP 0x00000010
3268 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
3269 #define IGB_TX_FLAGS_VLAN_SHIFT 16
3271 static inline int igb_tso_adv(struct igb_ring *tx_ring,
3272 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
3274 struct e1000_adv_tx_context_desc *context_desc;
3277 struct igb_buffer *buffer_info;
3278 u32 info = 0, tu_cmd = 0;
3279 u32 mss_l4len_idx, l4len;
3282 if (skb_header_cloned(skb)) {
3283 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3288 l4len = tcp_hdrlen(skb);
3291 if (skb->protocol == htons(ETH_P_IP)) {
3292 struct iphdr *iph = ip_hdr(skb);
3295 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3299 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3300 ipv6_hdr(skb)->payload_len = 0;
3301 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3302 &ipv6_hdr(skb)->daddr,
3306 i = tx_ring->next_to_use;
3308 buffer_info = &tx_ring->buffer_info[i];
3309 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
3310 /* VLAN MACLEN IPLEN */
3311 if (tx_flags & IGB_TX_FLAGS_VLAN)
3312 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
3313 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
3314 *hdr_len += skb_network_offset(skb);
3315 info |= skb_network_header_len(skb);
3316 *hdr_len += skb_network_header_len(skb);
3317 context_desc->vlan_macip_lens = cpu_to_le32(info);
3319 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
3320 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
3322 if (skb->protocol == htons(ETH_P_IP))
3323 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
3324 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
3326 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
3329 mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
3330 mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
3332 /* For 82575, context index must be unique per ring. */
3333 if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
3334 mss_l4len_idx |= tx_ring->reg_idx << 4;
3336 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3337 context_desc->seqnum_seed = 0;
3339 buffer_info->time_stamp = jiffies;
3340 buffer_info->next_to_watch = i;
3341 buffer_info->dma = 0;
3343 if (i == tx_ring->count)
3346 tx_ring->next_to_use = i;
3351 static inline bool igb_tx_csum_adv(struct igb_ring *tx_ring,
3352 struct sk_buff *skb, u32 tx_flags)
3354 struct e1000_adv_tx_context_desc *context_desc;
3355 struct pci_dev *pdev = tx_ring->pdev;
3356 struct igb_buffer *buffer_info;
3357 u32 info = 0, tu_cmd = 0;
3360 if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
3361 (tx_flags & IGB_TX_FLAGS_VLAN)) {
3362 i = tx_ring->next_to_use;
3363 buffer_info = &tx_ring->buffer_info[i];
3364 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
3366 if (tx_flags & IGB_TX_FLAGS_VLAN)
3367 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
3368 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
3369 if (skb->ip_summed == CHECKSUM_PARTIAL)
3370 info |= skb_network_header_len(skb);
3372 context_desc->vlan_macip_lens = cpu_to_le32(info);
3374 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
3376 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3379 if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
3380 const struct vlan_ethhdr *vhdr =
3381 (const struct vlan_ethhdr*)skb->data;
3383 protocol = vhdr->h_vlan_encapsulated_proto;
3385 protocol = skb->protocol;
3389 case cpu_to_be16(ETH_P_IP):
3390 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
3391 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3392 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
3393 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
3394 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
3396 case cpu_to_be16(ETH_P_IPV6):
3397 /* XXX what about other V6 headers?? */
3398 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3399 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
3400 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
3401 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
3404 if (unlikely(net_ratelimit()))
3405 dev_warn(&pdev->dev,
3406 "partial checksum but proto=%x!\n",
3412 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
3413 context_desc->seqnum_seed = 0;
3414 if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
3415 context_desc->mss_l4len_idx =
3416 cpu_to_le32(tx_ring->reg_idx << 4);
3418 buffer_info->time_stamp = jiffies;
3419 buffer_info->next_to_watch = i;
3420 buffer_info->dma = 0;
3423 if (i == tx_ring->count)
3425 tx_ring->next_to_use = i;
3432 #define IGB_MAX_TXD_PWR 16
3433 #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
3435 static inline int igb_tx_map_adv(struct igb_ring *tx_ring, struct sk_buff *skb,
3438 struct igb_buffer *buffer_info;
3439 struct pci_dev *pdev = tx_ring->pdev;
3440 unsigned int len = skb_headlen(skb);
3441 unsigned int count = 0, i;
3445 i = tx_ring->next_to_use;
3447 if (skb_dma_map(&pdev->dev, skb, DMA_TO_DEVICE)) {
3448 dev_err(&pdev->dev, "TX DMA map failed\n");
3452 map = skb_shinfo(skb)->dma_maps;
3454 buffer_info = &tx_ring->buffer_info[i];
3455 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
3456 buffer_info->length = len;
3457 /* set time_stamp *before* dma to help avoid a possible race */
3458 buffer_info->time_stamp = jiffies;
3459 buffer_info->next_to_watch = i;
3460 buffer_info->dma = skb_shinfo(skb)->dma_head;
3462 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
3463 struct skb_frag_struct *frag;
3466 if (i == tx_ring->count)
3469 frag = &skb_shinfo(skb)->frags[f];
3472 buffer_info = &tx_ring->buffer_info[i];
3473 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
3474 buffer_info->length = len;
3475 buffer_info->time_stamp = jiffies;
3476 buffer_info->next_to_watch = i;
3477 buffer_info->dma = map[count];
3481 tx_ring->buffer_info[i].skb = skb;
3482 tx_ring->buffer_info[first].next_to_watch = i;
3487 static inline void igb_tx_queue_adv(struct igb_ring *tx_ring,
3488 int tx_flags, int count, u32 paylen,
3491 union e1000_adv_tx_desc *tx_desc = NULL;
3492 struct igb_buffer *buffer_info;
3493 u32 olinfo_status = 0, cmd_type_len;
3496 cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
3497 E1000_ADVTXD_DCMD_DEXT);
3499 if (tx_flags & IGB_TX_FLAGS_VLAN)
3500 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
3502 if (tx_flags & IGB_TX_FLAGS_TSTAMP)
3503 cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
3505 if (tx_flags & IGB_TX_FLAGS_TSO) {
3506 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
3508 /* insert tcp checksum */
3509 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
3511 /* insert ip checksum */
3512 if (tx_flags & IGB_TX_FLAGS_IPV4)
3513 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
3515 } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
3516 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
3519 if ((tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) &&
3520 (tx_flags & (IGB_TX_FLAGS_CSUM |
3522 IGB_TX_FLAGS_VLAN)))
3523 olinfo_status |= tx_ring->reg_idx << 4;
3525 olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
3527 i = tx_ring->next_to_use;
3529 buffer_info = &tx_ring->buffer_info[i];
3530 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
3531 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
3532 tx_desc->read.cmd_type_len =
3533 cpu_to_le32(cmd_type_len | buffer_info->length);
3534 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3536 if (i == tx_ring->count)
3540 tx_desc->read.cmd_type_len |= cpu_to_le32(IGB_ADVTXD_DCMD);
3541 /* Force memory writes to complete before letting h/w
3542 * know there are new descriptors to fetch. (Only
3543 * applicable for weak-ordered memory model archs,
3544 * such as IA-64). */
3547 tx_ring->next_to_use = i;
3548 writel(i, tx_ring->tail);
3549 /* we need this if more than one processor can write to our tail
3550 * at a time, it syncronizes IO on IA64/Altix systems */
3554 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
3556 struct net_device *netdev = tx_ring->netdev;
3558 netif_stop_subqueue(netdev, tx_ring->queue_index);
3560 /* Herbert's original patch had:
3561 * smp_mb__after_netif_stop_queue();
3562 * but since that doesn't exist yet, just open code it. */
3565 /* We need to check again in a case another CPU has just
3566 * made room available. */
3567 if (igb_desc_unused(tx_ring) < size)
3571 netif_wake_subqueue(netdev, tx_ring->queue_index);
3572 tx_ring->tx_stats.restart_queue++;
3576 static int igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
3578 if (igb_desc_unused(tx_ring) >= size)
3580 return __igb_maybe_stop_tx(tx_ring, size);
3583 static netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *skb,
3584 struct igb_ring *tx_ring)
3586 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
3588 unsigned int tx_flags = 0;
3592 union skb_shared_tx *shtx;
3594 if (test_bit(__IGB_DOWN, &adapter->state)) {
3595 dev_kfree_skb_any(skb);
3596 return NETDEV_TX_OK;
3599 if (skb->len <= 0) {
3600 dev_kfree_skb_any(skb);
3601 return NETDEV_TX_OK;
3604 /* need: 1 descriptor per page,
3605 * + 2 desc gap to keep tail from touching head,
3606 * + 1 desc for skb->data,
3607 * + 1 desc for context descriptor,
3608 * otherwise try next time */
3609 if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
3610 /* this is a hard error */
3611 return NETDEV_TX_BUSY;
3615 * TODO: check that there currently is no other packet with
3616 * time stamping in the queue
3618 * When doing time stamping, keep the connection to the socket
3619 * a while longer: it is still needed by skb_hwtstamp_tx(),
3620 * called either in igb_tx_hwtstamp() or by our caller when
3621 * doing software time stamping.
3624 if (unlikely(shtx->hardware)) {
3625 shtx->in_progress = 1;
3626 tx_flags |= IGB_TX_FLAGS_TSTAMP;
3629 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3630 tx_flags |= IGB_TX_FLAGS_VLAN;
3631 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
3634 if (skb->protocol == htons(ETH_P_IP))
3635 tx_flags |= IGB_TX_FLAGS_IPV4;
3637 first = tx_ring->next_to_use;
3638 if (skb_is_gso(skb)) {
3639 tso = igb_tso_adv(tx_ring, skb, tx_flags, &hdr_len);
3641 dev_kfree_skb_any(skb);
3642 return NETDEV_TX_OK;
3647 tx_flags |= IGB_TX_FLAGS_TSO;
3648 else if (igb_tx_csum_adv(tx_ring, skb, tx_flags) &&
3649 (skb->ip_summed == CHECKSUM_PARTIAL))
3650 tx_flags |= IGB_TX_FLAGS_CSUM;
3653 * count reflects descriptors mapped, if 0 then mapping error
3654 * has occured and we need to rewind the descriptor queue
3656 count = igb_tx_map_adv(tx_ring, skb, first);
3659 dev_kfree_skb_any(skb);
3660 tx_ring->buffer_info[first].time_stamp = 0;
3661 tx_ring->next_to_use = first;
3662 return NETDEV_TX_OK;
3665 igb_tx_queue_adv(tx_ring, tx_flags, count, skb->len, hdr_len);
3667 /* Make sure there is space in the ring for the next send. */
3668 igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
3670 return NETDEV_TX_OK;
3673 static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
3674 struct net_device *netdev)
3676 struct igb_adapter *adapter = netdev_priv(netdev);
3677 struct igb_ring *tx_ring;
3680 r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1);
3681 tx_ring = adapter->multi_tx_table[r_idx];
3683 /* This goes back to the question of how to logically map a tx queue
3684 * to a flow. Right now, performance is impacted slightly negatively
3685 * if using multiple tx queues. If the stack breaks away from a
3686 * single qdisc implementation, we can look at this again. */
3687 return igb_xmit_frame_ring_adv(skb, tx_ring);
3691 * igb_tx_timeout - Respond to a Tx Hang
3692 * @netdev: network interface device structure
3694 static void igb_tx_timeout(struct net_device *netdev)
3696 struct igb_adapter *adapter = netdev_priv(netdev);
3697 struct e1000_hw *hw = &adapter->hw;
3699 /* Do the reset outside of interrupt context */
3700 adapter->tx_timeout_count++;
3701 schedule_work(&adapter->reset_task);
3703 (adapter->eims_enable_mask & ~adapter->eims_other));
3706 static void igb_reset_task(struct work_struct *work)
3708 struct igb_adapter *adapter;
3709 adapter = container_of(work, struct igb_adapter, reset_task);
3711 igb_reinit_locked(adapter);
3715 * igb_get_stats - Get System Network Statistics
3716 * @netdev: network interface device structure
3718 * Returns the address of the device statistics structure.
3719 * The statistics are actually updated from the timer callback.
3721 static struct net_device_stats *igb_get_stats(struct net_device *netdev)
3723 /* only return the current stats */
3724 return &netdev->stats;
3728 * igb_change_mtu - Change the Maximum Transfer Unit
3729 * @netdev: network interface device structure
3730 * @new_mtu: new value for maximum frame size
3732 * Returns 0 on success, negative on failure
3734 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
3736 struct igb_adapter *adapter = netdev_priv(netdev);
3737 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3738 u32 rx_buffer_len, i;
3740 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
3741 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3742 dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
3746 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3747 dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
3751 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
3754 /* igb_down has a dependency on max_frame_size */
3755 adapter->max_frame_size = max_frame;
3756 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3757 * means we reserve 2 more, this pushes us to allocate from the next
3759 * i.e. RXBUFFER_2048 --> size-4096 slab
3762 if (max_frame <= IGB_RXBUFFER_1024)
3763 rx_buffer_len = IGB_RXBUFFER_1024;
3764 else if (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE)
3765 rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3767 rx_buffer_len = IGB_RXBUFFER_128;
3769 if (netif_running(netdev))
3772 dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
3773 netdev->mtu, new_mtu);
3774 netdev->mtu = new_mtu;
3776 for (i = 0; i < adapter->num_rx_queues; i++)
3777 adapter->rx_ring[i].rx_buffer_len = rx_buffer_len;
3779 if (netif_running(netdev))
3784 clear_bit(__IGB_RESETTING, &adapter->state);
3790 * igb_update_stats - Update the board statistics counters
3791 * @adapter: board private structure
3794 void igb_update_stats(struct igb_adapter *adapter)
3796 struct net_device *netdev = adapter->netdev;
3797 struct e1000_hw *hw = &adapter->hw;
3798 struct pci_dev *pdev = adapter->pdev;
3801 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3804 * Prevent stats update while adapter is being reset, or if the pci
3805 * connection is down.
3807 if (adapter->link_speed == 0)
3809 if (pci_channel_offline(pdev))
3812 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
3813 adapter->stats.gprc += rd32(E1000_GPRC);
3814 adapter->stats.gorc += rd32(E1000_GORCL);
3815 rd32(E1000_GORCH); /* clear GORCL */
3816 adapter->stats.bprc += rd32(E1000_BPRC);
3817 adapter->stats.mprc += rd32(E1000_MPRC);
3818 adapter->stats.roc += rd32(E1000_ROC);
3820 adapter->stats.prc64 += rd32(E1000_PRC64);
3821 adapter->stats.prc127 += rd32(E1000_PRC127);
3822 adapter->stats.prc255 += rd32(E1000_PRC255);
3823 adapter->stats.prc511 += rd32(E1000_PRC511);
3824 adapter->stats.prc1023 += rd32(E1000_PRC1023);
3825 adapter->stats.prc1522 += rd32(E1000_PRC1522);
3826 adapter->stats.symerrs += rd32(E1000_SYMERRS);
3827 adapter->stats.sec += rd32(E1000_SEC);
3829 adapter->stats.mpc += rd32(E1000_MPC);
3830 adapter->stats.scc += rd32(E1000_SCC);
3831 adapter->stats.ecol += rd32(E1000_ECOL);
3832 adapter->stats.mcc += rd32(E1000_MCC);
3833 adapter->stats.latecol += rd32(E1000_LATECOL);
3834 adapter->stats.dc += rd32(E1000_DC);
3835 adapter->stats.rlec += rd32(E1000_RLEC);
3836 adapter->stats.xonrxc += rd32(E1000_XONRXC);
3837 adapter->stats.xontxc += rd32(E1000_XONTXC);
3838 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
3839 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
3840 adapter->stats.fcruc += rd32(E1000_FCRUC);
3841 adapter->stats.gptc += rd32(E1000_GPTC);
3842 adapter->stats.gotc += rd32(E1000_GOTCL);
3843 rd32(E1000_GOTCH); /* clear GOTCL */
3844 adapter->stats.rnbc += rd32(E1000_RNBC);
3845 adapter->stats.ruc += rd32(E1000_RUC);
3846 adapter->stats.rfc += rd32(E1000_RFC);
3847 adapter->stats.rjc += rd32(E1000_RJC);
3848 adapter->stats.tor += rd32(E1000_TORH);
3849 adapter->stats.tot += rd32(E1000_TOTH);
3850 adapter->stats.tpr += rd32(E1000_TPR);
3852 adapter->stats.ptc64 += rd32(E1000_PTC64);
3853 adapter->stats.ptc127 += rd32(E1000_PTC127);
3854 adapter->stats.ptc255 += rd32(E1000_PTC255);
3855 adapter->stats.ptc511 += rd32(E1000_PTC511);
3856 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
3857 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
3859 adapter->stats.mptc += rd32(E1000_MPTC);
3860 adapter->stats.bptc += rd32(E1000_BPTC);
3862 /* used for adaptive IFS */
3864 hw->mac.tx_packet_delta = rd32(E1000_TPT);
3865 adapter->stats.tpt += hw->mac.tx_packet_delta;
3866 hw->mac.collision_delta = rd32(E1000_COLC);
3867 adapter->stats.colc += hw->mac.collision_delta;
3869 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
3870 adapter->stats.rxerrc += rd32(E1000_RXERRC);
3871 adapter->stats.tncrs += rd32(E1000_TNCRS);
3872 adapter->stats.tsctc += rd32(E1000_TSCTC);
3873 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
3875 adapter->stats.iac += rd32(E1000_IAC);
3876 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
3877 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
3878 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
3879 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
3880 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
3881 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
3882 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
3883 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
3885 /* Fill out the OS statistics structure */
3886 netdev->stats.multicast = adapter->stats.mprc;
3887 netdev->stats.collisions = adapter->stats.colc;
3891 if (hw->mac.type != e1000_82575) {
3893 u64 rqdpc_total = 0;
3895 /* Read out drops stats per RX queue. Notice RQDPC (Receive
3896 * Queue Drop Packet Count) stats only gets incremented, if
3897 * the DROP_EN but it set (in the SRRCTL register for that
3898 * queue). If DROP_EN bit is NOT set, then the some what
3899 * equivalent count is stored in RNBC (not per queue basis).
3900 * Also note the drop count is due to lack of available
3903 for (i = 0; i < adapter->num_rx_queues; i++) {
3904 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0xFFF;
3905 adapter->rx_ring[i].rx_stats.drops += rqdpc_tmp;
3906 rqdpc_total += adapter->rx_ring[i].rx_stats.drops;
3908 netdev->stats.rx_fifo_errors = rqdpc_total;
3911 /* Note RNBC (Receive No Buffers Count) is an not an exact
3912 * drop count as the hardware FIFO might save the day. Thats
3913 * one of the reason for saving it in rx_fifo_errors, as its
3914 * potentially not a true drop.
3916 netdev->stats.rx_fifo_errors += adapter->stats.rnbc;
3918 /* RLEC on some newer hardware can be incorrect so build
3919 * our own version based on RUC and ROC */
3920 netdev->stats.rx_errors = adapter->stats.rxerrc +
3921 adapter->stats.crcerrs + adapter->stats.algnerrc +
3922 adapter->stats.ruc + adapter->stats.roc +
3923 adapter->stats.cexterr;
3924 netdev->stats.rx_length_errors = adapter->stats.ruc +
3926 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3927 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3928 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3931 netdev->stats.tx_errors = adapter->stats.ecol +
3932 adapter->stats.latecol;
3933 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3934 netdev->stats.tx_window_errors = adapter->stats.latecol;
3935 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3937 /* Tx Dropped needs to be maintained elsewhere */
3940 if (hw->phy.media_type == e1000_media_type_copper) {
3941 if ((adapter->link_speed == SPEED_1000) &&
3942 (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3943 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3944 adapter->phy_stats.idle_errors += phy_tmp;
3948 /* Management Stats */
3949 adapter->stats.mgptc += rd32(E1000_MGTPTC);
3950 adapter->stats.mgprc += rd32(E1000_MGTPRC);
3951 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
3954 static irqreturn_t igb_msix_other(int irq, void *data)
3956 struct igb_adapter *adapter = data;
3957 struct e1000_hw *hw = &adapter->hw;
3958 u32 icr = rd32(E1000_ICR);
3959 /* reading ICR causes bit 31 of EICR to be cleared */
3961 if (icr & E1000_ICR_DOUTSYNC) {
3962 /* HW is reporting DMA is out of sync */
3963 adapter->stats.doosync++;
3966 /* Check for a mailbox event */
3967 if (icr & E1000_ICR_VMMB)
3968 igb_msg_task(adapter);
3970 if (icr & E1000_ICR_LSC) {
3971 hw->mac.get_link_status = 1;
3972 /* guard against interrupt when we're going down */
3973 if (!test_bit(__IGB_DOWN, &adapter->state))
3974 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3977 wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_VMMB);
3978 wr32(E1000_EIMS, adapter->eims_other);
3983 static void igb_write_itr(struct igb_q_vector *q_vector)
3985 u32 itr_val = q_vector->itr_val & 0x7FFC;
3987 if (!q_vector->set_itr)
3993 if (q_vector->itr_shift)
3994 itr_val |= itr_val << q_vector->itr_shift;
3996 itr_val |= 0x8000000;
3998 writel(itr_val, q_vector->itr_register);
3999 q_vector->set_itr = 0;
4002 static irqreturn_t igb_msix_ring(int irq, void *data)
4004 struct igb_q_vector *q_vector = data;
4006 /* Write the ITR value calculated from the previous interrupt. */
4007 igb_write_itr(q_vector);
4009 napi_schedule(&q_vector->napi);
4014 #ifdef CONFIG_IGB_DCA
4015 static void igb_update_dca(struct igb_q_vector *q_vector)
4017 struct igb_adapter *adapter = q_vector->adapter;
4018 struct e1000_hw *hw = &adapter->hw;
4019 int cpu = get_cpu();
4021 if (q_vector->cpu == cpu)
4024 if (q_vector->tx_ring) {
4025 int q = q_vector->tx_ring->reg_idx;
4026 u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
4027 if (hw->mac.type == e1000_82575) {
4028 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
4029 dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
4031 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
4032 dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
4033 E1000_DCA_TXCTRL_CPUID_SHIFT;
4035 dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
4036 wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
4038 if (q_vector->rx_ring) {
4039 int q = q_vector->rx_ring->reg_idx;
4040 u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
4041 if (hw->mac.type == e1000_82575) {
4042 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
4043 dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
4045 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
4046 dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
4047 E1000_DCA_RXCTRL_CPUID_SHIFT;
4049 dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
4050 dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
4051 dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
4052 wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
4054 q_vector->cpu = cpu;
4059 static void igb_setup_dca(struct igb_adapter *adapter)
4061 struct e1000_hw *hw = &adapter->hw;
4064 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
4067 /* Always use CB2 mode, difference is masked in the CB driver. */
4068 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
4070 for (i = 0; i < adapter->num_q_vectors; i++) {
4071 struct igb_q_vector *q_vector = adapter->q_vector[i];
4073 igb_update_dca(q_vector);
4077 static int __igb_notify_dca(struct device *dev, void *data)
4079 struct net_device *netdev = dev_get_drvdata(dev);
4080 struct igb_adapter *adapter = netdev_priv(netdev);
4081 struct e1000_hw *hw = &adapter->hw;
4082 unsigned long event = *(unsigned long *)data;
4085 case DCA_PROVIDER_ADD:
4086 /* if already enabled, don't do it again */
4087 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
4089 /* Always use CB2 mode, difference is masked
4090 * in the CB driver. */
4091 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
4092 if (dca_add_requester(dev) == 0) {
4093 adapter->flags |= IGB_FLAG_DCA_ENABLED;
4094 dev_info(&adapter->pdev->dev, "DCA enabled\n");
4095 igb_setup_dca(adapter);
4098 /* Fall Through since DCA is disabled. */
4099 case DCA_PROVIDER_REMOVE:
4100 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
4101 /* without this a class_device is left
4102 * hanging around in the sysfs model */
4103 dca_remove_requester(dev);
4104 dev_info(&adapter->pdev->dev, "DCA disabled\n");
4105 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
4106 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
4114 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
4119 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
4122 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4124 #endif /* CONFIG_IGB_DCA */
4126 static void igb_ping_all_vfs(struct igb_adapter *adapter)
4128 struct e1000_hw *hw = &adapter->hw;
4132 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
4133 ping = E1000_PF_CONTROL_MSG;
4134 if (adapter->vf_data[i].clear_to_send)
4135 ping |= E1000_VT_MSGTYPE_CTS;
4136 igb_write_mbx(hw, &ping, 1, i);
4140 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
4141 u32 *msgbuf, u32 vf)
4143 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
4144 u16 *hash_list = (u16 *)&msgbuf[1];
4145 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
4148 /* only up to 30 hash values supported */
4152 /* salt away the number of multi cast addresses assigned
4153 * to this VF for later use to restore when the PF multi cast
4156 vf_data->num_vf_mc_hashes = n;
4158 /* VFs are limited to using the MTA hash table for their multicast
4160 for (i = 0; i < n; i++)
4161 vf_data->vf_mc_hashes[i] = hash_list[i];
4163 /* Flush and reset the mta with the new values */
4164 igb_set_rx_mode(adapter->netdev);
4169 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
4171 struct e1000_hw *hw = &adapter->hw;
4172 struct vf_data_storage *vf_data;
4175 for (i = 0; i < adapter->vfs_allocated_count; i++) {
4176 vf_data = &adapter->vf_data[i];
4177 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
4178 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
4182 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
4184 struct e1000_hw *hw = &adapter->hw;
4185 u32 pool_mask, reg, vid;
4188 pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
4190 /* Find the vlan filter for this id */
4191 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
4192 reg = rd32(E1000_VLVF(i));
4194 /* remove the vf from the pool */
4197 /* if pool is empty then remove entry from vfta */
4198 if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
4199 (reg & E1000_VLVF_VLANID_ENABLE)) {
4201 vid = reg & E1000_VLVF_VLANID_MASK;
4202 igb_vfta_set(hw, vid, false);
4205 wr32(E1000_VLVF(i), reg);
4208 adapter->vf_data[vf].vlans_enabled = 0;
4211 static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
4213 struct e1000_hw *hw = &adapter->hw;
4216 /* It is an error to call this function when VFs are not enabled */
4217 if (!adapter->vfs_allocated_count)
4220 /* Find the vlan filter for this id */
4221 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
4222 reg = rd32(E1000_VLVF(i));
4223 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
4224 vid == (reg & E1000_VLVF_VLANID_MASK))
4229 if (i == E1000_VLVF_ARRAY_SIZE) {
4230 /* Did not find a matching VLAN ID entry that was
4231 * enabled. Search for a free filter entry, i.e.
4232 * one without the enable bit set
4234 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
4235 reg = rd32(E1000_VLVF(i));
4236 if (!(reg & E1000_VLVF_VLANID_ENABLE))
4240 if (i < E1000_VLVF_ARRAY_SIZE) {
4241 /* Found an enabled/available entry */
4242 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
4244 /* if !enabled we need to set this up in vfta */
4245 if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
4246 /* add VID to filter table, if bit already set
4247 * PF must have added it outside of table */
4248 if (igb_vfta_set(hw, vid, true))
4249 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT +
4250 adapter->vfs_allocated_count);
4251 reg |= E1000_VLVF_VLANID_ENABLE;
4253 reg &= ~E1000_VLVF_VLANID_MASK;
4256 wr32(E1000_VLVF(i), reg);
4258 /* do not modify RLPML for PF devices */
4259 if (vf >= adapter->vfs_allocated_count)
4262 if (!adapter->vf_data[vf].vlans_enabled) {
4264 reg = rd32(E1000_VMOLR(vf));
4265 size = reg & E1000_VMOLR_RLPML_MASK;
4267 reg &= ~E1000_VMOLR_RLPML_MASK;
4269 wr32(E1000_VMOLR(vf), reg);
4271 adapter->vf_data[vf].vlans_enabled++;
4276 if (i < E1000_VLVF_ARRAY_SIZE) {
4277 /* remove vf from the pool */
4278 reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
4279 /* if pool is empty then remove entry from vfta */
4280 if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
4282 igb_vfta_set(hw, vid, false);
4284 wr32(E1000_VLVF(i), reg);
4286 /* do not modify RLPML for PF devices */
4287 if (vf >= adapter->vfs_allocated_count)
4290 adapter->vf_data[vf].vlans_enabled--;
4291 if (!adapter->vf_data[vf].vlans_enabled) {
4293 reg = rd32(E1000_VMOLR(vf));
4294 size = reg & E1000_VMOLR_RLPML_MASK;
4296 reg &= ~E1000_VMOLR_RLPML_MASK;
4298 wr32(E1000_VMOLR(vf), reg);
4306 static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
4308 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
4309 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
4311 return igb_vlvf_set(adapter, vid, add, vf);
4314 static inline void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
4316 struct e1000_hw *hw = &adapter->hw;
4318 /* disable mailbox functionality for vf */
4319 adapter->vf_data[vf].clear_to_send = false;
4321 /* reset offloads to defaults */
4322 igb_set_vmolr(hw, vf);
4324 /* reset vlans for device */
4325 igb_clear_vf_vfta(adapter, vf);
4327 /* reset multicast table array for vf */
4328 adapter->vf_data[vf].num_vf_mc_hashes = 0;
4330 /* Flush and reset the mta with the new values */
4331 igb_set_rx_mode(adapter->netdev);
4334 static inline void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
4336 struct e1000_hw *hw = &adapter->hw;
4337 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
4338 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
4340 u8 *addr = (u8 *)(&msgbuf[1]);
4342 /* process all the same items cleared in a function level reset */
4343 igb_vf_reset_event(adapter, vf);
4345 /* set vf mac address */
4346 igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
4348 /* enable transmit and receive for vf */
4349 reg = rd32(E1000_VFTE);
4350 wr32(E1000_VFTE, reg | (1 << vf));
4351 reg = rd32(E1000_VFRE);
4352 wr32(E1000_VFRE, reg | (1 << vf));
4354 /* enable mailbox functionality for vf */
4355 adapter->vf_data[vf].clear_to_send = true;
4357 /* reply to reset with ack and vf mac address */
4358 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
4359 memcpy(addr, vf_mac, 6);
4360 igb_write_mbx(hw, msgbuf, 3, vf);
4363 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
4365 unsigned char *addr = (char *)&msg[1];
4368 if (is_valid_ether_addr(addr))
4369 err = igb_set_vf_mac(adapter, vf, addr);
4375 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
4377 struct e1000_hw *hw = &adapter->hw;
4378 u32 msg = E1000_VT_MSGTYPE_NACK;
4380 /* if device isn't clear to send it shouldn't be reading either */
4381 if (!adapter->vf_data[vf].clear_to_send)
4382 igb_write_mbx(hw, &msg, 1, vf);
4386 static void igb_msg_task(struct igb_adapter *adapter)
4388 struct e1000_hw *hw = &adapter->hw;
4391 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
4392 /* process any reset requests */
4393 if (!igb_check_for_rst(hw, vf)) {
4394 adapter->vf_data[vf].clear_to_send = false;
4395 igb_vf_reset_event(adapter, vf);
4398 /* process any messages pending */
4399 if (!igb_check_for_msg(hw, vf))
4400 igb_rcv_msg_from_vf(adapter, vf);
4402 /* process any acks */
4403 if (!igb_check_for_ack(hw, vf))
4404 igb_rcv_ack_from_vf(adapter, vf);
4409 static int igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
4411 u32 mbx_size = E1000_VFMAILBOX_SIZE;
4412 u32 msgbuf[mbx_size];
4413 struct e1000_hw *hw = &adapter->hw;
4416 retval = igb_read_mbx(hw, msgbuf, mbx_size, vf);
4419 dev_err(&adapter->pdev->dev,
4420 "Error receiving message from VF\n");
4422 /* this is a message we already processed, do nothing */
4423 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
4427 * until the vf completes a reset it should not be
4428 * allowed to start any configuration.
4431 if (msgbuf[0] == E1000_VF_RESET) {
4432 igb_vf_reset_msg(adapter, vf);
4437 if (!adapter->vf_data[vf].clear_to_send) {
4438 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
4439 igb_write_mbx(hw, msgbuf, 1, vf);
4443 switch ((msgbuf[0] & 0xFFFF)) {
4444 case E1000_VF_SET_MAC_ADDR:
4445 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
4447 case E1000_VF_SET_MULTICAST:
4448 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
4450 case E1000_VF_SET_LPE:
4451 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
4453 case E1000_VF_SET_VLAN:
4454 retval = igb_set_vf_vlan(adapter, msgbuf, vf);
4457 dev_err(&adapter->pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
4462 /* notify the VF of the results of what it sent us */
4464 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
4466 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
4468 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
4470 igb_write_mbx(hw, msgbuf, 1, vf);
4476 * igb_set_uta - Set unicast filter table address
4477 * @adapter: board private structure
4479 * The unicast table address is a register array of 32-bit registers.
4480 * The table is meant to be used in a way similar to how the MTA is used
4481 * however due to certain limitations in the hardware it is necessary to
4482 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscous
4483 * enable bit to allow vlan tag stripping when promiscous mode is enabled
4485 static void igb_set_uta(struct igb_adapter *adapter)
4487 struct e1000_hw *hw = &adapter->hw;
4490 /* The UTA table only exists on 82576 hardware and newer */
4491 if (hw->mac.type < e1000_82576)
4494 /* we only need to do this if VMDq is enabled */
4495 if (!adapter->vfs_allocated_count)
4498 for (i = 0; i < hw->mac.uta_reg_count; i++)
4499 array_wr32(E1000_UTA, i, ~0);
4503 * igb_intr_msi - Interrupt Handler
4504 * @irq: interrupt number
4505 * @data: pointer to a network interface device structure
4507 static irqreturn_t igb_intr_msi(int irq, void *data)
4509 struct igb_adapter *adapter = data;
4510 struct igb_q_vector *q_vector = adapter->q_vector[0];
4511 struct e1000_hw *hw = &adapter->hw;
4512 /* read ICR disables interrupts using IAM */
4513 u32 icr = rd32(E1000_ICR);
4515 igb_write_itr(q_vector);
4517 if (icr & E1000_ICR_DOUTSYNC) {
4518 /* HW is reporting DMA is out of sync */
4519 adapter->stats.doosync++;
4522 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
4523 hw->mac.get_link_status = 1;
4524 if (!test_bit(__IGB_DOWN, &adapter->state))
4525 mod_timer(&adapter->watchdog_timer, jiffies + 1);
4528 napi_schedule(&q_vector->napi);
4534 * igb_intr - Legacy Interrupt Handler
4535 * @irq: interrupt number
4536 * @data: pointer to a network interface device structure
4538 static irqreturn_t igb_intr(int irq, void *data)
4540 struct igb_adapter *adapter = data;
4541 struct igb_q_vector *q_vector = adapter->q_vector[0];
4542 struct e1000_hw *hw = &adapter->hw;
4543 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
4544 * need for the IMC write */
4545 u32 icr = rd32(E1000_ICR);
4547 return IRQ_NONE; /* Not our interrupt */
4549 igb_write_itr(q_vector);
4551 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
4552 * not set, then the adapter didn't send an interrupt */
4553 if (!(icr & E1000_ICR_INT_ASSERTED))
4556 if (icr & E1000_ICR_DOUTSYNC) {
4557 /* HW is reporting DMA is out of sync */
4558 adapter->stats.doosync++;
4561 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
4562 hw->mac.get_link_status = 1;
4563 /* guard against interrupt when we're going down */
4564 if (!test_bit(__IGB_DOWN, &adapter->state))
4565 mod_timer(&adapter->watchdog_timer, jiffies + 1);
4568 napi_schedule(&q_vector->napi);
4573 static inline void igb_ring_irq_enable(struct igb_q_vector *q_vector)
4575 struct igb_adapter *adapter = q_vector->adapter;
4576 struct e1000_hw *hw = &adapter->hw;
4578 if (adapter->itr_setting & 3) {
4579 if (!adapter->msix_entries)
4580 igb_set_itr(adapter);
4582 igb_update_ring_itr(q_vector);
4585 if (!test_bit(__IGB_DOWN, &adapter->state)) {
4586 if (adapter->msix_entries)
4587 wr32(E1000_EIMS, q_vector->eims_value);
4589 igb_irq_enable(adapter);
4594 * igb_poll - NAPI Rx polling callback
4595 * @napi: napi polling structure
4596 * @budget: count of how many packets we should handle
4598 static int igb_poll(struct napi_struct *napi, int budget)
4600 struct igb_q_vector *q_vector = container_of(napi,
4601 struct igb_q_vector,
4603 int tx_clean_complete = 1, work_done = 0;
4605 #ifdef CONFIG_IGB_DCA
4606 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
4607 igb_update_dca(q_vector);
4609 if (q_vector->tx_ring)
4610 tx_clean_complete = igb_clean_tx_irq(q_vector);
4612 if (q_vector->rx_ring)
4613 igb_clean_rx_irq_adv(q_vector, &work_done, budget);
4615 if (!tx_clean_complete)
4618 /* If not enough Rx work done, exit the polling mode */
4619 if (work_done < budget) {
4620 napi_complete(napi);
4621 igb_ring_irq_enable(q_vector);
4628 * igb_hwtstamp - utility function which checks for TX time stamp
4629 * @adapter: board private structure
4630 * @skb: packet that was just sent
4632 * If we were asked to do hardware stamping and such a time stamp is
4633 * available, then it must have been for this skb here because we only
4634 * allow only one such packet into the queue.
4636 static void igb_tx_hwtstamp(struct igb_adapter *adapter, struct sk_buff *skb)
4638 union skb_shared_tx *shtx = skb_tx(skb);
4639 struct e1000_hw *hw = &adapter->hw;
4641 if (unlikely(shtx->hardware)) {
4642 u32 valid = rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID;
4644 u64 regval = rd32(E1000_TXSTMPL);
4646 struct skb_shared_hwtstamps shhwtstamps;
4648 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
4649 regval |= (u64)rd32(E1000_TXSTMPH) << 32;
4650 ns = timecounter_cyc2time(&adapter->clock,
4652 timecompare_update(&adapter->compare, ns);
4653 shhwtstamps.hwtstamp = ns_to_ktime(ns);
4654 shhwtstamps.syststamp =
4655 timecompare_transform(&adapter->compare, ns);
4656 skb_tstamp_tx(skb, &shhwtstamps);
4662 * igb_clean_tx_irq - Reclaim resources after transmit completes
4663 * @q_vector: pointer to q_vector containing needed info
4664 * returns true if ring is completely cleaned
4666 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
4668 struct igb_adapter *adapter = q_vector->adapter;
4669 struct igb_ring *tx_ring = q_vector->tx_ring;
4670 struct net_device *netdev = tx_ring->netdev;
4671 struct e1000_hw *hw = &adapter->hw;
4672 struct igb_buffer *buffer_info;
4673 struct sk_buff *skb;
4674 union e1000_adv_tx_desc *tx_desc, *eop_desc;
4675 unsigned int total_bytes = 0, total_packets = 0;
4676 unsigned int i, eop, count = 0;
4677 bool cleaned = false;
4679 i = tx_ring->next_to_clean;
4680 eop = tx_ring->buffer_info[i].next_to_watch;
4681 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
4683 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
4684 (count < tx_ring->count)) {
4685 for (cleaned = false; !cleaned; count++) {
4686 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
4687 buffer_info = &tx_ring->buffer_info[i];
4688 cleaned = (i == eop);
4689 skb = buffer_info->skb;
4692 unsigned int segs, bytecount;
4693 /* gso_segs is currently only valid for tcp */
4694 segs = skb_shinfo(skb)->gso_segs ?: 1;
4695 /* multiply data chunks by size of headers */
4696 bytecount = ((segs - 1) * skb_headlen(skb)) +
4698 total_packets += segs;
4699 total_bytes += bytecount;
4701 igb_tx_hwtstamp(adapter, skb);
4704 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
4705 tx_desc->wb.status = 0;
4708 if (i == tx_ring->count)
4711 eop = tx_ring->buffer_info[i].next_to_watch;
4712 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
4715 tx_ring->next_to_clean = i;
4717 if (unlikely(count &&
4718 netif_carrier_ok(netdev) &&
4719 igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
4720 /* Make sure that anybody stopping the queue after this
4721 * sees the new next_to_clean.
4724 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
4725 !(test_bit(__IGB_DOWN, &adapter->state))) {
4726 netif_wake_subqueue(netdev, tx_ring->queue_index);
4727 tx_ring->tx_stats.restart_queue++;
4731 if (tx_ring->detect_tx_hung) {
4732 /* Detect a transmit hang in hardware, this serializes the
4733 * check with the clearing of time_stamp and movement of i */
4734 tx_ring->detect_tx_hung = false;
4735 if (tx_ring->buffer_info[i].time_stamp &&
4736 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
4737 (adapter->tx_timeout_factor * HZ))
4738 && !(rd32(E1000_STATUS) &
4739 E1000_STATUS_TXOFF)) {
4741 /* detected Tx unit hang */
4742 dev_err(&tx_ring->pdev->dev,
4743 "Detected Tx Unit Hang\n"
4747 " next_to_use <%x>\n"
4748 " next_to_clean <%x>\n"
4749 "buffer_info[next_to_clean]\n"
4750 " time_stamp <%lx>\n"
4751 " next_to_watch <%x>\n"
4753 " desc.status <%x>\n",
4754 tx_ring->queue_index,
4755 readl(tx_ring->head),
4756 readl(tx_ring->tail),
4757 tx_ring->next_to_use,
4758 tx_ring->next_to_clean,
4759 tx_ring->buffer_info[i].time_stamp,
4762 eop_desc->wb.status);
4763 netif_stop_subqueue(netdev, tx_ring->queue_index);
4766 tx_ring->total_bytes += total_bytes;
4767 tx_ring->total_packets += total_packets;
4768 tx_ring->tx_stats.bytes += total_bytes;
4769 tx_ring->tx_stats.packets += total_packets;
4770 netdev->stats.tx_bytes += total_bytes;
4771 netdev->stats.tx_packets += total_packets;
4772 return (count < tx_ring->count);
4776 * igb_receive_skb - helper function to handle rx indications
4777 * @q_vector: structure containing interrupt and ring information
4778 * @skb: packet to send up
4779 * @vlan_tag: vlan tag for packet
4781 static void igb_receive_skb(struct igb_q_vector *q_vector,
4782 struct sk_buff *skb,
4785 struct igb_adapter *adapter = q_vector->adapter;
4788 vlan_gro_receive(&q_vector->napi, adapter->vlgrp,
4791 napi_gro_receive(&q_vector->napi, skb);
4794 static inline void igb_rx_checksum_adv(struct igb_ring *ring,
4795 u32 status_err, struct sk_buff *skb)
4797 skb->ip_summed = CHECKSUM_NONE;
4799 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
4800 if (!(ring->flags & IGB_RING_FLAG_RX_CSUM) ||
4801 (status_err & E1000_RXD_STAT_IXSM))
4804 /* TCP/UDP checksum error bit is set */
4806 (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
4808 * work around errata with sctp packets where the TCPE aka
4809 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
4810 * packets, (aka let the stack check the crc32c)
4812 if ((skb->len == 60) &&
4813 (ring->flags & IGB_RING_FLAG_RX_SCTP_CSUM))
4814 ring->rx_stats.csum_err++;
4816 /* let the stack verify checksum errors */
4819 /* It must be a TCP or UDP packet with a valid checksum */
4820 if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
4821 skb->ip_summed = CHECKSUM_UNNECESSARY;
4823 dev_dbg(&ring->pdev->dev, "cksum success: bits %08X\n", status_err);
4826 static inline u16 igb_get_hlen(struct igb_ring *rx_ring,
4827 union e1000_adv_rx_desc *rx_desc)
4829 /* HW will not DMA in data larger than the given buffer, even if it
4830 * parses the (NFS, of course) header to be larger. In that case, it
4831 * fills the header buffer and spills the rest into the page.
4833 u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
4834 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
4835 if (hlen > rx_ring->rx_buffer_len)
4836 hlen = rx_ring->rx_buffer_len;
4840 static bool igb_clean_rx_irq_adv(struct igb_q_vector *q_vector,
4841 int *work_done, int budget)
4843 struct igb_adapter *adapter = q_vector->adapter;
4844 struct igb_ring *rx_ring = q_vector->rx_ring;
4845 struct net_device *netdev = rx_ring->netdev;
4846 struct e1000_hw *hw = &adapter->hw;
4847 struct pci_dev *pdev = rx_ring->pdev;
4848 union e1000_adv_rx_desc *rx_desc , *next_rxd;
4849 struct igb_buffer *buffer_info , *next_buffer;
4850 struct sk_buff *skb;
4851 bool cleaned = false;
4852 int cleaned_count = 0;
4853 unsigned int total_bytes = 0, total_packets = 0;
4859 i = rx_ring->next_to_clean;
4860 buffer_info = &rx_ring->buffer_info[i];
4861 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
4862 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
4864 while (staterr & E1000_RXD_STAT_DD) {
4865 if (*work_done >= budget)
4869 skb = buffer_info->skb;
4870 prefetch(skb->data - NET_IP_ALIGN);
4871 buffer_info->skb = NULL;
4874 if (i == rx_ring->count)
4876 next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
4878 next_buffer = &rx_ring->buffer_info[i];
4880 length = le16_to_cpu(rx_desc->wb.upper.length);
4884 if (buffer_info->dma) {
4885 pci_unmap_single(pdev, buffer_info->dma,
4886 rx_ring->rx_buffer_len,
4887 PCI_DMA_FROMDEVICE);
4888 buffer_info->dma = 0;
4889 if (rx_ring->rx_buffer_len >= IGB_RXBUFFER_1024) {
4890 skb_put(skb, length);
4893 skb_put(skb, igb_get_hlen(rx_ring, rx_desc));
4897 pci_unmap_page(pdev, buffer_info->page_dma,
4898 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
4899 buffer_info->page_dma = 0;
4901 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
4903 buffer_info->page_offset,
4906 if (page_count(buffer_info->page) != 1)
4907 buffer_info->page = NULL;
4909 get_page(buffer_info->page);
4912 skb->data_len += length;
4914 skb->truesize += length;
4917 if (!(staterr & E1000_RXD_STAT_EOP)) {
4918 buffer_info->skb = next_buffer->skb;
4919 buffer_info->dma = next_buffer->dma;
4920 next_buffer->skb = skb;
4921 next_buffer->dma = 0;
4926 * If this bit is set, then the RX registers contain
4927 * the time stamp. No other packet will be time
4928 * stamped until we read these registers, so read the
4929 * registers to make them available again. Because
4930 * only one packet can be time stamped at a time, we
4931 * know that the register values must belong to this
4932 * one here and therefore we don't need to compare
4933 * any of the additional attributes stored for it.
4935 * If nothing went wrong, then it should have a
4936 * skb_shared_tx that we can turn into a
4937 * skb_shared_hwtstamps.
4939 * TODO: can time stamping be triggered (thus locking
4940 * the registers) without the packet reaching this point
4941 * here? In that case RX time stamping would get stuck.
4943 * TODO: in "time stamp all packets" mode this bit is
4944 * not set. Need a global flag for this mode and then
4945 * always read the registers. Cannot be done without
4948 if (unlikely(staterr & E1000_RXD_STAT_TS)) {
4951 struct skb_shared_hwtstamps *shhwtstamps =
4954 WARN(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID),
4955 "igb: no RX time stamp available for time stamped packet");
4956 regval = rd32(E1000_RXSTMPL);
4957 regval |= (u64)rd32(E1000_RXSTMPH) << 32;
4958 ns = timecounter_cyc2time(&adapter->clock, regval);
4959 timecompare_update(&adapter->compare, ns);
4960 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
4961 shhwtstamps->hwtstamp = ns_to_ktime(ns);
4962 shhwtstamps->syststamp =
4963 timecompare_transform(&adapter->compare, ns);
4966 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
4967 dev_kfree_skb_irq(skb);
4971 total_bytes += skb->len;
4974 igb_rx_checksum_adv(rx_ring, staterr, skb);
4976 skb->protocol = eth_type_trans(skb, netdev);
4977 skb_record_rx_queue(skb, rx_ring->queue_index);
4979 vlan_tag = ((staterr & E1000_RXD_STAT_VP) ?
4980 le16_to_cpu(rx_desc->wb.upper.vlan) : 0);
4982 igb_receive_skb(q_vector, skb, vlan_tag);
4985 rx_desc->wb.upper.status_error = 0;
4987 /* return some buffers to hardware, one at a time is too slow */
4988 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
4989 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
4993 /* use prefetched values */
4995 buffer_info = next_buffer;
4996 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
4999 rx_ring->next_to_clean = i;
5000 cleaned_count = igb_desc_unused(rx_ring);
5003 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
5005 rx_ring->total_packets += total_packets;
5006 rx_ring->total_bytes += total_bytes;
5007 rx_ring->rx_stats.packets += total_packets;
5008 rx_ring->rx_stats.bytes += total_bytes;
5009 netdev->stats.rx_bytes += total_bytes;
5010 netdev->stats.rx_packets += total_packets;
5015 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
5016 * @adapter: address of board private structure
5018 static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
5021 struct net_device *netdev = rx_ring->netdev;
5022 union e1000_adv_rx_desc *rx_desc;
5023 struct igb_buffer *buffer_info;
5024 struct sk_buff *skb;
5028 i = rx_ring->next_to_use;
5029 buffer_info = &rx_ring->buffer_info[i];
5031 bufsz = rx_ring->rx_buffer_len;
5033 while (cleaned_count--) {
5034 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
5036 if ((bufsz < IGB_RXBUFFER_1024) && !buffer_info->page_dma) {
5037 if (!buffer_info->page) {
5038 buffer_info->page = alloc_page(GFP_ATOMIC);
5039 if (!buffer_info->page) {
5040 rx_ring->rx_stats.alloc_failed++;
5043 buffer_info->page_offset = 0;
5045 buffer_info->page_offset ^= PAGE_SIZE / 2;
5047 buffer_info->page_dma =
5048 pci_map_page(rx_ring->pdev, buffer_info->page,
5049 buffer_info->page_offset,
5051 PCI_DMA_FROMDEVICE);
5054 if (!buffer_info->skb) {
5055 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
5057 rx_ring->rx_stats.alloc_failed++;
5061 buffer_info->skb = skb;
5062 buffer_info->dma = pci_map_single(rx_ring->pdev,
5065 PCI_DMA_FROMDEVICE);
5067 /* Refresh the desc even if buffer_addrs didn't change because
5068 * each write-back erases this info. */
5069 if (bufsz < IGB_RXBUFFER_1024) {
5070 rx_desc->read.pkt_addr =
5071 cpu_to_le64(buffer_info->page_dma);
5072 rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
5074 rx_desc->read.pkt_addr =
5075 cpu_to_le64(buffer_info->dma);
5076 rx_desc->read.hdr_addr = 0;
5080 if (i == rx_ring->count)
5082 buffer_info = &rx_ring->buffer_info[i];
5086 if (rx_ring->next_to_use != i) {
5087 rx_ring->next_to_use = i;
5089 i = (rx_ring->count - 1);
5093 /* Force memory writes to complete before letting h/w
5094 * know there are new descriptors to fetch. (Only
5095 * applicable for weak-ordered memory model archs,
5096 * such as IA-64). */
5098 writel(i, rx_ring->tail);
5108 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5110 struct igb_adapter *adapter = netdev_priv(netdev);
5111 struct mii_ioctl_data *data = if_mii(ifr);
5113 if (adapter->hw.phy.media_type != e1000_media_type_copper)
5118 data->phy_id = adapter->hw.phy.addr;
5121 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
5133 * igb_hwtstamp_ioctl - control hardware time stamping
5138 * Outgoing time stamping can be enabled and disabled. Play nice and
5139 * disable it when requested, although it shouldn't case any overhead
5140 * when no packet needs it. At most one packet in the queue may be
5141 * marked for time stamping, otherwise it would be impossible to tell
5142 * for sure to which packet the hardware time stamp belongs.
5144 * Incoming time stamping has to be configured via the hardware
5145 * filters. Not all combinations are supported, in particular event
5146 * type has to be specified. Matching the kind of event packet is
5147 * not supported, with the exception of "all V2 events regardless of
5151 static int igb_hwtstamp_ioctl(struct net_device *netdev,
5152 struct ifreq *ifr, int cmd)
5154 struct igb_adapter *adapter = netdev_priv(netdev);
5155 struct e1000_hw *hw = &adapter->hw;
5156 struct hwtstamp_config config;
5157 u32 tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
5158 u32 tsync_rx_ctl_bit = E1000_TSYNCRXCTL_ENABLED;
5159 u32 tsync_rx_ctl_type = 0;
5160 u32 tsync_rx_cfg = 0;
5163 short port = 319; /* PTP */
5166 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5169 /* reserved for future extensions */
5173 switch (config.tx_type) {
5174 case HWTSTAMP_TX_OFF:
5175 tsync_tx_ctl_bit = 0;
5177 case HWTSTAMP_TX_ON:
5178 tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
5184 switch (config.rx_filter) {
5185 case HWTSTAMP_FILTER_NONE:
5186 tsync_rx_ctl_bit = 0;
5188 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5189 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5190 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5191 case HWTSTAMP_FILTER_ALL:
5193 * register TSYNCRXCFG must be set, therefore it is not
5194 * possible to time stamp both Sync and Delay_Req messages
5195 * => fall back to time stamping all packets
5197 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_ALL;
5198 config.rx_filter = HWTSTAMP_FILTER_ALL;
5200 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5201 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
5202 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
5205 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5206 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
5207 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
5210 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5211 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5212 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
5213 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
5216 config.rx_filter = HWTSTAMP_FILTER_SOME;
5218 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5219 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5220 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
5221 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
5224 config.rx_filter = HWTSTAMP_FILTER_SOME;
5226 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5227 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5228 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5229 tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_EVENT_V2;
5230 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
5237 /* enable/disable TX */
5238 regval = rd32(E1000_TSYNCTXCTL);
5239 regval = (regval & ~E1000_TSYNCTXCTL_ENABLED) | tsync_tx_ctl_bit;
5240 wr32(E1000_TSYNCTXCTL, regval);
5242 /* enable/disable RX, define which PTP packets are time stamped */
5243 regval = rd32(E1000_TSYNCRXCTL);
5244 regval = (regval & ~E1000_TSYNCRXCTL_ENABLED) | tsync_rx_ctl_bit;
5245 regval = (regval & ~0xE) | tsync_rx_ctl_type;
5246 wr32(E1000_TSYNCRXCTL, regval);
5247 wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
5250 * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
5251 * (Ethertype to filter on)
5252 * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
5253 * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
5255 wr32(E1000_ETQF0, is_l2 ? 0x440088f7 : 0);
5257 /* L4 Queue Filter[0]: only filter by source and destination port */
5258 wr32(E1000_SPQF0, htons(port));
5259 wr32(E1000_IMIREXT(0), is_l4 ?
5260 ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
5261 wr32(E1000_IMIR(0), is_l4 ?
5263 | (0<<16) /* immediate interrupt disabled */
5264 | 0 /* (1<<17) bit cleared: do not bypass
5265 destination port check */)
5267 wr32(E1000_FTQF0, is_l4 ?
5269 | (1<<15) /* VF not compared */
5270 | (1<<27) /* Enable Timestamping */
5271 | (7<<28) /* only source port filter enabled,
5272 source/target address and protocol
5274 : ((1<<15) | (15<<28) /* all mask bits set = filter not
5279 adapter->hwtstamp_config = config;
5281 /* clear TX/RX time stamp registers, just to be sure */
5282 regval = rd32(E1000_TXSTMPH);
5283 regval = rd32(E1000_RXSTMPH);
5285 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
5295 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5301 return igb_mii_ioctl(netdev, ifr, cmd);
5303 return igb_hwtstamp_ioctl(netdev, ifr, cmd);
5309 s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
5311 struct igb_adapter *adapter = hw->back;
5314 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
5316 return -E1000_ERR_CONFIG;
5318 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
5323 s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
5325 struct igb_adapter *adapter = hw->back;
5328 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
5330 return -E1000_ERR_CONFIG;
5332 pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
5337 static void igb_vlan_rx_register(struct net_device *netdev,
5338 struct vlan_group *grp)
5340 struct igb_adapter *adapter = netdev_priv(netdev);
5341 struct e1000_hw *hw = &adapter->hw;
5344 igb_irq_disable(adapter);
5345 adapter->vlgrp = grp;
5348 /* enable VLAN tag insert/strip */
5349 ctrl = rd32(E1000_CTRL);
5350 ctrl |= E1000_CTRL_VME;
5351 wr32(E1000_CTRL, ctrl);
5353 /* enable VLAN receive filtering */
5354 rctl = rd32(E1000_RCTL);
5355 rctl &= ~E1000_RCTL_CFIEN;
5356 wr32(E1000_RCTL, rctl);
5357 igb_update_mng_vlan(adapter);
5359 /* disable VLAN tag insert/strip */
5360 ctrl = rd32(E1000_CTRL);
5361 ctrl &= ~E1000_CTRL_VME;
5362 wr32(E1000_CTRL, ctrl);
5364 if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) {
5365 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
5366 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
5370 igb_rlpml_set(adapter);
5372 if (!test_bit(__IGB_DOWN, &adapter->state))
5373 igb_irq_enable(adapter);
5376 static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
5378 struct igb_adapter *adapter = netdev_priv(netdev);
5379 struct e1000_hw *hw = &adapter->hw;
5380 int pf_id = adapter->vfs_allocated_count;
5382 if ((hw->mng_cookie.status &
5383 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
5384 (vid == adapter->mng_vlan_id))
5387 /* add vid to vlvf if sr-iov is enabled,
5388 * if that fails add directly to filter table */
5389 if (igb_vlvf_set(adapter, vid, true, pf_id))
5390 igb_vfta_set(hw, vid, true);
5394 static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
5396 struct igb_adapter *adapter = netdev_priv(netdev);
5397 struct e1000_hw *hw = &adapter->hw;
5398 int pf_id = adapter->vfs_allocated_count;
5400 igb_irq_disable(adapter);
5401 vlan_group_set_device(adapter->vlgrp, vid, NULL);
5403 if (!test_bit(__IGB_DOWN, &adapter->state))
5404 igb_irq_enable(adapter);
5406 if ((adapter->hw.mng_cookie.status &
5407 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
5408 (vid == adapter->mng_vlan_id)) {
5409 /* release control to f/w */
5410 igb_release_hw_control(adapter);
5414 /* remove vid from vlvf if sr-iov is enabled,
5415 * if not in vlvf remove from vfta */
5416 if (igb_vlvf_set(adapter, vid, false, pf_id))
5417 igb_vfta_set(hw, vid, false);
5420 static void igb_restore_vlan(struct igb_adapter *adapter)
5422 igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5424 if (adapter->vlgrp) {
5426 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
5427 if (!vlan_group_get_device(adapter->vlgrp, vid))
5429 igb_vlan_rx_add_vid(adapter->netdev, vid);
5434 int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
5436 struct e1000_mac_info *mac = &adapter->hw.mac;
5441 case SPEED_10 + DUPLEX_HALF:
5442 mac->forced_speed_duplex = ADVERTISE_10_HALF;
5444 case SPEED_10 + DUPLEX_FULL:
5445 mac->forced_speed_duplex = ADVERTISE_10_FULL;
5447 case SPEED_100 + DUPLEX_HALF:
5448 mac->forced_speed_duplex = ADVERTISE_100_HALF;
5450 case SPEED_100 + DUPLEX_FULL:
5451 mac->forced_speed_duplex = ADVERTISE_100_FULL;
5453 case SPEED_1000 + DUPLEX_FULL:
5455 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
5457 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5459 dev_err(&adapter->pdev->dev,
5460 "Unsupported Speed/Duplex configuration\n");
5466 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake)
5468 struct net_device *netdev = pci_get_drvdata(pdev);
5469 struct igb_adapter *adapter = netdev_priv(netdev);
5470 struct e1000_hw *hw = &adapter->hw;
5471 u32 ctrl, rctl, status;
5472 u32 wufc = adapter->wol;
5477 netif_device_detach(netdev);
5479 if (netif_running(netdev))
5482 igb_clear_interrupt_scheme(adapter);
5485 retval = pci_save_state(pdev);
5490 status = rd32(E1000_STATUS);
5491 if (status & E1000_STATUS_LU)
5492 wufc &= ~E1000_WUFC_LNKC;
5495 igb_setup_rctl(adapter);
5496 igb_set_rx_mode(netdev);
5498 /* turn on all-multi mode if wake on multicast is enabled */
5499 if (wufc & E1000_WUFC_MC) {
5500 rctl = rd32(E1000_RCTL);
5501 rctl |= E1000_RCTL_MPE;
5502 wr32(E1000_RCTL, rctl);
5505 ctrl = rd32(E1000_CTRL);
5506 /* advertise wake from D3Cold */
5507 #define E1000_CTRL_ADVD3WUC 0x00100000
5508 /* phy power management enable */
5509 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5510 ctrl |= E1000_CTRL_ADVD3WUC;
5511 wr32(E1000_CTRL, ctrl);
5513 /* Allow time for pending master requests to run */
5514 igb_disable_pcie_master(&adapter->hw);
5516 wr32(E1000_WUC, E1000_WUC_PME_EN);
5517 wr32(E1000_WUFC, wufc);
5520 wr32(E1000_WUFC, 0);
5523 *enable_wake = wufc || adapter->en_mng_pt;
5525 igb_shutdown_serdes_link_82575(hw);
5527 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5528 * would have already happened in close and is redundant. */
5529 igb_release_hw_control(adapter);
5531 pci_disable_device(pdev);
5537 static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
5542 retval = __igb_shutdown(pdev, &wake);
5547 pci_prepare_to_sleep(pdev);
5549 pci_wake_from_d3(pdev, false);
5550 pci_set_power_state(pdev, PCI_D3hot);
5556 static int igb_resume(struct pci_dev *pdev)
5558 struct net_device *netdev = pci_get_drvdata(pdev);
5559 struct igb_adapter *adapter = netdev_priv(netdev);
5560 struct e1000_hw *hw = &adapter->hw;
5563 pci_set_power_state(pdev, PCI_D0);
5564 pci_restore_state(pdev);
5566 err = pci_enable_device_mem(pdev);
5569 "igb: Cannot enable PCI device from suspend\n");
5572 pci_set_master(pdev);
5574 pci_enable_wake(pdev, PCI_D3hot, 0);
5575 pci_enable_wake(pdev, PCI_D3cold, 0);
5577 if (igb_init_interrupt_scheme(adapter)) {
5578 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
5582 /* e1000_power_up_phy(adapter); */
5586 /* let the f/w know that the h/w is now under the control of the
5588 igb_get_hw_control(adapter);
5590 wr32(E1000_WUS, ~0);
5592 if (netif_running(netdev)) {
5593 err = igb_open(netdev);
5598 netif_device_attach(netdev);
5604 static void igb_shutdown(struct pci_dev *pdev)
5608 __igb_shutdown(pdev, &wake);
5610 if (system_state == SYSTEM_POWER_OFF) {
5611 pci_wake_from_d3(pdev, wake);
5612 pci_set_power_state(pdev, PCI_D3hot);
5616 #ifdef CONFIG_NET_POLL_CONTROLLER
5618 * Polling 'interrupt' - used by things like netconsole to send skbs
5619 * without having to re-enable interrupts. It's not called while
5620 * the interrupt routine is executing.
5622 static void igb_netpoll(struct net_device *netdev)
5624 struct igb_adapter *adapter = netdev_priv(netdev);
5625 struct e1000_hw *hw = &adapter->hw;
5628 if (!adapter->msix_entries) {
5629 struct igb_q_vector *q_vector = adapter->q_vector[0];
5630 igb_irq_disable(adapter);
5631 napi_schedule(&q_vector->napi);
5635 for (i = 0; i < adapter->num_q_vectors; i++) {
5636 struct igb_q_vector *q_vector = adapter->q_vector[i];
5637 wr32(E1000_EIMC, q_vector->eims_value);
5638 napi_schedule(&q_vector->napi);
5641 #endif /* CONFIG_NET_POLL_CONTROLLER */
5644 * igb_io_error_detected - called when PCI error is detected
5645 * @pdev: Pointer to PCI device
5646 * @state: The current pci connection state
5648 * This function is called after a PCI bus error affecting
5649 * this device has been detected.
5651 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
5652 pci_channel_state_t state)
5654 struct net_device *netdev = pci_get_drvdata(pdev);
5655 struct igb_adapter *adapter = netdev_priv(netdev);
5657 netif_device_detach(netdev);
5659 if (state == pci_channel_io_perm_failure)
5660 return PCI_ERS_RESULT_DISCONNECT;
5662 if (netif_running(netdev))
5664 pci_disable_device(pdev);
5666 /* Request a slot slot reset. */
5667 return PCI_ERS_RESULT_NEED_RESET;
5671 * igb_io_slot_reset - called after the pci bus has been reset.
5672 * @pdev: Pointer to PCI device
5674 * Restart the card from scratch, as if from a cold-boot. Implementation
5675 * resembles the first-half of the igb_resume routine.
5677 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
5679 struct net_device *netdev = pci_get_drvdata(pdev);
5680 struct igb_adapter *adapter = netdev_priv(netdev);
5681 struct e1000_hw *hw = &adapter->hw;
5682 pci_ers_result_t result;
5685 if (pci_enable_device_mem(pdev)) {
5687 "Cannot re-enable PCI device after reset.\n");
5688 result = PCI_ERS_RESULT_DISCONNECT;
5690 pci_set_master(pdev);
5691 pci_restore_state(pdev);
5693 pci_enable_wake(pdev, PCI_D3hot, 0);
5694 pci_enable_wake(pdev, PCI_D3cold, 0);
5697 wr32(E1000_WUS, ~0);
5698 result = PCI_ERS_RESULT_RECOVERED;
5701 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5703 dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
5704 "failed 0x%0x\n", err);
5705 /* non-fatal, continue */
5712 * igb_io_resume - called when traffic can start flowing again.
5713 * @pdev: Pointer to PCI device
5715 * This callback is called when the error recovery driver tells us that
5716 * its OK to resume normal operation. Implementation resembles the
5717 * second-half of the igb_resume routine.
5719 static void igb_io_resume(struct pci_dev *pdev)
5721 struct net_device *netdev = pci_get_drvdata(pdev);
5722 struct igb_adapter *adapter = netdev_priv(netdev);
5724 if (netif_running(netdev)) {
5725 if (igb_up(adapter)) {
5726 dev_err(&pdev->dev, "igb_up failed after reset\n");
5731 netif_device_attach(netdev);
5733 /* let the f/w know that the h/w is now under the control of the
5735 igb_get_hw_control(adapter);
5738 static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
5741 u32 rar_low, rar_high;
5742 struct e1000_hw *hw = &adapter->hw;
5744 /* HW expects these in little endian so we reverse the byte order
5745 * from network order (big endian) to little endian
5747 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
5748 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
5749 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
5751 /* Indicate to hardware the Address is Valid. */
5752 rar_high |= E1000_RAH_AV;
5754 if (hw->mac.type == e1000_82575)
5755 rar_high |= E1000_RAH_POOL_1 * qsel;
5757 rar_high |= E1000_RAH_POOL_1 << qsel;
5759 wr32(E1000_RAL(index), rar_low);
5761 wr32(E1000_RAH(index), rar_high);
5765 static int igb_set_vf_mac(struct igb_adapter *adapter,
5766 int vf, unsigned char *mac_addr)
5768 struct e1000_hw *hw = &adapter->hw;
5769 /* VF MAC addresses start at end of receive addresses and moves
5770 * torwards the first, as a result a collision should not be possible */
5771 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
5773 memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
5775 igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
5780 static void igb_vmm_control(struct igb_adapter *adapter)
5782 struct e1000_hw *hw = &adapter->hw;
5785 if (!adapter->vfs_allocated_count)
5788 /* VF's need PF reset indication before they
5789 * can send/receive mail */
5790 reg_data = rd32(E1000_CTRL_EXT);
5791 reg_data |= E1000_CTRL_EXT_PFRSTD;
5792 wr32(E1000_CTRL_EXT, reg_data);
5794 igb_vmdq_set_loopback_pf(hw, true);
5795 igb_vmdq_set_replication_pf(hw, true);