1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2013 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/tcp.h>
36 #include <net/checksum.h>
38 #include <linux/ipv6.h>
39 #include <net/ip6_checksum.h>
43 #include <linux/mii.h>
46 #include <linux/ethtool.h>
48 #include <linux/if_vlan.h>
49 #ifdef CONFIG_PM_RUNTIME
50 #include <linux/pm_runtime.h>
51 #endif /* CONFIG_PM_RUNTIME */
53 #include <linux/if_bridge.h>
57 #include <linux/uio_driver.h>
59 #if defined(DEBUG) || defined (DEBUG_DUMP) || defined (DEBUG_ICR) || defined(DEBUG_ITR)
60 #define DRV_DEBUG "_debug"
65 #define VERSION_SUFFIX
70 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." __stringify(BUILD) VERSION_SUFFIX DRV_DEBUG DRV_HW_PERF
72 char igb_driver_name[] = "igb";
73 char igb_driver_version[] = DRV_VERSION;
74 static const char igb_driver_string[] =
75 "Intel(R) Gigabit Ethernet Network Driver";
76 static const char igb_copyright[] =
77 "Copyright (c) 2007-2013 Intel Corporation.";
79 static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
81 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
83 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER) },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER) },
85 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES) },
86 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII) },
87 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
88 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
89 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER) },
90 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER) },
91 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER) },
92 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES) },
93 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII) },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER) },
95 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER) },
96 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER) },
97 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES) },
98 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII) },
99 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL) },
100 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII) },
101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES) },
102 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
103 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP) },
104 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576) },
105 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS) },
106 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES) },
107 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER) },
108 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES) },
109 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD) },
110 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
111 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER) },
112 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER) },
113 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES) },
114 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER) },
115 /* required last entry */
119 //MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
120 static void igb_set_sriov_capability(struct igb_adapter *adapter) __attribute__((__unused__));
121 void igb_reset(struct igb_adapter *);
122 static int igb_setup_all_tx_resources(struct igb_adapter *);
123 static int igb_setup_all_rx_resources(struct igb_adapter *);
124 static void igb_free_all_tx_resources(struct igb_adapter *);
125 static void igb_free_all_rx_resources(struct igb_adapter *);
126 static void igb_setup_mrqc(struct igb_adapter *);
127 void igb_update_stats(struct igb_adapter *);
128 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
129 static void __devexit igb_remove(struct pci_dev *pdev);
130 static int igb_sw_init(struct igb_adapter *);
131 static int igb_open(struct net_device *);
132 static int igb_close(struct net_device *);
133 static void igb_configure(struct igb_adapter *);
134 static void igb_configure_tx(struct igb_adapter *);
135 static void igb_configure_rx(struct igb_adapter *);
136 static void igb_clean_all_tx_rings(struct igb_adapter *);
137 static void igb_clean_all_rx_rings(struct igb_adapter *);
138 static void igb_clean_tx_ring(struct igb_ring *);
139 static void igb_set_rx_mode(struct net_device *);
140 static void igb_update_phy_info(unsigned long);
141 static void igb_watchdog(unsigned long);
142 static void igb_watchdog_task(struct work_struct *);
143 static void igb_dma_err_task(struct work_struct *);
144 static void igb_dma_err_timer(unsigned long data);
145 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
146 static struct net_device_stats *igb_get_stats(struct net_device *);
147 static int igb_change_mtu(struct net_device *, int);
148 void igb_full_sync_mac_table(struct igb_adapter *adapter);
149 static int igb_set_mac(struct net_device *, void *);
150 static void igb_set_uta(struct igb_adapter *adapter);
151 static irqreturn_t igb_intr(int irq, void *);
152 static irqreturn_t igb_intr_msi(int irq, void *);
153 static irqreturn_t igb_msix_other(int irq, void *);
154 static irqreturn_t igb_msix_ring(int irq, void *);
156 static void igb_update_dca(struct igb_q_vector *);
157 static void igb_setup_dca(struct igb_adapter *);
159 static int igb_poll(struct napi_struct *, int);
160 static bool igb_clean_tx_irq(struct igb_q_vector *);
161 static bool igb_clean_rx_irq(struct igb_q_vector *, int);
162 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
163 static void igb_tx_timeout(struct net_device *);
164 static void igb_reset_task(struct work_struct *);
165 #ifdef HAVE_VLAN_RX_REGISTER
166 static void igb_vlan_mode(struct net_device *, struct vlan_group *);
168 #ifdef HAVE_VLAN_PROTOCOL
169 static int igb_vlan_rx_add_vid(struct net_device *,
171 static int igb_vlan_rx_kill_vid(struct net_device *,
173 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
174 #ifdef NETIF_F_HW_VLAN_CTAG_RX
175 static int igb_vlan_rx_add_vid(struct net_device *,
176 __always_unused __be16 proto, u16);
177 static int igb_vlan_rx_kill_vid(struct net_device *,
178 __always_unused __be16 proto, u16);
180 static int igb_vlan_rx_add_vid(struct net_device *, u16);
181 static int igb_vlan_rx_kill_vid(struct net_device *, u16);
184 static void igb_vlan_rx_add_vid(struct net_device *, u16);
185 static void igb_vlan_rx_kill_vid(struct net_device *, u16);
187 static void igb_restore_vlan(struct igb_adapter *);
188 void igb_rar_set(struct igb_adapter *adapter, u32 index);
189 static void igb_ping_all_vfs(struct igb_adapter *);
190 static void igb_msg_task(struct igb_adapter *);
191 static void igb_vmm_control(struct igb_adapter *);
192 static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
193 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
194 static void igb_process_mdd_event(struct igb_adapter *);
196 static int igb_ndo_set_vf_mac( struct net_device *netdev, int vf, u8 *mac);
197 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
198 int vf, u16 vlan, u8 qos);
199 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
200 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
203 #ifdef HAVE_VF_MIN_MAX_TXRATE
204 static int igb_ndo_set_vf_bw(struct net_device *, int, int, int);
205 #else /* HAVE_VF_MIN_MAX_TXRATE */
206 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
207 #endif /* HAVE_VF_MIN_MAX_TXRATE */
208 static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
209 struct ifla_vf_info *ivi);
210 static void igb_check_vf_rate_limit(struct igb_adapter *);
212 static int igb_vf_configure(struct igb_adapter *adapter, int vf);
214 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
215 static int igb_suspend(struct device *dev);
216 static int igb_resume(struct device *dev);
217 #ifdef CONFIG_PM_RUNTIME
218 static int igb_runtime_suspend(struct device *dev);
219 static int igb_runtime_resume(struct device *dev);
220 static int igb_runtime_idle(struct device *dev);
221 #endif /* CONFIG_PM_RUNTIME */
222 static const struct dev_pm_ops igb_pm_ops = {
223 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
224 .suspend = igb_suspend,
225 .resume = igb_resume,
226 .freeze = igb_suspend,
228 .poweroff = igb_suspend,
229 .restore = igb_resume,
230 #ifdef CONFIG_PM_RUNTIME
231 .runtime_suspend = igb_runtime_suspend,
232 .runtime_resume = igb_runtime_resume,
233 .runtime_idle = igb_runtime_idle,
235 #else /* Linux >= 2.6.34 */
236 SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
237 #ifdef CONFIG_PM_RUNTIME
238 SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
240 #endif /* CONFIG_PM_RUNTIME */
241 #endif /* Linux version */
244 static int igb_suspend(struct pci_dev *pdev, pm_message_t state);
245 static int igb_resume(struct pci_dev *pdev);
246 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
247 #endif /* CONFIG_PM */
248 #ifndef USE_REBOOT_NOTIFIER
249 static void igb_shutdown(struct pci_dev *);
251 static int igb_notify_reboot(struct notifier_block *, unsigned long, void *);
252 static struct notifier_block igb_notifier_reboot = {
253 .notifier_call = igb_notify_reboot,
259 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
260 static struct notifier_block dca_notifier = {
261 .notifier_call = igb_notify_dca,
266 #ifdef CONFIG_NET_POLL_CONTROLLER
267 /* for netdump / net console */
268 static void igb_netpoll(struct net_device *);
272 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
273 pci_channel_state_t);
274 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
275 static void igb_io_resume(struct pci_dev *);
277 static struct pci_error_handlers igb_err_handler = {
278 .error_detected = igb_io_error_detected,
279 .slot_reset = igb_io_slot_reset,
280 .resume = igb_io_resume,
284 static void igb_init_fw(struct igb_adapter *adapter);
285 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
287 static struct pci_driver igb_driver = {
288 .name = igb_driver_name,
289 .id_table = igb_pci_tbl,
291 .remove = __devexit_p(igb_remove),
293 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
294 .driver.pm = &igb_pm_ops,
296 .suspend = igb_suspend,
297 .resume = igb_resume,
298 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
299 #endif /* CONFIG_PM */
300 #ifndef USE_REBOOT_NOTIFIER
301 .shutdown = igb_shutdown,
304 .err_handler = &igb_err_handler
308 //MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
309 //MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
310 //MODULE_LICENSE("GPL");
311 //MODULE_VERSION(DRV_VERSION);
313 static void igb_vfta_set(struct igb_adapter *adapter, u32 vid, bool add)
315 struct e1000_hw *hw = &adapter->hw;
316 struct e1000_host_mng_dhcp_cookie *mng_cookie = &hw->mng_cookie;
317 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
318 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
322 * if this is the management vlan the only option is to add it in so
323 * that the management pass through will continue to work
325 if ((mng_cookie->status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
326 (vid == mng_cookie->vlan_id))
329 vfta = adapter->shadow_vfta[index];
336 e1000_write_vfta(hw, index, vfta);
337 adapter->shadow_vfta[index] = vfta;
340 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
341 //module_param(debug, int, 0);
342 //MODULE_PARM_DESC(debug, "Debug level (0=none, ..., 16=all)");
345 * igb_init_module - Driver Registration Routine
347 * igb_init_module is the first routine called when the driver is
348 * loaded. All it does is register with the PCI subsystem.
350 static int __init igb_init_module(void)
354 printk(KERN_INFO "%s - version %s\n",
355 igb_driver_string, igb_driver_version);
357 printk(KERN_INFO "%s\n", igb_copyright);
359 /* only use IGB_PROCFS if IGB_HWMON is not defined */
362 if (igb_procfs_topdir_init())
363 printk(KERN_INFO "Procfs failed to initialize topdir\n");
364 #endif /* IGB_PROCFS */
365 #endif /* IGB_HWMON */
368 dca_register_notify(&dca_notifier);
370 ret = pci_register_driver(&igb_driver);
371 #ifdef USE_REBOOT_NOTIFIER
373 register_reboot_notifier(&igb_notifier_reboot);
380 #define module_init(x) static int x(void) __attribute__((__unused__));
381 module_init(igb_init_module);
384 * igb_exit_module - Driver Exit Cleanup Routine
386 * igb_exit_module is called just before the driver is removed
389 static void __exit igb_exit_module(void)
392 dca_unregister_notify(&dca_notifier);
394 #ifdef USE_REBOOT_NOTIFIER
395 unregister_reboot_notifier(&igb_notifier_reboot);
397 pci_unregister_driver(&igb_driver);
400 /* only compile IGB_PROCFS if IGB_HWMON is not defined */
403 igb_procfs_topdir_exit();
404 #endif /* IGB_PROCFS */
405 #endif /* IGB_HWMON */
409 #define module_exit(x) static void x(void) __attribute__((__unused__));
410 module_exit(igb_exit_module);
412 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
414 * igb_cache_ring_register - Descriptor ring to register mapping
415 * @adapter: board private structure to initialize
417 * Once we know the feature-set enabled for the device, we'll cache
418 * the register offset the descriptor ring is assigned to.
420 static void igb_cache_ring_register(struct igb_adapter *adapter)
423 u32 rbase_offset = adapter->vfs_allocated_count;
425 switch (adapter->hw.mac.type) {
427 /* The queues are allocated for virtualization such that VF 0
428 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
429 * In order to avoid collision we start at the first free queue
430 * and continue consuming queues in the same sequence
432 if ((adapter->rss_queues > 1) && adapter->vmdq_pools) {
433 for (; i < adapter->rss_queues; i++)
434 adapter->rx_ring[i]->reg_idx = rbase_offset +
444 for (; i < adapter->num_rx_queues; i++)
445 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
446 for (; j < adapter->num_tx_queues; j++)
447 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
452 static void igb_configure_lli(struct igb_adapter *adapter)
454 struct e1000_hw *hw = &adapter->hw;
457 /* LLI should only be enabled for MSI-X or MSI interrupts */
458 if (!adapter->msix_entries && !(adapter->flags & IGB_FLAG_HAS_MSI))
461 if (adapter->lli_port) {
462 /* use filter 0 for port */
463 port = htons((u16)adapter->lli_port);
464 E1000_WRITE_REG(hw, E1000_IMIR(0),
465 (port | E1000_IMIR_PORT_IM_EN));
466 E1000_WRITE_REG(hw, E1000_IMIREXT(0),
467 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
470 if (adapter->flags & IGB_FLAG_LLI_PUSH) {
471 /* use filter 1 for push flag */
472 E1000_WRITE_REG(hw, E1000_IMIR(1),
473 (E1000_IMIR_PORT_BP | E1000_IMIR_PORT_IM_EN));
474 E1000_WRITE_REG(hw, E1000_IMIREXT(1),
475 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_PSH));
478 if (adapter->lli_size) {
479 /* use filter 2 for size */
480 E1000_WRITE_REG(hw, E1000_IMIR(2),
481 (E1000_IMIR_PORT_BP | E1000_IMIR_PORT_IM_EN));
482 E1000_WRITE_REG(hw, E1000_IMIREXT(2),
483 (adapter->lli_size | E1000_IMIREXT_CTRL_BP));
489 * igb_write_ivar - configure ivar for given MSI-X vector
490 * @hw: pointer to the HW structure
491 * @msix_vector: vector number we are allocating to a given ring
492 * @index: row index of IVAR register to write within IVAR table
493 * @offset: column offset of in IVAR, should be multiple of 8
495 * This function is intended to handle the writing of the IVAR register
496 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
497 * each containing an cause allocation for an Rx and Tx ring, and a
498 * variable number of rows depending on the number of queues supported.
500 static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
501 int index, int offset)
503 u32 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
505 /* clear any bits that are currently set */
506 ivar &= ~((u32)0xFF << offset);
508 /* write vector and valid bit */
509 ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
511 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
514 #define IGB_N0_QUEUE -1
515 static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
517 struct igb_adapter *adapter = q_vector->adapter;
518 struct e1000_hw *hw = &adapter->hw;
519 int rx_queue = IGB_N0_QUEUE;
520 int tx_queue = IGB_N0_QUEUE;
523 if (q_vector->rx.ring)
524 rx_queue = q_vector->rx.ring->reg_idx;
525 if (q_vector->tx.ring)
526 tx_queue = q_vector->tx.ring->reg_idx;
528 switch (hw->mac.type) {
530 /* The 82575 assigns vectors using a bitmask, which matches the
531 bitmask for the EICR/EIMS/EIMC registers. To assign one
532 or more queues to a vector, we write the appropriate bits
533 into the MSIXBM register for that vector. */
534 if (rx_queue > IGB_N0_QUEUE)
535 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
536 if (tx_queue > IGB_N0_QUEUE)
537 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
538 if (!adapter->msix_entries && msix_vector == 0)
539 msixbm |= E1000_EIMS_OTHER;
540 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), msix_vector, msixbm);
541 q_vector->eims_value = msixbm;
545 * 82576 uses a table that essentially consists of 2 columns
546 * with 8 rows. The ordering is column-major so we use the
547 * lower 3 bits as the row index, and the 4th bit as the
550 if (rx_queue > IGB_N0_QUEUE)
551 igb_write_ivar(hw, msix_vector,
553 (rx_queue & 0x8) << 1);
554 if (tx_queue > IGB_N0_QUEUE)
555 igb_write_ivar(hw, msix_vector,
557 ((tx_queue & 0x8) << 1) + 8);
558 q_vector->eims_value = 1 << msix_vector;
566 * On 82580 and newer adapters the scheme is similar to 82576
567 * however instead of ordering column-major we have things
568 * ordered row-major. So we traverse the table by using
569 * bit 0 as the column offset, and the remaining bits as the
572 if (rx_queue > IGB_N0_QUEUE)
573 igb_write_ivar(hw, msix_vector,
575 (rx_queue & 0x1) << 4);
576 if (tx_queue > IGB_N0_QUEUE)
577 igb_write_ivar(hw, msix_vector,
579 ((tx_queue & 0x1) << 4) + 8);
580 q_vector->eims_value = 1 << msix_vector;
587 /* add q_vector eims value to global eims_enable_mask */
588 adapter->eims_enable_mask |= q_vector->eims_value;
590 /* configure q_vector to set itr on first interrupt */
591 q_vector->set_itr = 1;
595 * igb_configure_msix - Configure MSI-X hardware
597 * igb_configure_msix sets up the hardware to properly
598 * generate MSI-X interrupts.
600 static void igb_configure_msix(struct igb_adapter *adapter)
604 struct e1000_hw *hw = &adapter->hw;
606 adapter->eims_enable_mask = 0;
608 /* set vector for other causes, i.e. link changes */
609 switch (hw->mac.type) {
611 tmp = E1000_READ_REG(hw, E1000_CTRL_EXT);
612 /* enable MSI-X PBA support*/
613 tmp |= E1000_CTRL_EXT_PBA_CLR;
615 /* Auto-Mask interrupts upon ICR read. */
616 tmp |= E1000_CTRL_EXT_EIAME;
617 tmp |= E1000_CTRL_EXT_IRCA;
619 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmp);
621 /* enable msix_other interrupt */
622 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), vector++,
624 adapter->eims_other = E1000_EIMS_OTHER;
634 /* Turn on MSI-X capability first, or our settings
635 * won't stick. And it will take days to debug. */
636 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
637 E1000_GPIE_PBA | E1000_GPIE_EIAME |
640 /* enable msix_other interrupt */
641 adapter->eims_other = 1 << vector;
642 tmp = (vector++ | E1000_IVAR_VALID) << 8;
644 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmp);
647 /* do nothing, since nothing else supports MSI-X */
649 } /* switch (hw->mac.type) */
651 adapter->eims_enable_mask |= adapter->eims_other;
653 for (i = 0; i < adapter->num_q_vectors; i++)
654 igb_assign_vector(adapter->q_vector[i], vector++);
656 E1000_WRITE_FLUSH(hw);
660 * igb_request_msix - Initialize MSI-X interrupts
662 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
665 static int igb_request_msix(struct igb_adapter *adapter)
667 struct net_device *netdev = adapter->netdev;
668 struct e1000_hw *hw = &adapter->hw;
669 int i, err = 0, vector = 0, free_vector = 0;
671 err = request_irq(adapter->msix_entries[vector].vector,
672 &igb_msix_other, 0, netdev->name, adapter);
676 for (i = 0; i < adapter->num_q_vectors; i++) {
677 struct igb_q_vector *q_vector = adapter->q_vector[i];
681 q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
683 if (q_vector->rx.ring && q_vector->tx.ring)
684 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
685 q_vector->rx.ring->queue_index);
686 else if (q_vector->tx.ring)
687 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
688 q_vector->tx.ring->queue_index);
689 else if (q_vector->rx.ring)
690 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
691 q_vector->rx.ring->queue_index);
693 sprintf(q_vector->name, "%s-unused", netdev->name);
695 err = request_irq(adapter->msix_entries[vector].vector,
696 igb_msix_ring, 0, q_vector->name,
702 igb_configure_msix(adapter);
706 /* free already assigned IRQs */
707 free_irq(adapter->msix_entries[free_vector++].vector, adapter);
710 for (i = 0; i < vector; i++) {
711 free_irq(adapter->msix_entries[free_vector++].vector,
712 adapter->q_vector[i]);
718 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
720 if (adapter->msix_entries) {
721 pci_disable_msix(adapter->pdev);
722 kfree(adapter->msix_entries);
723 adapter->msix_entries = NULL;
724 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
725 pci_disable_msi(adapter->pdev);
730 * igb_free_q_vector - Free memory allocated for specific interrupt vector
731 * @adapter: board private structure to initialize
732 * @v_idx: Index of vector to be freed
734 * This function frees the memory allocated to the q_vector. In addition if
735 * NAPI is enabled it will delete any references to the NAPI struct prior
736 * to freeing the q_vector.
738 static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
740 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
742 if (q_vector->tx.ring)
743 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
745 if (q_vector->rx.ring)
746 adapter->tx_ring[q_vector->rx.ring->queue_index] = NULL;
748 adapter->q_vector[v_idx] = NULL;
749 netif_napi_del(&q_vector->napi);
751 __skb_queue_purge(&q_vector->lrolist.active);
757 * igb_free_q_vectors - Free memory allocated for interrupt vectors
758 * @adapter: board private structure to initialize
760 * This function frees the memory allocated to the q_vectors. In addition if
761 * NAPI is enabled it will delete any references to the NAPI struct prior
762 * to freeing the q_vector.
764 static void igb_free_q_vectors(struct igb_adapter *adapter)
766 int v_idx = adapter->num_q_vectors;
768 adapter->num_tx_queues = 0;
769 adapter->num_rx_queues = 0;
770 adapter->num_q_vectors = 0;
773 igb_free_q_vector(adapter, v_idx);
777 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
779 * This function resets the device so that it has 0 rx queues, tx queues, and
780 * MSI-X interrupts allocated.
782 static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
784 igb_free_q_vectors(adapter);
785 igb_reset_interrupt_capability(adapter);
789 * igb_process_mdd_event
790 * @adapter - board private structure
792 * Identify a malicious VF, disable the VF TX/RX queues and log a message.
794 static void igb_process_mdd_event(struct igb_adapter *adapter)
796 struct e1000_hw *hw = &adapter->hw;
797 u32 lvmmc, vfte, vfre, mdfb;
800 lvmmc = E1000_READ_REG(hw, E1000_LVMMC);
801 vf_queue = lvmmc >> 29;
803 /* VF index cannot be bigger or equal to VFs allocated */
804 if (vf_queue >= adapter->vfs_allocated_count)
807 netdev_info(adapter->netdev,
808 "VF %d misbehaved. VF queues are disabled. "
809 "VM misbehavior code is 0x%x\n", vf_queue, lvmmc);
811 /* Disable VFTE and VFRE related bits */
812 vfte = E1000_READ_REG(hw, E1000_VFTE);
813 vfte &= ~(1 << vf_queue);
814 E1000_WRITE_REG(hw, E1000_VFTE, vfte);
816 vfre = E1000_READ_REG(hw, E1000_VFRE);
817 vfre &= ~(1 << vf_queue);
818 E1000_WRITE_REG(hw, E1000_VFRE, vfre);
820 /* Disable MDFB related bit. Clear on write */
821 mdfb = E1000_READ_REG(hw, E1000_MDFB);
822 mdfb |= (1 << vf_queue);
823 E1000_WRITE_REG(hw, E1000_MDFB, mdfb);
825 /* Reset the specific VF */
826 E1000_WRITE_REG(hw, E1000_VTCTRL(vf_queue), E1000_VTCTRL_RST);
831 * @adapter - board private structure
833 * Disable MDD behavior in the HW
835 static void igb_disable_mdd(struct igb_adapter *adapter)
837 struct e1000_hw *hw = &adapter->hw;
840 if ((hw->mac.type != e1000_i350) ||
841 (hw->mac.type != e1000_i354))
844 reg = E1000_READ_REG(hw, E1000_DTXCTL);
845 reg &= (~E1000_DTXCTL_MDP_EN);
846 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
851 * @adapter - board private structure
853 * Enable the HW to detect malicious driver and sends an interrupt to
856 static void igb_enable_mdd(struct igb_adapter *adapter)
858 struct e1000_hw *hw = &adapter->hw;
861 /* Only available on i350 device */
862 if (hw->mac.type != e1000_i350)
865 reg = E1000_READ_REG(hw, E1000_DTXCTL);
866 reg |= E1000_DTXCTL_MDP_EN;
867 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
871 * igb_reset_sriov_capability - disable SR-IOV if enabled
873 * Attempt to disable single root IO virtualization capabilites present in the
876 static void igb_reset_sriov_capability(struct igb_adapter *adapter)
878 struct pci_dev *pdev = adapter->pdev;
879 struct e1000_hw *hw = &adapter->hw;
881 /* reclaim resources allocated to VFs */
882 if (adapter->vf_data) {
883 if (!pci_vfs_assigned(pdev)) {
885 * disable iov and allow time for transactions to
888 pci_disable_sriov(pdev);
891 dev_info(pci_dev_to_dev(pdev), "IOV Disabled\n");
893 dev_info(pci_dev_to_dev(pdev), "IOV Not Disabled\n "
894 "VF(s) are assigned to guests!\n");
896 /* Disable Malicious Driver Detection */
897 igb_disable_mdd(adapter);
899 /* free vf data storage */
900 kfree(adapter->vf_data);
901 adapter->vf_data = NULL;
903 /* switch rings back to PF ownership */
904 E1000_WRITE_REG(hw, E1000_IOVCTL,
905 E1000_IOVCTL_REUSE_VFQ);
906 E1000_WRITE_FLUSH(hw);
910 adapter->vfs_allocated_count = 0;
914 * igb_set_sriov_capability - setup SR-IOV if supported
916 * Attempt to enable single root IO virtualization capabilites present in the
919 static void igb_set_sriov_capability(struct igb_adapter *adapter)
921 struct pci_dev *pdev = adapter->pdev;
925 old_vfs = pci_num_vf(pdev);
927 dev_info(pci_dev_to_dev(pdev),
928 "%d pre-allocated VFs found - override "
929 "max_vfs setting of %d\n", old_vfs,
930 adapter->vfs_allocated_count);
931 adapter->vfs_allocated_count = old_vfs;
933 /* no VFs requested, do nothing */
934 if (!adapter->vfs_allocated_count)
937 /* allocate vf data storage */
938 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
939 sizeof(struct vf_data_storage),
942 if (adapter->vf_data) {
944 if (pci_enable_sriov(pdev,
945 adapter->vfs_allocated_count))
948 for (i = 0; i < adapter->vfs_allocated_count; i++)
949 igb_vf_configure(adapter, i);
951 switch (adapter->hw.mac.type) {
954 /* Enable VM to VM loopback by default */
955 adapter->flags |= IGB_FLAG_LOOPBACK_ENABLE;
958 /* Currently no other hardware supports loopback */
962 /* DMA Coalescing is not supported in IOV mode. */
963 if (adapter->hw.mac.type >= e1000_i350)
964 adapter->dmac = IGB_DMAC_DISABLE;
965 if (adapter->hw.mac.type < e1000_i350)
966 adapter->flags |= IGB_FLAG_DETECT_BAD_DMA;
972 kfree(adapter->vf_data);
973 adapter->vf_data = NULL;
974 adapter->vfs_allocated_count = 0;
975 dev_warn(pci_dev_to_dev(pdev),
976 "Failed to initialize SR-IOV virtualization\n");
980 * igb_set_interrupt_capability - set MSI or MSI-X if supported
982 * Attempt to configure interrupts using the best available
983 * capabilities of the hardware and kernel.
985 static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
987 struct pci_dev *pdev = adapter->pdev;
992 adapter->int_mode = IGB_INT_MODE_MSI;
994 /* Number of supported queues. */
995 adapter->num_rx_queues = adapter->rss_queues;
997 if (adapter->vmdq_pools > 1)
998 adapter->num_rx_queues += adapter->vmdq_pools - 1;
1001 if (adapter->vmdq_pools)
1002 adapter->num_tx_queues = adapter->vmdq_pools;
1004 adapter->num_tx_queues = adapter->num_rx_queues;
1006 adapter->num_tx_queues = max_t(u32, 1, adapter->vmdq_pools);
1009 switch (adapter->int_mode) {
1010 case IGB_INT_MODE_MSIX:
1011 /* start with one vector for every rx queue */
1012 numvecs = adapter->num_rx_queues;
1014 /* if tx handler is separate add 1 for every tx queue */
1015 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
1016 numvecs += adapter->num_tx_queues;
1018 /* store the number of vectors reserved for queues */
1019 adapter->num_q_vectors = numvecs;
1021 /* add 1 vector for link status interrupts */
1023 adapter->msix_entries = kcalloc(numvecs,
1024 sizeof(struct msix_entry),
1026 if (adapter->msix_entries) {
1027 for (i = 0; i < numvecs; i++)
1028 adapter->msix_entries[i].entry = i;
1030 err = pci_enable_msix(pdev,
1031 adapter->msix_entries, numvecs);
1035 /* MSI-X failed, so fall through and try MSI */
1036 dev_warn(pci_dev_to_dev(pdev), "Failed to initialize MSI-X interrupts. "
1037 "Falling back to MSI interrupts.\n");
1038 igb_reset_interrupt_capability(adapter);
1039 case IGB_INT_MODE_MSI:
1040 if (!pci_enable_msi(pdev))
1041 adapter->flags |= IGB_FLAG_HAS_MSI;
1043 dev_warn(pci_dev_to_dev(pdev), "Failed to initialize MSI "
1044 "interrupts. Falling back to legacy "
1047 case IGB_INT_MODE_LEGACY:
1048 /* disable advanced features and set number of queues to 1 */
1049 igb_reset_sriov_capability(adapter);
1050 adapter->vmdq_pools = 0;
1051 adapter->rss_queues = 1;
1052 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
1053 adapter->num_rx_queues = 1;
1054 adapter->num_tx_queues = 1;
1055 adapter->num_q_vectors = 1;
1056 /* Don't do anything; this is system default */
1061 static void igb_add_ring(struct igb_ring *ring,
1062 struct igb_ring_container *head)
1069 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1070 * @adapter: board private structure to initialize
1071 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1072 * @v_idx: index of vector in adapter struct
1073 * @txr_count: total number of Tx rings to allocate
1074 * @txr_idx: index of first Tx ring to allocate
1075 * @rxr_count: total number of Rx rings to allocate
1076 * @rxr_idx: index of first Rx ring to allocate
1078 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1080 static int igb_alloc_q_vector(struct igb_adapter *adapter,
1081 unsigned int v_count, unsigned int v_idx,
1082 unsigned int txr_count, unsigned int txr_idx,
1083 unsigned int rxr_count, unsigned int rxr_idx)
1085 struct igb_q_vector *q_vector;
1086 struct igb_ring *ring;
1087 int ring_count, size;
1089 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1090 if (txr_count > 1 || rxr_count > 1)
1093 ring_count = txr_count + rxr_count;
1094 size = sizeof(struct igb_q_vector) +
1095 (sizeof(struct igb_ring) * ring_count);
1097 /* allocate q_vector and rings */
1098 q_vector = kzalloc(size, GFP_KERNEL);
1103 /* initialize LRO */
1104 __skb_queue_head_init(&q_vector->lrolist.active);
1107 /* initialize NAPI */
1108 netif_napi_add(adapter->netdev, &q_vector->napi,
1111 /* tie q_vector and adapter together */
1112 adapter->q_vector[v_idx] = q_vector;
1113 q_vector->adapter = adapter;
1115 /* initialize work limits */
1116 q_vector->tx.work_limit = adapter->tx_work_limit;
1118 /* initialize ITR configuration */
1119 q_vector->itr_register = adapter->hw.hw_addr + E1000_EITR(0);
1120 q_vector->itr_val = IGB_START_ITR;
1122 /* initialize pointer to rings */
1123 ring = q_vector->ring;
1127 /* rx or rx/tx vector */
1128 if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
1129 q_vector->itr_val = adapter->rx_itr_setting;
1131 /* tx only vector */
1132 if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
1133 q_vector->itr_val = adapter->tx_itr_setting;
1137 /* assign generic ring traits */
1138 ring->dev = &adapter->pdev->dev;
1139 ring->netdev = adapter->netdev;
1141 /* configure backlink on ring */
1142 ring->q_vector = q_vector;
1144 /* update q_vector Tx values */
1145 igb_add_ring(ring, &q_vector->tx);
1147 /* For 82575, context index must be unique per ring. */
1148 if (adapter->hw.mac.type == e1000_82575)
1149 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1151 /* apply Tx specific ring traits */
1152 ring->count = adapter->tx_ring_count;
1153 ring->queue_index = txr_idx;
1155 /* assign ring to adapter */
1156 adapter->tx_ring[txr_idx] = ring;
1158 /* push pointer to next ring */
1163 /* assign generic ring traits */
1164 ring->dev = &adapter->pdev->dev;
1165 ring->netdev = adapter->netdev;
1167 /* configure backlink on ring */
1168 ring->q_vector = q_vector;
1170 /* update q_vector Rx values */
1171 igb_add_ring(ring, &q_vector->rx);
1173 #ifndef HAVE_NDO_SET_FEATURES
1174 /* enable rx checksum */
1175 set_bit(IGB_RING_FLAG_RX_CSUM, &ring->flags);
1178 /* set flag indicating ring supports SCTP checksum offload */
1179 if (adapter->hw.mac.type >= e1000_82576)
1180 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1182 if ((adapter->hw.mac.type == e1000_i350) ||
1183 (adapter->hw.mac.type == e1000_i354))
1184 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1186 /* apply Rx specific ring traits */
1187 ring->count = adapter->rx_ring_count;
1188 ring->queue_index = rxr_idx;
1190 /* assign ring to adapter */
1191 adapter->rx_ring[rxr_idx] = ring;
1198 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1199 * @adapter: board private structure to initialize
1201 * We allocate one q_vector per queue interrupt. If allocation fails we
1204 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1206 int q_vectors = adapter->num_q_vectors;
1207 int rxr_remaining = adapter->num_rx_queues;
1208 int txr_remaining = adapter->num_tx_queues;
1209 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1212 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1213 for (; rxr_remaining; v_idx++) {
1214 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1220 /* update counts and index */
1226 for (; v_idx < q_vectors; v_idx++) {
1227 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1228 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1229 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1230 tqpv, txr_idx, rqpv, rxr_idx);
1235 /* update counts and index */
1236 rxr_remaining -= rqpv;
1237 txr_remaining -= tqpv;
1245 adapter->num_tx_queues = 0;
1246 adapter->num_rx_queues = 0;
1247 adapter->num_q_vectors = 0;
1250 igb_free_q_vector(adapter, v_idx);
1256 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1258 * This function initializes the interrupts and allocates all of the queues.
1260 static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
1262 struct pci_dev *pdev = adapter->pdev;
1265 igb_set_interrupt_capability(adapter, msix);
1267 err = igb_alloc_q_vectors(adapter);
1269 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for vectors\n");
1270 goto err_alloc_q_vectors;
1273 igb_cache_ring_register(adapter);
1277 err_alloc_q_vectors:
1278 igb_reset_interrupt_capability(adapter);
1283 * igb_request_irq - initialize interrupts
1285 * Attempts to configure interrupts using the best available
1286 * capabilities of the hardware and kernel.
1288 static int igb_request_irq(struct igb_adapter *adapter)
1290 struct net_device *netdev = adapter->netdev;
1291 struct pci_dev *pdev = adapter->pdev;
1294 if (adapter->msix_entries) {
1295 err = igb_request_msix(adapter);
1298 /* fall back to MSI */
1299 igb_free_all_tx_resources(adapter);
1300 igb_free_all_rx_resources(adapter);
1302 igb_clear_interrupt_scheme(adapter);
1303 igb_reset_sriov_capability(adapter);
1304 err = igb_init_interrupt_scheme(adapter, false);
1307 igb_setup_all_tx_resources(adapter);
1308 igb_setup_all_rx_resources(adapter);
1309 igb_configure(adapter);
1312 igb_assign_vector(adapter->q_vector[0], 0);
1314 if (adapter->flags & IGB_FLAG_HAS_MSI) {
1315 err = request_irq(pdev->irq, &igb_intr_msi, 0,
1316 netdev->name, adapter);
1320 /* fall back to legacy interrupts */
1321 igb_reset_interrupt_capability(adapter);
1322 adapter->flags &= ~IGB_FLAG_HAS_MSI;
1325 err = request_irq(pdev->irq, &igb_intr, IRQF_SHARED,
1326 netdev->name, adapter);
1329 dev_err(pci_dev_to_dev(pdev), "Error %d getting interrupt\n",
1336 static void igb_free_irq(struct igb_adapter *adapter)
1338 if (adapter->msix_entries) {
1341 free_irq(adapter->msix_entries[vector++].vector, adapter);
1343 for (i = 0; i < adapter->num_q_vectors; i++)
1344 free_irq(adapter->msix_entries[vector++].vector,
1345 adapter->q_vector[i]);
1347 free_irq(adapter->pdev->irq, adapter);
1352 * igb_irq_disable - Mask off interrupt generation on the NIC
1353 * @adapter: board private structure
1355 static void igb_irq_disable(struct igb_adapter *adapter)
1357 struct e1000_hw *hw = &adapter->hw;
1360 * we need to be careful when disabling interrupts. The VFs are also
1361 * mapped into these registers and so clearing the bits can cause
1362 * issues on the VF drivers so we only need to clear what we set
1364 if (adapter->msix_entries) {
1365 u32 regval = E1000_READ_REG(hw, E1000_EIAM);
1366 E1000_WRITE_REG(hw, E1000_EIAM, regval & ~adapter->eims_enable_mask);
1367 E1000_WRITE_REG(hw, E1000_EIMC, adapter->eims_enable_mask);
1368 regval = E1000_READ_REG(hw, E1000_EIAC);
1369 E1000_WRITE_REG(hw, E1000_EIAC, regval & ~adapter->eims_enable_mask);
1372 E1000_WRITE_REG(hw, E1000_IAM, 0);
1373 E1000_WRITE_REG(hw, E1000_IMC, ~0);
1374 E1000_WRITE_FLUSH(hw);
1376 if (adapter->msix_entries) {
1379 synchronize_irq(adapter->msix_entries[vector++].vector);
1381 for (i = 0; i < adapter->num_q_vectors; i++)
1382 synchronize_irq(adapter->msix_entries[vector++].vector);
1384 synchronize_irq(adapter->pdev->irq);
1389 * igb_irq_enable - Enable default interrupt generation settings
1390 * @adapter: board private structure
1392 static void igb_irq_enable(struct igb_adapter *adapter)
1394 struct e1000_hw *hw = &adapter->hw;
1396 if (adapter->msix_entries) {
1397 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
1398 u32 regval = E1000_READ_REG(hw, E1000_EIAC);
1399 E1000_WRITE_REG(hw, E1000_EIAC, regval | adapter->eims_enable_mask);
1400 regval = E1000_READ_REG(hw, E1000_EIAM);
1401 E1000_WRITE_REG(hw, E1000_EIAM, regval | adapter->eims_enable_mask);
1402 E1000_WRITE_REG(hw, E1000_EIMS, adapter->eims_enable_mask);
1403 if (adapter->vfs_allocated_count) {
1404 E1000_WRITE_REG(hw, E1000_MBVFIMR, 0xFF);
1405 ims |= E1000_IMS_VMMB;
1407 if ((adapter->hw.mac.type == e1000_i350) ||
1408 (adapter->hw.mac.type == e1000_i354))
1409 ims |= E1000_IMS_MDDET;
1411 E1000_WRITE_REG(hw, E1000_IMS, ims);
1413 E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK |
1415 E1000_WRITE_REG(hw, E1000_IAM, IMS_ENABLE_MASK |
1420 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1422 struct e1000_hw *hw = &adapter->hw;
1423 u16 vid = adapter->hw.mng_cookie.vlan_id;
1424 u16 old_vid = adapter->mng_vlan_id;
1426 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1427 /* add VID to filter table */
1428 igb_vfta_set(adapter, vid, TRUE);
1429 adapter->mng_vlan_id = vid;
1431 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1434 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1436 #ifdef HAVE_VLAN_RX_REGISTER
1437 !vlan_group_get_device(adapter->vlgrp, old_vid)) {
1439 !test_bit(old_vid, adapter->active_vlans)) {
1441 /* remove VID from filter table */
1442 igb_vfta_set(adapter, old_vid, FALSE);
1447 * igb_release_hw_control - release control of the h/w to f/w
1448 * @adapter: address of board private structure
1450 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1451 * For ASF and Pass Through versions of f/w this means that the
1452 * driver is no longer loaded.
1455 static void igb_release_hw_control(struct igb_adapter *adapter)
1457 struct e1000_hw *hw = &adapter->hw;
1460 /* Let firmware take over control of h/w */
1461 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1462 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1463 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1467 * igb_get_hw_control - get control of the h/w from f/w
1468 * @adapter: address of board private structure
1470 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1471 * For ASF and Pass Through versions of f/w this means that
1472 * the driver is loaded.
1475 static void igb_get_hw_control(struct igb_adapter *adapter)
1477 struct e1000_hw *hw = &adapter->hw;
1480 /* Let firmware know the driver has taken over */
1481 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1482 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1483 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1487 * igb_configure - configure the hardware for RX and TX
1488 * @adapter: private board structure
1490 static void igb_configure(struct igb_adapter *adapter)
1492 struct net_device *netdev = adapter->netdev;
1495 igb_get_hw_control(adapter);
1496 igb_set_rx_mode(netdev);
1498 igb_restore_vlan(adapter);
1500 igb_setup_tctl(adapter);
1501 igb_setup_mrqc(adapter);
1502 igb_setup_rctl(adapter);
1504 igb_configure_tx(adapter);
1505 igb_configure_rx(adapter);
1507 e1000_rx_fifo_flush_82575(&adapter->hw);
1508 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1509 if (adapter->num_tx_queues > 1)
1510 netdev->features |= NETIF_F_MULTI_QUEUE;
1512 netdev->features &= ~NETIF_F_MULTI_QUEUE;
1515 /* call igb_desc_unused which always leaves
1516 * at least 1 descriptor unused to make sure
1517 * next_to_use != next_to_clean */
1518 for (i = 0; i < adapter->num_rx_queues; i++) {
1519 struct igb_ring *ring = adapter->rx_ring[i];
1520 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
1525 * igb_power_up_link - Power up the phy/serdes link
1526 * @adapter: address of board private structure
1528 void igb_power_up_link(struct igb_adapter *adapter)
1530 e1000_phy_hw_reset(&adapter->hw);
1532 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1533 e1000_power_up_phy(&adapter->hw);
1535 e1000_power_up_fiber_serdes_link(&adapter->hw);
1539 * igb_power_down_link - Power down the phy/serdes link
1540 * @adapter: address of board private structure
1542 static void igb_power_down_link(struct igb_adapter *adapter)
1544 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1545 e1000_power_down_phy(&adapter->hw);
1547 e1000_shutdown_fiber_serdes_link(&adapter->hw);
1550 /* Detect and switch function for Media Auto Sense */
1551 static void igb_check_swap_media(struct igb_adapter *adapter)
1553 struct e1000_hw *hw = &adapter->hw;
1554 u32 ctrl_ext, connsw;
1555 bool swap_now = false;
1558 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1559 connsw = E1000_READ_REG(hw, E1000_CONNSW);
1560 link = igb_has_link(adapter);
1562 /* need to live swap if current media is copper and we have fiber/serdes
1566 if ((hw->phy.media_type == e1000_media_type_copper) &&
1567 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
1569 } else if (!(connsw & E1000_CONNSW_SERDESD)) {
1570 /* copper signal takes time to appear */
1571 if (adapter->copper_tries < 2) {
1572 adapter->copper_tries++;
1573 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
1574 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1577 adapter->copper_tries = 0;
1578 if ((connsw & E1000_CONNSW_PHYSD) &&
1579 (!(connsw & E1000_CONNSW_PHY_PDN))) {
1581 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
1582 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1588 switch (hw->phy.media_type) {
1589 case e1000_media_type_copper:
1590 dev_info(pci_dev_to_dev(adapter->pdev),
1591 "%s:MAS: changing media to fiber/serdes\n",
1592 adapter->netdev->name);
1594 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1595 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1596 adapter->copper_tries = 0;
1598 case e1000_media_type_internal_serdes:
1599 case e1000_media_type_fiber:
1600 dev_info(pci_dev_to_dev(adapter->pdev),
1601 "%s:MAS: changing media to copper\n",
1602 adapter->netdev->name);
1604 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1605 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1608 /* shouldn't get here during regular operation */
1609 dev_err(pci_dev_to_dev(adapter->pdev),
1610 "%s:AMS: Invalid media type found, returning\n",
1611 adapter->netdev->name);
1614 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1618 #ifdef HAVE_I2C_SUPPORT
1619 /* igb_get_i2c_data - Reads the I2C SDA data bit
1620 * @hw: pointer to hardware structure
1621 * @i2cctl: Current value of I2CCTL register
1623 * Returns the I2C data bit value
1625 static int igb_get_i2c_data(void *data)
1627 struct igb_adapter *adapter = (struct igb_adapter *)data;
1628 struct e1000_hw *hw = &adapter->hw;
1629 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1631 return ((i2cctl & E1000_I2C_DATA_IN) != 0);
1634 /* igb_set_i2c_data - Sets the I2C data bit
1635 * @data: pointer to hardware structure
1636 * @state: I2C data value (0 or 1) to set
1638 * Sets the I2C data bit
1640 static void igb_set_i2c_data(void *data, int state)
1642 struct igb_adapter *adapter = (struct igb_adapter *)data;
1643 struct e1000_hw *hw = &adapter->hw;
1644 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1647 i2cctl |= E1000_I2C_DATA_OUT;
1649 i2cctl &= ~E1000_I2C_DATA_OUT;
1651 i2cctl &= ~E1000_I2C_DATA_OE_N;
1652 i2cctl |= E1000_I2C_CLK_OE_N;
1654 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
1655 E1000_WRITE_FLUSH(hw);
1659 /* igb_set_i2c_clk - Sets the I2C SCL clock
1660 * @data: pointer to hardware structure
1661 * @state: state to set clock
1663 * Sets the I2C clock line to state
1665 static void igb_set_i2c_clk(void *data, int state)
1667 struct igb_adapter *adapter = (struct igb_adapter *)data;
1668 struct e1000_hw *hw = &adapter->hw;
1669 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1672 i2cctl |= E1000_I2C_CLK_OUT;
1673 i2cctl &= ~E1000_I2C_CLK_OE_N;
1675 i2cctl &= ~E1000_I2C_CLK_OUT;
1676 i2cctl &= ~E1000_I2C_CLK_OE_N;
1678 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
1679 E1000_WRITE_FLUSH(hw);
1682 /* igb_get_i2c_clk - Gets the I2C SCL clock state
1683 * @data: pointer to hardware structure
1685 * Gets the I2C clock state
1687 static int igb_get_i2c_clk(void *data)
1689 struct igb_adapter *adapter = (struct igb_adapter *)data;
1690 struct e1000_hw *hw = &adapter->hw;
1691 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1693 return ((i2cctl & E1000_I2C_CLK_IN) != 0);
1696 static const struct i2c_algo_bit_data igb_i2c_algo = {
1697 .setsda = igb_set_i2c_data,
1698 .setscl = igb_set_i2c_clk,
1699 .getsda = igb_get_i2c_data,
1700 .getscl = igb_get_i2c_clk,
1705 /* igb_init_i2c - Init I2C interface
1706 * @adapter: pointer to adapter structure
1709 static s32 igb_init_i2c(struct igb_adapter *adapter)
1711 s32 status = E1000_SUCCESS;
1713 /* I2C interface supported on i350 devices */
1714 if (adapter->hw.mac.type != e1000_i350)
1715 return E1000_SUCCESS;
1717 /* Initialize the i2c bus which is controlled by the registers.
1718 * This bus will use the i2c_algo_bit structue that implements
1719 * the protocol through toggling of the 4 bits in the register.
1721 adapter->i2c_adap.owner = THIS_MODULE;
1722 adapter->i2c_algo = igb_i2c_algo;
1723 adapter->i2c_algo.data = adapter;
1724 adapter->i2c_adap.algo_data = &adapter->i2c_algo;
1725 adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
1726 strlcpy(adapter->i2c_adap.name, "igb BB",
1727 sizeof(adapter->i2c_adap.name));
1728 status = i2c_bit_add_bus(&adapter->i2c_adap);
1732 #endif /* HAVE_I2C_SUPPORT */
1734 * igb_up - Open the interface and prepare it to handle traffic
1735 * @adapter: board private structure
1737 int igb_up(struct igb_adapter *adapter)
1739 struct e1000_hw *hw = &adapter->hw;
1742 /* hardware has been reset, we need to reload some things */
1743 igb_configure(adapter);
1745 clear_bit(__IGB_DOWN, &adapter->state);
1747 for (i = 0; i < adapter->num_q_vectors; i++)
1748 napi_enable(&(adapter->q_vector[i]->napi));
1750 if (adapter->msix_entries)
1751 igb_configure_msix(adapter);
1753 igb_assign_vector(adapter->q_vector[0], 0);
1755 igb_configure_lli(adapter);
1757 /* Clear any pending interrupts. */
1758 E1000_READ_REG(hw, E1000_ICR);
1759 igb_irq_enable(adapter);
1761 /* notify VFs that reset has been completed */
1762 if (adapter->vfs_allocated_count) {
1763 u32 reg_data = E1000_READ_REG(hw, E1000_CTRL_EXT);
1764 reg_data |= E1000_CTRL_EXT_PFRSTD;
1765 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg_data);
1768 netif_tx_start_all_queues(adapter->netdev);
1770 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
1771 schedule_work(&adapter->dma_err_task);
1772 /* start the watchdog. */
1773 hw->mac.get_link_status = 1;
1774 schedule_work(&adapter->watchdog_task);
1776 if ((adapter->flags & IGB_FLAG_EEE) &&
1777 (!hw->dev_spec._82575.eee_disable))
1778 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
1783 void igb_down(struct igb_adapter *adapter)
1785 struct net_device *netdev = adapter->netdev;
1786 struct e1000_hw *hw = &adapter->hw;
1790 /* signal that we're down so the interrupt handler does not
1791 * reschedule our watchdog timer */
1792 set_bit(__IGB_DOWN, &adapter->state);
1794 /* disable receives in the hardware */
1795 rctl = E1000_READ_REG(hw, E1000_RCTL);
1796 E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
1797 /* flush and sleep below */
1799 netif_tx_stop_all_queues(netdev);
1801 /* disable transmits in the hardware */
1802 tctl = E1000_READ_REG(hw, E1000_TCTL);
1803 tctl &= ~E1000_TCTL_EN;
1804 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1805 /* flush both disables and wait for them to finish */
1806 E1000_WRITE_FLUSH(hw);
1807 usleep_range(10000, 20000);
1809 for (i = 0; i < adapter->num_q_vectors; i++)
1810 napi_disable(&(adapter->q_vector[i]->napi));
1812 igb_irq_disable(adapter);
1814 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1816 del_timer_sync(&adapter->watchdog_timer);
1817 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
1818 del_timer_sync(&adapter->dma_err_timer);
1819 del_timer_sync(&adapter->phy_info_timer);
1821 netif_carrier_off(netdev);
1823 /* record the stats before reset*/
1824 igb_update_stats(adapter);
1826 adapter->link_speed = 0;
1827 adapter->link_duplex = 0;
1830 if (!pci_channel_offline(adapter->pdev))
1835 igb_clean_all_tx_rings(adapter);
1836 igb_clean_all_rx_rings(adapter);
1838 /* since we reset the hardware DCA settings were cleared */
1839 igb_setup_dca(adapter);
1843 void igb_reinit_locked(struct igb_adapter *adapter)
1845 WARN_ON(in_interrupt());
1846 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1847 usleep_range(1000, 2000);
1850 clear_bit(__IGB_RESETTING, &adapter->state);
1854 * igb_enable_mas - Media Autosense re-enable after swap
1856 * @adapter: adapter struct
1858 static s32 igb_enable_mas(struct igb_adapter *adapter)
1860 struct e1000_hw *hw = &adapter->hw;
1862 s32 ret_val = E1000_SUCCESS;
1864 connsw = E1000_READ_REG(hw, E1000_CONNSW);
1865 if (hw->phy.media_type == e1000_media_type_copper) {
1866 /* configure for SerDes media detect */
1867 if (!(connsw & E1000_CONNSW_SERDESD)) {
1868 connsw |= E1000_CONNSW_ENRGSRC;
1869 connsw |= E1000_CONNSW_AUTOSENSE_EN;
1870 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1871 E1000_WRITE_FLUSH(hw);
1872 } else if (connsw & E1000_CONNSW_SERDESD) {
1873 /* already SerDes, no need to enable anything */
1876 dev_info(pci_dev_to_dev(adapter->pdev),
1877 "%s:MAS: Unable to configure feature, disabling..\n",
1878 adapter->netdev->name);
1879 adapter->flags &= ~IGB_FLAG_MAS_ENABLE;
1885 void igb_reset(struct igb_adapter *adapter)
1887 struct pci_dev *pdev = adapter->pdev;
1888 struct e1000_hw *hw = &adapter->hw;
1889 struct e1000_mac_info *mac = &hw->mac;
1890 struct e1000_fc_info *fc = &hw->fc;
1891 u32 pba = 0, tx_space, min_tx_space, min_rx_space, hwm;
1893 /* Repartition Pba for greater than 9k mtu
1894 * To take effect CTRL.RST is required.
1896 switch (mac->type) {
1900 pba = E1000_READ_REG(hw, E1000_RXPBS);
1901 pba = e1000_rxpbs_adjust_82580(pba);
1904 pba = E1000_READ_REG(hw, E1000_RXPBS);
1905 pba &= E1000_RXPBS_SIZE_MASK_82576;
1911 pba = E1000_PBA_34K;
1915 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
1916 (mac->type < e1000_82576)) {
1917 /* adjust PBA for jumbo frames */
1918 E1000_WRITE_REG(hw, E1000_PBA, pba);
1920 /* To maintain wire speed transmits, the Tx FIFO should be
1921 * large enough to accommodate two full transmit packets,
1922 * rounded up to the next 1KB and expressed in KB. Likewise,
1923 * the Rx FIFO should be large enough to accommodate at least
1924 * one full receive packet and is similarly rounded up and
1925 * expressed in KB. */
1926 pba = E1000_READ_REG(hw, E1000_PBA);
1927 /* upper 16 bits has Tx packet buffer allocation size in KB */
1928 tx_space = pba >> 16;
1929 /* lower 16 bits has Rx packet buffer allocation size in KB */
1931 /* the tx fifo also stores 16 bytes of information about the tx
1932 * but don't include ethernet FCS because hardware appends it */
1933 min_tx_space = (adapter->max_frame_size +
1934 sizeof(union e1000_adv_tx_desc) -
1936 min_tx_space = ALIGN(min_tx_space, 1024);
1937 min_tx_space >>= 10;
1938 /* software strips receive CRC, so leave room for it */
1939 min_rx_space = adapter->max_frame_size;
1940 min_rx_space = ALIGN(min_rx_space, 1024);
1941 min_rx_space >>= 10;
1943 /* If current Tx allocation is less than the min Tx FIFO size,
1944 * and the min Tx FIFO size is less than the current Rx FIFO
1945 * allocation, take space away from current Rx allocation */
1946 if (tx_space < min_tx_space &&
1947 ((min_tx_space - tx_space) < pba)) {
1948 pba = pba - (min_tx_space - tx_space);
1950 /* if short on rx space, rx wins and must trump tx
1952 if (pba < min_rx_space)
1955 E1000_WRITE_REG(hw, E1000_PBA, pba);
1958 /* flow control settings */
1959 /* The high water mark must be low enough to fit one full frame
1960 * (or the size used for early receive) above it in the Rx FIFO.
1961 * Set it to the lower of:
1962 * - 90% of the Rx FIFO size, or
1963 * - the full Rx FIFO size minus one full frame */
1964 hwm = min(((pba << 10) * 9 / 10),
1965 ((pba << 10) - 2 * adapter->max_frame_size));
1967 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
1968 fc->low_water = fc->high_water - 16;
1969 fc->pause_time = 0xFFFF;
1971 fc->current_mode = fc->requested_mode;
1973 /* disable receive for all VFs and wait one second */
1974 if (adapter->vfs_allocated_count) {
1977 * Clear all flags except indication that the PF has set
1978 * the VF MAC addresses administratively
1980 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
1981 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
1983 /* ping all the active vfs to let them know we are going down */
1984 igb_ping_all_vfs(adapter);
1986 /* disable transmits and receives */
1987 E1000_WRITE_REG(hw, E1000_VFRE, 0);
1988 E1000_WRITE_REG(hw, E1000_VFTE, 0);
1991 /* Allow time for pending master requests to run */
1993 E1000_WRITE_REG(hw, E1000_WUC, 0);
1995 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
1996 e1000_setup_init_funcs(hw, TRUE);
1997 igb_check_options(adapter);
1998 e1000_get_bus_info(hw);
1999 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
2001 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
2002 if (igb_enable_mas(adapter))
2003 dev_err(pci_dev_to_dev(pdev),
2004 "Error enabling Media Auto Sense\n");
2006 if (e1000_init_hw(hw))
2007 dev_err(pci_dev_to_dev(pdev), "Hardware Error\n");
2010 * Flow control settings reset on hardware reset, so guarantee flow
2011 * control is off when forcing speed.
2013 if (!hw->mac.autoneg)
2014 e1000_force_mac_fc(hw);
2016 igb_init_dmac(adapter, pba);
2017 /* Re-initialize the thermal sensor on i350 devices. */
2018 if (mac->type == e1000_i350 && hw->bus.func == 0) {
2020 * If present, re-initialize the external thermal sensor
2024 e1000_set_i2c_bb(hw);
2025 e1000_init_thermal_sensor_thresh(hw);
2028 /*Re-establish EEE setting */
2029 if (hw->phy.media_type == e1000_media_type_copper) {
2030 switch (mac->type) {
2034 e1000_set_eee_i350(hw);
2037 e1000_set_eee_i354(hw);
2044 if (!netif_running(adapter->netdev))
2045 igb_power_down_link(adapter);
2047 igb_update_mng_vlan(adapter);
2049 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2050 E1000_WRITE_REG(hw, E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
2053 #ifdef HAVE_PTP_1588_CLOCK
2054 /* Re-enable PTP, where applicable. */
2055 igb_ptp_reset(adapter);
2056 #endif /* HAVE_PTP_1588_CLOCK */
2058 e1000_get_phy_info(hw);
2063 #ifdef HAVE_NDO_SET_FEATURES
2064 static kni_netdev_features_t igb_fix_features(struct net_device *netdev,
2065 kni_netdev_features_t features)
2068 * Since there is no support for separate tx vlan accel
2069 * enabled make sure tx flag is cleared if rx is.
2071 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2072 if (!(features & NETIF_F_HW_VLAN_CTAG_RX))
2073 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2075 if (!(features & NETIF_F_HW_VLAN_RX))
2076 features &= ~NETIF_F_HW_VLAN_TX;
2079 /* If Rx checksum is disabled, then LRO should also be disabled */
2080 if (!(features & NETIF_F_RXCSUM))
2081 features &= ~NETIF_F_LRO;
2086 static int igb_set_features(struct net_device *netdev,
2087 kni_netdev_features_t features)
2089 u32 changed = netdev->features ^ features;
2091 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2092 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2094 if (changed & NETIF_F_HW_VLAN_RX)
2096 igb_vlan_mode(netdev, features);
2102 #ifdef USE_CONST_DEV_UC_CHAR
2103 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
2104 struct net_device *dev,
2105 const unsigned char *addr,
2106 #ifdef HAVE_NDO_FDB_ADD_VID
2111 static int igb_ndo_fdb_add(struct ndmsg *ndm,
2112 struct net_device *dev,
2113 unsigned char *addr,
2117 struct igb_adapter *adapter = netdev_priv(dev);
2118 struct e1000_hw *hw = &adapter->hw;
2121 if (!(adapter->vfs_allocated_count))
2124 /* Hardware does not support aging addresses so if a
2125 * ndm_state is given only allow permanent addresses
2127 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2128 pr_info("%s: FDB only supports static addresses\n",
2133 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
2134 u32 rar_uc_entries = hw->mac.rar_entry_count -
2135 (adapter->vfs_allocated_count + 1);
2137 if (netdev_uc_count(dev) < rar_uc_entries)
2138 err = dev_uc_add_excl(dev, addr);
2141 } else if (is_multicast_ether_addr(addr)) {
2142 err = dev_mc_add_excl(dev, addr);
2147 /* Only return duplicate errors if NLM_F_EXCL is set */
2148 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2154 #ifndef USE_DEFAULT_FDB_DEL_DUMP
2155 #ifdef USE_CONST_DEV_UC_CHAR
2156 static int igb_ndo_fdb_del(struct ndmsg *ndm,
2157 struct net_device *dev,
2158 const unsigned char *addr)
2160 static int igb_ndo_fdb_del(struct ndmsg *ndm,
2161 struct net_device *dev,
2162 unsigned char *addr)
2165 struct igb_adapter *adapter = netdev_priv(dev);
2166 int err = -EOPNOTSUPP;
2168 if (ndm->ndm_state & NUD_PERMANENT) {
2169 pr_info("%s: FDB only supports static addresses\n",
2174 if (adapter->vfs_allocated_count) {
2175 if (is_unicast_ether_addr(addr))
2176 err = dev_uc_del(dev, addr);
2177 else if (is_multicast_ether_addr(addr))
2178 err = dev_mc_del(dev, addr);
2186 static int igb_ndo_fdb_dump(struct sk_buff *skb,
2187 struct netlink_callback *cb,
2188 struct net_device *dev,
2191 struct igb_adapter *adapter = netdev_priv(dev);
2193 if (adapter->vfs_allocated_count)
2194 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
2198 #endif /* USE_DEFAULT_FDB_DEL_DUMP */
2200 #ifdef HAVE_BRIDGE_ATTRIBS
2201 static int igb_ndo_bridge_setlink(struct net_device *dev,
2202 struct nlmsghdr *nlh)
2204 struct igb_adapter *adapter = netdev_priv(dev);
2205 struct e1000_hw *hw = &adapter->hw;
2206 struct nlattr *attr, *br_spec;
2209 if (!(adapter->vfs_allocated_count))
2212 switch (adapter->hw.mac.type) {
2221 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
2223 nla_for_each_nested(attr, br_spec, rem) {
2226 if (nla_type(attr) != IFLA_BRIDGE_MODE)
2229 mode = nla_get_u16(attr);
2230 if (mode == BRIDGE_MODE_VEPA) {
2231 e1000_vmdq_set_loopback_pf(hw, 0);
2232 adapter->flags &= ~IGB_FLAG_LOOPBACK_ENABLE;
2233 } else if (mode == BRIDGE_MODE_VEB) {
2234 e1000_vmdq_set_loopback_pf(hw, 1);
2235 adapter->flags |= IGB_FLAG_LOOPBACK_ENABLE;
2239 netdev_info(adapter->netdev, "enabling bridge mode: %s\n",
2240 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
2246 #ifdef HAVE_BRIDGE_FILTER
2247 static int igb_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2248 struct net_device *dev, u32 filter_mask)
2250 static int igb_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2251 struct net_device *dev)
2254 struct igb_adapter *adapter = netdev_priv(dev);
2257 if (!(adapter->vfs_allocated_count))
2260 if (adapter->flags & IGB_FLAG_LOOPBACK_ENABLE)
2261 mode = BRIDGE_MODE_VEB;
2263 mode = BRIDGE_MODE_VEPA;
2265 #ifdef HAVE_NDO_FDB_ADD_VID
2266 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 0, 0);
2268 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
2269 #endif /* HAVE_NDO_FDB_ADD_VID */
2271 #endif /* HAVE_BRIDGE_ATTRIBS */
2272 #endif /* NTF_SELF */
2274 #endif /* HAVE_NDO_SET_FEATURES */
2275 #ifdef HAVE_NET_DEVICE_OPS
2276 static const struct net_device_ops igb_netdev_ops = {
2277 .ndo_open = igb_open,
2278 .ndo_stop = igb_close,
2279 .ndo_start_xmit = igb_xmit_frame,
2280 .ndo_get_stats = igb_get_stats,
2281 .ndo_set_rx_mode = igb_set_rx_mode,
2282 .ndo_set_mac_address = igb_set_mac,
2283 .ndo_change_mtu = igb_change_mtu,
2284 .ndo_do_ioctl = igb_ioctl,
2285 .ndo_tx_timeout = igb_tx_timeout,
2286 .ndo_validate_addr = eth_validate_addr,
2287 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
2288 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
2290 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
2291 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
2292 #ifdef HAVE_VF_MIN_MAX_TXRATE
2293 .ndo_set_vf_rate = igb_ndo_set_vf_bw,
2294 #else /* HAVE_VF_MIN_MAX_TXRATE */
2295 .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
2296 #endif /* HAVE_VF_MIN_MAX_TXRATE */
2297 .ndo_get_vf_config = igb_ndo_get_vf_config,
2298 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
2299 .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
2300 #endif /* HAVE_VF_SPOOFCHK_CONFIGURE */
2301 #endif /* IFLA_VF_MAX */
2302 #ifdef CONFIG_NET_POLL_CONTROLLER
2303 .ndo_poll_controller = igb_netpoll,
2305 #ifdef HAVE_NDO_SET_FEATURES
2306 .ndo_fix_features = igb_fix_features,
2307 .ndo_set_features = igb_set_features,
2309 #ifdef HAVE_VLAN_RX_REGISTER
2310 .ndo_vlan_rx_register = igb_vlan_mode,
2312 #ifndef HAVE_RHEL6_NETDEV_OPS_EXT_FDB
2314 .ndo_fdb_add = igb_ndo_fdb_add,
2315 #ifndef USE_DEFAULT_FDB_DEL_DUMP
2316 .ndo_fdb_del = igb_ndo_fdb_del,
2317 .ndo_fdb_dump = igb_ndo_fdb_dump,
2319 #endif /* ! HAVE_RHEL6_NETDEV_OPS_EXT_FDB */
2320 #ifdef HAVE_BRIDGE_ATTRIBS
2321 .ndo_bridge_setlink = igb_ndo_bridge_setlink,
2322 .ndo_bridge_getlink = igb_ndo_bridge_getlink,
2323 #endif /* HAVE_BRIDGE_ATTRIBS */
2327 #ifdef CONFIG_IGB_VMDQ_NETDEV
2328 static const struct net_device_ops igb_vmdq_ops = {
2329 .ndo_open = &igb_vmdq_open,
2330 .ndo_stop = &igb_vmdq_close,
2331 .ndo_start_xmit = &igb_vmdq_xmit_frame,
2332 .ndo_get_stats = &igb_vmdq_get_stats,
2333 .ndo_set_rx_mode = &igb_vmdq_set_rx_mode,
2334 .ndo_validate_addr = eth_validate_addr,
2335 .ndo_set_mac_address = &igb_vmdq_set_mac,
2336 .ndo_change_mtu = &igb_vmdq_change_mtu,
2337 .ndo_tx_timeout = &igb_vmdq_tx_timeout,
2338 .ndo_vlan_rx_register = &igb_vmdq_vlan_rx_register,
2339 .ndo_vlan_rx_add_vid = &igb_vmdq_vlan_rx_add_vid,
2340 .ndo_vlan_rx_kill_vid = &igb_vmdq_vlan_rx_kill_vid,
2343 #endif /* CONFIG_IGB_VMDQ_NETDEV */
2344 #endif /* HAVE_NET_DEVICE_OPS */
2345 #ifdef CONFIG_IGB_VMDQ_NETDEV
2346 void igb_assign_vmdq_netdev_ops(struct net_device *vnetdev)
2348 #ifdef HAVE_NET_DEVICE_OPS
2349 vnetdev->netdev_ops = &igb_vmdq_ops;
2351 dev->open = &igb_vmdq_open;
2352 dev->stop = &igb_vmdq_close;
2353 dev->hard_start_xmit = &igb_vmdq_xmit_frame;
2354 dev->get_stats = &igb_vmdq_get_stats;
2355 #ifdef HAVE_SET_RX_MODE
2356 dev->set_rx_mode = &igb_vmdq_set_rx_mode;
2358 dev->set_multicast_list = &igb_vmdq_set_rx_mode;
2359 dev->set_mac_address = &igb_vmdq_set_mac;
2360 dev->change_mtu = &igb_vmdq_change_mtu;
2361 #ifdef HAVE_TX_TIMEOUT
2362 dev->tx_timeout = &igb_vmdq_tx_timeout;
2364 #if defined(NETIF_F_HW_VLAN_TX) || defined(NETIF_F_HW_VLAN_CTAG_TX)
2365 dev->vlan_rx_register = &igb_vmdq_vlan_rx_register;
2366 dev->vlan_rx_add_vid = &igb_vmdq_vlan_rx_add_vid;
2367 dev->vlan_rx_kill_vid = &igb_vmdq_vlan_rx_kill_vid;
2370 igb_vmdq_set_ethtool_ops(vnetdev);
2371 vnetdev->watchdog_timeo = 5 * HZ;
2375 int igb_init_vmdq_netdevs(struct igb_adapter *adapter)
2377 int pool, err = 0, base_queue;
2378 struct net_device *vnetdev;
2379 struct igb_vmdq_adapter *vmdq_adapter;
2381 for (pool = 1; pool < adapter->vmdq_pools; pool++) {
2382 int qpp = (!adapter->rss_queues ? 1 : adapter->rss_queues);
2383 base_queue = pool * qpp;
2384 vnetdev = alloc_etherdev(sizeof(struct igb_vmdq_adapter));
2389 vmdq_adapter = netdev_priv(vnetdev);
2390 vmdq_adapter->vnetdev = vnetdev;
2391 vmdq_adapter->real_adapter = adapter;
2392 vmdq_adapter->rx_ring = adapter->rx_ring[base_queue];
2393 vmdq_adapter->tx_ring = adapter->tx_ring[base_queue];
2394 igb_assign_vmdq_netdev_ops(vnetdev);
2395 snprintf(vnetdev->name, IFNAMSIZ, "%sv%d",
2396 adapter->netdev->name, pool);
2397 vnetdev->features = adapter->netdev->features;
2398 #ifdef HAVE_NETDEV_VLAN_FEATURES
2399 vnetdev->vlan_features = adapter->netdev->vlan_features;
2401 adapter->vmdq_netdev[pool-1] = vnetdev;
2402 err = register_netdev(vnetdev);
2409 int igb_remove_vmdq_netdevs(struct igb_adapter *adapter)
2413 for (pool = 1; pool < adapter->vmdq_pools; pool++) {
2414 unregister_netdev(adapter->vmdq_netdev[pool-1]);
2415 free_netdev(adapter->vmdq_netdev[pool-1]);
2416 adapter->vmdq_netdev[pool-1] = NULL;
2420 #endif /* CONFIG_IGB_VMDQ_NETDEV */
2423 * igb_set_fw_version - Configure version string for ethtool
2424 * @adapter: adapter struct
2427 static void igb_set_fw_version(struct igb_adapter *adapter)
2429 struct e1000_hw *hw = &adapter->hw;
2430 struct e1000_fw_version fw;
2432 e1000_get_fw_version(hw, &fw);
2434 switch (hw->mac.type) {
2437 if (!(e1000_get_flash_presence_i210(hw))) {
2438 snprintf(adapter->fw_version,
2439 sizeof(adapter->fw_version),
2441 fw.invm_major, fw.invm_minor, fw.invm_img_type);
2446 /* if option rom is valid, display its version too*/
2448 snprintf(adapter->fw_version,
2449 sizeof(adapter->fw_version),
2450 "%d.%d, 0x%08x, %d.%d.%d",
2451 fw.eep_major, fw.eep_minor, fw.etrack_id,
2452 fw.or_major, fw.or_build, fw.or_patch);
2455 if (fw.etrack_id != 0X0000) {
2456 snprintf(adapter->fw_version,
2457 sizeof(adapter->fw_version),
2459 fw.eep_major, fw.eep_minor, fw.etrack_id);
2461 snprintf(adapter->fw_version,
2462 sizeof(adapter->fw_version),
2464 fw.eep_major, fw.eep_minor, fw.eep_build);
2474 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2476 * @adapter: adapter struct
2478 static void igb_init_mas(struct igb_adapter *adapter)
2480 struct e1000_hw *hw = &adapter->hw;
2483 e1000_read_nvm(hw, NVM_COMPAT, 1, &eeprom_data);
2484 switch (hw->bus.func) {
2486 if (eeprom_data & IGB_MAS_ENABLE_0)
2487 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2490 if (eeprom_data & IGB_MAS_ENABLE_1)
2491 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2494 if (eeprom_data & IGB_MAS_ENABLE_2)
2495 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2498 if (eeprom_data & IGB_MAS_ENABLE_3)
2499 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2502 /* Shouldn't get here */
2503 dev_err(pci_dev_to_dev(adapter->pdev),
2504 "%s:AMS: Invalid port configuration, returning\n",
2505 adapter->netdev->name);
2511 * igb_probe - Device Initialization Routine
2512 * @pdev: PCI device information struct
2513 * @ent: entry in igb_pci_tbl
2515 * Returns 0 on success, negative on failure
2517 * igb_probe initializes an adapter identified by a pci_dev structure.
2518 * The OS initialization, configuring of the adapter private structure,
2519 * and a hardware reset occur.
2521 static int __devinit igb_probe(struct pci_dev *pdev,
2522 const struct pci_device_id *ent)
2524 struct net_device *netdev;
2525 struct igb_adapter *adapter;
2526 struct e1000_hw *hw;
2527 u16 eeprom_data = 0;
2528 u8 pba_str[E1000_PBANUM_LENGTH];
2530 static int global_quad_port_a; /* global quad port a indication */
2531 int i, err, pci_using_dac;
2532 static int cards_found;
2534 err = pci_enable_device_mem(pdev);
2539 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
2541 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
2545 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
2547 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
2549 IGB_ERR("No usable DMA configuration, "
2556 #ifndef HAVE_ASPM_QUIRKS
2557 /* 82575 requires that the pci-e link partner disable the L0s state */
2558 switch (pdev->device) {
2559 case E1000_DEV_ID_82575EB_COPPER:
2560 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2561 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2562 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
2567 #endif /* HAVE_ASPM_QUIRKS */
2568 err = pci_request_selected_regions(pdev,
2569 pci_select_bars(pdev,
2575 pci_enable_pcie_error_reporting(pdev);
2577 pci_set_master(pdev);
2581 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
2584 netdev = alloc_etherdev(sizeof(struct igb_adapter));
2585 #endif /* HAVE_TX_MQ */
2587 goto err_alloc_etherdev;
2589 SET_MODULE_OWNER(netdev);
2590 SET_NETDEV_DEV(netdev, &pdev->dev);
2592 pci_set_drvdata(pdev, netdev);
2593 adapter = netdev_priv(netdev);
2594 adapter->netdev = netdev;
2595 adapter->pdev = pdev;
2598 adapter->port_num = hw->bus.func;
2599 adapter->msg_enable = (1 << debug) - 1;
2602 err = pci_save_state(pdev);
2607 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2608 pci_resource_len(pdev, 0));
2612 #ifdef HAVE_NET_DEVICE_OPS
2613 netdev->netdev_ops = &igb_netdev_ops;
2614 #else /* HAVE_NET_DEVICE_OPS */
2615 netdev->open = &igb_open;
2616 netdev->stop = &igb_close;
2617 netdev->get_stats = &igb_get_stats;
2618 #ifdef HAVE_SET_RX_MODE
2619 netdev->set_rx_mode = &igb_set_rx_mode;
2621 netdev->set_multicast_list = &igb_set_rx_mode;
2622 netdev->set_mac_address = &igb_set_mac;
2623 netdev->change_mtu = &igb_change_mtu;
2624 netdev->do_ioctl = &igb_ioctl;
2625 #ifdef HAVE_TX_TIMEOUT
2626 netdev->tx_timeout = &igb_tx_timeout;
2628 netdev->vlan_rx_register = igb_vlan_mode;
2629 netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
2630 netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
2631 #ifdef CONFIG_NET_POLL_CONTROLLER
2632 netdev->poll_controller = igb_netpoll;
2634 netdev->hard_start_xmit = &igb_xmit_frame;
2635 #endif /* HAVE_NET_DEVICE_OPS */
2636 igb_set_ethtool_ops(netdev);
2637 #ifdef HAVE_TX_TIMEOUT
2638 netdev->watchdog_timeo = 5 * HZ;
2641 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2643 adapter->bd_number = cards_found;
2645 /* setup the private structure */
2646 err = igb_sw_init(adapter);
2650 e1000_get_bus_info(hw);
2652 hw->phy.autoneg_wait_to_complete = FALSE;
2653 hw->mac.adaptive_ifs = FALSE;
2655 /* Copper options */
2656 if (hw->phy.media_type == e1000_media_type_copper) {
2657 hw->phy.mdix = AUTO_ALL_MODES;
2658 hw->phy.disable_polarity_correction = FALSE;
2659 hw->phy.ms_type = e1000_ms_hw_default;
2662 if (e1000_check_reset_block(hw))
2663 dev_info(pci_dev_to_dev(pdev),
2664 "PHY reset is blocked due to SOL/IDER session.\n");
2667 * features is initialized to 0 in allocation, it might have bits
2668 * set by igb_sw_init so we should use an or instead of an
2671 netdev->features |= NETIF_F_SG |
2673 #ifdef NETIF_F_IPV6_CSUM
2681 #endif /* NETIF_F_TSO */
2682 #ifdef NETIF_F_RXHASH
2686 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2687 NETIF_F_HW_VLAN_CTAG_RX |
2688 NETIF_F_HW_VLAN_CTAG_TX;
2690 NETIF_F_HW_VLAN_RX |
2694 if (hw->mac.type >= e1000_82576)
2695 netdev->features |= NETIF_F_SCTP_CSUM;
2697 #ifdef HAVE_NDO_SET_FEATURES
2698 /* copy netdev features into list of user selectable features */
2699 netdev->hw_features |= netdev->features;
2702 /* give us the option of enabling LRO later */
2703 netdev->hw_features |= NETIF_F_LRO;
2708 /* this is only needed on kernels prior to 2.6.39 */
2709 netdev->features |= NETIF_F_GRO;
2713 /* set this bit last since it cannot be part of hw_features */
2714 #ifdef NETIF_F_HW_VLAN_CTAG_FILTER
2715 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2717 netdev->features |= NETIF_F_HW_VLAN_FILTER;
2720 #ifdef HAVE_NETDEV_VLAN_FEATURES
2721 netdev->vlan_features |= NETIF_F_TSO |
2729 netdev->features |= NETIF_F_HIGHDMA;
2731 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
2733 if (adapter->dmac != IGB_DMAC_DISABLE)
2734 printk("%s: DMA Coalescing is enabled..\n", netdev->name);
2737 /* before reading the NVM, reset the controller to put the device in a
2738 * known good starting state */
2741 /* make sure the NVM is good */
2742 if (e1000_validate_nvm_checksum(hw) < 0) {
2743 dev_err(pci_dev_to_dev(pdev), "The NVM Checksum Is Not"
2749 /* copy the MAC address out of the NVM */
2750 if (e1000_read_mac_addr(hw))
2751 dev_err(pci_dev_to_dev(pdev), "NVM Read Error\n");
2752 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2753 #ifdef ETHTOOL_GPERMADDR
2754 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
2756 if (!is_valid_ether_addr(netdev->perm_addr)) {
2758 if (!is_valid_ether_addr(netdev->dev_addr)) {
2760 dev_err(pci_dev_to_dev(pdev), "Invalid MAC Address\n");
2765 memcpy(&adapter->mac_table[0].addr, hw->mac.addr, netdev->addr_len);
2766 adapter->mac_table[0].queue = adapter->vfs_allocated_count;
2767 adapter->mac_table[0].state = (IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE);
2768 igb_rar_set(adapter, 0);
2770 /* get firmware version for ethtool -i */
2771 igb_set_fw_version(adapter);
2773 /* Check if Media Autosense is enabled */
2774 if (hw->mac.type == e1000_82580)
2775 igb_init_mas(adapter);
2776 setup_timer(&adapter->watchdog_timer, &igb_watchdog,
2777 (unsigned long) adapter);
2778 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
2779 setup_timer(&adapter->dma_err_timer, &igb_dma_err_timer,
2780 (unsigned long) adapter);
2781 setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
2782 (unsigned long) adapter);
2784 INIT_WORK(&adapter->reset_task, igb_reset_task);
2785 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
2786 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
2787 INIT_WORK(&adapter->dma_err_task, igb_dma_err_task);
2789 /* Initialize link properties that are user-changeable */
2790 adapter->fc_autoneg = true;
2791 hw->mac.autoneg = true;
2792 hw->phy.autoneg_advertised = 0x2f;
2794 hw->fc.requested_mode = e1000_fc_default;
2795 hw->fc.current_mode = e1000_fc_default;
2797 e1000_validate_mdi_setting(hw);
2799 /* By default, support wake on port A */
2800 if (hw->bus.func == 0)
2801 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2803 /* Check the NVM for wake support for non-port A ports */
2804 if (hw->mac.type >= e1000_82580)
2805 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2806 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2808 else if (hw->bus.func == 1)
2809 e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
2811 if (eeprom_data & IGB_EEPROM_APME)
2812 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2814 /* now that we have the eeprom settings, apply the special cases where
2815 * the eeprom may be wrong or the board simply won't support wake on
2816 * lan on a particular port */
2817 switch (pdev->device) {
2818 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2819 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2821 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2822 case E1000_DEV_ID_82576_FIBER:
2823 case E1000_DEV_ID_82576_SERDES:
2824 /* Wake events only supported on port A for dual fiber
2825 * regardless of eeprom setting */
2826 if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1)
2827 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2829 case E1000_DEV_ID_82576_QUAD_COPPER:
2830 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
2831 /* if quad port adapter, disable WoL on all but port A */
2832 if (global_quad_port_a != 0)
2833 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2835 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2836 /* Reset for multiple quad port adapters */
2837 if (++global_quad_port_a == 4)
2838 global_quad_port_a = 0;
2841 /* If the device can't wake, don't set software support */
2842 if (!device_can_wakeup(&adapter->pdev->dev))
2843 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2847 /* initialize the wol settings based on the eeprom settings */
2848 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
2849 adapter->wol |= E1000_WUFC_MAG;
2851 /* Some vendors want WoL disabled by default, but still supported */
2852 if ((hw->mac.type == e1000_i350) &&
2853 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
2854 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2858 device_set_wakeup_enable(pci_dev_to_dev(adapter->pdev),
2859 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
2861 /* reset the hardware with the new settings */
2865 #ifdef HAVE_I2C_SUPPORT
2866 /* Init the I2C interface */
2867 err = igb_init_i2c(adapter);
2869 dev_err(&pdev->dev, "failed to init i2c interface\n");
2872 #endif /* HAVE_I2C_SUPPORT */
2874 /* let the f/w know that the h/w is now under the control of the
2876 igb_get_hw_control(adapter);
2878 strncpy(netdev->name, "eth%d", IFNAMSIZ);
2879 err = register_netdev(netdev);
2883 #ifdef CONFIG_IGB_VMDQ_NETDEV
2884 err = igb_init_vmdq_netdevs(adapter);
2888 /* carrier off reporting is important to ethtool even BEFORE open */
2889 netif_carrier_off(netdev);
2892 if (dca_add_requester(&pdev->dev) == E1000_SUCCESS) {
2893 adapter->flags |= IGB_FLAG_DCA_ENABLED;
2894 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
2895 igb_setup_dca(adapter);
2899 #ifdef HAVE_PTP_1588_CLOCK
2900 /* do hw tstamp init after resetting */
2901 igb_ptp_init(adapter);
2902 #endif /* HAVE_PTP_1588_CLOCK */
2904 dev_info(pci_dev_to_dev(pdev), "Intel(R) Gigabit Ethernet Network Connection\n");
2905 /* print bus type/speed/width info */
2906 dev_info(pci_dev_to_dev(pdev), "%s: (PCIe:%s:%s) ",
2908 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5GT/s" :
2909 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0GT/s" :
2910 (hw->mac.type == e1000_i354) ? "integrated" :
2912 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
2913 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
2914 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
2915 (hw->mac.type == e1000_i354) ? "integrated" :
2917 dev_info(pci_dev_to_dev(pdev), "%s: MAC: ", netdev->name);
2918 for (i = 0; i < 6; i++)
2919 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
2921 ret_val = e1000_read_pba_string(hw, pba_str, E1000_PBANUM_LENGTH);
2923 strncpy(pba_str, "Unknown", sizeof(pba_str) - 1);
2924 dev_info(pci_dev_to_dev(pdev), "%s: PBA No: %s\n", netdev->name,
2928 /* Initialize the thermal sensor on i350 devices. */
2929 if (hw->mac.type == e1000_i350) {
2930 if (hw->bus.func == 0) {
2934 * Read the NVM to determine if this i350 device
2935 * supports an external thermal sensor.
2937 e1000_read_nvm(hw, NVM_ETS_CFG, 1, &ets_word);
2938 if (ets_word != 0x0000 && ets_word != 0xFFFF)
2939 adapter->ets = true;
2941 adapter->ets = false;
2945 igb_sysfs_init(adapter);
2949 igb_procfs_init(adapter);
2950 #endif /* IGB_PROCFS */
2951 #endif /* IGB_HWMON */
2953 adapter->ets = false;
2956 if (hw->phy.media_type == e1000_media_type_copper) {
2957 switch (hw->mac.type) {
2961 /* Enable EEE for internal copper PHY devices */
2962 err = e1000_set_eee_i350(hw);
2964 (adapter->flags & IGB_FLAG_EEE))
2965 adapter->eee_advert =
2966 MDIO_EEE_100TX | MDIO_EEE_1000T;
2969 if ((E1000_READ_REG(hw, E1000_CTRL_EXT)) &
2970 (E1000_CTRL_EXT_LINK_MODE_SGMII)) {
2971 err = e1000_set_eee_i354(hw);
2973 (adapter->flags & IGB_FLAG_EEE))
2974 adapter->eee_advert =
2975 MDIO_EEE_100TX | MDIO_EEE_1000T;
2983 /* send driver version info to firmware */
2984 if (hw->mac.type >= e1000_i350)
2985 igb_init_fw(adapter);
2988 if (netdev->features & NETIF_F_LRO)
2989 dev_info(pci_dev_to_dev(pdev), "Internal LRO is enabled \n");
2991 dev_info(pci_dev_to_dev(pdev), "LRO is disabled \n");
2993 dev_info(pci_dev_to_dev(pdev),
2994 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
2995 adapter->msix_entries ? "MSI-X" :
2996 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
2997 adapter->num_rx_queues, adapter->num_tx_queues);
3001 pm_runtime_put_noidle(&pdev->dev);
3005 igb_release_hw_control(adapter);
3006 #ifdef HAVE_I2C_SUPPORT
3007 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
3008 #endif /* HAVE_I2C_SUPPORT */
3010 if (!e1000_check_reset_block(hw))
3011 e1000_phy_hw_reset(hw);
3013 if (hw->flash_address)
3014 iounmap(hw->flash_address);
3016 igb_clear_interrupt_scheme(adapter);
3017 igb_reset_sriov_capability(adapter);
3018 iounmap(hw->hw_addr);
3020 free_netdev(netdev);
3022 pci_release_selected_regions(pdev,
3023 pci_select_bars(pdev, IORESOURCE_MEM));
3026 pci_disable_device(pdev);
3029 #ifdef HAVE_I2C_SUPPORT
3031 * igb_remove_i2c - Cleanup I2C interface
3032 * @adapter: pointer to adapter structure
3035 static void igb_remove_i2c(struct igb_adapter *adapter)
3038 /* free the adapter bus structure */
3039 i2c_del_adapter(&adapter->i2c_adap);
3041 #endif /* HAVE_I2C_SUPPORT */
3044 * igb_remove - Device Removal Routine
3045 * @pdev: PCI device information struct
3047 * igb_remove is called by the PCI subsystem to alert the driver
3048 * that it should release a PCI device. The could be caused by a
3049 * Hot-Plug event, or because the driver is going to be removed from
3052 static void __devexit igb_remove(struct pci_dev *pdev)
3054 struct net_device *netdev = pci_get_drvdata(pdev);
3055 struct igb_adapter *adapter = netdev_priv(netdev);
3056 struct e1000_hw *hw = &adapter->hw;
3058 pm_runtime_get_noresume(&pdev->dev);
3059 #ifdef HAVE_I2C_SUPPORT
3060 igb_remove_i2c(adapter);
3061 #endif /* HAVE_I2C_SUPPORT */
3062 #ifdef HAVE_PTP_1588_CLOCK
3063 igb_ptp_stop(adapter);
3064 #endif /* HAVE_PTP_1588_CLOCK */
3066 /* flush_scheduled work may reschedule our watchdog task, so
3067 * explicitly disable watchdog tasks from being rescheduled */
3068 set_bit(__IGB_DOWN, &adapter->state);
3069 del_timer_sync(&adapter->watchdog_timer);
3070 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
3071 del_timer_sync(&adapter->dma_err_timer);
3072 del_timer_sync(&adapter->phy_info_timer);
3074 flush_scheduled_work();
3077 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
3078 dev_info(pci_dev_to_dev(pdev), "DCA disabled\n");
3079 dca_remove_requester(&pdev->dev);
3080 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
3081 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_DISABLE);
3085 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3086 * would have already happened in close and is redundant. */
3087 igb_release_hw_control(adapter);
3089 unregister_netdev(netdev);
3090 #ifdef CONFIG_IGB_VMDQ_NETDEV
3091 igb_remove_vmdq_netdevs(adapter);
3094 igb_clear_interrupt_scheme(adapter);
3095 igb_reset_sriov_capability(adapter);
3097 iounmap(hw->hw_addr);
3098 if (hw->flash_address)
3099 iounmap(hw->flash_address);
3100 pci_release_selected_regions(pdev,
3101 pci_select_bars(pdev, IORESOURCE_MEM));
3104 igb_sysfs_exit(adapter);
3107 igb_procfs_exit(adapter);
3108 #endif /* IGB_PROCFS */
3109 #endif /* IGB_HWMON */
3110 kfree(adapter->mac_table);
3111 kfree(adapter->shadow_vfta);
3112 free_netdev(netdev);
3114 pci_disable_pcie_error_reporting(pdev);
3116 pci_disable_device(pdev);
3120 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3121 * @adapter: board private structure to initialize
3123 * igb_sw_init initializes the Adapter private data structure.
3124 * Fields are initialized based on PCI device information and
3125 * OS network device settings (MTU size).
3127 static int igb_sw_init(struct igb_adapter *adapter)
3129 struct e1000_hw *hw = &adapter->hw;
3130 struct net_device *netdev = adapter->netdev;
3131 struct pci_dev *pdev = adapter->pdev;
3133 /* PCI config space info */
3135 hw->vendor_id = pdev->vendor;
3136 hw->device_id = pdev->device;
3137 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3138 hw->subsystem_device_id = pdev->subsystem_device;
3140 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3142 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
3144 /* set default ring sizes */
3145 adapter->tx_ring_count = IGB_DEFAULT_TXD;
3146 adapter->rx_ring_count = IGB_DEFAULT_RXD;
3148 /* set default work limits */
3149 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
3151 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3154 /* Initialize the hardware-specific values */
3155 if (e1000_setup_init_funcs(hw, TRUE)) {
3156 dev_err(pci_dev_to_dev(pdev), "Hardware Initialization Failure\n");
3160 adapter->mac_table = kzalloc(sizeof(struct igb_mac_addr) *
3161 hw->mac.rar_entry_count,
3164 /* Setup and initialize a copy of the hw vlan table array */
3165 adapter->shadow_vfta = (u32 *)kzalloc(sizeof(u32) * E1000_VFTA_ENTRIES,
3168 /* These calls may decrease the number of queues */
3169 if (hw->mac.type < e1000_i210) {
3170 igb_set_sriov_capability(adapter);
3173 if (igb_init_interrupt_scheme(adapter, true)) {
3174 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for queues\n");
3178 /* Explicitly disable IRQ since the NIC can be in any state. */
3179 igb_irq_disable(adapter);
3181 set_bit(__IGB_DOWN, &adapter->state);
3187 * igb_open - Called when a network interface is made active
3188 * @netdev: network interface device structure
3190 * Returns 0 on success, negative value on failure
3192 * The open entry point is called when a network interface is made
3193 * active by the system (IFF_UP). At this point all resources needed
3194 * for transmit and receive operations are allocated, the interrupt
3195 * handler is registered with the OS, the watchdog timer is started,
3196 * and the stack is notified that the interface is ready.
3198 static int __igb_open(struct net_device *netdev, bool resuming)
3200 struct igb_adapter *adapter = netdev_priv(netdev);
3201 struct e1000_hw *hw = &adapter->hw;
3202 #ifdef CONFIG_PM_RUNTIME
3203 struct pci_dev *pdev = adapter->pdev;
3204 #endif /* CONFIG_PM_RUNTIME */
3208 /* disallow open during test */
3209 if (test_bit(__IGB_TESTING, &adapter->state)) {
3214 #ifdef CONFIG_PM_RUNTIME
3216 pm_runtime_get_sync(&pdev->dev);
3217 #endif /* CONFIG_PM_RUNTIME */
3219 netif_carrier_off(netdev);
3221 /* allocate transmit descriptors */
3222 err = igb_setup_all_tx_resources(adapter);
3226 /* allocate receive descriptors */
3227 err = igb_setup_all_rx_resources(adapter);
3231 igb_power_up_link(adapter);
3233 /* before we allocate an interrupt, we must be ready to handle it.
3234 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3235 * as soon as we call pci_request_irq, so we have to setup our
3236 * clean_rx handler before we do so. */
3237 igb_configure(adapter);
3239 err = igb_request_irq(adapter);
3243 /* Notify the stack of the actual queue counts. */
3244 netif_set_real_num_tx_queues(netdev,
3245 adapter->vmdq_pools ? 1 :
3246 adapter->num_tx_queues);
3248 err = netif_set_real_num_rx_queues(netdev,
3249 adapter->vmdq_pools ? 1 :
3250 adapter->num_rx_queues);
3252 goto err_set_queues;
3254 /* From here on the code is the same as igb_up() */
3255 clear_bit(__IGB_DOWN, &adapter->state);
3257 for (i = 0; i < adapter->num_q_vectors; i++)
3258 napi_enable(&(adapter->q_vector[i]->napi));
3259 igb_configure_lli(adapter);
3261 /* Clear any pending interrupts. */
3262 E1000_READ_REG(hw, E1000_ICR);
3264 igb_irq_enable(adapter);
3266 /* notify VFs that reset has been completed */
3267 if (adapter->vfs_allocated_count) {
3268 u32 reg_data = E1000_READ_REG(hw, E1000_CTRL_EXT);
3269 reg_data |= E1000_CTRL_EXT_PFRSTD;
3270 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg_data);
3273 netif_tx_start_all_queues(netdev);
3275 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
3276 schedule_work(&adapter->dma_err_task);
3278 /* start the watchdog. */
3279 hw->mac.get_link_status = 1;
3280 schedule_work(&adapter->watchdog_task);
3282 return E1000_SUCCESS;
3285 igb_free_irq(adapter);
3287 igb_release_hw_control(adapter);
3288 igb_power_down_link(adapter);
3289 igb_free_all_rx_resources(adapter);
3291 igb_free_all_tx_resources(adapter);
3295 #ifdef CONFIG_PM_RUNTIME
3297 pm_runtime_put(&pdev->dev);
3298 #endif /* CONFIG_PM_RUNTIME */
3303 static int igb_open(struct net_device *netdev)
3305 return __igb_open(netdev, false);
3309 * igb_close - Disables a network interface
3310 * @netdev: network interface device structure
3312 * Returns 0, this is not allowed to fail
3314 * The close entry point is called when an interface is de-activated
3315 * by the OS. The hardware is still under the driver's control, but
3316 * needs to be disabled. A global MAC reset is issued to stop the
3317 * hardware, and all transmit and receive resources are freed.
3319 static int __igb_close(struct net_device *netdev, bool suspending)
3321 struct igb_adapter *adapter = netdev_priv(netdev);
3322 #ifdef CONFIG_PM_RUNTIME
3323 struct pci_dev *pdev = adapter->pdev;
3324 #endif /* CONFIG_PM_RUNTIME */
3326 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
3328 #ifdef CONFIG_PM_RUNTIME
3330 pm_runtime_get_sync(&pdev->dev);
3331 #endif /* CONFIG_PM_RUNTIME */
3335 igb_release_hw_control(adapter);
3337 igb_free_irq(adapter);
3339 igb_free_all_tx_resources(adapter);
3340 igb_free_all_rx_resources(adapter);
3342 #ifdef CONFIG_PM_RUNTIME
3344 pm_runtime_put_sync(&pdev->dev);
3345 #endif /* CONFIG_PM_RUNTIME */
3350 static int igb_close(struct net_device *netdev)
3352 return __igb_close(netdev, false);
3356 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
3357 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3359 * Return 0 on success, negative on failure
3361 int igb_setup_tx_resources(struct igb_ring *tx_ring)
3363 struct device *dev = tx_ring->dev;
3366 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3367 tx_ring->tx_buffer_info = vzalloc(size);
3368 if (!tx_ring->tx_buffer_info)
3371 /* round up to nearest 4K */
3372 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
3373 tx_ring->size = ALIGN(tx_ring->size, 4096);
3375 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
3376 &tx_ring->dma, GFP_KERNEL);
3381 tx_ring->next_to_use = 0;
3382 tx_ring->next_to_clean = 0;
3387 vfree(tx_ring->tx_buffer_info);
3389 "Unable to allocate memory for the transmit descriptor ring\n");
3394 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
3395 * (Descriptors) for all queues
3396 * @adapter: board private structure
3398 * Return 0 on success, negative on failure
3400 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
3402 struct pci_dev *pdev = adapter->pdev;
3405 for (i = 0; i < adapter->num_tx_queues; i++) {
3406 err = igb_setup_tx_resources(adapter->tx_ring[i]);
3408 dev_err(pci_dev_to_dev(pdev),
3409 "Allocation for Tx Queue %u failed\n", i);
3410 for (i--; i >= 0; i--)
3411 igb_free_tx_resources(adapter->tx_ring[i]);
3420 * igb_setup_tctl - configure the transmit control registers
3421 * @adapter: Board private structure
3423 void igb_setup_tctl(struct igb_adapter *adapter)
3425 struct e1000_hw *hw = &adapter->hw;
3428 /* disable queue 0 which is enabled by default on 82575 and 82576 */
3429 E1000_WRITE_REG(hw, E1000_TXDCTL(0), 0);
3431 /* Program the Transmit Control Register */
3432 tctl = E1000_READ_REG(hw, E1000_TCTL);
3433 tctl &= ~E1000_TCTL_CT;
3434 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3435 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3437 e1000_config_collision_dist(hw);
3439 /* Enable transmits */
3440 tctl |= E1000_TCTL_EN;
3442 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
3445 static u32 igb_tx_wthresh(struct igb_adapter *adapter)
3447 struct e1000_hw *hw = &adapter->hw;
3448 switch (hw->mac.type) {
3452 if (adapter->msix_entries)
3462 * igb_configure_tx_ring - Configure transmit ring after Reset
3463 * @adapter: board private structure
3464 * @ring: tx ring to configure
3466 * Configure a transmit ring after a reset.
3468 void igb_configure_tx_ring(struct igb_adapter *adapter,
3469 struct igb_ring *ring)
3471 struct e1000_hw *hw = &adapter->hw;
3473 u64 tdba = ring->dma;
3474 int reg_idx = ring->reg_idx;
3476 /* disable the queue */
3477 E1000_WRITE_REG(hw, E1000_TXDCTL(reg_idx), 0);
3478 E1000_WRITE_FLUSH(hw);
3481 E1000_WRITE_REG(hw, E1000_TDLEN(reg_idx),
3482 ring->count * sizeof(union e1000_adv_tx_desc));
3483 E1000_WRITE_REG(hw, E1000_TDBAL(reg_idx),
3484 tdba & 0x00000000ffffffffULL);
3485 E1000_WRITE_REG(hw, E1000_TDBAH(reg_idx), tdba >> 32);
3487 ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
3488 E1000_WRITE_REG(hw, E1000_TDH(reg_idx), 0);
3489 writel(0, ring->tail);
3491 txdctl |= IGB_TX_PTHRESH;
3492 txdctl |= IGB_TX_HTHRESH << 8;
3493 txdctl |= igb_tx_wthresh(adapter) << 16;
3495 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
3496 E1000_WRITE_REG(hw, E1000_TXDCTL(reg_idx), txdctl);
3500 * igb_configure_tx - Configure transmit Unit after Reset
3501 * @adapter: board private structure
3503 * Configure the Tx unit of the MAC after a reset.
3505 static void igb_configure_tx(struct igb_adapter *adapter)
3509 for (i = 0; i < adapter->num_tx_queues; i++)
3510 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
3514 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
3515 * @rx_ring: rx descriptor ring (for a specific queue) to setup
3517 * Returns 0 on success, negative on failure
3519 int igb_setup_rx_resources(struct igb_ring *rx_ring)
3521 struct device *dev = rx_ring->dev;
3524 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
3525 rx_ring->rx_buffer_info = vzalloc(size);
3526 if (!rx_ring->rx_buffer_info)
3529 desc_len = sizeof(union e1000_adv_rx_desc);
3531 /* Round up to nearest 4K */
3532 rx_ring->size = rx_ring->count * desc_len;
3533 rx_ring->size = ALIGN(rx_ring->size, 4096);
3535 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
3536 &rx_ring->dma, GFP_KERNEL);
3541 rx_ring->next_to_alloc = 0;
3542 rx_ring->next_to_clean = 0;
3543 rx_ring->next_to_use = 0;
3548 vfree(rx_ring->rx_buffer_info);
3549 rx_ring->rx_buffer_info = NULL;
3550 dev_err(dev, "Unable to allocate memory for the receive descriptor"
3556 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
3557 * (Descriptors) for all queues
3558 * @adapter: board private structure
3560 * Return 0 on success, negative on failure
3562 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
3564 struct pci_dev *pdev = adapter->pdev;
3567 for (i = 0; i < adapter->num_rx_queues; i++) {
3568 err = igb_setup_rx_resources(adapter->rx_ring[i]);
3570 dev_err(pci_dev_to_dev(pdev),
3571 "Allocation for Rx Queue %u failed\n", i);
3572 for (i--; i >= 0; i--)
3573 igb_free_rx_resources(adapter->rx_ring[i]);
3582 * igb_setup_mrqc - configure the multiple receive queue control registers
3583 * @adapter: Board private structure
3585 static void igb_setup_mrqc(struct igb_adapter *adapter)
3587 struct e1000_hw *hw = &adapter->hw;
3589 u32 j, num_rx_queues, shift = 0, shift2 = 0;
3590 static const u32 rsskey[10] = { 0xDA565A6D, 0xC20E5B25, 0x3D256741,
3591 0xB08FA343, 0xCB2BCAD0, 0xB4307BAE,
3592 0xA32DCB77, 0x0CF23080, 0x3BB7426A,
3595 /* Fill out hash function seeds */
3596 for (j = 0; j < 10; j++)
3597 E1000_WRITE_REG(hw, E1000_RSSRK(j), rsskey[j]);
3599 num_rx_queues = adapter->rss_queues;
3601 /* 82575 and 82576 supports 2 RSS queues for VMDq */
3602 switch (hw->mac.type) {
3604 if (adapter->vmdq_pools) {
3612 /* 82576 supports 2 RSS queues for SR-IOV */
3613 if (adapter->vfs_allocated_count || adapter->vmdq_pools) {
3623 * Populate the redirection table 4 entries at a time. To do this
3624 * we are generating the results for n and n+2 and then interleaving
3625 * those with the results with n+1 and n+3.
3627 for (j = 0; j < 32; j++) {
3628 /* first pass generates n and n+2 */
3629 u32 base = ((j * 0x00040004) + 0x00020000) * num_rx_queues;
3630 u32 reta = (base & 0x07800780) >> (7 - shift);
3632 /* second pass generates n+1 and n+3 */
3633 base += 0x00010001 * num_rx_queues;
3634 reta |= (base & 0x07800780) << (1 + shift);
3636 /* generate 2nd table for 82575 based parts */
3638 reta |= (0x01010101 * num_rx_queues) << shift2;
3640 E1000_WRITE_REG(hw, E1000_RETA(j), reta);
3644 * Disable raw packet checksumming so that RSS hash is placed in
3645 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
3646 * offloads as they are enabled by default
3648 rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
3649 rxcsum |= E1000_RXCSUM_PCSD;
3651 if (adapter->hw.mac.type >= e1000_82576)
3652 /* Enable Receive Checksum Offload for SCTP */
3653 rxcsum |= E1000_RXCSUM_CRCOFL;
3655 /* Don't need to set TUOFL or IPOFL, they default to 1 */
3656 E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
3658 /* Generate RSS hash based on packet types, TCP/UDP
3659 * port numbers and/or IPv4/v6 src and dst addresses
3661 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
3662 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3663 E1000_MRQC_RSS_FIELD_IPV6 |
3664 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3665 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
3667 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
3668 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
3669 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
3670 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
3672 /* If VMDq is enabled then we set the appropriate mode for that, else
3673 * we default to RSS so that an RSS hash is calculated per packet even
3674 * if we are only using one queue */
3675 if (adapter->vfs_allocated_count || adapter->vmdq_pools) {
3676 if (hw->mac.type > e1000_82575) {
3677 /* Set the default pool for the PF's first queue */
3678 u32 vtctl = E1000_READ_REG(hw, E1000_VT_CTL);
3679 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
3680 E1000_VT_CTL_DISABLE_DEF_POOL);
3681 vtctl |= adapter->vfs_allocated_count <<
3682 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
3683 E1000_WRITE_REG(hw, E1000_VT_CTL, vtctl);
3684 } else if (adapter->rss_queues > 1) {
3685 /* set default queue for pool 1 to queue 2 */
3686 E1000_WRITE_REG(hw, E1000_VT_CTL,
3687 adapter->rss_queues << 7);
3689 if (adapter->rss_queues > 1)
3690 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
3692 mrqc |= E1000_MRQC_ENABLE_VMDQ;
3694 mrqc |= E1000_MRQC_ENABLE_RSS_4Q;
3696 igb_vmm_control(adapter);
3698 E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
3702 * igb_setup_rctl - configure the receive control registers
3703 * @adapter: Board private structure
3705 void igb_setup_rctl(struct igb_adapter *adapter)
3707 struct e1000_hw *hw = &adapter->hw;
3710 rctl = E1000_READ_REG(hw, E1000_RCTL);
3712 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3713 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
3715 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
3716 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3719 * enable stripping of CRC. It's unlikely this will break BMC
3720 * redirection as it did with e1000. Newer features require
3721 * that the HW strips the CRC.
3723 rctl |= E1000_RCTL_SECRC;
3725 /* disable store bad packets and clear size bits. */
3726 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
3728 /* enable LPE to prevent packets larger than max_frame_size */
3729 rctl |= E1000_RCTL_LPE;
3731 /* disable queue 0 to prevent tail write w/o re-config */
3732 E1000_WRITE_REG(hw, E1000_RXDCTL(0), 0);
3734 /* Attention!!! For SR-IOV PF driver operations you must enable
3735 * queue drop for all VF and PF queues to prevent head of line blocking
3736 * if an un-trusted VF does not provide descriptors to hardware.
3738 if (adapter->vfs_allocated_count) {
3739 /* set all queue drop enable bits */
3740 E1000_WRITE_REG(hw, E1000_QDE, ALL_QUEUES);
3743 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3746 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
3749 struct e1000_hw *hw = &adapter->hw;
3752 /* if it isn't the PF check to see if VFs are enabled and
3753 * increase the size to support vlan tags */
3754 if (vfn < adapter->vfs_allocated_count &&
3755 adapter->vf_data[vfn].vlans_enabled)
3758 #ifdef CONFIG_IGB_VMDQ_NETDEV
3759 if (vfn >= adapter->vfs_allocated_count) {
3760 int queue = vfn - adapter->vfs_allocated_count;
3761 struct igb_vmdq_adapter *vadapter;
3763 vadapter = netdev_priv(adapter->vmdq_netdev[queue-1]);
3764 if (vadapter->vlgrp)
3768 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vfn));
3769 vmolr &= ~E1000_VMOLR_RLPML_MASK;
3770 vmolr |= size | E1000_VMOLR_LPE;
3771 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
3777 * igb_rlpml_set - set maximum receive packet size
3778 * @adapter: board private structure
3780 * Configure maximum receivable packet size.
3782 static void igb_rlpml_set(struct igb_adapter *adapter)
3784 u32 max_frame_size = adapter->max_frame_size;
3785 struct e1000_hw *hw = &adapter->hw;
3786 u16 pf_id = adapter->vfs_allocated_count;
3788 if (adapter->vmdq_pools && hw->mac.type != e1000_82575) {
3790 for (i = 0; i < adapter->vmdq_pools; i++)
3791 igb_set_vf_rlpml(adapter, max_frame_size, pf_id + i);
3793 * If we're in VMDQ or SR-IOV mode, then set global RLPML
3794 * to our max jumbo frame size, in case we need to enable
3795 * jumbo frames on one of the rings later.
3796 * This will not pass over-length frames into the default
3797 * queue because it's gated by the VMOLR.RLPML.
3799 max_frame_size = MAX_JUMBO_FRAME_SIZE;
3801 /* Set VF RLPML for the PF device. */
3802 if (adapter->vfs_allocated_count)
3803 igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
3805 E1000_WRITE_REG(hw, E1000_RLPML, max_frame_size);
3808 static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
3809 int vfn, bool enable)
3811 struct e1000_hw *hw = &adapter->hw;
3815 if (hw->mac.type < e1000_82576)
3818 if (hw->mac.type == e1000_i350)
3819 reg = hw->hw_addr + E1000_DVMOLR(vfn);
3821 reg = hw->hw_addr + E1000_VMOLR(vfn);
3825 val |= E1000_VMOLR_STRVLAN;
3827 val &= ~(E1000_VMOLR_STRVLAN);
3830 static inline void igb_set_vmolr(struct igb_adapter *adapter,
3833 struct e1000_hw *hw = &adapter->hw;
3837 * This register exists only on 82576 and newer so if we are older then
3838 * we should exit and do nothing
3840 if (hw->mac.type < e1000_82576)
3843 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vfn));
3846 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
3848 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
3850 /* clear all bits that might not be set */
3851 vmolr &= ~E1000_VMOLR_RSSE;
3853 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
3854 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
3856 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
3857 vmolr |= E1000_VMOLR_LPE; /* Accept long packets */
3859 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
3863 * igb_configure_rx_ring - Configure a receive ring after Reset
3864 * @adapter: board private structure
3865 * @ring: receive ring to be configured
3867 * Configure the Rx unit of the MAC after a reset.
3869 void igb_configure_rx_ring(struct igb_adapter *adapter,
3870 struct igb_ring *ring)
3872 struct e1000_hw *hw = &adapter->hw;
3873 u64 rdba = ring->dma;
3874 int reg_idx = ring->reg_idx;
3875 u32 srrctl = 0, rxdctl = 0;
3877 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
3879 * RLPML prevents us from receiving a frame larger than max_frame so
3880 * it is safe to just set the rx_buffer_len to max_frame without the
3881 * risk of an skb over panic.
3883 ring->rx_buffer_len = max_t(u32, adapter->max_frame_size,
3884 MAXIMUM_ETHERNET_VLAN_SIZE);
3887 /* disable the queue */
3888 E1000_WRITE_REG(hw, E1000_RXDCTL(reg_idx), 0);
3890 /* Set DMA base address registers */
3891 E1000_WRITE_REG(hw, E1000_RDBAL(reg_idx),
3892 rdba & 0x00000000ffffffffULL);
3893 E1000_WRITE_REG(hw, E1000_RDBAH(reg_idx), rdba >> 32);
3894 E1000_WRITE_REG(hw, E1000_RDLEN(reg_idx),
3895 ring->count * sizeof(union e1000_adv_rx_desc));
3897 /* initialize head and tail */
3898 ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
3899 E1000_WRITE_REG(hw, E1000_RDH(reg_idx), 0);
3900 writel(0, ring->tail);
3902 /* reset next-to- use/clean to place SW in sync with hardwdare */
3903 ring->next_to_clean = 0;
3904 ring->next_to_use = 0;
3905 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
3906 ring->next_to_alloc = 0;
3909 /* set descriptor configuration */
3910 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
3911 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
3912 srrctl |= IGB_RX_BUFSZ >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3913 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
3914 srrctl = ALIGN(ring->rx_buffer_len, 1024) >>
3915 E1000_SRRCTL_BSIZEPKT_SHIFT;
3916 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
3917 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3918 #ifdef HAVE_PTP_1588_CLOCK
3919 if (hw->mac.type >= e1000_82580)
3920 srrctl |= E1000_SRRCTL_TIMESTAMP;
3921 #endif /* HAVE_PTP_1588_CLOCK */
3923 * We should set the drop enable bit if:
3926 * Flow Control is disabled and number of RX queues > 1
3928 * This allows us to avoid head of line blocking for security
3929 * and performance reasons.
3931 if (adapter->vfs_allocated_count ||
3932 (adapter->num_rx_queues > 1 &&
3933 (hw->fc.requested_mode == e1000_fc_none ||
3934 hw->fc.requested_mode == e1000_fc_rx_pause)))
3935 srrctl |= E1000_SRRCTL_DROP_EN;
3937 E1000_WRITE_REG(hw, E1000_SRRCTL(reg_idx), srrctl);
3939 /* set filtering for VMDQ pools */
3940 igb_set_vmolr(adapter, reg_idx & 0x7, true);
3942 rxdctl |= IGB_RX_PTHRESH;
3943 rxdctl |= IGB_RX_HTHRESH << 8;
3944 rxdctl |= IGB_RX_WTHRESH << 16;
3946 /* enable receive descriptor fetching */
3947 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3948 E1000_WRITE_REG(hw, E1000_RXDCTL(reg_idx), rxdctl);
3952 * igb_configure_rx - Configure receive Unit after Reset
3953 * @adapter: board private structure
3955 * Configure the Rx unit of the MAC after a reset.
3957 static void igb_configure_rx(struct igb_adapter *adapter)
3961 /* set UTA to appropriate mode */
3962 igb_set_uta(adapter);
3964 igb_full_sync_mac_table(adapter);
3965 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3966 * the Base and Length of the Rx Descriptor Ring */
3967 for (i = 0; i < adapter->num_rx_queues; i++)
3968 igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
3972 * igb_free_tx_resources - Free Tx Resources per Queue
3973 * @tx_ring: Tx descriptor ring for a specific queue
3975 * Free all transmit software resources
3977 void igb_free_tx_resources(struct igb_ring *tx_ring)
3979 igb_clean_tx_ring(tx_ring);
3981 vfree(tx_ring->tx_buffer_info);
3982 tx_ring->tx_buffer_info = NULL;
3984 /* if not set, then don't free */
3988 dma_free_coherent(tx_ring->dev, tx_ring->size,
3989 tx_ring->desc, tx_ring->dma);
3991 tx_ring->desc = NULL;
3995 * igb_free_all_tx_resources - Free Tx Resources for All Queues
3996 * @adapter: board private structure
3998 * Free all transmit software resources
4000 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
4004 for (i = 0; i < adapter->num_tx_queues; i++)
4005 igb_free_tx_resources(adapter->tx_ring[i]);
4008 void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
4009 struct igb_tx_buffer *tx_buffer)
4011 if (tx_buffer->skb) {
4012 dev_kfree_skb_any(tx_buffer->skb);
4013 if (dma_unmap_len(tx_buffer, len))
4014 dma_unmap_single(ring->dev,
4015 dma_unmap_addr(tx_buffer, dma),
4016 dma_unmap_len(tx_buffer, len),
4018 } else if (dma_unmap_len(tx_buffer, len)) {
4019 dma_unmap_page(ring->dev,
4020 dma_unmap_addr(tx_buffer, dma),
4021 dma_unmap_len(tx_buffer, len),
4024 tx_buffer->next_to_watch = NULL;
4025 tx_buffer->skb = NULL;
4026 dma_unmap_len_set(tx_buffer, len, 0);
4027 /* buffer_info must be completely set up in the transmit path */
4031 * igb_clean_tx_ring - Free Tx Buffers
4032 * @tx_ring: ring to be cleaned
4034 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
4036 struct igb_tx_buffer *buffer_info;
4040 if (!tx_ring->tx_buffer_info)
4042 /* Free all the Tx ring sk_buffs */
4044 for (i = 0; i < tx_ring->count; i++) {
4045 buffer_info = &tx_ring->tx_buffer_info[i];
4046 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
4049 netdev_tx_reset_queue(txring_txq(tx_ring));
4051 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
4052 memset(tx_ring->tx_buffer_info, 0, size);
4054 /* Zero out the descriptor ring */
4055 memset(tx_ring->desc, 0, tx_ring->size);
4057 tx_ring->next_to_use = 0;
4058 tx_ring->next_to_clean = 0;
4062 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
4063 * @adapter: board private structure
4065 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
4069 for (i = 0; i < adapter->num_tx_queues; i++)
4070 igb_clean_tx_ring(adapter->tx_ring[i]);
4074 * igb_free_rx_resources - Free Rx Resources
4075 * @rx_ring: ring to clean the resources from
4077 * Free all receive software resources
4079 void igb_free_rx_resources(struct igb_ring *rx_ring)
4081 igb_clean_rx_ring(rx_ring);
4083 vfree(rx_ring->rx_buffer_info);
4084 rx_ring->rx_buffer_info = NULL;
4086 /* if not set, then don't free */
4090 dma_free_coherent(rx_ring->dev, rx_ring->size,
4091 rx_ring->desc, rx_ring->dma);
4093 rx_ring->desc = NULL;
4097 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4098 * @adapter: board private structure
4100 * Free all receive software resources
4102 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
4106 for (i = 0; i < adapter->num_rx_queues; i++)
4107 igb_free_rx_resources(adapter->rx_ring[i]);
4111 * igb_clean_rx_ring - Free Rx Buffers per Queue
4112 * @rx_ring: ring to free buffers from
4114 void igb_clean_rx_ring(struct igb_ring *rx_ring)
4119 if (!rx_ring->rx_buffer_info)
4122 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
4124 dev_kfree_skb(rx_ring->skb);
4125 rx_ring->skb = NULL;
4128 /* Free all the Rx ring sk_buffs */
4129 for (i = 0; i < rx_ring->count; i++) {
4130 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
4131 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
4132 if (buffer_info->dma) {
4133 dma_unmap_single(rx_ring->dev,
4135 rx_ring->rx_buffer_len,
4137 buffer_info->dma = 0;
4140 if (buffer_info->skb) {
4141 dev_kfree_skb(buffer_info->skb);
4142 buffer_info->skb = NULL;
4145 if (!buffer_info->page)
4148 dma_unmap_page(rx_ring->dev,
4152 __free_page(buffer_info->page);
4154 buffer_info->page = NULL;
4158 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
4159 memset(rx_ring->rx_buffer_info, 0, size);
4161 /* Zero out the descriptor ring */
4162 memset(rx_ring->desc, 0, rx_ring->size);
4164 rx_ring->next_to_alloc = 0;
4165 rx_ring->next_to_clean = 0;
4166 rx_ring->next_to_use = 0;
4170 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4171 * @adapter: board private structure
4173 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
4177 for (i = 0; i < adapter->num_rx_queues; i++)
4178 igb_clean_rx_ring(adapter->rx_ring[i]);
4182 * igb_set_mac - Change the Ethernet Address of the NIC
4183 * @netdev: network interface device structure
4184 * @p: pointer to an address structure
4186 * Returns 0 on success, negative on failure
4188 static int igb_set_mac(struct net_device *netdev, void *p)
4190 struct igb_adapter *adapter = netdev_priv(netdev);
4191 struct e1000_hw *hw = &adapter->hw;
4192 struct sockaddr *addr = p;
4194 if (!is_valid_ether_addr(addr->sa_data))
4195 return -EADDRNOTAVAIL;
4197 igb_del_mac_filter(adapter, hw->mac.addr,
4198 adapter->vfs_allocated_count);
4199 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4200 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4202 /* set the correct pool for the new PF MAC address in entry 0 */
4203 return igb_add_mac_filter(adapter, hw->mac.addr,
4204 adapter->vfs_allocated_count);
4208 * igb_write_mc_addr_list - write multicast addresses to MTA
4209 * @netdev: network interface device structure
4211 * Writes multicast address list to the MTA hash table.
4212 * Returns: -ENOMEM on failure
4213 * 0 on no addresses written
4214 * X on writing X addresses to MTA
4216 int igb_write_mc_addr_list(struct net_device *netdev)
4218 struct igb_adapter *adapter = netdev_priv(netdev);
4219 struct e1000_hw *hw = &adapter->hw;
4220 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4221 struct netdev_hw_addr *ha;
4223 struct dev_mc_list *ha;
4227 #ifdef CONFIG_IGB_VMDQ_NETDEV
4230 count = netdev_mc_count(netdev);
4231 #ifdef CONFIG_IGB_VMDQ_NETDEV
4232 for (vm = 1; vm < adapter->vmdq_pools; vm++) {
4233 if (!adapter->vmdq_netdev[vm])
4235 if (!netif_running(adapter->vmdq_netdev[vm]))
4237 count += netdev_mc_count(adapter->vmdq_netdev[vm]);
4242 e1000_update_mc_addr_list(hw, NULL, 0);
4245 mta_list = kzalloc(count * 6, GFP_ATOMIC);
4249 /* The shared function expects a packed array of only addresses. */
4251 netdev_for_each_mc_addr(ha, netdev)
4252 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4253 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
4255 memcpy(mta_list + (i++ * ETH_ALEN), ha->dmi_addr, ETH_ALEN);
4257 #ifdef CONFIG_IGB_VMDQ_NETDEV
4258 for (vm = 1; vm < adapter->vmdq_pools; vm++) {
4259 if (!adapter->vmdq_netdev[vm])
4261 if (!netif_running(adapter->vmdq_netdev[vm]) ||
4262 !netdev_mc_count(adapter->vmdq_netdev[vm]))
4264 netdev_for_each_mc_addr(ha, adapter->vmdq_netdev[vm])
4265 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4266 memcpy(mta_list + (i++ * ETH_ALEN),
4267 ha->addr, ETH_ALEN);
4269 memcpy(mta_list + (i++ * ETH_ALEN),
4270 ha->dmi_addr, ETH_ALEN);
4274 e1000_update_mc_addr_list(hw, mta_list, i);
4280 void igb_rar_set(struct igb_adapter *adapter, u32 index)
4282 u32 rar_low, rar_high;
4283 struct e1000_hw *hw = &adapter->hw;
4284 u8 *addr = adapter->mac_table[index].addr;
4285 /* HW expects these in little endian so we reverse the byte order
4286 * from network order (big endian) to little endian
4288 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4289 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4290 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4292 /* Indicate to hardware the Address is Valid. */
4293 if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE)
4294 rar_high |= E1000_RAH_AV;
4296 if (hw->mac.type == e1000_82575)
4297 rar_high |= E1000_RAH_POOL_1 * adapter->mac_table[index].queue;
4299 rar_high |= E1000_RAH_POOL_1 << adapter->mac_table[index].queue;
4301 E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
4302 E1000_WRITE_FLUSH(hw);
4303 E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
4304 E1000_WRITE_FLUSH(hw);
4307 void igb_full_sync_mac_table(struct igb_adapter *adapter)
4309 struct e1000_hw *hw = &adapter->hw;
4311 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4312 igb_rar_set(adapter, i);
4316 void igb_sync_mac_table(struct igb_adapter *adapter)
4318 struct e1000_hw *hw = &adapter->hw;
4320 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4321 if (adapter->mac_table[i].state & IGB_MAC_STATE_MODIFIED)
4322 igb_rar_set(adapter, i);
4323 adapter->mac_table[i].state &= ~(IGB_MAC_STATE_MODIFIED);
4327 int igb_available_rars(struct igb_adapter *adapter)
4329 struct e1000_hw *hw = &adapter->hw;
4332 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4333 if (adapter->mac_table[i].state == 0)
4339 #ifdef HAVE_SET_RX_MODE
4341 * igb_write_uc_addr_list - write unicast addresses to RAR table
4342 * @netdev: network interface device structure
4344 * Writes unicast address list to the RAR table.
4345 * Returns: -ENOMEM on failure/insufficient address space
4346 * 0 on no addresses written
4347 * X on writing X addresses to the RAR table
4349 static int igb_write_uc_addr_list(struct net_device *netdev)
4351 struct igb_adapter *adapter = netdev_priv(netdev);
4352 unsigned int vfn = adapter->vfs_allocated_count;
4355 /* return ENOMEM indicating insufficient memory for addresses */
4356 if (netdev_uc_count(netdev) > igb_available_rars(adapter))
4358 if (!netdev_uc_empty(netdev)) {
4359 #ifdef NETDEV_HW_ADDR_T_UNICAST
4360 struct netdev_hw_addr *ha;
4362 struct dev_mc_list *ha;
4364 netdev_for_each_uc_addr(ha, netdev) {
4365 #ifdef NETDEV_HW_ADDR_T_UNICAST
4366 igb_del_mac_filter(adapter, ha->addr, vfn);
4367 igb_add_mac_filter(adapter, ha->addr, vfn);
4369 igb_del_mac_filter(adapter, ha->da_addr, vfn);
4370 igb_add_mac_filter(adapter, ha->da_addr, vfn);
4378 #endif /* HAVE_SET_RX_MODE */
4380 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
4381 * @netdev: network interface device structure
4383 * The set_rx_mode entry point is called whenever the unicast or multicast
4384 * address lists or the network interface flags are updated. This routine is
4385 * responsible for configuring the hardware for proper unicast, multicast,
4386 * promiscuous mode, and all-multi behavior.
4388 static void igb_set_rx_mode(struct net_device *netdev)
4390 struct igb_adapter *adapter = netdev_priv(netdev);
4391 struct e1000_hw *hw = &adapter->hw;
4392 unsigned int vfn = adapter->vfs_allocated_count;
4393 u32 rctl, vmolr = 0;
4396 /* Check for Promiscuous and All Multicast modes */
4397 rctl = E1000_READ_REG(hw, E1000_RCTL);
4399 /* clear the effected bits */
4400 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
4402 if (netdev->flags & IFF_PROMISC) {
4403 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
4404 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
4405 /* retain VLAN HW filtering if in VT mode */
4406 if (adapter->vfs_allocated_count || adapter->vmdq_pools)
4407 rctl |= E1000_RCTL_VFE;
4409 if (netdev->flags & IFF_ALLMULTI) {
4410 rctl |= E1000_RCTL_MPE;
4411 vmolr |= E1000_VMOLR_MPME;
4414 * Write addresses to the MTA, if the attempt fails
4415 * then we should just turn on promiscuous mode so
4416 * that we can at least receive multicast traffic
4418 count = igb_write_mc_addr_list(netdev);
4420 rctl |= E1000_RCTL_MPE;
4421 vmolr |= E1000_VMOLR_MPME;
4423 vmolr |= E1000_VMOLR_ROMPE;
4426 #ifdef HAVE_SET_RX_MODE
4428 * Write addresses to available RAR registers, if there is not
4429 * sufficient space to store all the addresses then enable
4430 * unicast promiscuous mode
4432 count = igb_write_uc_addr_list(netdev);
4434 rctl |= E1000_RCTL_UPE;
4435 vmolr |= E1000_VMOLR_ROPE;
4437 #endif /* HAVE_SET_RX_MODE */
4438 rctl |= E1000_RCTL_VFE;
4440 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4443 * In order to support SR-IOV and eventually VMDq it is necessary to set
4444 * the VMOLR to enable the appropriate modes. Without this workaround
4445 * we will have issues with VLAN tag stripping not being done for frames
4446 * that are only arriving because we are the default pool
4448 if (hw->mac.type < e1000_82576)
4451 vmolr |= E1000_READ_REG(hw, E1000_VMOLR(vfn)) &
4452 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
4453 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
4454 igb_restore_vf_multicasts(adapter);
4457 static void igb_check_wvbr(struct igb_adapter *adapter)
4459 struct e1000_hw *hw = &adapter->hw;
4462 switch (hw->mac.type) {
4465 if (!(wvbr = E1000_READ_REG(hw, E1000_WVBR)))
4472 adapter->wvbr |= wvbr;
4475 #define IGB_STAGGERED_QUEUE_OFFSET 8
4477 static void igb_spoof_check(struct igb_adapter *adapter)
4484 switch (adapter->hw.mac.type) {
4486 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4487 if (adapter->wvbr & (1 << j) ||
4488 adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
4489 DPRINTK(DRV, WARNING,
4490 "Spoof event(s) detected on VF %d\n", j);
4493 (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
4498 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4499 if (adapter->wvbr & (1 << j)) {
4500 DPRINTK(DRV, WARNING,
4501 "Spoof event(s) detected on VF %d\n", j);
4502 adapter->wvbr &= ~(1 << j);
4511 /* Need to wait a few seconds after link up to get diagnostic information from
4513 static void igb_update_phy_info(unsigned long data)
4515 struct igb_adapter *adapter = (struct igb_adapter *) data;
4516 e1000_get_phy_info(&adapter->hw);
4520 * igb_has_link - check shared code for link and determine up/down
4521 * @adapter: pointer to driver private info
4523 bool igb_has_link(struct igb_adapter *adapter)
4525 struct e1000_hw *hw = &adapter->hw;
4526 bool link_active = FALSE;
4528 /* get_link_status is set on LSC (link status) interrupt or
4529 * rx sequence error interrupt. get_link_status will stay
4530 * false until the e1000_check_for_link establishes link
4531 * for copper adapters ONLY
4533 switch (hw->phy.media_type) {
4534 case e1000_media_type_copper:
4535 if (!hw->mac.get_link_status)
4537 case e1000_media_type_internal_serdes:
4538 e1000_check_for_link(hw);
4539 link_active = !hw->mac.get_link_status;
4541 case e1000_media_type_unknown:
4546 if (((hw->mac.type == e1000_i210) ||
4547 (hw->mac.type == e1000_i211)) &&
4548 (hw->phy.id == I210_I_PHY_ID)) {
4549 if (!netif_carrier_ok(adapter->netdev)) {
4550 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4551 } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
4552 adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
4553 adapter->link_check_timeout = jiffies;
4561 * igb_watchdog - Timer Call-back
4562 * @data: pointer to adapter cast into an unsigned long
4564 static void igb_watchdog(unsigned long data)
4566 struct igb_adapter *adapter = (struct igb_adapter *)data;
4567 /* Do the rest outside of interrupt context */
4568 schedule_work(&adapter->watchdog_task);
4571 static void igb_watchdog_task(struct work_struct *work)
4573 struct igb_adapter *adapter = container_of(work,
4576 struct e1000_hw *hw = &adapter->hw;
4577 struct net_device *netdev = adapter->netdev;
4580 u32 thstat, ctrl_ext;
4583 link = igb_has_link(adapter);
4584 /* Force link down if we have fiber to swap to */
4585 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4586 if (hw->phy.media_type == e1000_media_type_copper) {
4587 connsw = E1000_READ_REG(hw, E1000_CONNSW);
4588 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
4593 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
4594 if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
4595 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4601 /* Perform a reset if the media type changed. */
4602 if (hw->dev_spec._82575.media_changed) {
4603 hw->dev_spec._82575.media_changed = false;
4604 adapter->flags |= IGB_FLAG_MEDIA_RESET;
4608 /* Cancel scheduled suspend requests. */
4609 pm_runtime_resume(netdev->dev.parent);
4611 if (!netif_carrier_ok(netdev)) {
4613 e1000_get_speed_and_duplex(hw,
4614 &adapter->link_speed,
4615 &adapter->link_duplex);
4617 ctrl = E1000_READ_REG(hw, E1000_CTRL);
4618 /* Links status message must follow this format */
4619 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
4620 "Flow Control: %s\n",
4622 adapter->link_speed,
4623 adapter->link_duplex == FULL_DUPLEX ?
4624 "Full Duplex" : "Half Duplex",
4625 ((ctrl & E1000_CTRL_TFCE) &&
4626 (ctrl & E1000_CTRL_RFCE)) ? "RX/TX":
4627 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
4628 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None")));
4629 /* adjust timeout factor according to speed/duplex */
4630 adapter->tx_timeout_factor = 1;
4631 switch (adapter->link_speed) {
4633 adapter->tx_timeout_factor = 14;
4636 /* maybe add some timeout factor ? */
4642 netif_carrier_on(netdev);
4643 netif_tx_wake_all_queues(netdev);
4645 igb_ping_all_vfs(adapter);
4647 igb_check_vf_rate_limit(adapter);
4648 #endif /* IFLA_VF_MAX */
4650 /* link state has changed, schedule phy info update */
4651 if (!test_bit(__IGB_DOWN, &adapter->state))
4652 mod_timer(&adapter->phy_info_timer,
4653 round_jiffies(jiffies + 2 * HZ));
4656 if (netif_carrier_ok(netdev)) {
4657 adapter->link_speed = 0;
4658 adapter->link_duplex = 0;
4659 /* check for thermal sensor event on i350 */
4660 if (hw->mac.type == e1000_i350) {
4661 thstat = E1000_READ_REG(hw, E1000_THSTAT);
4662 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
4663 if ((hw->phy.media_type ==
4664 e1000_media_type_copper) &&
4666 E1000_CTRL_EXT_LINK_MODE_SGMII)) {
4667 if (thstat & E1000_THSTAT_PWR_DOWN) {
4668 printk(KERN_ERR "igb: %s The "
4669 "network adapter was stopped "
4670 "because it overheated.\n",
4673 if (thstat & E1000_THSTAT_LINK_THROTTLE) {
4675 "igb: %s The network "
4676 "adapter supported "
4686 /* Links status message must follow this format */
4687 printk(KERN_INFO "igb: %s NIC Link is Down\n",
4689 netif_carrier_off(netdev);
4690 netif_tx_stop_all_queues(netdev);
4692 igb_ping_all_vfs(adapter);
4694 /* link state has changed, schedule phy info update */
4695 if (!test_bit(__IGB_DOWN, &adapter->state))
4696 mod_timer(&adapter->phy_info_timer,
4697 round_jiffies(jiffies + 2 * HZ));
4698 /* link is down, time to check for alternate media */
4699 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4700 igb_check_swap_media(adapter);
4701 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4702 schedule_work(&adapter->reset_task);
4703 /* return immediately */
4707 pm_schedule_suspend(netdev->dev.parent,
4710 /* also check for alternate media here */
4711 } else if (!netif_carrier_ok(netdev) &&
4712 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
4713 hw->mac.ops.power_up_serdes(hw);
4714 igb_check_swap_media(adapter);
4715 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4716 schedule_work(&adapter->reset_task);
4717 /* return immediately */
4723 igb_update_stats(adapter);
4725 for (i = 0; i < adapter->num_tx_queues; i++) {
4726 struct igb_ring *tx_ring = adapter->tx_ring[i];
4727 if (!netif_carrier_ok(netdev)) {
4728 /* We've lost link, so the controller stops DMA,
4729 * but we've got queued Tx work that's never going
4730 * to get done, so reset controller to flush Tx.
4731 * (Do the reset outside of interrupt context). */
4732 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
4733 adapter->tx_timeout_count++;
4734 schedule_work(&adapter->reset_task);
4735 /* return immediately since reset is imminent */
4740 /* Force detection of hung controller every watchdog period */
4741 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
4744 /* Cause software interrupt to ensure rx ring is cleaned */
4745 if (adapter->msix_entries) {
4747 for (i = 0; i < adapter->num_q_vectors; i++)
4748 eics |= adapter->q_vector[i]->eims_value;
4749 E1000_WRITE_REG(hw, E1000_EICS, eics);
4751 E1000_WRITE_REG(hw, E1000_ICS, E1000_ICS_RXDMT0);
4754 igb_spoof_check(adapter);
4756 /* Reset the timer */
4757 if (!test_bit(__IGB_DOWN, &adapter->state)) {
4758 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
4759 mod_timer(&adapter->watchdog_timer,
4760 round_jiffies(jiffies + HZ));
4762 mod_timer(&adapter->watchdog_timer,
4763 round_jiffies(jiffies + 2 * HZ));
4767 static void igb_dma_err_task(struct work_struct *work)
4769 struct igb_adapter *adapter = container_of(work,
4773 struct e1000_hw *hw = &adapter->hw;
4774 struct net_device *netdev = adapter->netdev;
4778 hgptc = E1000_READ_REG(hw, E1000_HGPTC);
4779 if (hgptc) /* If incrementing then no need for the check below */
4780 goto dma_timer_reset;
4782 * Check to see if a bad DMA write target from an errant or
4783 * malicious VF has caused a PCIe error. If so then we can
4784 * issue a VFLR to the offending VF(s) and then resume without
4785 * requesting a full slot reset.
4788 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
4789 ciaa = (vf << 16) | 0x80000000;
4790 /* 32 bit read so align, we really want status at offset 6 */
4791 ciaa |= PCI_COMMAND;
4792 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4793 ciad = E1000_READ_REG(hw, E1000_CIAD);
4795 /* disable debug mode asap after reading data */
4796 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4797 /* Get the upper 16 bits which will be the PCI status reg */
4799 if (ciad & (PCI_STATUS_REC_MASTER_ABORT |
4800 PCI_STATUS_REC_TARGET_ABORT |
4801 PCI_STATUS_SIG_SYSTEM_ERROR)) {
4802 netdev_err(netdev, "VF %d suffered error\n", vf);
4804 ciaa = (vf << 16) | 0x80000000;
4806 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4807 ciad = 0x00008000; /* VFLR */
4808 E1000_WRITE_REG(hw, E1000_CIAD, ciad);
4810 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4814 /* Reset the timer */
4815 if (!test_bit(__IGB_DOWN, &adapter->state))
4816 mod_timer(&adapter->dma_err_timer,
4817 round_jiffies(jiffies + HZ / 10));
4821 * igb_dma_err_timer - Timer Call-back
4822 * @data: pointer to adapter cast into an unsigned long
4824 static void igb_dma_err_timer(unsigned long data)
4826 struct igb_adapter *adapter = (struct igb_adapter *)data;
4827 /* Do the rest outside of interrupt context */
4828 schedule_work(&adapter->dma_err_task);
4831 enum latency_range {
4835 latency_invalid = 255
4839 * igb_update_ring_itr - update the dynamic ITR value based on packet size
4841 * Stores a new ITR value based on strictly on packet size. This
4842 * algorithm is less sophisticated than that used in igb_update_itr,
4843 * due to the difficulty of synchronizing statistics across multiple
4844 * receive rings. The divisors and thresholds used by this function
4845 * were determined based on theoretical maximum wire speed and testing
4846 * data, in order to minimize response time while increasing bulk
4848 * This functionality is controlled by the InterruptThrottleRate module
4849 * parameter (see igb_param.c)
4850 * NOTE: This function is called only when operating in a multiqueue
4851 * receive environment.
4852 * @q_vector: pointer to q_vector
4854 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
4856 int new_val = q_vector->itr_val;
4857 int avg_wire_size = 0;
4858 struct igb_adapter *adapter = q_vector->adapter;
4859 unsigned int packets;
4861 /* For non-gigabit speeds, just fix the interrupt rate at 4000
4862 * ints/sec - ITR timer value of 120 ticks.
4864 switch (adapter->link_speed) {
4867 new_val = IGB_4K_ITR;
4873 packets = q_vector->rx.total_packets;
4875 avg_wire_size = q_vector->rx.total_bytes / packets;
4877 packets = q_vector->tx.total_packets;
4879 avg_wire_size = max_t(u32, avg_wire_size,
4880 q_vector->tx.total_bytes / packets);
4882 /* if avg_wire_size isn't set no work was done */
4886 /* Add 24 bytes to size to account for CRC, preamble, and gap */
4887 avg_wire_size += 24;
4889 /* Don't starve jumbo frames */
4890 avg_wire_size = min(avg_wire_size, 3000);
4892 /* Give a little boost to mid-size frames */
4893 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
4894 new_val = avg_wire_size / 3;
4896 new_val = avg_wire_size / 2;
4898 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4899 if (new_val < IGB_20K_ITR &&
4900 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4901 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4902 new_val = IGB_20K_ITR;
4905 if (new_val != q_vector->itr_val) {
4906 q_vector->itr_val = new_val;
4907 q_vector->set_itr = 1;
4910 q_vector->rx.total_bytes = 0;
4911 q_vector->rx.total_packets = 0;
4912 q_vector->tx.total_bytes = 0;
4913 q_vector->tx.total_packets = 0;
4917 * igb_update_itr - update the dynamic ITR value based on statistics
4918 * Stores a new ITR value based on packets and byte
4919 * counts during the last interrupt. The advantage of per interrupt
4920 * computation is faster updates and more accurate ITR for the current
4921 * traffic pattern. Constants in this function were computed
4922 * based on theoretical maximum wire speed and thresholds were set based
4923 * on testing data as well as attempting to minimize response time
4924 * while increasing bulk throughput.
4925 * this functionality is controlled by the InterruptThrottleRate module
4926 * parameter (see igb_param.c)
4927 * NOTE: These calculations are only valid when operating in a single-
4928 * queue environment.
4929 * @q_vector: pointer to q_vector
4930 * @ring_container: ring info to update the itr for
4932 static void igb_update_itr(struct igb_q_vector *q_vector,
4933 struct igb_ring_container *ring_container)
4935 unsigned int packets = ring_container->total_packets;
4936 unsigned int bytes = ring_container->total_bytes;
4937 u8 itrval = ring_container->itr;
4939 /* no packets, exit with status unchanged */
4944 case lowest_latency:
4945 /* handle TSO and jumbo frames */
4946 if (bytes/packets > 8000)
4947 itrval = bulk_latency;
4948 else if ((packets < 5) && (bytes > 512))
4949 itrval = low_latency;
4951 case low_latency: /* 50 usec aka 20000 ints/s */
4952 if (bytes > 10000) {
4953 /* this if handles the TSO accounting */
4954 if (bytes/packets > 8000) {
4955 itrval = bulk_latency;
4956 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
4957 itrval = bulk_latency;
4958 } else if ((packets > 35)) {
4959 itrval = lowest_latency;
4961 } else if (bytes/packets > 2000) {
4962 itrval = bulk_latency;
4963 } else if (packets <= 2 && bytes < 512) {
4964 itrval = lowest_latency;
4967 case bulk_latency: /* 250 usec aka 4000 ints/s */
4968 if (bytes > 25000) {
4970 itrval = low_latency;
4971 } else if (bytes < 1500) {
4972 itrval = low_latency;
4977 /* clear work counters since we have the values we need */
4978 ring_container->total_bytes = 0;
4979 ring_container->total_packets = 0;
4981 /* write updated itr to ring container */
4982 ring_container->itr = itrval;
4985 static void igb_set_itr(struct igb_q_vector *q_vector)
4987 struct igb_adapter *adapter = q_vector->adapter;
4988 u32 new_itr = q_vector->itr_val;
4991 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
4992 switch (adapter->link_speed) {
4996 new_itr = IGB_4K_ITR;
5002 igb_update_itr(q_vector, &q_vector->tx);
5003 igb_update_itr(q_vector, &q_vector->rx);
5005 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
5007 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5008 if (current_itr == lowest_latency &&
5009 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
5010 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
5011 current_itr = low_latency;
5013 switch (current_itr) {
5014 /* counts and packets in update_itr are dependent on these numbers */
5015 case lowest_latency:
5016 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
5019 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
5022 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
5029 if (new_itr != q_vector->itr_val) {
5030 /* this attempts to bias the interrupt rate towards Bulk
5031 * by adding intermediate steps when interrupt rate is
5033 new_itr = new_itr > q_vector->itr_val ?
5034 max((new_itr * q_vector->itr_val) /
5035 (new_itr + (q_vector->itr_val >> 2)),
5038 /* Don't write the value here; it resets the adapter's
5039 * internal timer, and causes us to delay far longer than
5040 * we should between interrupts. Instead, we write the ITR
5041 * value at the beginning of the next interrupt so the timing
5042 * ends up being correct.
5044 q_vector->itr_val = new_itr;
5045 q_vector->set_itr = 1;
5049 void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
5050 u32 type_tucmd, u32 mss_l4len_idx)
5052 struct e1000_adv_tx_context_desc *context_desc;
5053 u16 i = tx_ring->next_to_use;
5055 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
5058 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
5060 /* set bits to identify this as an advanced context descriptor */
5061 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
5063 /* For 82575, context index must be unique per ring. */
5064 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5065 mss_l4len_idx |= tx_ring->reg_idx << 4;
5067 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
5068 context_desc->seqnum_seed = 0;
5069 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
5070 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
5073 static int igb_tso(struct igb_ring *tx_ring,
5074 struct igb_tx_buffer *first,
5078 struct sk_buff *skb = first->skb;
5079 u32 vlan_macip_lens, type_tucmd;
5080 u32 mss_l4len_idx, l4len;
5082 if (skb->ip_summed != CHECKSUM_PARTIAL)
5085 if (!skb_is_gso(skb))
5086 #endif /* NETIF_F_TSO */
5090 if (skb_header_cloned(skb)) {
5091 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5096 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5097 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5099 if (first->protocol == __constant_htons(ETH_P_IP)) {
5100 struct iphdr *iph = ip_hdr(skb);
5103 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5107 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5108 first->tx_flags |= IGB_TX_FLAGS_TSO |
5112 } else if (skb_is_gso_v6(skb)) {
5113 ipv6_hdr(skb)->payload_len = 0;
5114 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5115 &ipv6_hdr(skb)->daddr,
5117 first->tx_flags |= IGB_TX_FLAGS_TSO |
5122 /* compute header lengths */
5123 l4len = tcp_hdrlen(skb);
5124 *hdr_len = skb_transport_offset(skb) + l4len;
5126 /* update gso size and bytecount with header size */
5127 first->gso_segs = skb_shinfo(skb)->gso_segs;
5128 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5131 mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
5132 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
5134 /* VLAN MACLEN IPLEN */
5135 vlan_macip_lens = skb_network_header_len(skb);
5136 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5137 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5139 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5142 #endif /* NETIF_F_TSO */
5145 static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5147 struct sk_buff *skb = first->skb;
5148 u32 vlan_macip_lens = 0;
5149 u32 mss_l4len_idx = 0;
5152 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5153 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
5157 switch (first->protocol) {
5158 case __constant_htons(ETH_P_IP):
5159 vlan_macip_lens |= skb_network_header_len(skb);
5160 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5161 nexthdr = ip_hdr(skb)->protocol;
5163 #ifdef NETIF_F_IPV6_CSUM
5164 case __constant_htons(ETH_P_IPV6):
5165 vlan_macip_lens |= skb_network_header_len(skb);
5166 nexthdr = ipv6_hdr(skb)->nexthdr;
5170 if (unlikely(net_ratelimit())) {
5171 dev_warn(tx_ring->dev,
5172 "partial checksum but proto=%x!\n",
5180 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
5181 mss_l4len_idx = tcp_hdrlen(skb) <<
5182 E1000_ADVTXD_L4LEN_SHIFT;
5186 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
5187 mss_l4len_idx = sizeof(struct sctphdr) <<
5188 E1000_ADVTXD_L4LEN_SHIFT;
5192 mss_l4len_idx = sizeof(struct udphdr) <<
5193 E1000_ADVTXD_L4LEN_SHIFT;
5196 if (unlikely(net_ratelimit())) {
5197 dev_warn(tx_ring->dev,
5198 "partial checksum but l4 proto=%x!\n",
5204 /* update TX checksum flag */
5205 first->tx_flags |= IGB_TX_FLAGS_CSUM;
5208 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5209 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5211 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5214 #define IGB_SET_FLAG(_input, _flag, _result) \
5215 ((_flag <= _result) ? \
5216 ((u32)(_input & _flag) * (_result / _flag)) : \
5217 ((u32)(_input & _flag) / (_flag / _result)))
5219 static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
5221 /* set type for advanced descriptor with frame checksum insertion */
5222 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
5223 E1000_ADVTXD_DCMD_DEXT |
5224 E1000_ADVTXD_DCMD_IFCS;
5226 /* set HW vlan bit if vlan is present */
5227 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
5228 (E1000_ADVTXD_DCMD_VLE));
5230 /* set segmentation bits for TSO */
5231 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
5232 (E1000_ADVTXD_DCMD_TSE));
5234 /* set timestamp bit if present */
5235 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
5236 (E1000_ADVTXD_MAC_TSTAMP));
5241 static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
5242 union e1000_adv_tx_desc *tx_desc,
5243 u32 tx_flags, unsigned int paylen)
5245 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
5247 /* 82575 requires a unique index per ring */
5248 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5249 olinfo_status |= tx_ring->reg_idx << 4;
5251 /* insert L4 checksum */
5252 olinfo_status |= IGB_SET_FLAG(tx_flags,
5254 (E1000_TXD_POPTS_TXSM << 8));
5256 /* insert IPv4 checksum */
5257 olinfo_status |= IGB_SET_FLAG(tx_flags,
5259 (E1000_TXD_POPTS_IXSM << 8));
5261 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5264 static void igb_tx_map(struct igb_ring *tx_ring,
5265 struct igb_tx_buffer *first,
5268 struct sk_buff *skb = first->skb;
5269 struct igb_tx_buffer *tx_buffer;
5270 union e1000_adv_tx_desc *tx_desc;
5271 struct skb_frag_struct *frag;
5273 unsigned int data_len, size;
5274 u32 tx_flags = first->tx_flags;
5275 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
5276 u16 i = tx_ring->next_to_use;
5278 tx_desc = IGB_TX_DESC(tx_ring, i);
5280 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
5282 size = skb_headlen(skb);
5283 data_len = skb->data_len;
5285 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5289 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
5290 if (dma_mapping_error(tx_ring->dev, dma))
5293 /* record length, and DMA address */
5294 dma_unmap_len_set(tx_buffer, len, size);
5295 dma_unmap_addr_set(tx_buffer, dma, dma);
5297 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5299 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
5300 tx_desc->read.cmd_type_len =
5301 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
5305 if (i == tx_ring->count) {
5306 tx_desc = IGB_TX_DESC(tx_ring, 0);
5309 tx_desc->read.olinfo_status = 0;
5311 dma += IGB_MAX_DATA_PER_TXD;
5312 size -= IGB_MAX_DATA_PER_TXD;
5314 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5317 if (likely(!data_len))
5320 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
5324 if (i == tx_ring->count) {
5325 tx_desc = IGB_TX_DESC(tx_ring, 0);
5328 tx_desc->read.olinfo_status = 0;
5330 size = skb_frag_size(frag);
5333 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
5334 size, DMA_TO_DEVICE);
5336 tx_buffer = &tx_ring->tx_buffer_info[i];
5339 /* write last descriptor with RS and EOP bits */
5340 cmd_type |= size | IGB_TXD_DCMD;
5341 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
5343 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
5344 /* set the timestamp */
5345 first->time_stamp = jiffies;
5348 * Force memory writes to complete before letting h/w know there
5349 * are new descriptors to fetch. (Only applicable for weak-ordered
5350 * memory model archs, such as IA-64).
5352 * We also need this memory barrier to make certain all of the
5353 * status bits have been updated before next_to_watch is written.
5357 /* set next_to_watch value indicating a packet is present */
5358 first->next_to_watch = tx_desc;
5361 if (i == tx_ring->count)
5364 tx_ring->next_to_use = i;
5366 writel(i, tx_ring->tail);
5368 /* we need this if more than one processor can write to our tail
5369 * at a time, it syncronizes IO on IA64/Altix systems */
5375 dev_err(tx_ring->dev, "TX DMA map failed\n");
5377 /* clear dma mappings for failed tx_buffer_info map */
5379 tx_buffer = &tx_ring->tx_buffer_info[i];
5380 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer);
5381 if (tx_buffer == first)
5388 tx_ring->next_to_use = i;
5391 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5393 struct net_device *netdev = netdev_ring(tx_ring);
5395 if (netif_is_multiqueue(netdev))
5396 netif_stop_subqueue(netdev, ring_queue_index(tx_ring));
5398 netif_stop_queue(netdev);
5400 /* Herbert's original patch had:
5401 * smp_mb__after_netif_stop_queue();
5402 * but since that doesn't exist yet, just open code it. */
5405 /* We need to check again in a case another CPU has just
5406 * made room available. */
5407 if (igb_desc_unused(tx_ring) < size)
5411 if (netif_is_multiqueue(netdev))
5412 netif_wake_subqueue(netdev, ring_queue_index(tx_ring));
5414 netif_wake_queue(netdev);
5416 tx_ring->tx_stats.restart_queue++;
5421 static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5423 if (igb_desc_unused(tx_ring) >= size)
5425 return __igb_maybe_stop_tx(tx_ring, size);
5428 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
5429 struct igb_ring *tx_ring)
5431 struct igb_tx_buffer *first;
5434 #if PAGE_SIZE > IGB_MAX_DATA_PER_TXD
5437 u16 count = TXD_USE_COUNT(skb_headlen(skb));
5438 __be16 protocol = vlan_get_protocol(skb);
5442 * need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
5443 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
5444 * + 2 desc gap to keep tail from touching head,
5445 * + 1 desc for context descriptor,
5446 * otherwise try next time
5448 #if PAGE_SIZE > IGB_MAX_DATA_PER_TXD
5449 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
5450 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5452 count += skb_shinfo(skb)->nr_frags;
5454 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
5455 /* this is a hard error */
5456 return NETDEV_TX_BUSY;
5459 /* record the location of the first descriptor for this packet */
5460 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
5462 first->bytecount = skb->len;
5463 first->gso_segs = 1;
5465 skb_tx_timestamp(skb);
5467 #ifdef HAVE_PTP_1588_CLOCK
5468 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
5469 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5470 if (!adapter->ptp_tx_skb) {
5471 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5472 tx_flags |= IGB_TX_FLAGS_TSTAMP;
5474 adapter->ptp_tx_skb = skb_get(skb);
5475 adapter->ptp_tx_start = jiffies;
5476 if (adapter->hw.mac.type == e1000_82576)
5477 schedule_work(&adapter->ptp_tx_work);
5480 #endif /* HAVE_PTP_1588_CLOCK */
5482 if (vlan_tx_tag_present(skb)) {
5483 tx_flags |= IGB_TX_FLAGS_VLAN;
5484 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
5487 /* record initial flags and protocol */
5488 first->tx_flags = tx_flags;
5489 first->protocol = protocol;
5491 tso = igb_tso(tx_ring, first, &hdr_len);
5495 igb_tx_csum(tx_ring, first);
5497 igb_tx_map(tx_ring, first, hdr_len);
5499 #ifndef HAVE_TRANS_START_IN_QUEUE
5500 netdev_ring(tx_ring)->trans_start = jiffies;
5503 /* Make sure there is space in the ring for the next send. */
5504 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
5506 return NETDEV_TX_OK;
5509 igb_unmap_and_free_tx_resource(tx_ring, first);
5511 return NETDEV_TX_OK;
5515 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
5516 struct sk_buff *skb)
5518 unsigned int r_idx = skb->queue_mapping;
5520 if (r_idx >= adapter->num_tx_queues)
5521 r_idx = r_idx % adapter->num_tx_queues;
5523 return adapter->tx_ring[r_idx];
5526 #define igb_tx_queue_mapping(_adapter, _skb) (_adapter)->tx_ring[0]
5529 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
5530 struct net_device *netdev)
5532 struct igb_adapter *adapter = netdev_priv(netdev);
5534 if (test_bit(__IGB_DOWN, &adapter->state)) {
5535 dev_kfree_skb_any(skb);
5536 return NETDEV_TX_OK;
5539 if (skb->len <= 0) {
5540 dev_kfree_skb_any(skb);
5541 return NETDEV_TX_OK;
5545 * The minimum packet size with TCTL.PSP set is 17 so pad the skb
5546 * in order to meet this minimum size requirement.
5548 if (skb->len < 17) {
5549 if (skb_padto(skb, 17))
5550 return NETDEV_TX_OK;
5554 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
5558 * igb_tx_timeout - Respond to a Tx Hang
5559 * @netdev: network interface device structure
5561 static void igb_tx_timeout(struct net_device *netdev)
5563 struct igb_adapter *adapter = netdev_priv(netdev);
5564 struct e1000_hw *hw = &adapter->hw;
5566 /* Do the reset outside of interrupt context */
5567 adapter->tx_timeout_count++;
5569 if (hw->mac.type >= e1000_82580)
5570 hw->dev_spec._82575.global_device_reset = true;
5572 schedule_work(&adapter->reset_task);
5573 E1000_WRITE_REG(hw, E1000_EICS,
5574 (adapter->eims_enable_mask & ~adapter->eims_other));
5577 static void igb_reset_task(struct work_struct *work)
5579 struct igb_adapter *adapter;
5580 adapter = container_of(work, struct igb_adapter, reset_task);
5582 igb_reinit_locked(adapter);
5586 * igb_get_stats - Get System Network Statistics
5587 * @netdev: network interface device structure
5589 * Returns the address of the device statistics structure.
5590 * The statistics are updated here and also from the timer callback.
5592 static struct net_device_stats *igb_get_stats(struct net_device *netdev)
5594 struct igb_adapter *adapter = netdev_priv(netdev);
5596 if (!test_bit(__IGB_RESETTING, &adapter->state))
5597 igb_update_stats(adapter);
5599 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
5600 /* only return the current stats */
5601 return &netdev->stats;
5603 /* only return the current stats */
5604 return &adapter->net_stats;
5605 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
5609 * igb_change_mtu - Change the Maximum Transfer Unit
5610 * @netdev: network interface device structure
5611 * @new_mtu: new value for maximum frame size
5613 * Returns 0 on success, negative on failure
5615 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
5617 struct igb_adapter *adapter = netdev_priv(netdev);
5618 struct e1000_hw *hw = &adapter->hw;
5619 struct pci_dev *pdev = adapter->pdev;
5620 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
5622 if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
5623 dev_err(pci_dev_to_dev(pdev), "Invalid MTU setting\n");
5627 #define MAX_STD_JUMBO_FRAME_SIZE 9238
5628 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
5629 dev_err(pci_dev_to_dev(pdev), "MTU > 9216 not supported.\n");
5633 /* adjust max frame to be at least the size of a standard frame */
5634 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
5635 max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
5637 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
5638 usleep_range(1000, 2000);
5640 /* igb_down has a dependency on max_frame_size */
5641 adapter->max_frame_size = max_frame;
5643 if (netif_running(netdev))
5646 dev_info(pci_dev_to_dev(pdev), "changing MTU from %d to %d\n",
5647 netdev->mtu, new_mtu);
5648 netdev->mtu = new_mtu;
5649 hw->dev_spec._82575.mtu = new_mtu;
5651 if (netif_running(netdev))
5656 clear_bit(__IGB_RESETTING, &adapter->state);
5662 * igb_update_stats - Update the board statistics counters
5663 * @adapter: board private structure
5666 void igb_update_stats(struct igb_adapter *adapter)
5668 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
5669 struct net_device_stats *net_stats = &adapter->netdev->stats;
5671 struct net_device_stats *net_stats = &adapter->net_stats;
5672 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
5673 struct e1000_hw *hw = &adapter->hw;
5675 struct pci_dev *pdev = adapter->pdev;
5682 u32 flushed = 0, coal = 0;
5683 struct igb_q_vector *q_vector;
5686 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
5689 * Prevent stats update while adapter is being reset, or if the pci
5690 * connection is down.
5692 if (adapter->link_speed == 0)
5695 if (pci_channel_offline(pdev))
5700 for (i = 0; i < adapter->num_q_vectors; i++) {
5701 q_vector = adapter->q_vector[i];
5704 flushed += q_vector->lrolist.stats.flushed;
5705 coal += q_vector->lrolist.stats.coal;
5707 adapter->lro_stats.flushed = flushed;
5708 adapter->lro_stats.coal = coal;
5713 for (i = 0; i < adapter->num_rx_queues; i++) {
5714 u32 rqdpc_tmp = E1000_READ_REG(hw, E1000_RQDPC(i)) & 0x0FFF;
5715 struct igb_ring *ring = adapter->rx_ring[i];
5716 ring->rx_stats.drops += rqdpc_tmp;
5717 net_stats->rx_fifo_errors += rqdpc_tmp;
5718 #ifdef CONFIG_IGB_VMDQ_NETDEV
5719 if (!ring->vmdq_netdev) {
5720 bytes += ring->rx_stats.bytes;
5721 packets += ring->rx_stats.packets;
5724 bytes += ring->rx_stats.bytes;
5725 packets += ring->rx_stats.packets;
5729 net_stats->rx_bytes = bytes;
5730 net_stats->rx_packets = packets;
5734 for (i = 0; i < adapter->num_tx_queues; i++) {
5735 struct igb_ring *ring = adapter->tx_ring[i];
5736 #ifdef CONFIG_IGB_VMDQ_NETDEV
5737 if (!ring->vmdq_netdev) {
5738 bytes += ring->tx_stats.bytes;
5739 packets += ring->tx_stats.packets;
5742 bytes += ring->tx_stats.bytes;
5743 packets += ring->tx_stats.packets;
5746 net_stats->tx_bytes = bytes;
5747 net_stats->tx_packets = packets;
5749 /* read stats registers */
5750 adapter->stats.crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
5751 adapter->stats.gprc += E1000_READ_REG(hw, E1000_GPRC);
5752 adapter->stats.gorc += E1000_READ_REG(hw, E1000_GORCL);
5753 E1000_READ_REG(hw, E1000_GORCH); /* clear GORCL */
5754 adapter->stats.bprc += E1000_READ_REG(hw, E1000_BPRC);
5755 adapter->stats.mprc += E1000_READ_REG(hw, E1000_MPRC);
5756 adapter->stats.roc += E1000_READ_REG(hw, E1000_ROC);
5758 adapter->stats.prc64 += E1000_READ_REG(hw, E1000_PRC64);
5759 adapter->stats.prc127 += E1000_READ_REG(hw, E1000_PRC127);
5760 adapter->stats.prc255 += E1000_READ_REG(hw, E1000_PRC255);
5761 adapter->stats.prc511 += E1000_READ_REG(hw, E1000_PRC511);
5762 adapter->stats.prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
5763 adapter->stats.prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
5764 adapter->stats.symerrs += E1000_READ_REG(hw, E1000_SYMERRS);
5765 adapter->stats.sec += E1000_READ_REG(hw, E1000_SEC);
5767 mpc = E1000_READ_REG(hw, E1000_MPC);
5768 adapter->stats.mpc += mpc;
5769 net_stats->rx_fifo_errors += mpc;
5770 adapter->stats.scc += E1000_READ_REG(hw, E1000_SCC);
5771 adapter->stats.ecol += E1000_READ_REG(hw, E1000_ECOL);
5772 adapter->stats.mcc += E1000_READ_REG(hw, E1000_MCC);
5773 adapter->stats.latecol += E1000_READ_REG(hw, E1000_LATECOL);
5774 adapter->stats.dc += E1000_READ_REG(hw, E1000_DC);
5775 adapter->stats.rlec += E1000_READ_REG(hw, E1000_RLEC);
5776 adapter->stats.xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
5777 adapter->stats.xontxc += E1000_READ_REG(hw, E1000_XONTXC);
5778 adapter->stats.xoffrxc += E1000_READ_REG(hw, E1000_XOFFRXC);
5779 adapter->stats.xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
5780 adapter->stats.fcruc += E1000_READ_REG(hw, E1000_FCRUC);
5781 adapter->stats.gptc += E1000_READ_REG(hw, E1000_GPTC);
5782 adapter->stats.gotc += E1000_READ_REG(hw, E1000_GOTCL);
5783 E1000_READ_REG(hw, E1000_GOTCH); /* clear GOTCL */
5784 adapter->stats.rnbc += E1000_READ_REG(hw, E1000_RNBC);
5785 adapter->stats.ruc += E1000_READ_REG(hw, E1000_RUC);
5786 adapter->stats.rfc += E1000_READ_REG(hw, E1000_RFC);
5787 adapter->stats.rjc += E1000_READ_REG(hw, E1000_RJC);
5788 adapter->stats.tor += E1000_READ_REG(hw, E1000_TORH);
5789 adapter->stats.tot += E1000_READ_REG(hw, E1000_TOTH);
5790 adapter->stats.tpr += E1000_READ_REG(hw, E1000_TPR);
5792 adapter->stats.ptc64 += E1000_READ_REG(hw, E1000_PTC64);
5793 adapter->stats.ptc127 += E1000_READ_REG(hw, E1000_PTC127);
5794 adapter->stats.ptc255 += E1000_READ_REG(hw, E1000_PTC255);
5795 adapter->stats.ptc511 += E1000_READ_REG(hw, E1000_PTC511);
5796 adapter->stats.ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
5797 adapter->stats.ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
5799 adapter->stats.mptc += E1000_READ_REG(hw, E1000_MPTC);
5800 adapter->stats.bptc += E1000_READ_REG(hw, E1000_BPTC);
5802 adapter->stats.tpt += E1000_READ_REG(hw, E1000_TPT);
5803 adapter->stats.colc += E1000_READ_REG(hw, E1000_COLC);
5805 adapter->stats.algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
5806 /* read internal phy sepecific stats */
5807 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
5808 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
5809 adapter->stats.rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
5811 /* this stat has invalid values on i210/i211 */
5812 if ((hw->mac.type != e1000_i210) &&
5813 (hw->mac.type != e1000_i211))
5814 adapter->stats.tncrs += E1000_READ_REG(hw, E1000_TNCRS);
5816 adapter->stats.tsctc += E1000_READ_REG(hw, E1000_TSCTC);
5817 adapter->stats.tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
5819 adapter->stats.iac += E1000_READ_REG(hw, E1000_IAC);
5820 adapter->stats.icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
5821 adapter->stats.icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
5822 adapter->stats.icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
5823 adapter->stats.ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
5824 adapter->stats.ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
5825 adapter->stats.ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
5826 adapter->stats.ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
5827 adapter->stats.icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
5829 /* Fill out the OS statistics structure */
5830 net_stats->multicast = adapter->stats.mprc;
5831 net_stats->collisions = adapter->stats.colc;
5835 /* RLEC on some newer hardware can be incorrect so build
5836 * our own version based on RUC and ROC */
5837 net_stats->rx_errors = adapter->stats.rxerrc +
5838 adapter->stats.crcerrs + adapter->stats.algnerrc +
5839 adapter->stats.ruc + adapter->stats.roc +
5840 adapter->stats.cexterr;
5841 net_stats->rx_length_errors = adapter->stats.ruc +
5843 net_stats->rx_crc_errors = adapter->stats.crcerrs;
5844 net_stats->rx_frame_errors = adapter->stats.algnerrc;
5845 net_stats->rx_missed_errors = adapter->stats.mpc;
5848 net_stats->tx_errors = adapter->stats.ecol +
5849 adapter->stats.latecol;
5850 net_stats->tx_aborted_errors = adapter->stats.ecol;
5851 net_stats->tx_window_errors = adapter->stats.latecol;
5852 net_stats->tx_carrier_errors = adapter->stats.tncrs;
5854 /* Tx Dropped needs to be maintained elsewhere */
5857 if (hw->phy.media_type == e1000_media_type_copper) {
5858 if ((adapter->link_speed == SPEED_1000) &&
5859 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
5860 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
5861 adapter->phy_stats.idle_errors += phy_tmp;
5865 /* Management Stats */
5866 adapter->stats.mgptc += E1000_READ_REG(hw, E1000_MGTPTC);
5867 adapter->stats.mgprc += E1000_READ_REG(hw, E1000_MGTPRC);
5868 if (hw->mac.type > e1000_82580) {
5869 adapter->stats.o2bgptc += E1000_READ_REG(hw, E1000_O2BGPTC);
5870 adapter->stats.o2bspc += E1000_READ_REG(hw, E1000_O2BSPC);
5871 adapter->stats.b2ospc += E1000_READ_REG(hw, E1000_B2OSPC);
5872 adapter->stats.b2ogprc += E1000_READ_REG(hw, E1000_B2OGPRC);
5876 static irqreturn_t igb_msix_other(int irq, void *data)
5878 struct igb_adapter *adapter = data;
5879 struct e1000_hw *hw = &adapter->hw;
5880 u32 icr = E1000_READ_REG(hw, E1000_ICR);
5881 /* reading ICR causes bit 31 of EICR to be cleared */
5883 if (icr & E1000_ICR_DRSTA)
5884 schedule_work(&adapter->reset_task);
5886 if (icr & E1000_ICR_DOUTSYNC) {
5887 /* HW is reporting DMA is out of sync */
5888 adapter->stats.doosync++;
5889 /* The DMA Out of Sync is also indication of a spoof event
5890 * in IOV mode. Check the Wrong VM Behavior register to
5891 * see if it is really a spoof event. */
5892 igb_check_wvbr(adapter);
5895 /* Check for a mailbox event */
5896 if (icr & E1000_ICR_VMMB)
5897 igb_msg_task(adapter);
5899 if (icr & E1000_ICR_LSC) {
5900 hw->mac.get_link_status = 1;
5901 /* guard against interrupt when we're going down */
5902 if (!test_bit(__IGB_DOWN, &adapter->state))
5903 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5906 #ifdef HAVE_PTP_1588_CLOCK
5907 if (icr & E1000_ICR_TS) {
5908 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
5910 if (tsicr & E1000_TSICR_TXTS) {
5911 /* acknowledge the interrupt */
5912 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
5913 /* retrieve hardware timestamp */
5914 schedule_work(&adapter->ptp_tx_work);
5917 #endif /* HAVE_PTP_1588_CLOCK */
5919 /* Check for MDD event */
5920 if (icr & E1000_ICR_MDDET)
5921 igb_process_mdd_event(adapter);
5923 E1000_WRITE_REG(hw, E1000_EIMS, adapter->eims_other);
5928 static void igb_write_itr(struct igb_q_vector *q_vector)
5930 struct igb_adapter *adapter = q_vector->adapter;
5931 u32 itr_val = q_vector->itr_val & 0x7FFC;
5933 if (!q_vector->set_itr)
5939 if (adapter->hw.mac.type == e1000_82575)
5940 itr_val |= itr_val << 16;
5942 itr_val |= E1000_EITR_CNT_IGNR;
5944 writel(itr_val, q_vector->itr_register);
5945 q_vector->set_itr = 0;
5948 static irqreturn_t igb_msix_ring(int irq, void *data)
5950 struct igb_q_vector *q_vector = data;
5952 /* Write the ITR value calculated from the previous interrupt. */
5953 igb_write_itr(q_vector);
5955 napi_schedule(&q_vector->napi);
5961 static void igb_update_tx_dca(struct igb_adapter *adapter,
5962 struct igb_ring *tx_ring,
5965 struct e1000_hw *hw = &adapter->hw;
5966 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
5968 if (hw->mac.type != e1000_82575)
5969 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT_82576;
5972 * We can enable relaxed ordering for reads, but not writes when
5973 * DCA is enabled. This is due to a known issue in some chipsets
5974 * which will cause the DCA tag to be cleared.
5976 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
5977 E1000_DCA_TXCTRL_DATA_RRO_EN |
5978 E1000_DCA_TXCTRL_DESC_DCA_EN;
5980 E1000_WRITE_REG(hw, E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
5983 static void igb_update_rx_dca(struct igb_adapter *adapter,
5984 struct igb_ring *rx_ring,
5987 struct e1000_hw *hw = &adapter->hw;
5988 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
5990 if (hw->mac.type != e1000_82575)
5991 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT_82576;
5994 * We can enable relaxed ordering for reads, but not writes when
5995 * DCA is enabled. This is due to a known issue in some chipsets
5996 * which will cause the DCA tag to be cleared.
5998 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
5999 E1000_DCA_RXCTRL_DESC_DCA_EN;
6001 E1000_WRITE_REG(hw, E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
6004 static void igb_update_dca(struct igb_q_vector *q_vector)
6006 struct igb_adapter *adapter = q_vector->adapter;
6007 int cpu = get_cpu();
6009 if (q_vector->cpu == cpu)
6012 if (q_vector->tx.ring)
6013 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
6015 if (q_vector->rx.ring)
6016 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
6018 q_vector->cpu = cpu;
6023 static void igb_setup_dca(struct igb_adapter *adapter)
6025 struct e1000_hw *hw = &adapter->hw;
6028 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
6031 /* Always use CB2 mode, difference is masked in the CB driver. */
6032 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
6034 for (i = 0; i < adapter->num_q_vectors; i++) {
6035 adapter->q_vector[i]->cpu = -1;
6036 igb_update_dca(adapter->q_vector[i]);
6040 static int __igb_notify_dca(struct device *dev, void *data)
6042 struct net_device *netdev = dev_get_drvdata(dev);
6043 struct igb_adapter *adapter = netdev_priv(netdev);
6044 struct pci_dev *pdev = adapter->pdev;
6045 struct e1000_hw *hw = &adapter->hw;
6046 unsigned long event = *(unsigned long *)data;
6049 case DCA_PROVIDER_ADD:
6050 /* if already enabled, don't do it again */
6051 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
6053 if (dca_add_requester(dev) == E1000_SUCCESS) {
6054 adapter->flags |= IGB_FLAG_DCA_ENABLED;
6055 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
6056 igb_setup_dca(adapter);
6059 /* Fall Through since DCA is disabled. */
6060 case DCA_PROVIDER_REMOVE:
6061 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
6062 /* without this a class_device is left
6063 * hanging around in the sysfs model */
6064 dca_remove_requester(dev);
6065 dev_info(pci_dev_to_dev(pdev), "DCA disabled\n");
6066 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
6067 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_DISABLE);
6072 return E1000_SUCCESS;
6075 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
6080 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
6083 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6085 #endif /* IGB_DCA */
6087 static int igb_vf_configure(struct igb_adapter *adapter, int vf)
6089 unsigned char mac_addr[ETH_ALEN];
6091 random_ether_addr(mac_addr);
6092 igb_set_vf_mac(adapter, vf, mac_addr);
6095 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
6096 /* By default spoof check is enabled for all VFs */
6097 adapter->vf_data[vf].spoofchk_enabled = true;
6104 static void igb_ping_all_vfs(struct igb_adapter *adapter)
6106 struct e1000_hw *hw = &adapter->hw;
6110 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
6111 ping = E1000_PF_CONTROL_MSG;
6112 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
6113 ping |= E1000_VT_MSGTYPE_CTS;
6114 e1000_write_mbx(hw, &ping, 1, i);
6119 * igb_mta_set_ - Set multicast filter table address
6120 * @adapter: pointer to the adapter structure
6121 * @hash_value: determines the MTA register and bit to set
6123 * The multicast table address is a register array of 32-bit registers.
6124 * The hash_value is used to determine what register the bit is in, the
6125 * current value is read, the new bit is OR'd in and the new value is
6126 * written back into the register.
6128 void igb_mta_set(struct igb_adapter *adapter, u32 hash_value)
6130 struct e1000_hw *hw = &adapter->hw;
6131 u32 hash_bit, hash_reg, mta;
6134 * The MTA is a register array of 32-bit registers. It is
6135 * treated like an array of (32*mta_reg_count) bits. We want to
6136 * set bit BitArray[hash_value]. So we figure out what register
6137 * the bit is in, read it, OR in the new bit, then write
6138 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
6139 * mask to bits 31:5 of the hash value which gives us the
6140 * register we're modifying. The hash bit within that register
6141 * is determined by the lower 5 bits of the hash value.
6143 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
6144 hash_bit = hash_value & 0x1F;
6146 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
6148 mta |= (1 << hash_bit);
6150 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
6151 E1000_WRITE_FLUSH(hw);
6154 static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6157 struct e1000_hw *hw = &adapter->hw;
6158 u32 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vf));
6159 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6161 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
6162 IGB_VF_FLAG_MULTI_PROMISC);
6163 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6165 #ifdef IGB_ENABLE_VF_PROMISC
6166 if (*msgbuf & E1000_VF_SET_PROMISC_UNICAST) {
6167 vmolr |= E1000_VMOLR_ROPE;
6168 vf_data->flags |= IGB_VF_FLAG_UNI_PROMISC;
6169 *msgbuf &= ~E1000_VF_SET_PROMISC_UNICAST;
6172 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
6173 vmolr |= E1000_VMOLR_MPME;
6174 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
6175 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
6178 * if we have hashes and we are clearing a multicast promisc
6179 * flag we need to write the hashes to the MTA as this step
6180 * was previously skipped
6182 if (vf_data->num_vf_mc_hashes > 30) {
6183 vmolr |= E1000_VMOLR_MPME;
6184 } else if (vf_data->num_vf_mc_hashes) {
6186 vmolr |= E1000_VMOLR_ROMPE;
6187 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6188 igb_mta_set(adapter, vf_data->vf_mc_hashes[j]);
6192 E1000_WRITE_REG(hw, E1000_VMOLR(vf), vmolr);
6194 /* there are flags left unprocessed, likely not supported */
6195 if (*msgbuf & E1000_VT_MSGINFO_MASK)
6202 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
6203 u32 *msgbuf, u32 vf)
6205 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6206 u16 *hash_list = (u16 *)&msgbuf[1];
6207 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6210 /* salt away the number of multicast addresses assigned
6211 * to this VF for later use to restore when the PF multi cast
6214 vf_data->num_vf_mc_hashes = n;
6216 /* only up to 30 hash values supported */
6220 /* store the hashes for later use */
6221 for (i = 0; i < n; i++)
6222 vf_data->vf_mc_hashes[i] = hash_list[i];
6224 /* Flush and reset the mta with the new values */
6225 igb_set_rx_mode(adapter->netdev);
6230 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
6232 struct e1000_hw *hw = &adapter->hw;
6233 struct vf_data_storage *vf_data;
6236 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6237 u32 vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
6238 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6240 vf_data = &adapter->vf_data[i];
6242 if ((vf_data->num_vf_mc_hashes > 30) ||
6243 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
6244 vmolr |= E1000_VMOLR_MPME;
6245 } else if (vf_data->num_vf_mc_hashes) {
6246 vmolr |= E1000_VMOLR_ROMPE;
6247 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6248 igb_mta_set(adapter, vf_data->vf_mc_hashes[j]);
6250 E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
6254 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
6256 struct e1000_hw *hw = &adapter->hw;
6257 u32 pool_mask, reg, vid;
6261 pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
6263 /* Find the vlan filter for this id */
6264 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6265 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6267 /* remove the vf from the pool */
6270 /* if pool is empty then remove entry from vfta */
6271 if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
6272 (reg & E1000_VLVF_VLANID_ENABLE)) {
6274 vid = reg & E1000_VLVF_VLANID_MASK;
6275 igb_vfta_set(adapter, vid, FALSE);
6278 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6281 adapter->vf_data[vf].vlans_enabled = 0;
6283 vlan_default = adapter->vf_data[vf].default_vf_vlan_id;
6285 igb_vlvf_set(adapter, vlan_default, true, vf);
6288 s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
6290 struct e1000_hw *hw = &adapter->hw;
6293 /* The vlvf table only exists on 82576 hardware and newer */
6294 if (hw->mac.type < e1000_82576)
6297 /* we only need to do this if VMDq is enabled */
6298 if (!adapter->vmdq_pools)
6301 /* Find the vlan filter for this id */
6302 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6303 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6304 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
6305 vid == (reg & E1000_VLVF_VLANID_MASK))
6310 if (i == E1000_VLVF_ARRAY_SIZE) {
6311 /* Did not find a matching VLAN ID entry that was
6312 * enabled. Search for a free filter entry, i.e.
6313 * one without the enable bit set
6315 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6316 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6317 if (!(reg & E1000_VLVF_VLANID_ENABLE))
6321 if (i < E1000_VLVF_ARRAY_SIZE) {
6322 /* Found an enabled/available entry */
6323 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
6325 /* if !enabled we need to set this up in vfta */
6326 if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
6327 /* add VID to filter table */
6328 igb_vfta_set(adapter, vid, TRUE);
6329 reg |= E1000_VLVF_VLANID_ENABLE;
6331 reg &= ~E1000_VLVF_VLANID_MASK;
6333 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6335 /* do not modify RLPML for PF devices */
6336 if (vf >= adapter->vfs_allocated_count)
6337 return E1000_SUCCESS;
6339 if (!adapter->vf_data[vf].vlans_enabled) {
6341 reg = E1000_READ_REG(hw, E1000_VMOLR(vf));
6342 size = reg & E1000_VMOLR_RLPML_MASK;
6344 reg &= ~E1000_VMOLR_RLPML_MASK;
6346 E1000_WRITE_REG(hw, E1000_VMOLR(vf), reg);
6349 adapter->vf_data[vf].vlans_enabled++;
6352 if (i < E1000_VLVF_ARRAY_SIZE) {
6353 /* remove vf from the pool */
6354 reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
6355 /* if pool is empty then remove entry from vfta */
6356 if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
6358 igb_vfta_set(adapter, vid, FALSE);
6360 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6362 /* do not modify RLPML for PF devices */
6363 if (vf >= adapter->vfs_allocated_count)
6364 return E1000_SUCCESS;
6366 adapter->vf_data[vf].vlans_enabled--;
6367 if (!adapter->vf_data[vf].vlans_enabled) {
6369 reg = E1000_READ_REG(hw, E1000_VMOLR(vf));
6370 size = reg & E1000_VMOLR_RLPML_MASK;
6372 reg &= ~E1000_VMOLR_RLPML_MASK;
6374 E1000_WRITE_REG(hw, E1000_VMOLR(vf), reg);
6378 return E1000_SUCCESS;
6382 static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
6384 struct e1000_hw *hw = &adapter->hw;
6387 E1000_WRITE_REG(hw, E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
6389 E1000_WRITE_REG(hw, E1000_VMVIR(vf), 0);
6392 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
6393 int vf, u16 vlan, u8 qos)
6396 struct igb_adapter *adapter = netdev_priv(netdev);
6398 /* VLAN IDs accepted range 0-4094 */
6399 if ((vf >= adapter->vfs_allocated_count) || (vlan > VLAN_VID_MASK-1) || (qos > 7))
6402 err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
6405 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
6406 igb_set_vmolr(adapter, vf, !vlan);
6407 adapter->vf_data[vf].pf_vlan = vlan;
6408 adapter->vf_data[vf].pf_qos = qos;
6409 igb_set_vf_vlan_strip(adapter, vf, true);
6410 dev_info(&adapter->pdev->dev,
6411 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
6412 if (test_bit(__IGB_DOWN, &adapter->state)) {
6413 dev_warn(&adapter->pdev->dev,
6414 "The VF VLAN has been set,"
6415 " but the PF device is not up.\n");
6416 dev_warn(&adapter->pdev->dev,
6417 "Bring the PF device up before"
6418 " attempting to use the VF device.\n");
6421 if (adapter->vf_data[vf].pf_vlan)
6422 dev_info(&adapter->pdev->dev,
6423 "Clearing VLAN on VF %d\n", vf);
6424 igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
6426 igb_set_vmvir(adapter, vlan, vf);
6427 igb_set_vmolr(adapter, vf, true);
6428 igb_set_vf_vlan_strip(adapter, vf, false);
6429 adapter->vf_data[vf].pf_vlan = 0;
6430 adapter->vf_data[vf].pf_qos = 0;
6436 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
6437 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
6440 struct igb_adapter *adapter = netdev_priv(netdev);
6441 struct e1000_hw *hw = &adapter->hw;
6442 u32 dtxswc, reg_offset;
6444 if (!adapter->vfs_allocated_count)
6447 if (vf >= adapter->vfs_allocated_count)
6450 reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
6451 dtxswc = E1000_READ_REG(hw, reg_offset);
6453 dtxswc |= ((1 << vf) |
6454 (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
6456 dtxswc &= ~((1 << vf) |
6457 (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
6458 E1000_WRITE_REG(hw, reg_offset, dtxswc);
6460 adapter->vf_data[vf].spoofchk_enabled = setting;
6461 return E1000_SUCCESS;
6463 #endif /* HAVE_VF_SPOOFCHK_CONFIGURE */
6464 #endif /* IFLA_VF_MAX */
6466 static int igb_find_vlvf_entry(struct igb_adapter *adapter, int vid)
6468 struct e1000_hw *hw = &adapter->hw;
6472 /* Find the vlan filter for this id */
6473 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6474 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6475 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
6476 vid == (reg & E1000_VLVF_VLANID_MASK))
6480 if (i >= E1000_VLVF_ARRAY_SIZE)
6486 static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6488 struct e1000_hw *hw = &adapter->hw;
6489 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6490 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
6494 igb_set_vf_vlan_strip(adapter, vf, true);
6496 igb_set_vf_vlan_strip(adapter, vf, false);
6498 /* If in promiscuous mode we need to make sure the PF also has
6499 * the VLAN filter set.
6501 if (add && (adapter->netdev->flags & IFF_PROMISC))
6502 err = igb_vlvf_set(adapter, vid, add,
6503 adapter->vfs_allocated_count);
6507 err = igb_vlvf_set(adapter, vid, add, vf);
6512 /* Go through all the checks to see if the VLAN filter should
6513 * be wiped completely.
6515 if (!add && (adapter->netdev->flags & IFF_PROMISC)) {
6518 int regndx = igb_find_vlvf_entry(adapter, vid);
6521 /* See if any other pools are set for this VLAN filter
6522 * entry other than the PF.
6524 vlvf = bits = E1000_READ_REG(hw, E1000_VLVF(regndx));
6525 bits &= 1 << (E1000_VLVF_POOLSEL_SHIFT +
6526 adapter->vfs_allocated_count);
6527 /* If the filter was removed then ensure PF pool bit
6528 * is cleared if the PF only added itself to the pool
6529 * because the PF is in promiscuous mode.
6531 if ((vlvf & VLAN_VID_MASK) == vid &&
6532 #ifndef HAVE_VLAN_RX_REGISTER
6533 !test_bit(vid, adapter->active_vlans) &&
6536 igb_vlvf_set(adapter, vid, add,
6537 adapter->vfs_allocated_count);
6544 static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
6546 struct e1000_hw *hw = &adapter->hw;
6548 /* clear flags except flag that the PF has set the MAC */
6549 adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
6550 adapter->vf_data[vf].last_nack = jiffies;
6552 /* reset offloads to defaults */
6553 igb_set_vmolr(adapter, vf, true);
6555 /* reset vlans for device */
6556 igb_clear_vf_vfta(adapter, vf);
6558 if (adapter->vf_data[vf].pf_vlan)
6559 igb_ndo_set_vf_vlan(adapter->netdev, vf,
6560 adapter->vf_data[vf].pf_vlan,
6561 adapter->vf_data[vf].pf_qos);
6563 igb_clear_vf_vfta(adapter, vf);
6566 /* reset multicast table array for vf */
6567 adapter->vf_data[vf].num_vf_mc_hashes = 0;
6569 /* Flush and reset the mta with the new values */
6570 igb_set_rx_mode(adapter->netdev);
6573 * Reset the VFs TDWBAL and TDWBAH registers which are not
6576 E1000_WRITE_REG(hw, E1000_TDWBAH(vf), 0);
6577 E1000_WRITE_REG(hw, E1000_TDWBAL(vf), 0);
6578 if (hw->mac.type == e1000_82576) {
6579 E1000_WRITE_REG(hw, E1000_TDWBAH(IGB_MAX_VF_FUNCTIONS + vf), 0);
6580 E1000_WRITE_REG(hw, E1000_TDWBAL(IGB_MAX_VF_FUNCTIONS + vf), 0);
6584 static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
6586 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6588 /* generate a new mac address as we were hotplug removed/added */
6589 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
6590 random_ether_addr(vf_mac);
6592 /* process remaining reset events */
6593 igb_vf_reset(adapter, vf);
6596 static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
6598 struct e1000_hw *hw = &adapter->hw;
6599 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6601 u8 *addr = (u8 *)(&msgbuf[1]);
6603 /* process all the same items cleared in a function level reset */
6604 igb_vf_reset(adapter, vf);
6606 /* set vf mac address */
6607 igb_del_mac_filter(adapter, vf_mac, vf);
6608 igb_add_mac_filter(adapter, vf_mac, vf);
6610 /* enable transmit and receive for vf */
6611 reg = E1000_READ_REG(hw, E1000_VFTE);
6612 E1000_WRITE_REG(hw, E1000_VFTE, reg | (1 << vf));
6613 reg = E1000_READ_REG(hw, E1000_VFRE);
6614 E1000_WRITE_REG(hw, E1000_VFRE, reg | (1 << vf));
6616 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
6618 /* reply to reset with ack and vf mac address */
6619 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
6620 memcpy(addr, vf_mac, 6);
6621 e1000_write_mbx(hw, msgbuf, 3, vf);
6624 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
6627 * The VF MAC Address is stored in a packed array of bytes
6628 * starting at the second 32 bit word of the msg array
6630 unsigned char *addr = (unsigned char *)&msg[1];
6633 if (is_valid_ether_addr(addr))
6634 err = igb_set_vf_mac(adapter, vf, addr);
6639 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
6641 struct e1000_hw *hw = &adapter->hw;
6642 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6643 u32 msg = E1000_VT_MSGTYPE_NACK;
6645 /* if device isn't clear to send it shouldn't be reading either */
6646 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
6647 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6648 e1000_write_mbx(hw, &msg, 1, vf);
6649 vf_data->last_nack = jiffies;
6653 static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
6655 struct pci_dev *pdev = adapter->pdev;
6656 u32 msgbuf[E1000_VFMAILBOX_SIZE];
6657 struct e1000_hw *hw = &adapter->hw;
6658 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6661 retval = e1000_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
6664 dev_err(pci_dev_to_dev(pdev), "Error receiving message from VF\n");
6668 /* this is a message we already processed, do nothing */
6669 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
6673 * until the vf completes a reset it should not be
6674 * allowed to start any configuration.
6677 if (msgbuf[0] == E1000_VF_RESET) {
6678 igb_vf_reset_msg(adapter, vf);
6682 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
6683 msgbuf[0] = E1000_VT_MSGTYPE_NACK;
6684 if (time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6685 e1000_write_mbx(hw, msgbuf, 1, vf);
6686 vf_data->last_nack = jiffies;
6691 switch ((msgbuf[0] & 0xFFFF)) {
6692 case E1000_VF_SET_MAC_ADDR:
6694 #ifndef IGB_DISABLE_VF_MAC_SET
6695 if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
6696 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
6699 "VF %d attempted to override administratively "
6700 "set MAC address\nReload the VF driver to "
6701 "resume operations\n", vf);
6704 case E1000_VF_SET_PROMISC:
6705 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
6707 case E1000_VF_SET_MULTICAST:
6708 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
6710 case E1000_VF_SET_LPE:
6711 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
6713 case E1000_VF_SET_VLAN:
6716 if (vf_data->pf_vlan)
6718 "VF %d attempted to override administratively "
6719 "set VLAN tag\nReload the VF driver to "
6720 "resume operations\n", vf);
6723 retval = igb_set_vf_vlan(adapter, msgbuf, vf);
6726 dev_err(pci_dev_to_dev(pdev), "Unhandled Msg %08x\n", msgbuf[0]);
6727 retval = -E1000_ERR_MBX;
6731 /* notify the VF of the results of what it sent us */
6733 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
6735 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
6737 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
6739 e1000_write_mbx(hw, msgbuf, 1, vf);
6742 static void igb_msg_task(struct igb_adapter *adapter)
6744 struct e1000_hw *hw = &adapter->hw;
6747 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
6748 /* process any reset requests */
6749 if (!e1000_check_for_rst(hw, vf))
6750 igb_vf_reset_event(adapter, vf);
6752 /* process any messages pending */
6753 if (!e1000_check_for_msg(hw, vf))
6754 igb_rcv_msg_from_vf(adapter, vf);
6756 /* process any acks */
6757 if (!e1000_check_for_ack(hw, vf))
6758 igb_rcv_ack_from_vf(adapter, vf);
6763 * igb_set_uta - Set unicast filter table address
6764 * @adapter: board private structure
6766 * The unicast table address is a register array of 32-bit registers.
6767 * The table is meant to be used in a way similar to how the MTA is used
6768 * however due to certain limitations in the hardware it is necessary to
6769 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
6770 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
6772 static void igb_set_uta(struct igb_adapter *adapter)
6774 struct e1000_hw *hw = &adapter->hw;
6777 /* The UTA table only exists on 82576 hardware and newer */
6778 if (hw->mac.type < e1000_82576)
6781 /* we only need to do this if VMDq is enabled */
6782 if (!adapter->vmdq_pools)
6785 for (i = 0; i < hw->mac.uta_reg_count; i++)
6786 E1000_WRITE_REG_ARRAY(hw, E1000_UTA, i, ~0);
6790 * igb_intr_msi - Interrupt Handler
6791 * @irq: interrupt number
6792 * @data: pointer to a network interface device structure
6794 static irqreturn_t igb_intr_msi(int irq, void *data)
6796 struct igb_adapter *adapter = data;
6797 struct igb_q_vector *q_vector = adapter->q_vector[0];
6798 struct e1000_hw *hw = &adapter->hw;
6799 /* read ICR disables interrupts using IAM */
6800 u32 icr = E1000_READ_REG(hw, E1000_ICR);
6802 igb_write_itr(q_vector);
6804 if (icr & E1000_ICR_DRSTA)
6805 schedule_work(&adapter->reset_task);
6807 if (icr & E1000_ICR_DOUTSYNC) {
6808 /* HW is reporting DMA is out of sync */
6809 adapter->stats.doosync++;
6812 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6813 hw->mac.get_link_status = 1;
6814 if (!test_bit(__IGB_DOWN, &adapter->state))
6815 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6818 #ifdef HAVE_PTP_1588_CLOCK
6819 if (icr & E1000_ICR_TS) {
6820 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
6822 if (tsicr & E1000_TSICR_TXTS) {
6823 /* acknowledge the interrupt */
6824 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
6825 /* retrieve hardware timestamp */
6826 schedule_work(&adapter->ptp_tx_work);
6829 #endif /* HAVE_PTP_1588_CLOCK */
6831 napi_schedule(&q_vector->napi);
6837 * igb_intr - Legacy Interrupt Handler
6838 * @irq: interrupt number
6839 * @data: pointer to a network interface device structure
6841 static irqreturn_t igb_intr(int irq, void *data)
6843 struct igb_adapter *adapter = data;
6844 struct igb_q_vector *q_vector = adapter->q_vector[0];
6845 struct e1000_hw *hw = &adapter->hw;
6846 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
6847 * need for the IMC write */
6848 u32 icr = E1000_READ_REG(hw, E1000_ICR);
6850 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
6851 * not set, then the adapter didn't send an interrupt */
6852 if (!(icr & E1000_ICR_INT_ASSERTED))
6855 igb_write_itr(q_vector);
6857 if (icr & E1000_ICR_DRSTA)
6858 schedule_work(&adapter->reset_task);
6860 if (icr & E1000_ICR_DOUTSYNC) {
6861 /* HW is reporting DMA is out of sync */
6862 adapter->stats.doosync++;
6865 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6866 hw->mac.get_link_status = 1;
6867 /* guard against interrupt when we're going down */
6868 if (!test_bit(__IGB_DOWN, &adapter->state))
6869 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6872 #ifdef HAVE_PTP_1588_CLOCK
6873 if (icr & E1000_ICR_TS) {
6874 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
6876 if (tsicr & E1000_TSICR_TXTS) {
6877 /* acknowledge the interrupt */
6878 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
6879 /* retrieve hardware timestamp */
6880 schedule_work(&adapter->ptp_tx_work);
6883 #endif /* HAVE_PTP_1588_CLOCK */
6885 napi_schedule(&q_vector->napi);
6890 void igb_ring_irq_enable(struct igb_q_vector *q_vector)
6892 struct igb_adapter *adapter = q_vector->adapter;
6893 struct e1000_hw *hw = &adapter->hw;
6895 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
6896 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
6897 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
6898 igb_set_itr(q_vector);
6900 igb_update_ring_itr(q_vector);
6903 if (!test_bit(__IGB_DOWN, &adapter->state)) {
6904 if (adapter->msix_entries)
6905 E1000_WRITE_REG(hw, E1000_EIMS, q_vector->eims_value);
6907 igb_irq_enable(adapter);
6912 * igb_poll - NAPI Rx polling callback
6913 * @napi: napi polling structure
6914 * @budget: count of how many packets we should handle
6916 static int igb_poll(struct napi_struct *napi, int budget)
6918 struct igb_q_vector *q_vector = container_of(napi, struct igb_q_vector, napi);
6919 bool clean_complete = true;
6922 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
6923 igb_update_dca(q_vector);
6925 if (q_vector->tx.ring)
6926 clean_complete = igb_clean_tx_irq(q_vector);
6928 if (q_vector->rx.ring)
6929 clean_complete &= igb_clean_rx_irq(q_vector, budget);
6931 #ifndef HAVE_NETDEV_NAPI_LIST
6932 /* if netdev is disabled we need to stop polling */
6933 if (!netif_running(q_vector->adapter->netdev))
6934 clean_complete = true;
6937 /* If all work not completed, return budget and keep polling */
6938 if (!clean_complete)
6941 /* If not enough Rx work done, exit the polling mode */
6942 napi_complete(napi);
6943 igb_ring_irq_enable(q_vector);
6949 * igb_clean_tx_irq - Reclaim resources after transmit completes
6950 * @q_vector: pointer to q_vector containing needed info
6951 * returns TRUE if ring is completely cleaned
6953 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
6955 struct igb_adapter *adapter = q_vector->adapter;
6956 struct igb_ring *tx_ring = q_vector->tx.ring;
6957 struct igb_tx_buffer *tx_buffer;
6958 union e1000_adv_tx_desc *tx_desc;
6959 unsigned int total_bytes = 0, total_packets = 0;
6960 unsigned int budget = q_vector->tx.work_limit;
6961 unsigned int i = tx_ring->next_to_clean;
6963 if (test_bit(__IGB_DOWN, &adapter->state))
6966 tx_buffer = &tx_ring->tx_buffer_info[i];
6967 tx_desc = IGB_TX_DESC(tx_ring, i);
6968 i -= tx_ring->count;
6971 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
6973 /* if next_to_watch is not set then there is no work pending */
6977 /* prevent any other reads prior to eop_desc */
6978 read_barrier_depends();
6980 /* if DD is not set pending work has not been completed */
6981 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
6984 /* clear next_to_watch to prevent false hangs */
6985 tx_buffer->next_to_watch = NULL;
6987 /* update the statistics for this packet */
6988 total_bytes += tx_buffer->bytecount;
6989 total_packets += tx_buffer->gso_segs;
6992 dev_kfree_skb_any(tx_buffer->skb);
6994 /* unmap skb header data */
6995 dma_unmap_single(tx_ring->dev,
6996 dma_unmap_addr(tx_buffer, dma),
6997 dma_unmap_len(tx_buffer, len),
7000 /* clear tx_buffer data */
7001 tx_buffer->skb = NULL;
7002 dma_unmap_len_set(tx_buffer, len, 0);
7004 /* clear last DMA location and unmap remaining buffers */
7005 while (tx_desc != eop_desc) {
7010 i -= tx_ring->count;
7011 tx_buffer = tx_ring->tx_buffer_info;
7012 tx_desc = IGB_TX_DESC(tx_ring, 0);
7015 /* unmap any remaining paged data */
7016 if (dma_unmap_len(tx_buffer, len)) {
7017 dma_unmap_page(tx_ring->dev,
7018 dma_unmap_addr(tx_buffer, dma),
7019 dma_unmap_len(tx_buffer, len),
7021 dma_unmap_len_set(tx_buffer, len, 0);
7025 /* move us one more past the eop_desc for start of next pkt */
7030 i -= tx_ring->count;
7031 tx_buffer = tx_ring->tx_buffer_info;
7032 tx_desc = IGB_TX_DESC(tx_ring, 0);
7035 /* issue prefetch for next Tx descriptor */
7038 /* update budget accounting */
7040 } while (likely(budget));
7042 netdev_tx_completed_queue(txring_txq(tx_ring),
7043 total_packets, total_bytes);
7045 i += tx_ring->count;
7046 tx_ring->next_to_clean = i;
7047 tx_ring->tx_stats.bytes += total_bytes;
7048 tx_ring->tx_stats.packets += total_packets;
7049 q_vector->tx.total_bytes += total_bytes;
7050 q_vector->tx.total_packets += total_packets;
7053 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags) &&
7054 !(adapter->disable_hw_reset && adapter->tx_hang_detected)) {
7056 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
7058 struct e1000_hw *hw = &adapter->hw;
7060 /* Detect a transmit hang in hardware, this serializes the
7061 * check with the clearing of time_stamp and movement of i */
7062 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
7063 if (tx_buffer->next_to_watch &&
7064 time_after(jiffies, tx_buffer->time_stamp +
7065 (adapter->tx_timeout_factor * HZ))
7066 && !(E1000_READ_REG(hw, E1000_STATUS) &
7067 E1000_STATUS_TXOFF)) {
7069 /* detected Tx unit hang */
7071 adapter->tx_hang_detected = TRUE;
7072 if (adapter->disable_hw_reset) {
7073 DPRINTK(DRV, WARNING,
7074 "Deactivating netdev watchdog timer\n");
7075 if (del_timer(&netdev_ring(tx_ring)->watchdog_timer))
7076 dev_put(netdev_ring(tx_ring));
7077 #ifndef HAVE_NET_DEVICE_OPS
7078 netdev_ring(tx_ring)->tx_timeout = NULL;
7082 dev_err(tx_ring->dev,
7083 "Detected Tx Unit Hang\n"
7087 " next_to_use <%x>\n"
7088 " next_to_clean <%x>\n"
7089 "buffer_info[next_to_clean]\n"
7090 " time_stamp <%lx>\n"
7091 " next_to_watch <%p>\n"
7093 " desc.status <%x>\n",
7094 tx_ring->queue_index,
7095 E1000_READ_REG(hw, E1000_TDH(tx_ring->reg_idx)),
7096 readl(tx_ring->tail),
7097 tx_ring->next_to_use,
7098 tx_ring->next_to_clean,
7099 tx_buffer->time_stamp,
7100 tx_buffer->next_to_watch,
7102 tx_buffer->next_to_watch->wb.status);
7103 if (netif_is_multiqueue(netdev_ring(tx_ring)))
7104 netif_stop_subqueue(netdev_ring(tx_ring),
7105 ring_queue_index(tx_ring));
7107 netif_stop_queue(netdev_ring(tx_ring));
7109 /* we are about to reset, no point in enabling stuff */
7114 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7115 if (unlikely(total_packets &&
7116 netif_carrier_ok(netdev_ring(tx_ring)) &&
7117 igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
7118 /* Make sure that anybody stopping the queue after this
7119 * sees the new next_to_clean.
7122 if (netif_is_multiqueue(netdev_ring(tx_ring))) {
7123 if (__netif_subqueue_stopped(netdev_ring(tx_ring),
7124 ring_queue_index(tx_ring)) &&
7125 !(test_bit(__IGB_DOWN, &adapter->state))) {
7126 netif_wake_subqueue(netdev_ring(tx_ring),
7127 ring_queue_index(tx_ring));
7128 tx_ring->tx_stats.restart_queue++;
7131 if (netif_queue_stopped(netdev_ring(tx_ring)) &&
7132 !(test_bit(__IGB_DOWN, &adapter->state))) {
7133 netif_wake_queue(netdev_ring(tx_ring));
7134 tx_ring->tx_stats.restart_queue++;
7142 #ifdef HAVE_VLAN_RX_REGISTER
7144 * igb_receive_skb - helper function to handle rx indications
7145 * @q_vector: structure containing interrupt and ring information
7146 * @skb: packet to send up
7148 static void igb_receive_skb(struct igb_q_vector *q_vector,
7149 struct sk_buff *skb)
7151 struct vlan_group **vlgrp = netdev_priv(skb->dev);
7153 if (IGB_CB(skb)->vid) {
7155 vlan_gro_receive(&q_vector->napi, *vlgrp,
7156 IGB_CB(skb)->vid, skb);
7158 dev_kfree_skb_any(skb);
7161 napi_gro_receive(&q_vector->napi, skb);
7165 #endif /* HAVE_VLAN_RX_REGISTER */
7166 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7168 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7169 * @rx_ring: rx descriptor ring to store buffers on
7170 * @old_buff: donor buffer to have page reused
7172 * Synchronizes page for reuse by the adapter
7174 static void igb_reuse_rx_page(struct igb_ring *rx_ring,
7175 struct igb_rx_buffer *old_buff)
7177 struct igb_rx_buffer *new_buff;
7178 u16 nta = rx_ring->next_to_alloc;
7180 new_buff = &rx_ring->rx_buffer_info[nta];
7182 /* update, and store next to alloc */
7184 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
7186 /* transfer page from old buffer to new buffer */
7187 memcpy(new_buff, old_buff, sizeof(struct igb_rx_buffer));
7189 /* sync the buffer for use by the device */
7190 dma_sync_single_range_for_device(rx_ring->dev, old_buff->dma,
7191 old_buff->page_offset,
7196 static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
7198 unsigned int truesize)
7200 /* avoid re-using remote pages */
7201 if (unlikely(page_to_nid(page) != numa_node_id()))
7204 #if (PAGE_SIZE < 8192)
7205 /* if we are only owner of page we can reuse it */
7206 if (unlikely(page_count(page) != 1))
7209 /* flip page offset to other buffer */
7210 rx_buffer->page_offset ^= IGB_RX_BUFSZ;
7213 /* move offset up to the next cache line */
7214 rx_buffer->page_offset += truesize;
7216 if (rx_buffer->page_offset > (PAGE_SIZE - IGB_RX_BUFSZ))
7220 /* bump ref count on page before it is given to the stack */
7227 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
7228 * @rx_ring: rx descriptor ring to transact packets on
7229 * @rx_buffer: buffer containing page to add
7230 * @rx_desc: descriptor containing length of buffer written by hardware
7231 * @skb: sk_buff to place the data into
7233 * This function will add the data contained in rx_buffer->page to the skb.
7234 * This is done either through a direct copy if the data in the buffer is
7235 * less than the skb header size, otherwise it will just attach the page as
7236 * a frag to the skb.
7238 * The function will then update the page offset if necessary and return
7239 * true if the buffer can be reused by the adapter.
7241 static bool igb_add_rx_frag(struct igb_ring *rx_ring,
7242 struct igb_rx_buffer *rx_buffer,
7243 union e1000_adv_rx_desc *rx_desc,
7244 struct sk_buff *skb)
7246 struct page *page = rx_buffer->page;
7247 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
7248 #if (PAGE_SIZE < 8192)
7249 unsigned int truesize = IGB_RX_BUFSZ;
7251 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
7254 if ((size <= IGB_RX_HDR_LEN) && !skb_is_nonlinear(skb)) {
7255 unsigned char *va = page_address(page) + rx_buffer->page_offset;
7257 #ifdef HAVE_PTP_1588_CLOCK
7258 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
7259 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
7260 va += IGB_TS_HDR_LEN;
7261 size -= IGB_TS_HDR_LEN;
7263 #endif /* HAVE_PTP_1588_CLOCK */
7265 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
7267 /* we can reuse buffer as-is, just make sure it is local */
7268 if (likely(page_to_nid(page) == numa_node_id()))
7271 /* this page cannot be reused so discard it */
7276 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
7277 rx_buffer->page_offset, size, truesize);
7279 return igb_can_reuse_rx_page(rx_buffer, page, truesize);
7282 static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,
7283 union e1000_adv_rx_desc *rx_desc,
7284 struct sk_buff *skb)
7286 struct igb_rx_buffer *rx_buffer;
7289 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
7291 page = rx_buffer->page;
7295 void *page_addr = page_address(page) +
7296 rx_buffer->page_offset;
7298 /* prefetch first cache line of first page */
7299 prefetch(page_addr);
7300 #if L1_CACHE_BYTES < 128
7301 prefetch(page_addr + L1_CACHE_BYTES);
7304 /* allocate a skb to store the frags */
7305 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
7307 if (unlikely(!skb)) {
7308 rx_ring->rx_stats.alloc_failed++;
7313 * we will be copying header into skb->data in
7314 * pskb_may_pull so it is in our interest to prefetch
7315 * it now to avoid a possible cache miss
7317 prefetchw(skb->data);
7320 /* we are reusing so sync this buffer for CPU use */
7321 dma_sync_single_range_for_cpu(rx_ring->dev,
7323 rx_buffer->page_offset,
7327 /* pull page into skb */
7328 if (igb_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
7329 /* hand second half of page back to the ring */
7330 igb_reuse_rx_page(rx_ring, rx_buffer);
7332 /* we are not reusing the buffer so unmap it */
7333 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
7334 PAGE_SIZE, DMA_FROM_DEVICE);
7337 /* clear contents of rx_buffer */
7338 rx_buffer->page = NULL;
7344 static inline void igb_rx_checksum(struct igb_ring *ring,
7345 union e1000_adv_rx_desc *rx_desc,
7346 struct sk_buff *skb)
7348 skb_checksum_none_assert(skb);
7350 /* Ignore Checksum bit is set */
7351 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
7354 /* Rx checksum disabled via ethtool */
7355 if (!(netdev_ring(ring)->features & NETIF_F_RXCSUM))
7358 /* TCP/UDP checksum error bit is set */
7359 if (igb_test_staterr(rx_desc,
7360 E1000_RXDEXT_STATERR_TCPE |
7361 E1000_RXDEXT_STATERR_IPE)) {
7363 * work around errata with sctp packets where the TCPE aka
7364 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
7365 * packets, (aka let the stack check the crc32c)
7367 if (!((skb->len == 60) &&
7368 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags)))
7369 ring->rx_stats.csum_err++;
7371 /* let the stack verify checksum errors */
7374 /* It must be a TCP or UDP packet with a valid checksum */
7375 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
7376 E1000_RXD_STAT_UDPCS))
7377 skb->ip_summed = CHECKSUM_UNNECESSARY;
7380 #ifdef NETIF_F_RXHASH
7381 static inline void igb_rx_hash(struct igb_ring *ring,
7382 union e1000_adv_rx_desc *rx_desc,
7383 struct sk_buff *skb)
7385 if (netdev_ring(ring)->features & NETIF_F_RXHASH)
7386 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
7392 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7394 * igb_merge_active_tail - merge active tail into lro skb
7395 * @tail: pointer to active tail in frag_list
7397 * This function merges the length and data of an active tail into the
7398 * skb containing the frag_list. It resets the tail's pointer to the head,
7399 * but it leaves the heads pointer to tail intact.
7401 static inline struct sk_buff *igb_merge_active_tail(struct sk_buff *tail)
7403 struct sk_buff *head = IGB_CB(tail)->head;
7408 head->len += tail->len;
7409 head->data_len += tail->len;
7410 head->truesize += tail->len;
7412 IGB_CB(tail)->head = NULL;
7418 * igb_add_active_tail - adds an active tail into the skb frag_list
7419 * @head: pointer to the start of the skb
7420 * @tail: pointer to active tail to add to frag_list
7422 * This function adds an active tail to the end of the frag list. This tail
7423 * will still be receiving data so we cannot yet ad it's stats to the main
7424 * skb. That is done via igb_merge_active_tail.
7426 static inline void igb_add_active_tail(struct sk_buff *head, struct sk_buff *tail)
7428 struct sk_buff *old_tail = IGB_CB(head)->tail;
7431 igb_merge_active_tail(old_tail);
7432 old_tail->next = tail;
7434 skb_shinfo(head)->frag_list = tail;
7437 IGB_CB(tail)->head = head;
7438 IGB_CB(head)->tail = tail;
7440 IGB_CB(head)->append_cnt++;
7444 * igb_close_active_frag_list - cleanup pointers on a frag_list skb
7445 * @head: pointer to head of an active frag list
7447 * This function will clear the frag_tail_tracker pointer on an active
7448 * frag_list and returns true if the pointer was actually set
7450 static inline bool igb_close_active_frag_list(struct sk_buff *head)
7452 struct sk_buff *tail = IGB_CB(head)->tail;
7457 igb_merge_active_tail(tail);
7459 IGB_CB(head)->tail = NULL;
7464 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
7466 * igb_can_lro - returns true if packet is TCP/IPV4 and LRO is enabled
7467 * @adapter: board private structure
7468 * @rx_desc: pointer to the rx descriptor
7469 * @skb: pointer to the skb to be merged
7472 static inline bool igb_can_lro(struct igb_ring *rx_ring,
7473 union e1000_adv_rx_desc *rx_desc,
7474 struct sk_buff *skb)
7476 struct iphdr *iph = (struct iphdr *)skb->data;
7477 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
7479 /* verify hardware indicates this is IPv4/TCP */
7480 if((!(pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_TCP)) ||
7481 !(pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4))))
7484 /* .. and LRO is enabled */
7485 if (!(netdev_ring(rx_ring)->features & NETIF_F_LRO))
7488 /* .. and we are not in promiscuous mode */
7489 if (netdev_ring(rx_ring)->flags & IFF_PROMISC)
7492 /* .. and the header is large enough for us to read IP/TCP fields */
7493 if (!pskb_may_pull(skb, sizeof(struct igb_lrohdr)))
7496 /* .. and there are no VLANs on packet */
7497 if (skb->protocol != __constant_htons(ETH_P_IP))
7500 /* .. and we are version 4 with no options */
7501 if (*(u8 *)iph != 0x45)
7504 /* .. and the packet is not fragmented */
7505 if (iph->frag_off & htons(IP_MF | IP_OFFSET))
7508 /* .. and that next header is TCP */
7509 if (iph->protocol != IPPROTO_TCP)
7515 static inline struct igb_lrohdr *igb_lro_hdr(struct sk_buff *skb)
7517 return (struct igb_lrohdr *)skb->data;
7521 * igb_lro_flush - Indicate packets to upper layer.
7523 * Update IP and TCP header part of head skb if more than one
7524 * skb's chained and indicate packets to upper layer.
7526 static void igb_lro_flush(struct igb_q_vector *q_vector,
7527 struct sk_buff *skb)
7529 struct igb_lro_list *lrolist = &q_vector->lrolist;
7531 __skb_unlink(skb, &lrolist->active);
7533 if (IGB_CB(skb)->append_cnt) {
7534 struct igb_lrohdr *lroh = igb_lro_hdr(skb);
7536 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7537 /* close any active lro contexts */
7538 igb_close_active_frag_list(skb);
7541 /* incorporate ip header and re-calculate checksum */
7542 lroh->iph.tot_len = ntohs(skb->len);
7543 lroh->iph.check = 0;
7545 /* header length is 5 since we know no options exist */
7546 lroh->iph.check = ip_fast_csum((u8 *)lroh, 5);
7548 /* clear TCP checksum to indicate we are an LRO frame */
7551 /* incorporate latest timestamp into the tcp header */
7552 if (IGB_CB(skb)->tsecr) {
7553 lroh->ts[2] = IGB_CB(skb)->tsecr;
7554 lroh->ts[1] = htonl(IGB_CB(skb)->tsval);
7558 skb_shinfo(skb)->gso_size = IGB_CB(skb)->mss;
7559 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
7563 #ifdef HAVE_VLAN_RX_REGISTER
7564 igb_receive_skb(q_vector, skb);
7566 napi_gro_receive(&q_vector->napi, skb);
7568 lrolist->stats.flushed++;
7571 static void igb_lro_flush_all(struct igb_q_vector *q_vector)
7573 struct igb_lro_list *lrolist = &q_vector->lrolist;
7574 struct sk_buff *skb, *tmp;
7576 skb_queue_reverse_walk_safe(&lrolist->active, skb, tmp)
7577 igb_lro_flush(q_vector, skb);
7581 * igb_lro_header_ok - Main LRO function.
7583 static void igb_lro_header_ok(struct sk_buff *skb)
7585 struct igb_lrohdr *lroh = igb_lro_hdr(skb);
7586 u16 opt_bytes, data_len;
7588 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7589 IGB_CB(skb)->tail = NULL;
7591 IGB_CB(skb)->tsecr = 0;
7592 IGB_CB(skb)->append_cnt = 0;
7593 IGB_CB(skb)->mss = 0;
7595 /* ensure that the checksum is valid */
7596 if (skb->ip_summed != CHECKSUM_UNNECESSARY)
7599 /* If we see CE codepoint in IP header, packet is not mergeable */
7600 if (INET_ECN_is_ce(ipv4_get_dsfield(&lroh->iph)))
7603 /* ensure no bits set besides ack or psh */
7604 if (lroh->th.fin || lroh->th.syn || lroh->th.rst ||
7605 lroh->th.urg || lroh->th.ece || lroh->th.cwr ||
7609 /* store the total packet length */
7610 data_len = ntohs(lroh->iph.tot_len);
7612 /* remove any padding from the end of the skb */
7613 __pskb_trim(skb, data_len);
7615 /* remove header length from data length */
7616 data_len -= sizeof(struct igb_lrohdr);
7619 * check for timestamps. Since the only option we handle are timestamps,
7620 * we only have to handle the simple case of aligned timestamps
7622 opt_bytes = (lroh->th.doff << 2) - sizeof(struct tcphdr);
7623 if (opt_bytes != 0) {
7624 if ((opt_bytes != TCPOLEN_TSTAMP_ALIGNED) ||
7625 !pskb_may_pull(skb, sizeof(struct igb_lrohdr) +
7626 TCPOLEN_TSTAMP_ALIGNED) ||
7627 (lroh->ts[0] != htonl((TCPOPT_NOP << 24) |
7628 (TCPOPT_NOP << 16) |
7629 (TCPOPT_TIMESTAMP << 8) |
7630 TCPOLEN_TIMESTAMP)) ||
7631 (lroh->ts[2] == 0)) {
7635 IGB_CB(skb)->tsval = ntohl(lroh->ts[1]);
7636 IGB_CB(skb)->tsecr = lroh->ts[2];
7638 data_len -= TCPOLEN_TSTAMP_ALIGNED;
7641 /* record data_len as mss for the packet */
7642 IGB_CB(skb)->mss = data_len;
7643 IGB_CB(skb)->next_seq = ntohl(lroh->th.seq);
7646 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7647 static void igb_merge_frags(struct sk_buff *lro_skb, struct sk_buff *new_skb)
7649 struct skb_shared_info *sh_info;
7650 struct skb_shared_info *new_skb_info;
7651 unsigned int data_len;
7653 sh_info = skb_shinfo(lro_skb);
7654 new_skb_info = skb_shinfo(new_skb);
7656 /* copy frags into the last skb */
7657 memcpy(sh_info->frags + sh_info->nr_frags,
7658 new_skb_info->frags,
7659 new_skb_info->nr_frags * sizeof(skb_frag_t));
7661 /* copy size data over */
7662 sh_info->nr_frags += new_skb_info->nr_frags;
7663 data_len = IGB_CB(new_skb)->mss;
7664 lro_skb->len += data_len;
7665 lro_skb->data_len += data_len;
7666 lro_skb->truesize += data_len;
7668 /* wipe record of data from new_skb */
7669 new_skb_info->nr_frags = 0;
7670 new_skb->len = new_skb->data_len = 0;
7671 dev_kfree_skb_any(new_skb);
7674 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
7676 * igb_lro_receive - if able, queue skb into lro chain
7677 * @q_vector: structure containing interrupt and ring information
7678 * @new_skb: pointer to current skb being checked
7680 * Checks whether the skb given is eligible for LRO and if that's
7681 * fine chains it to the existing lro_skb based on flowid. If an LRO for
7682 * the flow doesn't exist create one.
7684 static void igb_lro_receive(struct igb_q_vector *q_vector,
7685 struct sk_buff *new_skb)
7687 struct sk_buff *lro_skb;
7688 struct igb_lro_list *lrolist = &q_vector->lrolist;
7689 struct igb_lrohdr *lroh = igb_lro_hdr(new_skb);
7690 __be32 saddr = lroh->iph.saddr;
7691 __be32 daddr = lroh->iph.daddr;
7692 __be32 tcp_ports = *(__be32 *)&lroh->th;
7694 #ifdef HAVE_VLAN_RX_REGISTER
7695 u16 vid = IGB_CB(new_skb)->vid;
7697 u16 vid = new_skb->vlan_tci;
7700 igb_lro_header_ok(new_skb);
7703 * we have a packet that might be eligible for LRO,
7704 * so see if it matches anything we might expect
7706 skb_queue_walk(&lrolist->active, lro_skb) {
7707 if (*(__be32 *)&igb_lro_hdr(lro_skb)->th != tcp_ports ||
7708 igb_lro_hdr(lro_skb)->iph.saddr != saddr ||
7709 igb_lro_hdr(lro_skb)->iph.daddr != daddr)
7712 #ifdef HAVE_VLAN_RX_REGISTER
7713 if (IGB_CB(lro_skb)->vid != vid)
7715 if (lro_skb->vlan_tci != vid)
7719 /* out of order packet */
7720 if (IGB_CB(lro_skb)->next_seq != IGB_CB(new_skb)->next_seq) {
7721 igb_lro_flush(q_vector, lro_skb);
7722 IGB_CB(new_skb)->mss = 0;
7726 /* TCP timestamp options have changed */
7727 if (!IGB_CB(lro_skb)->tsecr != !IGB_CB(new_skb)->tsecr) {
7728 igb_lro_flush(q_vector, lro_skb);
7732 /* make sure timestamp values are increasing */
7733 if (IGB_CB(lro_skb)->tsecr &&
7734 IGB_CB(lro_skb)->tsval > IGB_CB(new_skb)->tsval) {
7735 igb_lro_flush(q_vector, lro_skb);
7736 IGB_CB(new_skb)->mss = 0;
7740 data_len = IGB_CB(new_skb)->mss;
7742 /* Check for all of the above below
7745 * resultant packet would be too large
7746 * new skb is larger than our current mss
7747 * data would remain in header
7748 * we would consume more frags then the sk_buff contains
7749 * ack sequence numbers changed
7750 * window size has changed
7752 if (data_len == 0 ||
7753 data_len > IGB_CB(lro_skb)->mss ||
7754 data_len > IGB_CB(lro_skb)->free ||
7755 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7756 data_len != new_skb->data_len ||
7757 skb_shinfo(new_skb)->nr_frags >=
7758 (MAX_SKB_FRAGS - skb_shinfo(lro_skb)->nr_frags) ||
7760 igb_lro_hdr(lro_skb)->th.ack_seq != lroh->th.ack_seq ||
7761 igb_lro_hdr(lro_skb)->th.window != lroh->th.window) {
7762 igb_lro_flush(q_vector, lro_skb);
7766 /* Remove IP and TCP header*/
7767 skb_pull(new_skb, new_skb->len - data_len);
7769 /* update timestamp and timestamp echo response */
7770 IGB_CB(lro_skb)->tsval = IGB_CB(new_skb)->tsval;
7771 IGB_CB(lro_skb)->tsecr = IGB_CB(new_skb)->tsecr;
7773 /* update sequence and free space */
7774 IGB_CB(lro_skb)->next_seq += data_len;
7775 IGB_CB(lro_skb)->free -= data_len;
7777 /* update append_cnt */
7778 IGB_CB(lro_skb)->append_cnt++;
7780 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7781 /* if header is empty pull pages into current skb */
7782 igb_merge_frags(lro_skb, new_skb);
7784 /* chain this new skb in frag_list */
7785 igb_add_active_tail(lro_skb, new_skb);
7788 if ((data_len < IGB_CB(lro_skb)->mss) || lroh->th.psh ||
7789 skb_shinfo(lro_skb)->nr_frags == MAX_SKB_FRAGS) {
7790 igb_lro_hdr(lro_skb)->th.psh |= lroh->th.psh;
7791 igb_lro_flush(q_vector, lro_skb);
7794 lrolist->stats.coal++;
7798 if (IGB_CB(new_skb)->mss && !lroh->th.psh) {
7799 /* if we are at capacity flush the tail */
7800 if (skb_queue_len(&lrolist->active) >= IGB_LRO_MAX) {
7801 lro_skb = skb_peek_tail(&lrolist->active);
7803 igb_lro_flush(q_vector, lro_skb);
7806 /* update sequence and free space */
7807 IGB_CB(new_skb)->next_seq += IGB_CB(new_skb)->mss;
7808 IGB_CB(new_skb)->free = 65521 - new_skb->len;
7810 /* .. and insert at the front of the active list */
7811 __skb_queue_head(&lrolist->active, new_skb);
7813 lrolist->stats.coal++;
7817 /* packet not handled by any of the above, pass it to the stack */
7818 #ifdef HAVE_VLAN_RX_REGISTER
7819 igb_receive_skb(q_vector, new_skb);
7821 napi_gro_receive(&q_vector->napi, new_skb);
7825 #endif /* IGB_NO_LRO */
7827 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
7828 * @rx_ring: rx descriptor ring packet is being transacted on
7829 * @rx_desc: pointer to the EOP Rx descriptor
7830 * @skb: pointer to current skb being populated
7832 * This function checks the ring, descriptor, and packet information in
7833 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
7834 * other fields within the skb.
7836 static void igb_process_skb_fields(struct igb_ring *rx_ring,
7837 union e1000_adv_rx_desc *rx_desc,
7838 struct sk_buff *skb)
7840 struct net_device *dev = rx_ring->netdev;
7841 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
7843 #ifdef NETIF_F_RXHASH
7844 igb_rx_hash(rx_ring, rx_desc, skb);
7847 igb_rx_checksum(rx_ring, rx_desc, skb);
7849 /* update packet type stats */
7850 if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4))
7851 rx_ring->rx_stats.ipv4_packets++;
7852 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4_EX))
7853 rx_ring->rx_stats.ipv4e_packets++;
7854 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV6))
7855 rx_ring->rx_stats.ipv6_packets++;
7856 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV6_EX))
7857 rx_ring->rx_stats.ipv6e_packets++;
7858 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_TCP))
7859 rx_ring->rx_stats.tcp_packets++;
7860 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_UDP))
7861 rx_ring->rx_stats.udp_packets++;
7862 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_SCTP))
7863 rx_ring->rx_stats.sctp_packets++;
7864 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_NFS))
7865 rx_ring->rx_stats.nfs_packets++;
7867 #ifdef HAVE_PTP_1588_CLOCK
7868 igb_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
7869 #endif /* HAVE_PTP_1588_CLOCK */
7871 #ifdef NETIF_F_HW_VLAN_CTAG_RX
7872 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
7874 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
7876 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
7878 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
7879 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
7880 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
7882 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
7883 #ifdef HAVE_VLAN_RX_REGISTER
7884 IGB_CB(skb)->vid = vid;
7886 IGB_CB(skb)->vid = 0;
7889 #ifdef HAVE_VLAN_PROTOCOL
7890 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7892 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7899 skb_record_rx_queue(skb, rx_ring->queue_index);
7901 skb->protocol = eth_type_trans(skb, dev);
7905 * igb_is_non_eop - process handling of non-EOP buffers
7906 * @rx_ring: Rx ring being processed
7907 * @rx_desc: Rx descriptor for current buffer
7909 * This function updates next to clean. If the buffer is an EOP buffer
7910 * this function exits returning false, otherwise it will place the
7911 * sk_buff in the next buffer to be chained and return true indicating
7912 * that this is in fact a non-EOP buffer.
7914 static bool igb_is_non_eop(struct igb_ring *rx_ring,
7915 union e1000_adv_rx_desc *rx_desc)
7917 u32 ntc = rx_ring->next_to_clean + 1;
7919 /* fetch, update, and store next to clean */
7920 ntc = (ntc < rx_ring->count) ? ntc : 0;
7921 rx_ring->next_to_clean = ntc;
7923 prefetch(IGB_RX_DESC(rx_ring, ntc));
7925 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
7931 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7932 /* igb_clean_rx_irq -- * legacy */
7933 static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
7935 struct igb_ring *rx_ring = q_vector->rx.ring;
7936 unsigned int total_bytes = 0, total_packets = 0;
7937 u16 cleaned_count = igb_desc_unused(rx_ring);
7940 struct igb_rx_buffer *rx_buffer;
7941 union e1000_adv_rx_desc *rx_desc;
7942 struct sk_buff *skb;
7945 /* return some buffers to hardware, one at a time is too slow */
7946 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
7947 igb_alloc_rx_buffers(rx_ring, cleaned_count);
7951 ntc = rx_ring->next_to_clean;
7952 rx_desc = IGB_RX_DESC(rx_ring, ntc);
7953 rx_buffer = &rx_ring->rx_buffer_info[ntc];
7955 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
7959 * This memory barrier is needed to keep us from reading
7960 * any other fields out of the rx_desc until we know the
7961 * RXD_STAT_DD bit is set
7965 skb = rx_buffer->skb;
7967 prefetch(skb->data);
7969 /* pull the header of the skb in */
7970 __skb_put(skb, le16_to_cpu(rx_desc->wb.upper.length));
7972 /* clear skb reference in buffer info structure */
7973 rx_buffer->skb = NULL;
7977 BUG_ON(igb_is_non_eop(rx_ring, rx_desc));
7979 dma_unmap_single(rx_ring->dev, rx_buffer->dma,
7980 rx_ring->rx_buffer_len,
7984 if (igb_test_staterr(rx_desc,
7985 E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
7986 dev_kfree_skb_any(skb);
7990 total_bytes += skb->len;
7992 /* populate checksum, timestamp, VLAN, and protocol */
7993 igb_process_skb_fields(rx_ring, rx_desc, skb);
7996 if (igb_can_lro(rx_ring, rx_desc, skb))
7997 igb_lro_receive(q_vector, skb);
8000 #ifdef HAVE_VLAN_RX_REGISTER
8001 igb_receive_skb(q_vector, skb);
8003 napi_gro_receive(&q_vector->napi, skb);
8007 netdev_ring(rx_ring)->last_rx = jiffies;
8010 /* update budget accounting */
8012 } while (likely(total_packets < budget));
8014 rx_ring->rx_stats.packets += total_packets;
8015 rx_ring->rx_stats.bytes += total_bytes;
8016 q_vector->rx.total_packets += total_packets;
8017 q_vector->rx.total_bytes += total_bytes;
8020 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8023 igb_lro_flush_all(q_vector);
8025 #endif /* IGB_NO_LRO */
8026 return (total_packets < budget);
8028 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8030 * igb_get_headlen - determine size of header for LRO/GRO
8031 * @data: pointer to the start of the headers
8032 * @max_len: total length of section to find headers in
8034 * This function is meant to determine the length of headers that will
8035 * be recognized by hardware for LRO, and GRO offloads. The main
8036 * motivation of doing this is to only perform one pull for IPv4 TCP
8037 * packets so that we can do basic things like calculating the gso_size
8038 * based on the average data per packet.
8040 static unsigned int igb_get_headlen(unsigned char *data,
8041 unsigned int max_len)
8044 unsigned char *network;
8047 struct vlan_hdr *vlan;
8050 struct ipv6hdr *ipv6;
8053 u8 nexthdr = 0; /* default to not TCP */
8056 /* this should never happen, but better safe than sorry */
8057 if (max_len < ETH_HLEN)
8060 /* initialize network frame pointer */
8063 /* set first protocol and move network header forward */
8064 protocol = hdr.eth->h_proto;
8065 hdr.network += ETH_HLEN;
8067 /* handle any vlan tag if present */
8068 if (protocol == __constant_htons(ETH_P_8021Q)) {
8069 if ((hdr.network - data) > (max_len - VLAN_HLEN))
8072 protocol = hdr.vlan->h_vlan_encapsulated_proto;
8073 hdr.network += VLAN_HLEN;
8076 /* handle L3 protocols */
8077 if (protocol == __constant_htons(ETH_P_IP)) {
8078 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
8081 /* access ihl as a u8 to avoid unaligned access on ia64 */
8082 hlen = (hdr.network[0] & 0x0F) << 2;
8084 /* verify hlen meets minimum size requirements */
8085 if (hlen < sizeof(struct iphdr))
8086 return hdr.network - data;
8088 /* record next protocol if header is present */
8089 if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
8090 nexthdr = hdr.ipv4->protocol;
8092 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
8093 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
8096 /* record next protocol */
8097 nexthdr = hdr.ipv6->nexthdr;
8098 hlen = sizeof(struct ipv6hdr);
8099 #endif /* NETIF_F_TSO6 */
8101 return hdr.network - data;
8104 /* relocate pointer to start of L4 header */
8105 hdr.network += hlen;
8107 /* finally sort out TCP */
8108 if (nexthdr == IPPROTO_TCP) {
8109 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
8112 /* access doff as a u8 to avoid unaligned access on ia64 */
8113 hlen = (hdr.network[12] & 0xF0) >> 2;
8115 /* verify hlen meets minimum size requirements */
8116 if (hlen < sizeof(struct tcphdr))
8117 return hdr.network - data;
8119 hdr.network += hlen;
8120 } else if (nexthdr == IPPROTO_UDP) {
8121 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
8124 hdr.network += sizeof(struct udphdr);
8128 * If everything has gone correctly hdr.network should be the
8129 * data section of the packet and will be the end of the header.
8130 * If not then it probably represents the end of the last recognized
8133 if ((hdr.network - data) < max_len)
8134 return hdr.network - data;
8140 * igb_pull_tail - igb specific version of skb_pull_tail
8141 * @rx_ring: rx descriptor ring packet is being transacted on
8142 * @rx_desc: pointer to the EOP Rx descriptor
8143 * @skb: pointer to current skb being adjusted
8145 * This function is an igb specific version of __pskb_pull_tail. The
8146 * main difference between this version and the original function is that
8147 * this function can make several assumptions about the state of things
8148 * that allow for significant optimizations versus the standard function.
8149 * As a result we can do things like drop a frag and maintain an accurate
8150 * truesize for the skb.
8152 static void igb_pull_tail(struct igb_ring *rx_ring,
8153 union e1000_adv_rx_desc *rx_desc,
8154 struct sk_buff *skb)
8156 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
8158 unsigned int pull_len;
8161 * it is valid to use page_address instead of kmap since we are
8162 * working with pages allocated out of the lomem pool per
8163 * alloc_page(GFP_ATOMIC)
8165 va = skb_frag_address(frag);
8167 #ifdef HAVE_PTP_1588_CLOCK
8168 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
8169 /* retrieve timestamp from buffer */
8170 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
8172 /* update pointers to remove timestamp header */
8173 skb_frag_size_sub(frag, IGB_TS_HDR_LEN);
8174 frag->page_offset += IGB_TS_HDR_LEN;
8175 skb->data_len -= IGB_TS_HDR_LEN;
8176 skb->len -= IGB_TS_HDR_LEN;
8178 /* move va to start of packet data */
8179 va += IGB_TS_HDR_LEN;
8181 #endif /* HAVE_PTP_1588_CLOCK */
8184 * we need the header to contain the greater of either ETH_HLEN or
8185 * 60 bytes if the skb->len is less than 60 for skb_pad.
8187 pull_len = igb_get_headlen(va, IGB_RX_HDR_LEN);
8189 /* align pull length to size of long to optimize memcpy performance */
8190 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
8192 /* update all of the pointers */
8193 skb_frag_size_sub(frag, pull_len);
8194 frag->page_offset += pull_len;
8195 skb->data_len -= pull_len;
8196 skb->tail += pull_len;
8200 * igb_cleanup_headers - Correct corrupted or empty headers
8201 * @rx_ring: rx descriptor ring packet is being transacted on
8202 * @rx_desc: pointer to the EOP Rx descriptor
8203 * @skb: pointer to current skb being fixed
8205 * Address the case where we are pulling data in on pages only
8206 * and as such no data is present in the skb header.
8208 * In addition if skb is not at least 60 bytes we need to pad it so that
8209 * it is large enough to qualify as a valid Ethernet frame.
8211 * Returns true if an error was encountered and skb was freed.
8213 static bool igb_cleanup_headers(struct igb_ring *rx_ring,
8214 union e1000_adv_rx_desc *rx_desc,
8215 struct sk_buff *skb)
8218 if (unlikely((igb_test_staterr(rx_desc,
8219 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
8220 struct net_device *netdev = rx_ring->netdev;
8221 if (!(netdev->features & NETIF_F_RXALL)) {
8222 dev_kfree_skb_any(skb);
8227 /* place header in linear portion of buffer */
8228 if (skb_is_nonlinear(skb))
8229 igb_pull_tail(rx_ring, rx_desc, skb);
8231 /* if skb_pad returns an error the skb was freed */
8232 if (unlikely(skb->len < 60)) {
8233 int pad_len = 60 - skb->len;
8235 if (skb_pad(skb, pad_len))
8237 __skb_put(skb, pad_len);
8243 /* igb_clean_rx_irq -- * packet split */
8244 static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
8246 struct igb_ring *rx_ring = q_vector->rx.ring;
8247 struct sk_buff *skb = rx_ring->skb;
8248 unsigned int total_bytes = 0, total_packets = 0;
8249 u16 cleaned_count = igb_desc_unused(rx_ring);
8252 union e1000_adv_rx_desc *rx_desc;
8254 /* return some buffers to hardware, one at a time is too slow */
8255 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
8256 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8260 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
8262 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
8266 * This memory barrier is needed to keep us from reading
8267 * any other fields out of the rx_desc until we know the
8268 * RXD_STAT_DD bit is set
8272 /* retrieve a buffer from the ring */
8273 skb = igb_fetch_rx_buffer(rx_ring, rx_desc, skb);
8275 /* exit if we failed to retrieve a buffer */
8281 /* fetch next buffer in frame if non-eop */
8282 if (igb_is_non_eop(rx_ring, rx_desc))
8285 /* verify the packet layout is correct */
8286 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
8291 /* probably a little skewed due to removing CRC */
8292 total_bytes += skb->len;
8294 /* populate checksum, timestamp, VLAN, and protocol */
8295 igb_process_skb_fields(rx_ring, rx_desc, skb);
8298 if (igb_can_lro(rx_ring, rx_desc, skb))
8299 igb_lro_receive(q_vector, skb);
8302 #ifdef HAVE_VLAN_RX_REGISTER
8303 igb_receive_skb(q_vector, skb);
8305 napi_gro_receive(&q_vector->napi, skb);
8309 netdev_ring(rx_ring)->last_rx = jiffies;
8312 /* reset skb pointer */
8315 /* update budget accounting */
8317 } while (likely(total_packets < budget));
8319 /* place incomplete frames back on ring for completion */
8322 rx_ring->rx_stats.packets += total_packets;
8323 rx_ring->rx_stats.bytes += total_bytes;
8324 q_vector->rx.total_packets += total_packets;
8325 q_vector->rx.total_bytes += total_bytes;
8328 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8331 igb_lro_flush_all(q_vector);
8333 #endif /* IGB_NO_LRO */
8334 return (total_packets < budget);
8336 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8338 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8339 static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring,
8340 struct igb_rx_buffer *bi)
8342 struct sk_buff *skb = bi->skb;
8343 dma_addr_t dma = bi->dma;
8349 skb = netdev_alloc_skb_ip_align(netdev_ring(rx_ring),
8350 rx_ring->rx_buffer_len);
8353 rx_ring->rx_stats.alloc_failed++;
8357 /* initialize skb for ring */
8358 skb_record_rx_queue(skb, ring_queue_index(rx_ring));
8361 dma = dma_map_single(rx_ring->dev, skb->data,
8362 rx_ring->rx_buffer_len, DMA_FROM_DEVICE);
8364 /* if mapping failed free memory back to system since
8365 * there isn't much point in holding memory we can't use
8367 if (dma_mapping_error(rx_ring->dev, dma)) {
8368 dev_kfree_skb_any(skb);
8371 rx_ring->rx_stats.alloc_failed++;
8379 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8380 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
8381 struct igb_rx_buffer *bi)
8383 struct page *page = bi->page;
8386 /* since we are recycling buffers we should seldom need to alloc */
8390 /* alloc new page for storage */
8391 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
8392 if (unlikely(!page)) {
8393 rx_ring->rx_stats.alloc_failed++;
8397 /* map page for use */
8398 dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
8401 * if mapping failed free memory back to system since
8402 * there isn't much point in holding memory we can't use
8404 if (dma_mapping_error(rx_ring->dev, dma)) {
8407 rx_ring->rx_stats.alloc_failed++;
8413 bi->page_offset = 0;
8418 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8420 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
8421 * @adapter: address of board private structure
8423 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
8425 union e1000_adv_rx_desc *rx_desc;
8426 struct igb_rx_buffer *bi;
8427 u16 i = rx_ring->next_to_use;
8433 rx_desc = IGB_RX_DESC(rx_ring, i);
8434 bi = &rx_ring->rx_buffer_info[i];
8435 i -= rx_ring->count;
8438 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8439 if (!igb_alloc_mapped_skb(rx_ring, bi))
8441 if (!igb_alloc_mapped_page(rx_ring, bi))
8442 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8446 * Refresh the desc even if buffer_addrs didn't change
8447 * because each write-back erases this info.
8449 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8450 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
8452 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
8459 rx_desc = IGB_RX_DESC(rx_ring, 0);
8460 bi = rx_ring->rx_buffer_info;
8461 i -= rx_ring->count;
8464 /* clear the hdr_addr for the next_to_use descriptor */
8465 rx_desc->read.hdr_addr = 0;
8468 } while (cleaned_count);
8470 i += rx_ring->count;
8472 if (rx_ring->next_to_use != i) {
8473 /* record the next descriptor to use */
8474 rx_ring->next_to_use = i;
8476 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
8477 /* update next to alloc since we have filled the ring */
8478 rx_ring->next_to_alloc = i;
8482 * Force memory writes to complete before letting h/w
8483 * know there are new descriptors to fetch. (Only
8484 * applicable for weak-ordered memory model archs,
8488 writel(i, rx_ring->tail);
8499 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8501 struct igb_adapter *adapter = netdev_priv(netdev);
8502 struct mii_ioctl_data *data = if_mii(ifr);
8504 if (adapter->hw.phy.media_type != e1000_media_type_copper)
8509 data->phy_id = adapter->hw.phy.addr;
8512 if (!capable(CAP_NET_ADMIN))
8514 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
8522 return E1000_SUCCESS;
8532 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8539 return igb_mii_ioctl(netdev, ifr, cmd);
8541 #ifdef HAVE_PTP_1588_CLOCK
8543 return igb_ptp_hwtstamp_ioctl(netdev, ifr, cmd);
8544 #endif /* HAVE_PTP_1588_CLOCK */
8545 #ifdef ETHTOOL_OPS_COMPAT
8547 return ethtool_ioctl(ifr);
8554 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8556 struct igb_adapter *adapter = hw->back;
8559 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
8561 return -E1000_ERR_CONFIG;
8563 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
8565 return E1000_SUCCESS;
8568 s32 e1000_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8570 struct igb_adapter *adapter = hw->back;
8573 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
8575 return -E1000_ERR_CONFIG;
8577 pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
8579 return E1000_SUCCESS;
8582 #ifdef HAVE_VLAN_RX_REGISTER
8583 static void igb_vlan_mode(struct net_device *netdev, struct vlan_group *vlgrp)
8585 void igb_vlan_mode(struct net_device *netdev, u32 features)
8588 struct igb_adapter *adapter = netdev_priv(netdev);
8589 struct e1000_hw *hw = &adapter->hw;
8592 #ifdef HAVE_VLAN_RX_REGISTER
8593 bool enable = !!vlgrp;
8595 igb_irq_disable(adapter);
8597 adapter->vlgrp = vlgrp;
8599 if (!test_bit(__IGB_DOWN, &adapter->state))
8600 igb_irq_enable(adapter);
8602 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8603 bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
8605 bool enable = !!(features & NETIF_F_HW_VLAN_RX);
8610 /* enable VLAN tag insert/strip */
8611 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8612 ctrl |= E1000_CTRL_VME;
8613 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8615 /* Disable CFI check */
8616 rctl = E1000_READ_REG(hw, E1000_RCTL);
8617 rctl &= ~E1000_RCTL_CFIEN;
8618 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
8620 /* disable VLAN tag insert/strip */
8621 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8622 ctrl &= ~E1000_CTRL_VME;
8623 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8626 #ifndef CONFIG_IGB_VMDQ_NETDEV
8627 for (i = 0; i < adapter->vmdq_pools; i++) {
8628 igb_set_vf_vlan_strip(adapter,
8629 adapter->vfs_allocated_count + i,
8634 igb_set_vf_vlan_strip(adapter,
8635 adapter->vfs_allocated_count,
8638 for (i = 1; i < adapter->vmdq_pools; i++) {
8639 #ifdef HAVE_VLAN_RX_REGISTER
8640 struct igb_vmdq_adapter *vadapter;
8641 vadapter = netdev_priv(adapter->vmdq_netdev[i-1]);
8642 enable = !!vadapter->vlgrp;
8644 struct net_device *vnetdev;
8645 vnetdev = adapter->vmdq_netdev[i-1];
8646 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8647 enable = !!(vnetdev->features & NETIF_F_HW_VLAN_CTAG_RX);
8649 enable = !!(vnetdev->features & NETIF_F_HW_VLAN_RX);
8652 igb_set_vf_vlan_strip(adapter,
8653 adapter->vfs_allocated_count + i,
8658 igb_rlpml_set(adapter);
8661 #ifdef HAVE_VLAN_PROTOCOL
8662 static int igb_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
8663 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
8664 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8665 static int igb_vlan_rx_add_vid(struct net_device *netdev,
8666 __always_unused __be16 proto, u16 vid)
8668 static int igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
8671 static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
8674 struct igb_adapter *adapter = netdev_priv(netdev);
8675 int pf_id = adapter->vfs_allocated_count;
8677 /* attempt to add filter to vlvf array */
8678 igb_vlvf_set(adapter, vid, TRUE, pf_id);
8680 /* add the filter since PF can receive vlans w/o entry in vlvf */
8681 igb_vfta_set(adapter, vid, TRUE);
8682 #ifndef HAVE_NETDEV_VLAN_FEATURES
8684 /* Copy feature flags from netdev to the vlan netdev for this vid.
8685 * This allows things like TSO to bubble down to our vlan device.
8686 * There is no need to update netdev for vlan 0 (DCB), since it
8687 * wouldn't has v_netdev.
8689 if (adapter->vlgrp) {
8690 struct vlan_group *vlgrp = adapter->vlgrp;
8691 struct net_device *v_netdev = vlan_group_get_device(vlgrp, vid);
8693 v_netdev->features |= netdev->features;
8694 vlan_group_set_device(vlgrp, vid, v_netdev);
8698 #ifndef HAVE_VLAN_RX_REGISTER
8700 set_bit(vid, adapter->active_vlans);
8702 #ifdef HAVE_INT_NDO_VLAN_RX_ADD_VID
8707 #ifdef HAVE_VLAN_PROTOCOL
8708 static int igb_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
8709 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
8710 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8711 static int igb_vlan_rx_kill_vid(struct net_device *netdev,
8712 __always_unused __be16 proto, u16 vid)
8714 static int igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
8717 static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
8720 struct igb_adapter *adapter = netdev_priv(netdev);
8721 int pf_id = adapter->vfs_allocated_count;
8724 #ifdef HAVE_VLAN_RX_REGISTER
8725 igb_irq_disable(adapter);
8727 vlan_group_set_device(adapter->vlgrp, vid, NULL);
8729 if (!test_bit(__IGB_DOWN, &adapter->state))
8730 igb_irq_enable(adapter);
8732 #endif /* HAVE_VLAN_RX_REGISTER */
8733 /* remove vlan from VLVF table array */
8734 err = igb_vlvf_set(adapter, vid, FALSE, pf_id);
8736 /* if vid was not present in VLVF just remove it from table */
8738 igb_vfta_set(adapter, vid, FALSE);
8739 #ifndef HAVE_VLAN_RX_REGISTER
8741 clear_bit(vid, adapter->active_vlans);
8743 #ifdef HAVE_INT_NDO_VLAN_RX_ADD_VID
8748 static void igb_restore_vlan(struct igb_adapter *adapter)
8750 #ifdef HAVE_VLAN_RX_REGISTER
8751 igb_vlan_mode(adapter->netdev, adapter->vlgrp);
8753 if (adapter->vlgrp) {
8755 for (vid = 0; vid < VLAN_N_VID; vid++) {
8756 if (!vlan_group_get_device(adapter->vlgrp, vid))
8758 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8759 igb_vlan_rx_add_vid(adapter->netdev,
8760 htons(ETH_P_8021Q), vid);
8762 igb_vlan_rx_add_vid(adapter->netdev, vid);
8769 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
8771 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
8772 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8773 igb_vlan_rx_add_vid(adapter->netdev,
8774 htons(ETH_P_8021Q), vid);
8776 igb_vlan_rx_add_vid(adapter->netdev, vid);
8781 int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
8783 struct pci_dev *pdev = adapter->pdev;
8784 struct e1000_mac_info *mac = &adapter->hw.mac;
8788 /* SerDes device's does not support 10Mbps Full/duplex
8789 * and 100Mbps Half duplex
8791 if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
8793 case SPEED_10 + DUPLEX_HALF:
8794 case SPEED_10 + DUPLEX_FULL:
8795 case SPEED_100 + DUPLEX_HALF:
8796 dev_err(pci_dev_to_dev(pdev),
8797 "Unsupported Speed/Duplex configuration\n");
8805 case SPEED_10 + DUPLEX_HALF:
8806 mac->forced_speed_duplex = ADVERTISE_10_HALF;
8808 case SPEED_10 + DUPLEX_FULL:
8809 mac->forced_speed_duplex = ADVERTISE_10_FULL;
8811 case SPEED_100 + DUPLEX_HALF:
8812 mac->forced_speed_duplex = ADVERTISE_100_HALF;
8814 case SPEED_100 + DUPLEX_FULL:
8815 mac->forced_speed_duplex = ADVERTISE_100_FULL;
8817 case SPEED_1000 + DUPLEX_FULL:
8819 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
8821 case SPEED_1000 + DUPLEX_HALF: /* not supported */
8823 dev_err(pci_dev_to_dev(pdev), "Unsupported Speed/Duplex configuration\n");
8827 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
8828 adapter->hw.phy.mdix = AUTO_ALL_MODES;
8833 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
8836 struct net_device *netdev = pci_get_drvdata(pdev);
8837 struct igb_adapter *adapter = netdev_priv(netdev);
8838 struct e1000_hw *hw = &adapter->hw;
8839 u32 ctrl, rctl, status;
8840 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
8845 netif_device_detach(netdev);
8847 status = E1000_READ_REG(hw, E1000_STATUS);
8848 if (status & E1000_STATUS_LU)
8849 wufc &= ~E1000_WUFC_LNKC;
8851 if (netif_running(netdev))
8852 __igb_close(netdev, true);
8854 igb_clear_interrupt_scheme(adapter);
8857 retval = pci_save_state(pdev);
8863 igb_setup_rctl(adapter);
8864 igb_set_rx_mode(netdev);
8866 /* turn on all-multi mode if wake on multicast is enabled */
8867 if (wufc & E1000_WUFC_MC) {
8868 rctl = E1000_READ_REG(hw, E1000_RCTL);
8869 rctl |= E1000_RCTL_MPE;
8870 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
8873 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8874 /* phy power management enable */
8875 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
8876 ctrl |= E1000_CTRL_ADVD3WUC;
8877 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8879 /* Allow time for pending master requests to run */
8880 e1000_disable_pcie_master(hw);
8882 E1000_WRITE_REG(hw, E1000_WUC, E1000_WUC_PME_EN);
8883 E1000_WRITE_REG(hw, E1000_WUFC, wufc);
8885 E1000_WRITE_REG(hw, E1000_WUC, 0);
8886 E1000_WRITE_REG(hw, E1000_WUFC, 0);
8889 *enable_wake = wufc || adapter->en_mng_pt;
8891 igb_power_down_link(adapter);
8893 igb_power_up_link(adapter);
8895 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8896 * would have already happened in close and is redundant. */
8897 igb_release_hw_control(adapter);
8899 pci_disable_device(pdev);
8905 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8906 static int igb_suspend(struct device *dev)
8908 static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
8909 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8911 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8912 struct pci_dev *pdev = to_pci_dev(dev);
8913 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8917 retval = __igb_shutdown(pdev, &wake, 0);
8922 pci_prepare_to_sleep(pdev);
8924 pci_wake_from_d3(pdev, false);
8925 pci_set_power_state(pdev, PCI_D3hot);
8931 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8932 static int igb_resume(struct device *dev)
8934 static int igb_resume(struct pci_dev *pdev)
8935 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8937 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8938 struct pci_dev *pdev = to_pci_dev(dev);
8939 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8940 struct net_device *netdev = pci_get_drvdata(pdev);
8941 struct igb_adapter *adapter = netdev_priv(netdev);
8942 struct e1000_hw *hw = &adapter->hw;
8945 pci_set_power_state(pdev, PCI_D0);
8946 pci_restore_state(pdev);
8947 pci_save_state(pdev);
8949 err = pci_enable_device_mem(pdev);
8951 dev_err(pci_dev_to_dev(pdev),
8952 "igb: Cannot enable PCI device from suspend\n");
8955 pci_set_master(pdev);
8957 pci_enable_wake(pdev, PCI_D3hot, 0);
8958 pci_enable_wake(pdev, PCI_D3cold, 0);
8960 if (igb_init_interrupt_scheme(adapter, true)) {
8961 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for queues\n");
8967 /* let the f/w know that the h/w is now under the control of the
8969 igb_get_hw_control(adapter);
8971 E1000_WRITE_REG(hw, E1000_WUS, ~0);
8973 if (netdev->flags & IFF_UP) {
8975 err = __igb_open(netdev, true);
8981 netif_device_attach(netdev);
8986 #ifdef CONFIG_PM_RUNTIME
8987 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8988 static int igb_runtime_idle(struct device *dev)
8990 struct pci_dev *pdev = to_pci_dev(dev);
8991 struct net_device *netdev = pci_get_drvdata(pdev);
8992 struct igb_adapter *adapter = netdev_priv(netdev);
8994 if (!igb_has_link(adapter))
8995 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
9000 static int igb_runtime_suspend(struct device *dev)
9002 struct pci_dev *pdev = to_pci_dev(dev);
9006 retval = __igb_shutdown(pdev, &wake, 1);
9011 pci_prepare_to_sleep(pdev);
9013 pci_wake_from_d3(pdev, false);
9014 pci_set_power_state(pdev, PCI_D3hot);
9020 static int igb_runtime_resume(struct device *dev)
9022 return igb_resume(dev);
9024 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
9025 #endif /* CONFIG_PM_RUNTIME */
9026 #endif /* CONFIG_PM */
9028 #ifdef USE_REBOOT_NOTIFIER
9029 /* only want to do this for 2.4 kernels? */
9030 static int igb_notify_reboot(struct notifier_block *nb, unsigned long event,
9033 struct pci_dev *pdev = NULL;
9040 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
9041 if (pci_dev_driver(pdev) == &igb_driver) {
9042 __igb_shutdown(pdev, &wake, 0);
9043 if (event == SYS_POWER_OFF) {
9044 pci_wake_from_d3(pdev, wake);
9045 pci_set_power_state(pdev, PCI_D3hot);
9053 static void igb_shutdown(struct pci_dev *pdev)
9057 __igb_shutdown(pdev, &wake, 0);
9059 if (system_state == SYSTEM_POWER_OFF) {
9060 pci_wake_from_d3(pdev, wake);
9061 pci_set_power_state(pdev, PCI_D3hot);
9064 #endif /* USE_REBOOT_NOTIFIER */
9066 #ifdef CONFIG_NET_POLL_CONTROLLER
9068 * Polling 'interrupt' - used by things like netconsole to send skbs
9069 * without having to re-enable interrupts. It's not called while
9070 * the interrupt routine is executing.
9072 static void igb_netpoll(struct net_device *netdev)
9074 struct igb_adapter *adapter = netdev_priv(netdev);
9075 struct e1000_hw *hw = &adapter->hw;
9076 struct igb_q_vector *q_vector;
9079 for (i = 0; i < adapter->num_q_vectors; i++) {
9080 q_vector = adapter->q_vector[i];
9081 if (adapter->msix_entries)
9082 E1000_WRITE_REG(hw, E1000_EIMC, q_vector->eims_value);
9084 igb_irq_disable(adapter);
9085 napi_schedule(&q_vector->napi);
9088 #endif /* CONFIG_NET_POLL_CONTROLLER */
9091 #define E1000_DEV_ID_82576_VF 0x10CA
9093 * igb_io_error_detected - called when PCI error is detected
9094 * @pdev: Pointer to PCI device
9095 * @state: The current pci connection state
9097 * This function is called after a PCI bus error affecting
9098 * this device has been detected.
9100 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
9101 pci_channel_state_t state)
9103 struct net_device *netdev = pci_get_drvdata(pdev);
9104 struct igb_adapter *adapter = netdev_priv(netdev);
9106 #ifdef CONFIG_PCI_IOV__UNUSED
9107 struct pci_dev *bdev, *vfdev;
9108 u32 dw0, dw1, dw2, dw3;
9110 u16 req_id, pf_func;
9112 if (!(adapter->flags & IGB_FLAG_DETECT_BAD_DMA))
9113 goto skip_bad_vf_detection;
9115 bdev = pdev->bus->self;
9116 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
9117 bdev = bdev->bus->self;
9120 goto skip_bad_vf_detection;
9122 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
9124 goto skip_bad_vf_detection;
9126 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
9127 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
9128 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
9129 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
9132 /* On the 82576 if bit 7 of the requestor ID is set then it's a VF */
9133 if (!(req_id & 0x0080))
9134 goto skip_bad_vf_detection;
9136 pf_func = req_id & 0x01;
9137 if ((pf_func & 1) == (pdev->devfn & 1)) {
9139 vf = (req_id & 0x7F) >> 1;
9140 dev_err(pci_dev_to_dev(pdev),
9141 "VF %d has caused a PCIe error\n", vf);
9142 dev_err(pci_dev_to_dev(pdev),
9143 "TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9144 "%8.8x\tdw3: %8.8x\n",
9145 dw0, dw1, dw2, dw3);
9147 /* Find the pci device of the offending VF */
9148 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
9149 E1000_DEV_ID_82576_VF, NULL);
9151 if (vfdev->devfn == (req_id & 0xFF))
9153 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
9154 E1000_DEV_ID_82576_VF, vfdev);
9157 * There's a slim chance the VF could have been hot plugged,
9158 * so if it is no longer present we don't need to issue the
9159 * VFLR. Just clean up the AER in that case.
9162 dev_err(pci_dev_to_dev(pdev),
9163 "Issuing VFLR to VF %d\n", vf);
9164 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
9167 pci_cleanup_aer_uncorrect_error_status(pdev);
9171 * Even though the error may have occurred on the other port
9172 * we still need to increment the vf error reference count for
9173 * both ports because the I/O resume function will be called
9176 adapter->vferr_refcount++;
9178 return PCI_ERS_RESULT_RECOVERED;
9180 skip_bad_vf_detection:
9181 #endif /* CONFIG_PCI_IOV */
9183 netif_device_detach(netdev);
9185 if (state == pci_channel_io_perm_failure)
9186 return PCI_ERS_RESULT_DISCONNECT;
9188 if (netif_running(netdev))
9190 pci_disable_device(pdev);
9192 /* Request a slot slot reset. */
9193 return PCI_ERS_RESULT_NEED_RESET;
9197 * igb_io_slot_reset - called after the pci bus has been reset.
9198 * @pdev: Pointer to PCI device
9200 * Restart the card from scratch, as if from a cold-boot. Implementation
9201 * resembles the first-half of the igb_resume routine.
9203 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
9205 struct net_device *netdev = pci_get_drvdata(pdev);
9206 struct igb_adapter *adapter = netdev_priv(netdev);
9207 struct e1000_hw *hw = &adapter->hw;
9208 pci_ers_result_t result;
9210 if (pci_enable_device_mem(pdev)) {
9211 dev_err(pci_dev_to_dev(pdev),
9212 "Cannot re-enable PCI device after reset.\n");
9213 result = PCI_ERS_RESULT_DISCONNECT;
9215 pci_set_master(pdev);
9216 pci_restore_state(pdev);
9217 pci_save_state(pdev);
9219 pci_enable_wake(pdev, PCI_D3hot, 0);
9220 pci_enable_wake(pdev, PCI_D3cold, 0);
9222 schedule_work(&adapter->reset_task);
9223 E1000_WRITE_REG(hw, E1000_WUS, ~0);
9224 result = PCI_ERS_RESULT_RECOVERED;
9227 pci_cleanup_aer_uncorrect_error_status(pdev);
9233 * igb_io_resume - called when traffic can start flowing again.
9234 * @pdev: Pointer to PCI device
9236 * This callback is called when the error recovery driver tells us that
9237 * its OK to resume normal operation. Implementation resembles the
9238 * second-half of the igb_resume routine.
9240 static void igb_io_resume(struct pci_dev *pdev)
9242 struct net_device *netdev = pci_get_drvdata(pdev);
9243 struct igb_adapter *adapter = netdev_priv(netdev);
9245 if (adapter->vferr_refcount) {
9246 dev_info(pci_dev_to_dev(pdev), "Resuming after VF err\n");
9247 adapter->vferr_refcount--;
9251 if (netif_running(netdev)) {
9252 if (igb_up(adapter)) {
9253 dev_err(pci_dev_to_dev(pdev), "igb_up failed after reset\n");
9258 netif_device_attach(netdev);
9260 /* let the f/w know that the h/w is now under the control of the
9262 igb_get_hw_control(adapter);
9265 #endif /* HAVE_PCI_ERS */
9267 int igb_add_mac_filter(struct igb_adapter *adapter, u8 *addr, u16 queue)
9269 struct e1000_hw *hw = &adapter->hw;
9272 if (is_zero_ether_addr(addr))
9275 for (i = 0; i < hw->mac.rar_entry_count; i++) {
9276 if (adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE)
9278 adapter->mac_table[i].state = (IGB_MAC_STATE_MODIFIED |
9279 IGB_MAC_STATE_IN_USE);
9280 memcpy(adapter->mac_table[i].addr, addr, ETH_ALEN);
9281 adapter->mac_table[i].queue = queue;
9282 igb_sync_mac_table(adapter);
9287 int igb_del_mac_filter(struct igb_adapter *adapter, u8* addr, u16 queue)
9289 /* search table for addr, if found, set to 0 and sync */
9291 struct e1000_hw *hw = &adapter->hw;
9293 if (is_zero_ether_addr(addr))
9295 for (i = 0; i < hw->mac.rar_entry_count; i++) {
9296 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
9297 adapter->mac_table[i].queue == queue) {
9298 adapter->mac_table[i].state = IGB_MAC_STATE_MODIFIED;
9299 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
9300 adapter->mac_table[i].queue = 0;
9301 igb_sync_mac_table(adapter);
9307 static int igb_set_vf_mac(struct igb_adapter *adapter,
9308 int vf, unsigned char *mac_addr)
9310 igb_del_mac_filter(adapter, adapter->vf_data[vf].vf_mac_addresses, vf);
9311 memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
9313 igb_add_mac_filter(adapter, mac_addr, vf);
9319 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
9321 struct igb_adapter *adapter = netdev_priv(netdev);
9322 if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
9324 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
9325 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
9326 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
9327 " change effective.\n");
9328 if (test_bit(__IGB_DOWN, &adapter->state)) {
9329 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
9330 " but the PF device is not up.\n");
9331 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
9332 " attempting to use the VF device.\n");
9334 return igb_set_vf_mac(adapter, vf, mac);
9337 static int igb_link_mbps(int internal_link_speed)
9339 switch (internal_link_speed) {
9351 static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
9358 /* Calculate the rate factor values to set */
9359 rf_int = link_speed / tx_rate;
9360 rf_dec = (link_speed - (rf_int * tx_rate));
9361 rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
9363 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
9364 bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
9365 E1000_RTTBCNRC_RF_INT_MASK);
9366 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
9371 E1000_WRITE_REG(hw, E1000_RTTDQSEL, vf); /* vf X uses queue X */
9373 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
9374 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
9376 E1000_WRITE_REG(hw, E1000_RTTBCNRM(0), 0x14);
9377 E1000_WRITE_REG(hw, E1000_RTTBCNRC, bcnrc_val);
9380 static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
9382 int actual_link_speed, i;
9383 bool reset_rate = false;
9385 /* VF TX rate limit was not set */
9386 if ((adapter->vf_rate_link_speed == 0) ||
9387 (adapter->hw.mac.type != e1000_82576))
9390 actual_link_speed = igb_link_mbps(adapter->link_speed);
9391 if (actual_link_speed != adapter->vf_rate_link_speed) {
9393 adapter->vf_rate_link_speed = 0;
9394 dev_info(&adapter->pdev->dev,
9395 "Link speed has been changed. VF Transmit rate is disabled\n");
9398 for (i = 0; i < adapter->vfs_allocated_count; i++) {
9400 adapter->vf_data[i].tx_rate = 0;
9402 igb_set_vf_rate_limit(&adapter->hw, i,
9403 adapter->vf_data[i].tx_rate, actual_link_speed);
9407 #ifdef HAVE_VF_MIN_MAX_TXRATE
9408 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int min_tx_rate,
9410 #else /* HAVE_VF_MIN_MAX_TXRATE */
9411 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
9412 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9414 struct igb_adapter *adapter = netdev_priv(netdev);
9415 struct e1000_hw *hw = &adapter->hw;
9416 int actual_link_speed;
9418 if (hw->mac.type != e1000_82576)
9421 #ifdef HAVE_VF_MIN_MAX_TXRATE
9424 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9426 actual_link_speed = igb_link_mbps(adapter->link_speed);
9427 if ((vf >= adapter->vfs_allocated_count) ||
9428 (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) ||
9429 (tx_rate < 0) || (tx_rate > actual_link_speed))
9432 adapter->vf_rate_link_speed = actual_link_speed;
9433 adapter->vf_data[vf].tx_rate = (u16)tx_rate;
9434 igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
9439 static int igb_ndo_get_vf_config(struct net_device *netdev,
9440 int vf, struct ifla_vf_info *ivi)
9442 struct igb_adapter *adapter = netdev_priv(netdev);
9443 if (vf >= adapter->vfs_allocated_count)
9446 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
9447 #ifdef HAVE_VF_MIN_MAX_TXRATE
9448 ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
9449 ivi->min_tx_rate = 0;
9450 #else /* HAVE_VF_MIN_MAX_TXRATE */
9451 ivi->tx_rate = adapter->vf_data[vf].tx_rate;
9452 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9453 ivi->vlan = adapter->vf_data[vf].pf_vlan;
9454 ivi->qos = adapter->vf_data[vf].pf_qos;
9455 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
9456 ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
9461 static void igb_vmm_control(struct igb_adapter *adapter)
9463 struct e1000_hw *hw = &adapter->hw;
9467 switch (hw->mac.type) {
9470 /* replication is not supported for 82575 */
9473 /* notify HW that the MAC is adding vlan tags */
9474 reg = E1000_READ_REG(hw, E1000_DTXCTL);
9475 reg |= (E1000_DTXCTL_VLAN_ADDED |
9476 E1000_DTXCTL_SPOOF_INT);
9477 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
9479 /* enable replication vlan tag stripping */
9480 reg = E1000_READ_REG(hw, E1000_RPLOLR);
9481 reg |= E1000_RPLOLR_STRVLAN;
9482 E1000_WRITE_REG(hw, E1000_RPLOLR, reg);
9485 /* none of the above registers are supported by i350 */
9489 /* Enable Malicious Driver Detection */
9490 if ((adapter->vfs_allocated_count) &&
9492 if (hw->mac.type == e1000_i350)
9493 igb_enable_mdd(adapter);
9496 /* enable replication and loopback support */
9497 count = adapter->vfs_allocated_count || adapter->vmdq_pools;
9498 if (adapter->flags & IGB_FLAG_LOOPBACK_ENABLE && count)
9499 e1000_vmdq_set_loopback_pf(hw, 1);
9500 e1000_vmdq_set_anti_spoofing_pf(hw,
9501 adapter->vfs_allocated_count || adapter->vmdq_pools,
9502 adapter->vfs_allocated_count);
9503 e1000_vmdq_set_replication_pf(hw, adapter->vfs_allocated_count ||
9504 adapter->vmdq_pools);
9507 static void igb_init_fw(struct igb_adapter *adapter)
9509 struct e1000_fw_drv_info fw_cmd;
9510 struct e1000_hw *hw = &adapter->hw;
9514 if (hw->mac.type == e1000_i210)
9515 mask = E1000_SWFW_EEP_SM;
9517 mask = E1000_SWFW_PHY0_SM;
9518 /* i211 parts do not support this feature */
9519 if (hw->mac.type == e1000_i211)
9520 hw->mac.arc_subsystem_valid = false;
9522 if (!hw->mac.ops.acquire_swfw_sync(hw, mask)) {
9523 for (i = 0; i <= FW_MAX_RETRIES; i++) {
9524 E1000_WRITE_REG(hw, E1000_FWSTS, E1000_FWSTS_FWRI);
9525 fw_cmd.hdr.cmd = FW_CMD_DRV_INFO;
9526 fw_cmd.hdr.buf_len = FW_CMD_DRV_INFO_LEN;
9527 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CMD_RESERVED;
9528 fw_cmd.port_num = hw->bus.func;
9529 fw_cmd.drv_version = FW_FAMILY_DRV_VER;
9530 fw_cmd.hdr.checksum = 0;
9531 fw_cmd.hdr.checksum = e1000_calculate_checksum((u8 *)&fw_cmd,
9533 fw_cmd.hdr.buf_len));
9534 e1000_host_interface_command(hw, (u8*)&fw_cmd,
9536 if (fw_cmd.hdr.cmd_or_resp.ret_status == FW_STATUS_SUCCESS)
9540 dev_warn(pci_dev_to_dev(adapter->pdev),
9541 "Unable to get semaphore, firmware init failed.\n");
9542 hw->mac.ops.release_swfw_sync(hw, mask);
9545 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
9547 struct e1000_hw *hw = &adapter->hw;
9552 if (hw->mac.type == e1000_i211)
9555 if (hw->mac.type > e1000_82580) {
9556 if (adapter->dmac != IGB_DMAC_DISABLE) {
9559 /* force threshold to 0. */
9560 E1000_WRITE_REG(hw, E1000_DMCTXTH, 0);
9563 * DMA Coalescing high water mark needs to be greater
9564 * than the Rx threshold. Set hwm to PBA - max frame
9565 * size in 16B units, capping it at PBA - 6KB.
9567 hwm = 64 * pba - adapter->max_frame_size / 16;
9568 if (hwm < 64 * (pba - 6))
9569 hwm = 64 * (pba - 6);
9570 reg = E1000_READ_REG(hw, E1000_FCRTC);
9571 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
9572 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
9573 & E1000_FCRTC_RTH_COAL_MASK);
9574 E1000_WRITE_REG(hw, E1000_FCRTC, reg);
9577 * Set the DMA Coalescing Rx threshold to PBA - 2 * max
9578 * frame size, capping it at PBA - 10KB.
9580 dmac_thr = pba - adapter->max_frame_size / 512;
9581 if (dmac_thr < pba - 10)
9582 dmac_thr = pba - 10;
9583 reg = E1000_READ_REG(hw, E1000_DMACR);
9584 reg &= ~E1000_DMACR_DMACTHR_MASK;
9585 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
9586 & E1000_DMACR_DMACTHR_MASK);
9588 /* transition to L0x or L1 if available..*/
9589 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
9591 /* Check if status is 2.5Gb backplane connection
9592 * before configuration of watchdog timer, which is
9593 * in msec values in 12.8usec intervals
9594 * watchdog timer= msec values in 32usec intervals
9595 * for non 2.5Gb connection
9597 if (hw->mac.type == e1000_i354) {
9598 status = E1000_READ_REG(hw, E1000_STATUS);
9599 if ((status & E1000_STATUS_2P5_SKU) &&
9600 (!(status & E1000_STATUS_2P5_SKU_OVER)))
9601 reg |= ((adapter->dmac * 5) >> 6);
9603 reg |= ((adapter->dmac) >> 5);
9605 reg |= ((adapter->dmac) >> 5);
9609 * Disable BMC-to-OS Watchdog enable
9610 * on devices that support OS-to-BMC
9612 if (hw->mac.type != e1000_i354)
9613 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
9614 E1000_WRITE_REG(hw, E1000_DMACR, reg);
9616 /* no lower threshold to disable coalescing(smart fifb)-UTRESH=0*/
9617 E1000_WRITE_REG(hw, E1000_DMCRTRH, 0);
9619 /* This sets the time to wait before requesting
9620 * transition to low power state to number of usecs
9621 * needed to receive 1 512 byte frame at gigabit
9622 * line rate. On i350 device, time to make transition
9623 * to Lx state is delayed by 4 usec with flush disable
9624 * bit set to avoid losing mailbox interrupts
9626 reg = E1000_READ_REG(hw, E1000_DMCTLX);
9627 if (hw->mac.type == e1000_i350)
9628 reg |= IGB_DMCTLX_DCFLUSH_DIS;
9630 /* in 2.5Gb connection, TTLX unit is 0.4 usec
9631 * which is 0x4*2 = 0xA. But delay is still 4 usec
9633 if (hw->mac.type == e1000_i354) {
9634 status = E1000_READ_REG(hw, E1000_STATUS);
9635 if ((status & E1000_STATUS_2P5_SKU) &&
9636 (!(status & E1000_STATUS_2P5_SKU_OVER)))
9643 E1000_WRITE_REG(hw, E1000_DMCTLX, reg);
9645 /* free space in tx packet buffer to wake from DMA coal */
9646 E1000_WRITE_REG(hw, E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
9647 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
9649 /* make low power state decision controlled by DMA coal */
9650 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
9651 reg &= ~E1000_PCIEMISC_LX_DECISION;
9652 E1000_WRITE_REG(hw, E1000_PCIEMISC, reg);
9653 } /* endif adapter->dmac is not disabled */
9654 } else if (hw->mac.type == e1000_82580) {
9655 u32 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
9656 E1000_WRITE_REG(hw, E1000_PCIEMISC,
9657 reg & ~E1000_PCIEMISC_LX_DECISION);
9658 E1000_WRITE_REG(hw, E1000_DMACR, 0);
9662 #ifdef HAVE_I2C_SUPPORT
9663 /* igb_read_i2c_byte - Reads 8 bit word over I2C
9664 * @hw: pointer to hardware structure
9665 * @byte_offset: byte offset to read
9666 * @dev_addr: device address
9669 * Performs byte read operation over I2C interface at
9670 * a specified device address.
9672 s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9673 u8 dev_addr, u8 *data)
9675 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9676 struct i2c_client *this_client = adapter->i2c_client;
9681 return E1000_ERR_I2C;
9683 swfw_mask = E1000_SWFW_PHY0_SM;
9685 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
9687 return E1000_ERR_SWFW_SYNC;
9689 status = i2c_smbus_read_byte_data(this_client, byte_offset);
9690 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9693 return E1000_ERR_I2C;
9696 return E1000_SUCCESS;
9700 /* igb_write_i2c_byte - Writes 8 bit word over I2C
9701 * @hw: pointer to hardware structure
9702 * @byte_offset: byte offset to write
9703 * @dev_addr: device address
9704 * @data: value to write
9706 * Performs byte write operation over I2C interface at
9707 * a specified device address.
9709 s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9710 u8 dev_addr, u8 data)
9712 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9713 struct i2c_client *this_client = adapter->i2c_client;
9715 u16 swfw_mask = E1000_SWFW_PHY0_SM;
9718 return E1000_ERR_I2C;
9720 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != E1000_SUCCESS)
9721 return E1000_ERR_SWFW_SYNC;
9722 status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
9723 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9726 return E1000_ERR_I2C;
9728 return E1000_SUCCESS;
9730 #endif /* HAVE_I2C_SUPPORT */
9735 * igb_probe - Device Initialization Routine
9736 * @pdev: PCI device information struct
9737 * @ent: entry in igb_pci_tbl
9739 * Returns 0 on success, negative on failure
9741 * igb_probe initializes an adapter identified by a pci_dev structure.
9742 * The OS initialization, configuring of the adapter private structure,
9743 * and a hardware reset occur.
9745 int igb_kni_probe(struct pci_dev *pdev,
9746 struct net_device **lad_dev)
9748 struct net_device *netdev;
9749 struct igb_adapter *adapter;
9750 struct e1000_hw *hw;
9751 u16 eeprom_data = 0;
9752 u8 pba_str[E1000_PBANUM_LENGTH];
9754 static int global_quad_port_a; /* global quad port a indication */
9755 int i, err, pci_using_dac = 0;
9756 static int cards_found;
9758 err = pci_enable_device_mem(pdev);
9764 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
9766 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
9770 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
9772 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
9774 IGB_ERR("No usable DMA configuration, "
9781 #ifndef HAVE_ASPM_QUIRKS
9782 /* 82575 requires that the pci-e link partner disable the L0s state */
9783 switch (pdev->device) {
9784 case E1000_DEV_ID_82575EB_COPPER:
9785 case E1000_DEV_ID_82575EB_FIBER_SERDES:
9786 case E1000_DEV_ID_82575GB_QUAD_COPPER:
9787 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
9792 #endif /* HAVE_ASPM_QUIRKS */
9793 err = pci_request_selected_regions(pdev,
9794 pci_select_bars(pdev,
9800 pci_enable_pcie_error_reporting(pdev);
9802 pci_set_master(pdev);
9807 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
9810 netdev = alloc_etherdev(sizeof(struct igb_adapter));
9811 #endif /* HAVE_TX_MQ */
9813 goto err_alloc_etherdev;
9815 SET_MODULE_OWNER(netdev);
9816 SET_NETDEV_DEV(netdev, &pdev->dev);
9818 //pci_set_drvdata(pdev, netdev);
9819 adapter = netdev_priv(netdev);
9820 adapter->netdev = netdev;
9821 adapter->pdev = pdev;
9824 adapter->port_num = hw->bus.func;
9825 adapter->msg_enable = (1 << debug) - 1;
9828 err = pci_save_state(pdev);
9833 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
9834 pci_resource_len(pdev, 0));
9838 #ifdef HAVE_NET_DEVICE_OPS
9839 netdev->netdev_ops = &igb_netdev_ops;
9840 #else /* HAVE_NET_DEVICE_OPS */
9841 netdev->open = &igb_open;
9842 netdev->stop = &igb_close;
9843 netdev->get_stats = &igb_get_stats;
9844 #ifdef HAVE_SET_RX_MODE
9845 netdev->set_rx_mode = &igb_set_rx_mode;
9847 netdev->set_multicast_list = &igb_set_rx_mode;
9848 netdev->set_mac_address = &igb_set_mac;
9849 netdev->change_mtu = &igb_change_mtu;
9850 netdev->do_ioctl = &igb_ioctl;
9851 #ifdef HAVE_TX_TIMEOUT
9852 netdev->tx_timeout = &igb_tx_timeout;
9854 netdev->vlan_rx_register = igb_vlan_mode;
9855 netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
9856 netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
9857 #ifdef CONFIG_NET_POLL_CONTROLLER
9858 netdev->poll_controller = igb_netpoll;
9860 netdev->hard_start_xmit = &igb_xmit_frame;
9861 #endif /* HAVE_NET_DEVICE_OPS */
9862 igb_set_ethtool_ops(netdev);
9863 #ifdef HAVE_TX_TIMEOUT
9864 netdev->watchdog_timeo = 5 * HZ;
9867 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
9869 adapter->bd_number = cards_found;
9871 /* setup the private structure */
9872 err = igb_sw_init(adapter);
9876 e1000_get_bus_info(hw);
9878 hw->phy.autoneg_wait_to_complete = FALSE;
9879 hw->mac.adaptive_ifs = FALSE;
9881 /* Copper options */
9882 if (hw->phy.media_type == e1000_media_type_copper) {
9883 hw->phy.mdix = AUTO_ALL_MODES;
9884 hw->phy.disable_polarity_correction = FALSE;
9885 hw->phy.ms_type = e1000_ms_hw_default;
9888 if (e1000_check_reset_block(hw))
9889 dev_info(pci_dev_to_dev(pdev),
9890 "PHY reset is blocked due to SOL/IDER session.\n");
9893 * features is initialized to 0 in allocation, it might have bits
9894 * set by igb_sw_init so we should use an or instead of an
9897 netdev->features |= NETIF_F_SG |
9899 #ifdef NETIF_F_IPV6_CSUM
9907 #endif /* NETIF_F_TSO */
9908 #ifdef NETIF_F_RXHASH
9912 #ifdef NETIF_F_HW_VLAN_CTAG_RX
9913 NETIF_F_HW_VLAN_CTAG_RX |
9914 NETIF_F_HW_VLAN_CTAG_TX;
9916 NETIF_F_HW_VLAN_RX |
9920 if (hw->mac.type >= e1000_82576)
9921 netdev->features |= NETIF_F_SCTP_CSUM;
9923 #ifdef HAVE_NDO_SET_FEATURES
9924 /* copy netdev features into list of user selectable features */
9925 netdev->hw_features |= netdev->features;
9928 /* give us the option of enabling LRO later */
9929 netdev->hw_features |= NETIF_F_LRO;
9934 /* this is only needed on kernels prior to 2.6.39 */
9935 netdev->features |= NETIF_F_GRO;
9939 /* set this bit last since it cannot be part of hw_features */
9940 #ifdef NETIF_F_HW_VLAN_CTAG_FILTER
9941 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
9943 netdev->features |= NETIF_F_HW_VLAN_FILTER;
9946 #ifdef HAVE_NETDEV_VLAN_FEATURES
9947 netdev->vlan_features |= NETIF_F_TSO |
9955 netdev->features |= NETIF_F_HIGHDMA;
9958 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
9960 if (adapter->dmac != IGB_DMAC_DISABLE)
9961 printk("%s: DMA Coalescing is enabled..\n", netdev->name);
9964 /* before reading the NVM, reset the controller to put the device in a
9965 * known good starting state */
9969 /* make sure the NVM is good */
9970 if (e1000_validate_nvm_checksum(hw) < 0) {
9971 dev_err(pci_dev_to_dev(pdev), "The NVM Checksum Is Not"
9977 /* copy the MAC address out of the NVM */
9978 if (e1000_read_mac_addr(hw))
9979 dev_err(pci_dev_to_dev(pdev), "NVM Read Error\n");
9980 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
9981 #ifdef ETHTOOL_GPERMADDR
9982 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
9984 if (!is_valid_ether_addr(netdev->perm_addr)) {
9986 if (!is_valid_ether_addr(netdev->dev_addr)) {
9988 dev_err(pci_dev_to_dev(pdev), "Invalid MAC Address\n");
9993 memcpy(&adapter->mac_table[0].addr, hw->mac.addr, netdev->addr_len);
9994 adapter->mac_table[0].queue = adapter->vfs_allocated_count;
9995 adapter->mac_table[0].state = (IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE);
9996 igb_rar_set(adapter, 0);
9998 /* get firmware version for ethtool -i */
9999 igb_set_fw_version(adapter);
10001 /* Check if Media Autosense is enabled */
10002 if (hw->mac.type == e1000_82580)
10003 igb_init_mas(adapter);
10006 setup_timer(&adapter->watchdog_timer, &igb_watchdog,
10007 (unsigned long) adapter);
10008 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
10009 setup_timer(&adapter->dma_err_timer, &igb_dma_err_timer,
10010 (unsigned long) adapter);
10011 setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
10012 (unsigned long) adapter);
10014 INIT_WORK(&adapter->reset_task, igb_reset_task);
10015 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
10016 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
10017 INIT_WORK(&adapter->dma_err_task, igb_dma_err_task);
10020 /* Initialize link properties that are user-changeable */
10021 adapter->fc_autoneg = true;
10022 hw->mac.autoneg = true;
10023 hw->phy.autoneg_advertised = 0x2f;
10025 hw->fc.requested_mode = e1000_fc_default;
10026 hw->fc.current_mode = e1000_fc_default;
10028 e1000_validate_mdi_setting(hw);
10030 /* By default, support wake on port A */
10031 if (hw->bus.func == 0)
10032 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10034 /* Check the NVM for wake support for non-port A ports */
10035 if (hw->mac.type >= e1000_82580)
10036 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
10037 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
10039 else if (hw->bus.func == 1)
10040 e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
10042 if (eeprom_data & IGB_EEPROM_APME)
10043 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10045 /* now that we have the eeprom settings, apply the special cases where
10046 * the eeprom may be wrong or the board simply won't support wake on
10047 * lan on a particular port */
10048 switch (pdev->device) {
10049 case E1000_DEV_ID_82575GB_QUAD_COPPER:
10050 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10052 case E1000_DEV_ID_82575EB_FIBER_SERDES:
10053 case E1000_DEV_ID_82576_FIBER:
10054 case E1000_DEV_ID_82576_SERDES:
10055 /* Wake events only supported on port A for dual fiber
10056 * regardless of eeprom setting */
10057 if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1)
10058 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10060 case E1000_DEV_ID_82576_QUAD_COPPER:
10061 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
10062 /* if quad port adapter, disable WoL on all but port A */
10063 if (global_quad_port_a != 0)
10064 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10066 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
10067 /* Reset for multiple quad port adapters */
10068 if (++global_quad_port_a == 4)
10069 global_quad_port_a = 0;
10072 /* If the device can't wake, don't set software support */
10073 if (!device_can_wakeup(&adapter->pdev->dev))
10074 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10078 /* initialize the wol settings based on the eeprom settings */
10079 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
10080 adapter->wol |= E1000_WUFC_MAG;
10082 /* Some vendors want WoL disabled by default, but still supported */
10083 if ((hw->mac.type == e1000_i350) &&
10084 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
10085 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10090 device_set_wakeup_enable(pci_dev_to_dev(adapter->pdev),
10091 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
10093 /* reset the hardware with the new settings */
10094 igb_reset(adapter);
10095 adapter->devrc = 0;
10097 #ifdef HAVE_I2C_SUPPORT
10098 /* Init the I2C interface */
10099 err = igb_init_i2c(adapter);
10101 dev_err(&pdev->dev, "failed to init i2c interface\n");
10104 #endif /* HAVE_I2C_SUPPORT */
10106 /* let the f/w know that the h/w is now under the control of the
10108 igb_get_hw_control(adapter);
10110 strncpy(netdev->name, "eth%d", IFNAMSIZ);
10111 err = register_netdev(netdev);
10115 #ifdef CONFIG_IGB_VMDQ_NETDEV
10116 err = igb_init_vmdq_netdevs(adapter);
10120 /* carrier off reporting is important to ethtool even BEFORE open */
10121 netif_carrier_off(netdev);
10124 if (dca_add_requester(&pdev->dev) == E1000_SUCCESS) {
10125 adapter->flags |= IGB_FLAG_DCA_ENABLED;
10126 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
10127 igb_setup_dca(adapter);
10131 #ifdef HAVE_PTP_1588_CLOCK
10132 /* do hw tstamp init after resetting */
10133 igb_ptp_init(adapter);
10134 #endif /* HAVE_PTP_1588_CLOCK */
10136 #endif /* NO_KNI */
10137 dev_info(pci_dev_to_dev(pdev), "Intel(R) Gigabit Ethernet Network Connection\n");
10138 /* print bus type/speed/width info */
10139 dev_info(pci_dev_to_dev(pdev), "%s: (PCIe:%s:%s) ",
10141 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5GT/s" :
10142 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0GT/s" :
10143 (hw->mac.type == e1000_i354) ? "integrated" :
10145 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
10146 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
10147 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
10148 (hw->mac.type == e1000_i354) ? "integrated" :
10150 dev_info(pci_dev_to_dev(pdev), "%s: MAC: ", netdev->name);
10151 for (i = 0; i < 6; i++)
10152 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
10154 ret_val = e1000_read_pba_string(hw, pba_str, E1000_PBANUM_LENGTH);
10156 strncpy(pba_str, "Unknown", sizeof(pba_str) - 1);
10157 dev_info(pci_dev_to_dev(pdev), "%s: PBA No: %s\n", netdev->name,
10161 /* Initialize the thermal sensor on i350 devices. */
10162 if (hw->mac.type == e1000_i350) {
10163 if (hw->bus.func == 0) {
10167 * Read the NVM to determine if this i350 device
10168 * supports an external thermal sensor.
10170 e1000_read_nvm(hw, NVM_ETS_CFG, 1, &ets_word);
10171 if (ets_word != 0x0000 && ets_word != 0xFFFF)
10172 adapter->ets = true;
10174 adapter->ets = false;
10179 igb_sysfs_init(adapter);
10183 igb_procfs_init(adapter);
10184 #endif /* IGB_PROCFS */
10185 #endif /* IGB_HWMON */
10186 #endif /* NO_KNI */
10188 adapter->ets = false;
10191 if (hw->phy.media_type == e1000_media_type_copper) {
10192 switch (hw->mac.type) {
10196 /* Enable EEE for internal copper PHY devices */
10197 err = e1000_set_eee_i350(hw);
10199 (adapter->flags & IGB_FLAG_EEE))
10200 adapter->eee_advert =
10201 MDIO_EEE_100TX | MDIO_EEE_1000T;
10204 if ((E1000_READ_REG(hw, E1000_CTRL_EXT)) &
10205 (E1000_CTRL_EXT_LINK_MODE_SGMII)) {
10206 err = e1000_set_eee_i354(hw);
10208 (adapter->flags & IGB_FLAG_EEE))
10209 adapter->eee_advert =
10210 MDIO_EEE_100TX | MDIO_EEE_1000T;
10218 /* send driver version info to firmware */
10219 if (hw->mac.type >= e1000_i350)
10220 igb_init_fw(adapter);
10223 if (netdev->features & NETIF_F_LRO)
10224 dev_info(pci_dev_to_dev(pdev), "Internal LRO is enabled \n");
10226 dev_info(pci_dev_to_dev(pdev), "LRO is disabled \n");
10228 dev_info(pci_dev_to_dev(pdev),
10229 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
10230 adapter->msix_entries ? "MSI-X" :
10231 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
10232 adapter->num_rx_queues, adapter->num_tx_queues);
10237 pm_runtime_put_noidle(&pdev->dev);
10241 // igb_release_hw_control(adapter);
10242 #ifdef HAVE_I2C_SUPPORT
10243 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
10244 #endif /* HAVE_I2C_SUPPORT */
10246 // if (!e1000_check_reset_block(hw))
10247 // e1000_phy_hw_reset(hw);
10249 if (hw->flash_address)
10250 iounmap(hw->flash_address);
10252 // igb_clear_interrupt_scheme(adapter);
10253 // igb_reset_sriov_capability(adapter);
10254 iounmap(hw->hw_addr);
10256 free_netdev(netdev);
10257 err_alloc_etherdev:
10258 // pci_release_selected_regions(pdev,
10259 // pci_select_bars(pdev, IORESOURCE_MEM));
10262 pci_disable_device(pdev);
10267 void igb_kni_remove(struct pci_dev *pdev)
10269 pci_disable_device(pdev);