1 // SPDX-License-Identifier: GPL-2.0
2 /*******************************************************************************
4 Intel(R) Gigabit Ethernet Linux driver
5 Copyright(c) 2007-2013 Intel Corporation.
8 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 *******************************************************************************/
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/init.h>
16 #include <linux/vmalloc.h>
17 #include <linux/pagemap.h>
18 #include <linux/netdevice.h>
19 #include <linux/tcp.h>
21 #include <net/checksum.h>
23 #include <linux/ipv6.h>
24 #include <net/ip6_checksum.h>
28 #include <linux/mii.h>
31 #include <linux/ethtool.h>
33 #include <linux/if_vlan.h>
34 #ifdef CONFIG_PM_RUNTIME
35 #include <linux/pm_runtime.h>
36 #endif /* CONFIG_PM_RUNTIME */
38 #include <linux/if_bridge.h>
42 #include <linux/uio_driver.h>
44 #if defined(DEBUG) || defined (DEBUG_DUMP) || defined (DEBUG_ICR) || defined(DEBUG_ITR)
45 #define DRV_DEBUG "_debug"
50 #define VERSION_SUFFIX
55 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." __stringify(BUILD) VERSION_SUFFIX DRV_DEBUG DRV_HW_PERF
57 char igb_driver_name[] = "igb";
58 char igb_driver_version[] = DRV_VERSION;
59 static const char igb_driver_string[] =
60 "Intel(R) Gigabit Ethernet Network Driver";
61 static const char igb_copyright[] =
62 "Copyright (c) 2007-2013 Intel Corporation.";
64 const struct pci_device_id igb_pci_tbl[] = {
65 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
66 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
67 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
68 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER) },
69 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER) },
70 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES) },
71 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII) },
72 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
73 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
74 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER) },
75 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER) },
76 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER) },
77 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES) },
78 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII) },
79 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER) },
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER) },
81 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER) },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES) },
83 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII) },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL) },
85 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII) },
86 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES) },
87 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
88 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP) },
89 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576) },
90 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS) },
91 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES) },
92 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER) },
93 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES) },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD) },
95 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
96 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER) },
97 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER) },
98 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES) },
99 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER) },
100 /* required last entry */
104 //MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
105 static void igb_set_sriov_capability(struct igb_adapter *adapter) __attribute__((__unused__));
106 void igb_reset(struct igb_adapter *);
107 static int igb_setup_all_tx_resources(struct igb_adapter *);
108 static int igb_setup_all_rx_resources(struct igb_adapter *);
109 static void igb_free_all_tx_resources(struct igb_adapter *);
110 static void igb_free_all_rx_resources(struct igb_adapter *);
111 static void igb_setup_mrqc(struct igb_adapter *);
112 void igb_update_stats(struct igb_adapter *);
113 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
114 static void __devexit igb_remove(struct pci_dev *pdev);
115 static int igb_sw_init(struct igb_adapter *);
116 static int igb_open(struct net_device *);
117 static int igb_close(struct net_device *);
118 static void igb_configure(struct igb_adapter *);
119 static void igb_configure_tx(struct igb_adapter *);
120 static void igb_configure_rx(struct igb_adapter *);
121 static void igb_clean_all_tx_rings(struct igb_adapter *);
122 static void igb_clean_all_rx_rings(struct igb_adapter *);
123 static void igb_clean_tx_ring(struct igb_ring *);
124 static void igb_set_rx_mode(struct net_device *);
125 #ifdef HAVE_TIMER_SETUP
126 static void igb_update_phy_info(struct timer_list *);
127 static void igb_watchdog(struct timer_list *);
129 static void igb_update_phy_info(unsigned long);
130 static void igb_watchdog(unsigned long);
132 static void igb_watchdog_task(struct work_struct *);
133 static void igb_dma_err_task(struct work_struct *);
134 #ifdef HAVE_TIMER_SETUP
135 static void igb_dma_err_timer(struct timer_list *);
137 static void igb_dma_err_timer(unsigned long data);
139 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
140 static struct net_device_stats *igb_get_stats(struct net_device *);
141 static int igb_change_mtu(struct net_device *, int);
142 void igb_full_sync_mac_table(struct igb_adapter *adapter);
143 static int igb_set_mac(struct net_device *, void *);
144 static void igb_set_uta(struct igb_adapter *adapter);
145 static irqreturn_t igb_intr(int irq, void *);
146 static irqreturn_t igb_intr_msi(int irq, void *);
147 static irqreturn_t igb_msix_other(int irq, void *);
148 static irqreturn_t igb_msix_ring(int irq, void *);
150 static void igb_update_dca(struct igb_q_vector *);
151 static void igb_setup_dca(struct igb_adapter *);
153 static int igb_poll(struct napi_struct *, int);
154 static bool igb_clean_tx_irq(struct igb_q_vector *);
155 static bool igb_clean_rx_irq(struct igb_q_vector *, int);
156 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
157 static void igb_tx_timeout(struct net_device *);
158 static void igb_reset_task(struct work_struct *);
159 #ifdef HAVE_VLAN_RX_REGISTER
160 static void igb_vlan_mode(struct net_device *, struct vlan_group *);
162 #ifdef HAVE_VLAN_PROTOCOL
163 static int igb_vlan_rx_add_vid(struct net_device *,
165 static int igb_vlan_rx_kill_vid(struct net_device *,
167 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
168 #ifdef NETIF_F_HW_VLAN_CTAG_RX
169 static int igb_vlan_rx_add_vid(struct net_device *,
170 __always_unused __be16 proto, u16);
171 static int igb_vlan_rx_kill_vid(struct net_device *,
172 __always_unused __be16 proto, u16);
174 static int igb_vlan_rx_add_vid(struct net_device *, u16);
175 static int igb_vlan_rx_kill_vid(struct net_device *, u16);
178 static void igb_vlan_rx_add_vid(struct net_device *, u16);
179 static void igb_vlan_rx_kill_vid(struct net_device *, u16);
181 static void igb_restore_vlan(struct igb_adapter *);
182 void igb_rar_set(struct igb_adapter *adapter, u32 index);
183 static void igb_ping_all_vfs(struct igb_adapter *);
184 static void igb_msg_task(struct igb_adapter *);
185 static void igb_vmm_control(struct igb_adapter *);
186 static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
187 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
188 static void igb_process_mdd_event(struct igb_adapter *);
190 static int igb_ndo_set_vf_mac( struct net_device *netdev, int vf, u8 *mac);
191 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
192 #ifdef HAVE_VF_VLAN_PROTO
193 int vf, u16 vlan, u8 qos, __be16 vlan_proto);
195 int vf, u16 vlan, u8 qos);
197 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
198 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
201 #ifdef HAVE_VF_MIN_MAX_TXRATE
202 static int igb_ndo_set_vf_bw(struct net_device *, int, int, int);
203 #else /* HAVE_VF_MIN_MAX_TXRATE */
204 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
205 #endif /* HAVE_VF_MIN_MAX_TXRATE */
206 static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
207 struct ifla_vf_info *ivi);
208 static void igb_check_vf_rate_limit(struct igb_adapter *);
210 static int igb_vf_configure(struct igb_adapter *adapter, int vf);
212 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
213 static int igb_suspend(struct device *dev);
214 static int igb_resume(struct device *dev);
215 #ifdef CONFIG_PM_RUNTIME
216 static int igb_runtime_suspend(struct device *dev);
217 static int igb_runtime_resume(struct device *dev);
218 static int igb_runtime_idle(struct device *dev);
219 #endif /* CONFIG_PM_RUNTIME */
220 static const struct dev_pm_ops igb_pm_ops = {
221 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
222 .suspend = igb_suspend,
223 .resume = igb_resume,
224 .freeze = igb_suspend,
226 .poweroff = igb_suspend,
227 .restore = igb_resume,
228 #ifdef CONFIG_PM_RUNTIME
229 .runtime_suspend = igb_runtime_suspend,
230 .runtime_resume = igb_runtime_resume,
231 .runtime_idle = igb_runtime_idle,
233 #else /* Linux >= 2.6.34 */
234 SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
235 #ifdef CONFIG_PM_RUNTIME
236 SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
238 #endif /* CONFIG_PM_RUNTIME */
239 #endif /* Linux version */
242 static int igb_suspend(struct pci_dev *pdev, pm_message_t state);
243 static int igb_resume(struct pci_dev *pdev);
244 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
245 #endif /* CONFIG_PM */
246 #ifndef USE_REBOOT_NOTIFIER
247 static void igb_shutdown(struct pci_dev *);
249 static int igb_notify_reboot(struct notifier_block *, unsigned long, void *);
250 static struct notifier_block igb_notifier_reboot = {
251 .notifier_call = igb_notify_reboot,
257 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
258 static struct notifier_block dca_notifier = {
259 .notifier_call = igb_notify_dca,
264 #ifdef CONFIG_NET_POLL_CONTROLLER
265 /* for netdump / net console */
266 static void igb_netpoll(struct net_device *);
270 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
271 pci_channel_state_t);
272 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
273 static void igb_io_resume(struct pci_dev *);
275 static struct pci_error_handlers igb_err_handler = {
276 .error_detected = igb_io_error_detected,
277 .slot_reset = igb_io_slot_reset,
278 .resume = igb_io_resume,
282 static void igb_init_fw(struct igb_adapter *adapter);
283 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
285 static struct pci_driver igb_driver = {
286 .name = igb_driver_name,
287 .id_table = igb_pci_tbl,
289 .remove = __devexit_p(igb_remove),
291 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
292 .driver.pm = &igb_pm_ops,
294 .suspend = igb_suspend,
295 .resume = igb_resume,
296 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
297 #endif /* CONFIG_PM */
298 #ifndef USE_REBOOT_NOTIFIER
299 .shutdown = igb_shutdown,
302 .err_handler = &igb_err_handler
306 //MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
307 //MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
308 //MODULE_LICENSE("GPL");
309 //MODULE_VERSION(DRV_VERSION);
311 static void igb_vfta_set(struct igb_adapter *adapter, u32 vid, bool add)
313 struct e1000_hw *hw = &adapter->hw;
314 struct e1000_host_mng_dhcp_cookie *mng_cookie = &hw->mng_cookie;
315 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
316 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
320 * if this is the management vlan the only option is to add it in so
321 * that the management pass through will continue to work
323 if ((mng_cookie->status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
324 (vid == mng_cookie->vlan_id))
327 vfta = adapter->shadow_vfta[index];
334 e1000_write_vfta(hw, index, vfta);
335 adapter->shadow_vfta[index] = vfta;
338 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
339 //module_param(debug, int, 0);
340 //MODULE_PARM_DESC(debug, "Debug level (0=none, ..., 16=all)");
343 * igb_init_module - Driver Registration Routine
345 * igb_init_module is the first routine called when the driver is
346 * loaded. All it does is register with the PCI subsystem.
348 static int __init igb_init_module(void)
352 printk(KERN_INFO "%s - version %s\n",
353 igb_driver_string, igb_driver_version);
355 printk(KERN_INFO "%s\n", igb_copyright);
357 /* only use IGB_PROCFS if IGB_HWMON is not defined */
360 if (igb_procfs_topdir_init())
361 printk(KERN_INFO "Procfs failed to initialize topdir\n");
362 #endif /* IGB_PROCFS */
363 #endif /* IGB_HWMON */
366 dca_register_notify(&dca_notifier);
368 ret = pci_register_driver(&igb_driver);
369 #ifdef USE_REBOOT_NOTIFIER
371 register_reboot_notifier(&igb_notifier_reboot);
378 #define module_init(x) static int x(void) __attribute__((__unused__));
379 module_init(igb_init_module);
382 * igb_exit_module - Driver Exit Cleanup Routine
384 * igb_exit_module is called just before the driver is removed
387 static void __exit igb_exit_module(void)
390 dca_unregister_notify(&dca_notifier);
392 #ifdef USE_REBOOT_NOTIFIER
393 unregister_reboot_notifier(&igb_notifier_reboot);
395 pci_unregister_driver(&igb_driver);
398 /* only compile IGB_PROCFS if IGB_HWMON is not defined */
401 igb_procfs_topdir_exit();
402 #endif /* IGB_PROCFS */
403 #endif /* IGB_HWMON */
407 #define module_exit(x) static void x(void) __attribute__((__unused__));
408 module_exit(igb_exit_module);
410 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
412 * igb_cache_ring_register - Descriptor ring to register mapping
413 * @adapter: board private structure to initialize
415 * Once we know the feature-set enabled for the device, we'll cache
416 * the register offset the descriptor ring is assigned to.
418 static void igb_cache_ring_register(struct igb_adapter *adapter)
421 u32 rbase_offset = adapter->vfs_allocated_count;
423 switch (adapter->hw.mac.type) {
425 /* The queues are allocated for virtualization such that VF 0
426 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
427 * In order to avoid collision we start at the first free queue
428 * and continue consuming queues in the same sequence
430 if ((adapter->rss_queues > 1) && adapter->vmdq_pools) {
431 for (; i < adapter->rss_queues; i++)
432 adapter->rx_ring[i]->reg_idx = rbase_offset +
442 for (; i < adapter->num_rx_queues; i++)
443 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
444 for (; j < adapter->num_tx_queues; j++)
445 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
450 static void igb_configure_lli(struct igb_adapter *adapter)
452 struct e1000_hw *hw = &adapter->hw;
455 /* LLI should only be enabled for MSI-X or MSI interrupts */
456 if (!adapter->msix_entries && !(adapter->flags & IGB_FLAG_HAS_MSI))
459 if (adapter->lli_port) {
460 /* use filter 0 for port */
461 port = htons((u16)adapter->lli_port);
462 E1000_WRITE_REG(hw, E1000_IMIR(0),
463 (port | E1000_IMIR_PORT_IM_EN));
464 E1000_WRITE_REG(hw, E1000_IMIREXT(0),
465 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
468 if (adapter->flags & IGB_FLAG_LLI_PUSH) {
469 /* use filter 1 for push flag */
470 E1000_WRITE_REG(hw, E1000_IMIR(1),
471 (E1000_IMIR_PORT_BP | E1000_IMIR_PORT_IM_EN));
472 E1000_WRITE_REG(hw, E1000_IMIREXT(1),
473 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_PSH));
476 if (adapter->lli_size) {
477 /* use filter 2 for size */
478 E1000_WRITE_REG(hw, E1000_IMIR(2),
479 (E1000_IMIR_PORT_BP | E1000_IMIR_PORT_IM_EN));
480 E1000_WRITE_REG(hw, E1000_IMIREXT(2),
481 (adapter->lli_size | E1000_IMIREXT_CTRL_BP));
487 * igb_write_ivar - configure ivar for given MSI-X vector
488 * @hw: pointer to the HW structure
489 * @msix_vector: vector number we are allocating to a given ring
490 * @index: row index of IVAR register to write within IVAR table
491 * @offset: column offset of in IVAR, should be multiple of 8
493 * This function is intended to handle the writing of the IVAR register
494 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
495 * each containing an cause allocation for an Rx and Tx ring, and a
496 * variable number of rows depending on the number of queues supported.
498 static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
499 int index, int offset)
501 u32 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
503 /* clear any bits that are currently set */
504 ivar &= ~((u32)0xFF << offset);
506 /* write vector and valid bit */
507 ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
509 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
512 #define IGB_N0_QUEUE -1
513 static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
515 struct igb_adapter *adapter = q_vector->adapter;
516 struct e1000_hw *hw = &adapter->hw;
517 int rx_queue = IGB_N0_QUEUE;
518 int tx_queue = IGB_N0_QUEUE;
521 if (q_vector->rx.ring)
522 rx_queue = q_vector->rx.ring->reg_idx;
523 if (q_vector->tx.ring)
524 tx_queue = q_vector->tx.ring->reg_idx;
526 switch (hw->mac.type) {
528 /* The 82575 assigns vectors using a bitmask, which matches the
529 bitmask for the EICR/EIMS/EIMC registers. To assign one
530 or more queues to a vector, we write the appropriate bits
531 into the MSIXBM register for that vector. */
532 if (rx_queue > IGB_N0_QUEUE)
533 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
534 if (tx_queue > IGB_N0_QUEUE)
535 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
536 if (!adapter->msix_entries && msix_vector == 0)
537 msixbm |= E1000_EIMS_OTHER;
538 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), msix_vector, msixbm);
539 q_vector->eims_value = msixbm;
543 * 82576 uses a table that essentially consists of 2 columns
544 * with 8 rows. The ordering is column-major so we use the
545 * lower 3 bits as the row index, and the 4th bit as the
548 if (rx_queue > IGB_N0_QUEUE)
549 igb_write_ivar(hw, msix_vector,
551 (rx_queue & 0x8) << 1);
552 if (tx_queue > IGB_N0_QUEUE)
553 igb_write_ivar(hw, msix_vector,
555 ((tx_queue & 0x8) << 1) + 8);
556 q_vector->eims_value = 1 << msix_vector;
564 * On 82580 and newer adapters the scheme is similar to 82576
565 * however instead of ordering column-major we have things
566 * ordered row-major. So we traverse the table by using
567 * bit 0 as the column offset, and the remaining bits as the
570 if (rx_queue > IGB_N0_QUEUE)
571 igb_write_ivar(hw, msix_vector,
573 (rx_queue & 0x1) << 4);
574 if (tx_queue > IGB_N0_QUEUE)
575 igb_write_ivar(hw, msix_vector,
577 ((tx_queue & 0x1) << 4) + 8);
578 q_vector->eims_value = 1 << msix_vector;
585 /* add q_vector eims value to global eims_enable_mask */
586 adapter->eims_enable_mask |= q_vector->eims_value;
588 /* configure q_vector to set itr on first interrupt */
589 q_vector->set_itr = 1;
593 * igb_configure_msix - Configure MSI-X hardware
595 * igb_configure_msix sets up the hardware to properly
596 * generate MSI-X interrupts.
598 static void igb_configure_msix(struct igb_adapter *adapter)
602 struct e1000_hw *hw = &adapter->hw;
604 adapter->eims_enable_mask = 0;
606 /* set vector for other causes, i.e. link changes */
607 switch (hw->mac.type) {
609 tmp = E1000_READ_REG(hw, E1000_CTRL_EXT);
610 /* enable MSI-X PBA support*/
611 tmp |= E1000_CTRL_EXT_PBA_CLR;
613 /* Auto-Mask interrupts upon ICR read. */
614 tmp |= E1000_CTRL_EXT_EIAME;
615 tmp |= E1000_CTRL_EXT_IRCA;
617 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmp);
619 /* enable msix_other interrupt */
620 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), vector++,
622 adapter->eims_other = E1000_EIMS_OTHER;
632 /* Turn on MSI-X capability first, or our settings
633 * won't stick. And it will take days to debug. */
634 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
635 E1000_GPIE_PBA | E1000_GPIE_EIAME |
638 /* enable msix_other interrupt */
639 adapter->eims_other = 1 << vector;
640 tmp = (vector++ | E1000_IVAR_VALID) << 8;
642 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmp);
645 /* do nothing, since nothing else supports MSI-X */
647 } /* switch (hw->mac.type) */
649 adapter->eims_enable_mask |= adapter->eims_other;
651 for (i = 0; i < adapter->num_q_vectors; i++)
652 igb_assign_vector(adapter->q_vector[i], vector++);
654 E1000_WRITE_FLUSH(hw);
658 * igb_request_msix - Initialize MSI-X interrupts
660 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
663 static int igb_request_msix(struct igb_adapter *adapter)
665 struct net_device *netdev = adapter->netdev;
666 struct e1000_hw *hw = &adapter->hw;
667 int i, err = 0, vector = 0, free_vector = 0;
669 err = request_irq(adapter->msix_entries[vector].vector,
670 &igb_msix_other, 0, netdev->name, adapter);
674 for (i = 0; i < adapter->num_q_vectors; i++) {
675 struct igb_q_vector *q_vector = adapter->q_vector[i];
679 q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
681 if (q_vector->rx.ring && q_vector->tx.ring)
682 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
683 q_vector->rx.ring->queue_index);
684 else if (q_vector->tx.ring)
685 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
686 q_vector->tx.ring->queue_index);
687 else if (q_vector->rx.ring)
688 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
689 q_vector->rx.ring->queue_index);
691 sprintf(q_vector->name, "%s-unused", netdev->name);
693 err = request_irq(adapter->msix_entries[vector].vector,
694 igb_msix_ring, 0, q_vector->name,
700 igb_configure_msix(adapter);
704 /* free already assigned IRQs */
705 free_irq(adapter->msix_entries[free_vector++].vector, adapter);
708 for (i = 0; i < vector; i++) {
709 free_irq(adapter->msix_entries[free_vector++].vector,
710 adapter->q_vector[i]);
716 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
718 if (adapter->msix_entries) {
719 pci_disable_msix(adapter->pdev);
720 kfree(adapter->msix_entries);
721 adapter->msix_entries = NULL;
722 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
723 pci_disable_msi(adapter->pdev);
728 * igb_free_q_vector - Free memory allocated for specific interrupt vector
729 * @adapter: board private structure to initialize
730 * @v_idx: Index of vector to be freed
732 * This function frees the memory allocated to the q_vector. In addition if
733 * NAPI is enabled it will delete any references to the NAPI struct prior
734 * to freeing the q_vector.
736 static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
738 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
740 if (q_vector->tx.ring)
741 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
743 if (q_vector->rx.ring)
744 adapter->tx_ring[q_vector->rx.ring->queue_index] = NULL;
746 adapter->q_vector[v_idx] = NULL;
747 netif_napi_del(&q_vector->napi);
749 __skb_queue_purge(&q_vector->lrolist.active);
755 * igb_free_q_vectors - Free memory allocated for interrupt vectors
756 * @adapter: board private structure to initialize
758 * This function frees the memory allocated to the q_vectors. In addition if
759 * NAPI is enabled it will delete any references to the NAPI struct prior
760 * to freeing the q_vector.
762 static void igb_free_q_vectors(struct igb_adapter *adapter)
764 int v_idx = adapter->num_q_vectors;
766 adapter->num_tx_queues = 0;
767 adapter->num_rx_queues = 0;
768 adapter->num_q_vectors = 0;
771 igb_free_q_vector(adapter, v_idx);
775 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
777 * This function resets the device so that it has 0 rx queues, tx queues, and
778 * MSI-X interrupts allocated.
780 static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
782 igb_free_q_vectors(adapter);
783 igb_reset_interrupt_capability(adapter);
787 * igb_process_mdd_event
788 * @adapter - board private structure
790 * Identify a malicious VF, disable the VF TX/RX queues and log a message.
792 static void igb_process_mdd_event(struct igb_adapter *adapter)
794 struct e1000_hw *hw = &adapter->hw;
795 u32 lvmmc, vfte, vfre, mdfb;
798 lvmmc = E1000_READ_REG(hw, E1000_LVMMC);
799 vf_queue = lvmmc >> 29;
801 /* VF index cannot be bigger or equal to VFs allocated */
802 if (vf_queue >= adapter->vfs_allocated_count)
805 netdev_info(adapter->netdev,
806 "VF %d misbehaved. VF queues are disabled. "
807 "VM misbehavior code is 0x%x\n", vf_queue, lvmmc);
809 /* Disable VFTE and VFRE related bits */
810 vfte = E1000_READ_REG(hw, E1000_VFTE);
811 vfte &= ~(1 << vf_queue);
812 E1000_WRITE_REG(hw, E1000_VFTE, vfte);
814 vfre = E1000_READ_REG(hw, E1000_VFRE);
815 vfre &= ~(1 << vf_queue);
816 E1000_WRITE_REG(hw, E1000_VFRE, vfre);
818 /* Disable MDFB related bit. Clear on write */
819 mdfb = E1000_READ_REG(hw, E1000_MDFB);
820 mdfb |= (1 << vf_queue);
821 E1000_WRITE_REG(hw, E1000_MDFB, mdfb);
823 /* Reset the specific VF */
824 E1000_WRITE_REG(hw, E1000_VTCTRL(vf_queue), E1000_VTCTRL_RST);
829 * @adapter - board private structure
831 * Disable MDD behavior in the HW
833 static void igb_disable_mdd(struct igb_adapter *adapter)
835 struct e1000_hw *hw = &adapter->hw;
838 if ((hw->mac.type != e1000_i350) ||
839 (hw->mac.type != e1000_i354))
842 reg = E1000_READ_REG(hw, E1000_DTXCTL);
843 reg &= (~E1000_DTXCTL_MDP_EN);
844 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
849 * @adapter - board private structure
851 * Enable the HW to detect malicious driver and sends an interrupt to
854 static void igb_enable_mdd(struct igb_adapter *adapter)
856 struct e1000_hw *hw = &adapter->hw;
859 /* Only available on i350 device */
860 if (hw->mac.type != e1000_i350)
863 reg = E1000_READ_REG(hw, E1000_DTXCTL);
864 reg |= E1000_DTXCTL_MDP_EN;
865 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
869 * igb_reset_sriov_capability - disable SR-IOV if enabled
871 * Attempt to disable single root IO virtualization capabilites present in the
874 static void igb_reset_sriov_capability(struct igb_adapter *adapter)
876 struct pci_dev *pdev = adapter->pdev;
877 struct e1000_hw *hw = &adapter->hw;
879 /* reclaim resources allocated to VFs */
880 if (adapter->vf_data) {
881 if (!pci_vfs_assigned(pdev)) {
883 * disable iov and allow time for transactions to
886 pci_disable_sriov(pdev);
889 dev_info(pci_dev_to_dev(pdev), "IOV Disabled\n");
891 dev_info(pci_dev_to_dev(pdev), "IOV Not Disabled\n "
892 "VF(s) are assigned to guests!\n");
894 /* Disable Malicious Driver Detection */
895 igb_disable_mdd(adapter);
897 /* free vf data storage */
898 kfree(adapter->vf_data);
899 adapter->vf_data = NULL;
901 /* switch rings back to PF ownership */
902 E1000_WRITE_REG(hw, E1000_IOVCTL,
903 E1000_IOVCTL_REUSE_VFQ);
904 E1000_WRITE_FLUSH(hw);
908 adapter->vfs_allocated_count = 0;
912 * igb_set_sriov_capability - setup SR-IOV if supported
914 * Attempt to enable single root IO virtualization capabilites present in the
917 static void igb_set_sriov_capability(struct igb_adapter *adapter)
919 struct pci_dev *pdev = adapter->pdev;
923 old_vfs = pci_num_vf(pdev);
925 dev_info(pci_dev_to_dev(pdev),
926 "%d pre-allocated VFs found - override "
927 "max_vfs setting of %d\n", old_vfs,
928 adapter->vfs_allocated_count);
929 adapter->vfs_allocated_count = old_vfs;
931 /* no VFs requested, do nothing */
932 if (!adapter->vfs_allocated_count)
935 /* allocate vf data storage */
936 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
937 sizeof(struct vf_data_storage),
940 if (adapter->vf_data) {
942 if (pci_enable_sriov(pdev,
943 adapter->vfs_allocated_count))
946 for (i = 0; i < adapter->vfs_allocated_count; i++)
947 igb_vf_configure(adapter, i);
949 switch (adapter->hw.mac.type) {
952 /* Enable VM to VM loopback by default */
953 adapter->flags |= IGB_FLAG_LOOPBACK_ENABLE;
956 /* Currently no other hardware supports loopback */
960 /* DMA Coalescing is not supported in IOV mode. */
961 if (adapter->hw.mac.type >= e1000_i350)
962 adapter->dmac = IGB_DMAC_DISABLE;
963 if (adapter->hw.mac.type < e1000_i350)
964 adapter->flags |= IGB_FLAG_DETECT_BAD_DMA;
970 kfree(adapter->vf_data);
971 adapter->vf_data = NULL;
972 adapter->vfs_allocated_count = 0;
973 dev_warn(pci_dev_to_dev(pdev),
974 "Failed to initialize SR-IOV virtualization\n");
978 * igb_set_interrupt_capability - set MSI or MSI-X if supported
980 * Attempt to configure interrupts using the best available
981 * capabilities of the hardware and kernel.
983 static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
985 struct pci_dev *pdev = adapter->pdev;
990 adapter->int_mode = IGB_INT_MODE_MSI;
992 /* Number of supported queues. */
993 adapter->num_rx_queues = adapter->rss_queues;
995 if (adapter->vmdq_pools > 1)
996 adapter->num_rx_queues += adapter->vmdq_pools - 1;
999 if (adapter->vmdq_pools)
1000 adapter->num_tx_queues = adapter->vmdq_pools;
1002 adapter->num_tx_queues = adapter->num_rx_queues;
1004 adapter->num_tx_queues = max_t(u32, 1, adapter->vmdq_pools);
1007 switch (adapter->int_mode) {
1008 case IGB_INT_MODE_MSIX:
1009 /* start with one vector for every rx queue */
1010 numvecs = adapter->num_rx_queues;
1012 /* if tx handler is separate add 1 for every tx queue */
1013 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
1014 numvecs += adapter->num_tx_queues;
1016 /* store the number of vectors reserved for queues */
1017 adapter->num_q_vectors = numvecs;
1019 /* add 1 vector for link status interrupts */
1021 adapter->msix_entries = kcalloc(numvecs,
1022 sizeof(struct msix_entry),
1024 if (adapter->msix_entries) {
1025 for (i = 0; i < numvecs; i++)
1026 adapter->msix_entries[i].entry = i;
1028 #ifdef HAVE_PCI_ENABLE_MSIX
1029 err = pci_enable_msix(pdev,
1030 adapter->msix_entries, numvecs);
1032 err = pci_enable_msix_range(pdev,
1033 adapter->msix_entries,
1040 /* MSI-X failed, so fall through and try MSI */
1041 dev_warn(pci_dev_to_dev(pdev), "Failed to initialize MSI-X interrupts. "
1042 "Falling back to MSI interrupts.\n");
1043 igb_reset_interrupt_capability(adapter);
1044 case IGB_INT_MODE_MSI:
1045 if (!pci_enable_msi(pdev))
1046 adapter->flags |= IGB_FLAG_HAS_MSI;
1048 dev_warn(pci_dev_to_dev(pdev), "Failed to initialize MSI "
1049 "interrupts. Falling back to legacy "
1052 case IGB_INT_MODE_LEGACY:
1053 /* disable advanced features and set number of queues to 1 */
1054 igb_reset_sriov_capability(adapter);
1055 adapter->vmdq_pools = 0;
1056 adapter->rss_queues = 1;
1057 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
1058 adapter->num_rx_queues = 1;
1059 adapter->num_tx_queues = 1;
1060 adapter->num_q_vectors = 1;
1061 /* Don't do anything; this is system default */
1066 static void igb_add_ring(struct igb_ring *ring,
1067 struct igb_ring_container *head)
1074 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1075 * @adapter: board private structure to initialize
1076 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1077 * @v_idx: index of vector in adapter struct
1078 * @txr_count: total number of Tx rings to allocate
1079 * @txr_idx: index of first Tx ring to allocate
1080 * @rxr_count: total number of Rx rings to allocate
1081 * @rxr_idx: index of first Rx ring to allocate
1083 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1085 static int igb_alloc_q_vector(struct igb_adapter *adapter,
1086 unsigned int v_count, unsigned int v_idx,
1087 unsigned int txr_count, unsigned int txr_idx,
1088 unsigned int rxr_count, unsigned int rxr_idx)
1090 struct igb_q_vector *q_vector;
1091 struct igb_ring *ring;
1092 int ring_count, size;
1094 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1095 if (txr_count > 1 || rxr_count > 1)
1098 ring_count = txr_count + rxr_count;
1099 size = sizeof(struct igb_q_vector) +
1100 (sizeof(struct igb_ring) * ring_count);
1102 /* allocate q_vector and rings */
1103 q_vector = kzalloc(size, GFP_KERNEL);
1108 /* initialize LRO */
1109 __skb_queue_head_init(&q_vector->lrolist.active);
1112 /* initialize NAPI */
1113 netif_napi_add(adapter->netdev, &q_vector->napi,
1116 /* tie q_vector and adapter together */
1117 adapter->q_vector[v_idx] = q_vector;
1118 q_vector->adapter = adapter;
1120 /* initialize work limits */
1121 q_vector->tx.work_limit = adapter->tx_work_limit;
1123 /* initialize ITR configuration */
1124 q_vector->itr_register = adapter->hw.hw_addr + E1000_EITR(0);
1125 q_vector->itr_val = IGB_START_ITR;
1127 /* initialize pointer to rings */
1128 ring = q_vector->ring;
1130 /* initialize ITR */
1132 /* rx or rx/tx vector */
1133 if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
1134 q_vector->itr_val = adapter->rx_itr_setting;
1136 /* tx only vector */
1137 if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
1138 q_vector->itr_val = adapter->tx_itr_setting;
1142 /* assign generic ring traits */
1143 ring->dev = &adapter->pdev->dev;
1144 ring->netdev = adapter->netdev;
1146 /* configure backlink on ring */
1147 ring->q_vector = q_vector;
1149 /* update q_vector Tx values */
1150 igb_add_ring(ring, &q_vector->tx);
1152 /* For 82575, context index must be unique per ring. */
1153 if (adapter->hw.mac.type == e1000_82575)
1154 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1156 /* apply Tx specific ring traits */
1157 ring->count = adapter->tx_ring_count;
1158 ring->queue_index = txr_idx;
1160 /* assign ring to adapter */
1161 adapter->tx_ring[txr_idx] = ring;
1163 /* push pointer to next ring */
1168 /* assign generic ring traits */
1169 ring->dev = &adapter->pdev->dev;
1170 ring->netdev = adapter->netdev;
1172 /* configure backlink on ring */
1173 ring->q_vector = q_vector;
1175 /* update q_vector Rx values */
1176 igb_add_ring(ring, &q_vector->rx);
1178 #ifndef HAVE_NDO_SET_FEATURES
1179 /* enable rx checksum */
1180 set_bit(IGB_RING_FLAG_RX_CSUM, &ring->flags);
1183 /* set flag indicating ring supports SCTP checksum offload */
1184 if (adapter->hw.mac.type >= e1000_82576)
1185 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1187 if ((adapter->hw.mac.type == e1000_i350) ||
1188 (adapter->hw.mac.type == e1000_i354))
1189 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1191 /* apply Rx specific ring traits */
1192 ring->count = adapter->rx_ring_count;
1193 ring->queue_index = rxr_idx;
1195 /* assign ring to adapter */
1196 adapter->rx_ring[rxr_idx] = ring;
1203 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1204 * @adapter: board private structure to initialize
1206 * We allocate one q_vector per queue interrupt. If allocation fails we
1209 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1211 int q_vectors = adapter->num_q_vectors;
1212 int rxr_remaining = adapter->num_rx_queues;
1213 int txr_remaining = adapter->num_tx_queues;
1214 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1217 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1218 for (; rxr_remaining; v_idx++) {
1219 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1225 /* update counts and index */
1231 for (; v_idx < q_vectors; v_idx++) {
1232 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1233 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1234 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1235 tqpv, txr_idx, rqpv, rxr_idx);
1240 /* update counts and index */
1241 rxr_remaining -= rqpv;
1242 txr_remaining -= tqpv;
1250 adapter->num_tx_queues = 0;
1251 adapter->num_rx_queues = 0;
1252 adapter->num_q_vectors = 0;
1255 igb_free_q_vector(adapter, v_idx);
1261 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1263 * This function initializes the interrupts and allocates all of the queues.
1265 static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
1267 struct pci_dev *pdev = adapter->pdev;
1270 igb_set_interrupt_capability(adapter, msix);
1272 err = igb_alloc_q_vectors(adapter);
1274 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for vectors\n");
1275 goto err_alloc_q_vectors;
1278 igb_cache_ring_register(adapter);
1282 err_alloc_q_vectors:
1283 igb_reset_interrupt_capability(adapter);
1288 * igb_request_irq - initialize interrupts
1290 * Attempts to configure interrupts using the best available
1291 * capabilities of the hardware and kernel.
1293 static int igb_request_irq(struct igb_adapter *adapter)
1295 struct net_device *netdev = adapter->netdev;
1296 struct pci_dev *pdev = adapter->pdev;
1299 if (adapter->msix_entries) {
1300 err = igb_request_msix(adapter);
1303 /* fall back to MSI */
1304 igb_free_all_tx_resources(adapter);
1305 igb_free_all_rx_resources(adapter);
1307 igb_clear_interrupt_scheme(adapter);
1308 igb_reset_sriov_capability(adapter);
1309 err = igb_init_interrupt_scheme(adapter, false);
1312 igb_setup_all_tx_resources(adapter);
1313 igb_setup_all_rx_resources(adapter);
1314 igb_configure(adapter);
1317 igb_assign_vector(adapter->q_vector[0], 0);
1319 if (adapter->flags & IGB_FLAG_HAS_MSI) {
1320 err = request_irq(pdev->irq, &igb_intr_msi, 0,
1321 netdev->name, adapter);
1325 /* fall back to legacy interrupts */
1326 igb_reset_interrupt_capability(adapter);
1327 adapter->flags &= ~IGB_FLAG_HAS_MSI;
1330 err = request_irq(pdev->irq, &igb_intr, IRQF_SHARED,
1331 netdev->name, adapter);
1334 dev_err(pci_dev_to_dev(pdev), "Error %d getting interrupt\n",
1341 static void igb_free_irq(struct igb_adapter *adapter)
1343 if (adapter->msix_entries) {
1346 free_irq(adapter->msix_entries[vector++].vector, adapter);
1348 for (i = 0; i < adapter->num_q_vectors; i++)
1349 free_irq(adapter->msix_entries[vector++].vector,
1350 adapter->q_vector[i]);
1352 free_irq(adapter->pdev->irq, adapter);
1357 * igb_irq_disable - Mask off interrupt generation on the NIC
1358 * @adapter: board private structure
1360 static void igb_irq_disable(struct igb_adapter *adapter)
1362 struct e1000_hw *hw = &adapter->hw;
1365 * we need to be careful when disabling interrupts. The VFs are also
1366 * mapped into these registers and so clearing the bits can cause
1367 * issues on the VF drivers so we only need to clear what we set
1369 if (adapter->msix_entries) {
1370 u32 regval = E1000_READ_REG(hw, E1000_EIAM);
1371 E1000_WRITE_REG(hw, E1000_EIAM, regval & ~adapter->eims_enable_mask);
1372 E1000_WRITE_REG(hw, E1000_EIMC, adapter->eims_enable_mask);
1373 regval = E1000_READ_REG(hw, E1000_EIAC);
1374 E1000_WRITE_REG(hw, E1000_EIAC, regval & ~adapter->eims_enable_mask);
1377 E1000_WRITE_REG(hw, E1000_IAM, 0);
1378 E1000_WRITE_REG(hw, E1000_IMC, ~0);
1379 E1000_WRITE_FLUSH(hw);
1381 if (adapter->msix_entries) {
1384 synchronize_irq(adapter->msix_entries[vector++].vector);
1386 for (i = 0; i < adapter->num_q_vectors; i++)
1387 synchronize_irq(adapter->msix_entries[vector++].vector);
1389 synchronize_irq(adapter->pdev->irq);
1394 * igb_irq_enable - Enable default interrupt generation settings
1395 * @adapter: board private structure
1397 static void igb_irq_enable(struct igb_adapter *adapter)
1399 struct e1000_hw *hw = &adapter->hw;
1401 if (adapter->msix_entries) {
1402 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
1403 u32 regval = E1000_READ_REG(hw, E1000_EIAC);
1404 E1000_WRITE_REG(hw, E1000_EIAC, regval | adapter->eims_enable_mask);
1405 regval = E1000_READ_REG(hw, E1000_EIAM);
1406 E1000_WRITE_REG(hw, E1000_EIAM, regval | adapter->eims_enable_mask);
1407 E1000_WRITE_REG(hw, E1000_EIMS, adapter->eims_enable_mask);
1408 if (adapter->vfs_allocated_count) {
1409 E1000_WRITE_REG(hw, E1000_MBVFIMR, 0xFF);
1410 ims |= E1000_IMS_VMMB;
1412 if ((adapter->hw.mac.type == e1000_i350) ||
1413 (adapter->hw.mac.type == e1000_i354))
1414 ims |= E1000_IMS_MDDET;
1416 E1000_WRITE_REG(hw, E1000_IMS, ims);
1418 E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK |
1420 E1000_WRITE_REG(hw, E1000_IAM, IMS_ENABLE_MASK |
1425 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1427 struct e1000_hw *hw = &adapter->hw;
1428 u16 vid = adapter->hw.mng_cookie.vlan_id;
1429 u16 old_vid = adapter->mng_vlan_id;
1431 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1432 /* add VID to filter table */
1433 igb_vfta_set(adapter, vid, TRUE);
1434 adapter->mng_vlan_id = vid;
1436 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1439 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1441 #ifdef HAVE_VLAN_RX_REGISTER
1442 !vlan_group_get_device(adapter->vlgrp, old_vid)) {
1444 !test_bit(old_vid, adapter->active_vlans)) {
1446 /* remove VID from filter table */
1447 igb_vfta_set(adapter, old_vid, FALSE);
1452 * igb_release_hw_control - release control of the h/w to f/w
1453 * @adapter: address of board private structure
1455 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1456 * For ASF and Pass Through versions of f/w this means that the
1457 * driver is no longer loaded.
1460 static void igb_release_hw_control(struct igb_adapter *adapter)
1462 struct e1000_hw *hw = &adapter->hw;
1465 /* Let firmware take over control of h/w */
1466 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1467 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1468 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1472 * igb_get_hw_control - get control of the h/w from f/w
1473 * @adapter: address of board private structure
1475 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1476 * For ASF and Pass Through versions of f/w this means that
1477 * the driver is loaded.
1480 static void igb_get_hw_control(struct igb_adapter *adapter)
1482 struct e1000_hw *hw = &adapter->hw;
1485 /* Let firmware know the driver has taken over */
1486 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1487 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1488 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1492 * igb_configure - configure the hardware for RX and TX
1493 * @adapter: private board structure
1495 static void igb_configure(struct igb_adapter *adapter)
1497 struct net_device *netdev = adapter->netdev;
1500 igb_get_hw_control(adapter);
1501 igb_set_rx_mode(netdev);
1503 igb_restore_vlan(adapter);
1505 igb_setup_tctl(adapter);
1506 igb_setup_mrqc(adapter);
1507 igb_setup_rctl(adapter);
1509 igb_configure_tx(adapter);
1510 igb_configure_rx(adapter);
1512 e1000_rx_fifo_flush_82575(&adapter->hw);
1513 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
1514 if (adapter->num_tx_queues > 1)
1515 netdev->features |= NETIF_F_MULTI_QUEUE;
1517 netdev->features &= ~NETIF_F_MULTI_QUEUE;
1520 /* call igb_desc_unused which always leaves
1521 * at least 1 descriptor unused to make sure
1522 * next_to_use != next_to_clean */
1523 for (i = 0; i < adapter->num_rx_queues; i++) {
1524 struct igb_ring *ring = adapter->rx_ring[i];
1525 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
1530 * igb_power_up_link - Power up the phy/serdes link
1531 * @adapter: address of board private structure
1533 void igb_power_up_link(struct igb_adapter *adapter)
1535 e1000_phy_hw_reset(&adapter->hw);
1537 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1538 e1000_power_up_phy(&adapter->hw);
1540 e1000_power_up_fiber_serdes_link(&adapter->hw);
1544 * igb_power_down_link - Power down the phy/serdes link
1545 * @adapter: address of board private structure
1547 static void igb_power_down_link(struct igb_adapter *adapter)
1549 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1550 e1000_power_down_phy(&adapter->hw);
1552 e1000_shutdown_fiber_serdes_link(&adapter->hw);
1555 /* Detect and switch function for Media Auto Sense */
1556 static void igb_check_swap_media(struct igb_adapter *adapter)
1558 struct e1000_hw *hw = &adapter->hw;
1559 u32 ctrl_ext, connsw;
1560 bool swap_now = false;
1563 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1564 connsw = E1000_READ_REG(hw, E1000_CONNSW);
1565 link = igb_has_link(adapter);
1568 /* need to live swap if current media is copper and we have fiber/serdes
1572 if ((hw->phy.media_type == e1000_media_type_copper) &&
1573 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
1575 } else if (!(connsw & E1000_CONNSW_SERDESD)) {
1576 /* copper signal takes time to appear */
1577 if (adapter->copper_tries < 2) {
1578 adapter->copper_tries++;
1579 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
1580 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1583 adapter->copper_tries = 0;
1584 if ((connsw & E1000_CONNSW_PHYSD) &&
1585 (!(connsw & E1000_CONNSW_PHY_PDN))) {
1587 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
1588 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1594 switch (hw->phy.media_type) {
1595 case e1000_media_type_copper:
1596 dev_info(pci_dev_to_dev(adapter->pdev),
1597 "%s:MAS: changing media to fiber/serdes\n",
1598 adapter->netdev->name);
1600 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1601 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1602 adapter->copper_tries = 0;
1604 case e1000_media_type_internal_serdes:
1605 case e1000_media_type_fiber:
1606 dev_info(pci_dev_to_dev(adapter->pdev),
1607 "%s:MAS: changing media to copper\n",
1608 adapter->netdev->name);
1610 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1611 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1614 /* shouldn't get here during regular operation */
1615 dev_err(pci_dev_to_dev(adapter->pdev),
1616 "%s:AMS: Invalid media type found, returning\n",
1617 adapter->netdev->name);
1620 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1624 #ifdef HAVE_I2C_SUPPORT
1625 /* igb_get_i2c_data - Reads the I2C SDA data bit
1626 * @hw: pointer to hardware structure
1627 * @i2cctl: Current value of I2CCTL register
1629 * Returns the I2C data bit value
1631 static int igb_get_i2c_data(void *data)
1633 struct igb_adapter *adapter = data;
1634 struct e1000_hw *hw = &adapter->hw;
1635 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1637 return (i2cctl & E1000_I2C_DATA_IN) != 0;
1640 /* igb_set_i2c_data - Sets the I2C data bit
1641 * @data: pointer to hardware structure
1642 * @state: I2C data value (0 or 1) to set
1644 * Sets the I2C data bit
1646 static void igb_set_i2c_data(void *data, int state)
1648 struct igb_adapter *adapter = data;
1649 struct e1000_hw *hw = &adapter->hw;
1650 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1653 i2cctl |= E1000_I2C_DATA_OUT;
1655 i2cctl &= ~E1000_I2C_DATA_OUT;
1657 i2cctl &= ~E1000_I2C_DATA_OE_N;
1658 i2cctl |= E1000_I2C_CLK_OE_N;
1660 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
1661 E1000_WRITE_FLUSH(hw);
1665 /* igb_set_i2c_clk - Sets the I2C SCL clock
1666 * @data: pointer to hardware structure
1667 * @state: state to set clock
1669 * Sets the I2C clock line to state
1671 static void igb_set_i2c_clk(void *data, int state)
1673 struct igb_adapter *adapter = data;
1674 struct e1000_hw *hw = &adapter->hw;
1675 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1678 i2cctl |= E1000_I2C_CLK_OUT;
1679 i2cctl &= ~E1000_I2C_CLK_OE_N;
1681 i2cctl &= ~E1000_I2C_CLK_OUT;
1682 i2cctl &= ~E1000_I2C_CLK_OE_N;
1684 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
1685 E1000_WRITE_FLUSH(hw);
1688 /* igb_get_i2c_clk - Gets the I2C SCL clock state
1689 * @data: pointer to hardware structure
1691 * Gets the I2C clock state
1693 static int igb_get_i2c_clk(void *data)
1695 struct igb_adapter *adapter = data;
1696 struct e1000_hw *hw = &adapter->hw;
1697 s32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
1699 return (i2cctl & E1000_I2C_CLK_IN) != 0;
1702 static const struct i2c_algo_bit_data igb_i2c_algo = {
1703 .setsda = igb_set_i2c_data,
1704 .setscl = igb_set_i2c_clk,
1705 .getsda = igb_get_i2c_data,
1706 .getscl = igb_get_i2c_clk,
1711 /* igb_init_i2c - Init I2C interface
1712 * @adapter: pointer to adapter structure
1715 static s32 igb_init_i2c(struct igb_adapter *adapter)
1717 s32 status = E1000_SUCCESS;
1719 /* I2C interface supported on i350 devices */
1720 if (adapter->hw.mac.type != e1000_i350)
1721 return E1000_SUCCESS;
1723 /* Initialize the i2c bus which is controlled by the registers.
1724 * This bus will use the i2c_algo_bit structue that implements
1725 * the protocol through toggling of the 4 bits in the register.
1727 adapter->i2c_adap.owner = THIS_MODULE;
1728 adapter->i2c_algo = igb_i2c_algo;
1729 adapter->i2c_algo.data = adapter;
1730 adapter->i2c_adap.algo_data = &adapter->i2c_algo;
1731 adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
1732 strlcpy(adapter->i2c_adap.name, "igb BB",
1733 sizeof(adapter->i2c_adap.name));
1734 status = i2c_bit_add_bus(&adapter->i2c_adap);
1738 #endif /* HAVE_I2C_SUPPORT */
1740 * igb_up - Open the interface and prepare it to handle traffic
1741 * @adapter: board private structure
1743 int igb_up(struct igb_adapter *adapter)
1745 struct e1000_hw *hw = &adapter->hw;
1748 /* hardware has been reset, we need to reload some things */
1749 igb_configure(adapter);
1751 clear_bit(__IGB_DOWN, &adapter->state);
1753 for (i = 0; i < adapter->num_q_vectors; i++)
1754 napi_enable(&(adapter->q_vector[i]->napi));
1756 if (adapter->msix_entries)
1757 igb_configure_msix(adapter);
1759 igb_assign_vector(adapter->q_vector[0], 0);
1761 igb_configure_lli(adapter);
1763 /* Clear any pending interrupts. */
1764 E1000_READ_REG(hw, E1000_ICR);
1765 igb_irq_enable(adapter);
1767 /* notify VFs that reset has been completed */
1768 if (adapter->vfs_allocated_count) {
1769 u32 reg_data = E1000_READ_REG(hw, E1000_CTRL_EXT);
1770 reg_data |= E1000_CTRL_EXT_PFRSTD;
1771 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg_data);
1774 netif_tx_start_all_queues(adapter->netdev);
1776 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
1777 schedule_work(&adapter->dma_err_task);
1778 /* start the watchdog. */
1779 hw->mac.get_link_status = 1;
1780 schedule_work(&adapter->watchdog_task);
1782 if ((adapter->flags & IGB_FLAG_EEE) &&
1783 (!hw->dev_spec._82575.eee_disable))
1784 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
1789 void igb_down(struct igb_adapter *adapter)
1791 struct net_device *netdev = adapter->netdev;
1792 struct e1000_hw *hw = &adapter->hw;
1796 /* signal that we're down so the interrupt handler does not
1797 * reschedule our watchdog timer */
1798 set_bit(__IGB_DOWN, &adapter->state);
1800 /* disable receives in the hardware */
1801 rctl = E1000_READ_REG(hw, E1000_RCTL);
1802 E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
1803 /* flush and sleep below */
1805 netif_tx_stop_all_queues(netdev);
1807 /* disable transmits in the hardware */
1808 tctl = E1000_READ_REG(hw, E1000_TCTL);
1809 tctl &= ~E1000_TCTL_EN;
1810 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1811 /* flush both disables and wait for them to finish */
1812 E1000_WRITE_FLUSH(hw);
1813 usleep_range(10000, 20000);
1815 for (i = 0; i < adapter->num_q_vectors; i++)
1816 napi_disable(&(adapter->q_vector[i]->napi));
1818 igb_irq_disable(adapter);
1820 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1822 del_timer_sync(&adapter->watchdog_timer);
1823 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
1824 del_timer_sync(&adapter->dma_err_timer);
1825 del_timer_sync(&adapter->phy_info_timer);
1827 netif_carrier_off(netdev);
1829 /* record the stats before reset*/
1830 igb_update_stats(adapter);
1832 adapter->link_speed = 0;
1833 adapter->link_duplex = 0;
1836 if (!pci_channel_offline(adapter->pdev))
1841 igb_clean_all_tx_rings(adapter);
1842 igb_clean_all_rx_rings(adapter);
1844 /* since we reset the hardware DCA settings were cleared */
1845 igb_setup_dca(adapter);
1849 void igb_reinit_locked(struct igb_adapter *adapter)
1851 WARN_ON(in_interrupt());
1852 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1853 usleep_range(1000, 2000);
1856 clear_bit(__IGB_RESETTING, &adapter->state);
1860 * igb_enable_mas - Media Autosense re-enable after swap
1862 * @adapter: adapter struct
1864 static s32 igb_enable_mas(struct igb_adapter *adapter)
1866 struct e1000_hw *hw = &adapter->hw;
1868 s32 ret_val = E1000_SUCCESS;
1870 connsw = E1000_READ_REG(hw, E1000_CONNSW);
1871 if (hw->phy.media_type == e1000_media_type_copper) {
1872 /* configure for SerDes media detect */
1873 if (!(connsw & E1000_CONNSW_SERDESD)) {
1874 connsw |= E1000_CONNSW_ENRGSRC;
1875 connsw |= E1000_CONNSW_AUTOSENSE_EN;
1876 E1000_WRITE_REG(hw, E1000_CONNSW, connsw);
1877 E1000_WRITE_FLUSH(hw);
1878 } else if (connsw & E1000_CONNSW_SERDESD) {
1879 /* already SerDes, no need to enable anything */
1882 dev_info(pci_dev_to_dev(adapter->pdev),
1883 "%s:MAS: Unable to configure feature, disabling..\n",
1884 adapter->netdev->name);
1885 adapter->flags &= ~IGB_FLAG_MAS_ENABLE;
1891 void igb_reset(struct igb_adapter *adapter)
1893 struct pci_dev *pdev = adapter->pdev;
1894 struct e1000_hw *hw = &adapter->hw;
1895 struct e1000_mac_info *mac = &hw->mac;
1896 struct e1000_fc_info *fc = &hw->fc;
1897 u32 pba = 0, tx_space, min_tx_space, min_rx_space, hwm;
1899 /* Repartition Pba for greater than 9k mtu
1900 * To take effect CTRL.RST is required.
1902 switch (mac->type) {
1906 pba = E1000_READ_REG(hw, E1000_RXPBS);
1907 pba = e1000_rxpbs_adjust_82580(pba);
1910 pba = E1000_READ_REG(hw, E1000_RXPBS);
1911 pba &= E1000_RXPBS_SIZE_MASK_82576;
1917 pba = E1000_PBA_34K;
1921 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
1922 (mac->type < e1000_82576)) {
1923 /* adjust PBA for jumbo frames */
1924 E1000_WRITE_REG(hw, E1000_PBA, pba);
1926 /* To maintain wire speed transmits, the Tx FIFO should be
1927 * large enough to accommodate two full transmit packets,
1928 * rounded up to the next 1KB and expressed in KB. Likewise,
1929 * the Rx FIFO should be large enough to accommodate at least
1930 * one full receive packet and is similarly rounded up and
1931 * expressed in KB. */
1932 pba = E1000_READ_REG(hw, E1000_PBA);
1933 /* upper 16 bits has Tx packet buffer allocation size in KB */
1934 tx_space = pba >> 16;
1935 /* lower 16 bits has Rx packet buffer allocation size in KB */
1937 /* the tx fifo also stores 16 bytes of information about the tx
1938 * but don't include ethernet FCS because hardware appends it */
1939 min_tx_space = (adapter->max_frame_size +
1940 sizeof(union e1000_adv_tx_desc) -
1942 min_tx_space = ALIGN(min_tx_space, 1024);
1943 min_tx_space >>= 10;
1944 /* software strips receive CRC, so leave room for it */
1945 min_rx_space = adapter->max_frame_size;
1946 min_rx_space = ALIGN(min_rx_space, 1024);
1947 min_rx_space >>= 10;
1949 /* If current Tx allocation is less than the min Tx FIFO size,
1950 * and the min Tx FIFO size is less than the current Rx FIFO
1951 * allocation, take space away from current Rx allocation */
1952 if (tx_space < min_tx_space &&
1953 ((min_tx_space - tx_space) < pba)) {
1954 pba = pba - (min_tx_space - tx_space);
1956 /* if short on rx space, rx wins and must trump tx
1958 if (pba < min_rx_space)
1961 E1000_WRITE_REG(hw, E1000_PBA, pba);
1964 /* flow control settings */
1965 /* The high water mark must be low enough to fit one full frame
1966 * (or the size used for early receive) above it in the Rx FIFO.
1967 * Set it to the lower of:
1968 * - 90% of the Rx FIFO size, or
1969 * - the full Rx FIFO size minus one full frame */
1970 hwm = min(((pba << 10) * 9 / 10),
1971 ((pba << 10) - 2 * adapter->max_frame_size));
1973 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
1974 fc->low_water = fc->high_water - 16;
1975 fc->pause_time = 0xFFFF;
1977 fc->current_mode = fc->requested_mode;
1979 /* disable receive for all VFs and wait one second */
1980 if (adapter->vfs_allocated_count) {
1983 * Clear all flags except indication that the PF has set
1984 * the VF MAC addresses administratively
1986 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
1987 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
1989 /* ping all the active vfs to let them know we are going down */
1990 igb_ping_all_vfs(adapter);
1992 /* disable transmits and receives */
1993 E1000_WRITE_REG(hw, E1000_VFRE, 0);
1994 E1000_WRITE_REG(hw, E1000_VFTE, 0);
1997 /* Allow time for pending master requests to run */
1999 E1000_WRITE_REG(hw, E1000_WUC, 0);
2001 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
2002 e1000_setup_init_funcs(hw, TRUE);
2003 igb_check_options(adapter);
2004 e1000_get_bus_info(hw);
2005 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
2007 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
2008 if (igb_enable_mas(adapter))
2009 dev_err(pci_dev_to_dev(pdev),
2010 "Error enabling Media Auto Sense\n");
2012 if (e1000_init_hw(hw))
2013 dev_err(pci_dev_to_dev(pdev), "Hardware Error\n");
2016 * Flow control settings reset on hardware reset, so guarantee flow
2017 * control is off when forcing speed.
2019 if (!hw->mac.autoneg)
2020 e1000_force_mac_fc(hw);
2022 igb_init_dmac(adapter, pba);
2023 /* Re-initialize the thermal sensor on i350 devices. */
2024 if (mac->type == e1000_i350 && hw->bus.func == 0) {
2026 * If present, re-initialize the external thermal sensor
2030 e1000_set_i2c_bb(hw);
2031 e1000_init_thermal_sensor_thresh(hw);
2034 /*Re-establish EEE setting */
2035 if (hw->phy.media_type == e1000_media_type_copper) {
2036 switch (mac->type) {
2040 e1000_set_eee_i350(hw);
2043 e1000_set_eee_i354(hw);
2050 if (!netif_running(adapter->netdev))
2051 igb_power_down_link(adapter);
2053 igb_update_mng_vlan(adapter);
2055 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2056 E1000_WRITE_REG(hw, E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
2059 #ifdef HAVE_PTP_1588_CLOCK
2060 /* Re-enable PTP, where applicable. */
2061 igb_ptp_reset(adapter);
2062 #endif /* HAVE_PTP_1588_CLOCK */
2064 e1000_get_phy_info(hw);
2069 #ifdef HAVE_NDO_SET_FEATURES
2070 static kni_netdev_features_t igb_fix_features(struct net_device *netdev,
2071 kni_netdev_features_t features)
2074 * Since there is no support for separate tx vlan accel
2075 * enabled make sure tx flag is cleared if rx is.
2077 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2078 if (!(features & NETIF_F_HW_VLAN_CTAG_RX))
2079 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2081 if (!(features & NETIF_F_HW_VLAN_RX))
2082 features &= ~NETIF_F_HW_VLAN_TX;
2085 /* If Rx checksum is disabled, then LRO should also be disabled */
2086 if (!(features & NETIF_F_RXCSUM))
2087 features &= ~NETIF_F_LRO;
2092 static int igb_set_features(struct net_device *netdev,
2093 kni_netdev_features_t features)
2095 u32 changed = netdev->features ^ features;
2097 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2098 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2100 if (changed & NETIF_F_HW_VLAN_RX)
2102 igb_vlan_mode(netdev, features);
2108 #ifdef USE_CONST_DEV_UC_CHAR
2109 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
2110 struct net_device *dev,
2111 const unsigned char *addr,
2112 #ifdef HAVE_NDO_FDB_ADD_VID
2117 static int igb_ndo_fdb_add(struct ndmsg *ndm,
2118 struct net_device *dev,
2119 unsigned char *addr,
2123 struct igb_adapter *adapter = netdev_priv(dev);
2124 struct e1000_hw *hw = &adapter->hw;
2127 if (!(adapter->vfs_allocated_count))
2130 /* Hardware does not support aging addresses so if a
2131 * ndm_state is given only allow permanent addresses
2133 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2134 pr_info("%s: FDB only supports static addresses\n",
2139 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
2140 u32 rar_uc_entries = hw->mac.rar_entry_count -
2141 (adapter->vfs_allocated_count + 1);
2143 if (netdev_uc_count(dev) < rar_uc_entries)
2144 err = dev_uc_add_excl(dev, addr);
2147 } else if (is_multicast_ether_addr(addr)) {
2148 err = dev_mc_add_excl(dev, addr);
2153 /* Only return duplicate errors if NLM_F_EXCL is set */
2154 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2160 #ifndef USE_DEFAULT_FDB_DEL_DUMP
2161 #ifdef USE_CONST_DEV_UC_CHAR
2162 static int igb_ndo_fdb_del(struct ndmsg *ndm,
2163 struct net_device *dev,
2164 const unsigned char *addr)
2166 static int igb_ndo_fdb_del(struct ndmsg *ndm,
2167 struct net_device *dev,
2168 unsigned char *addr)
2171 struct igb_adapter *adapter = netdev_priv(dev);
2172 int err = -EOPNOTSUPP;
2174 if (ndm->ndm_state & NUD_PERMANENT) {
2175 pr_info("%s: FDB only supports static addresses\n",
2180 if (adapter->vfs_allocated_count) {
2181 if (is_unicast_ether_addr(addr))
2182 err = dev_uc_del(dev, addr);
2183 else if (is_multicast_ether_addr(addr))
2184 err = dev_mc_del(dev, addr);
2192 static int igb_ndo_fdb_dump(struct sk_buff *skb,
2193 struct netlink_callback *cb,
2194 struct net_device *dev,
2197 struct igb_adapter *adapter = netdev_priv(dev);
2199 if (adapter->vfs_allocated_count)
2200 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
2204 #endif /* USE_DEFAULT_FDB_DEL_DUMP */
2206 #ifdef HAVE_BRIDGE_ATTRIBS
2207 #ifdef HAVE_NDO_BRIDGE_SET_DEL_LINK_FLAGS
2208 static int igb_ndo_bridge_setlink(struct net_device *dev,
2209 struct nlmsghdr *nlh,
2210 #ifdef HAVE_NDO_BRIDGE_SETLINK_EXTACK
2211 u16 flags, struct netlink_ext_ack *extack)
2217 static int igb_ndo_bridge_setlink(struct net_device *dev,
2218 struct nlmsghdr *nlh)
2219 #endif /* HAVE_NDO_BRIDGE_SET_DEL_LINK_FLAGS */
2221 struct igb_adapter *adapter = netdev_priv(dev);
2222 struct e1000_hw *hw = &adapter->hw;
2223 struct nlattr *attr, *br_spec;
2226 if (!(adapter->vfs_allocated_count))
2229 switch (adapter->hw.mac.type) {
2238 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
2240 nla_for_each_nested(attr, br_spec, rem) {
2243 if (nla_type(attr) != IFLA_BRIDGE_MODE)
2246 mode = nla_get_u16(attr);
2247 if (mode == BRIDGE_MODE_VEPA) {
2248 e1000_vmdq_set_loopback_pf(hw, 0);
2249 adapter->flags &= ~IGB_FLAG_LOOPBACK_ENABLE;
2250 } else if (mode == BRIDGE_MODE_VEB) {
2251 e1000_vmdq_set_loopback_pf(hw, 1);
2252 adapter->flags |= IGB_FLAG_LOOPBACK_ENABLE;
2256 netdev_info(adapter->netdev, "enabling bridge mode: %s\n",
2257 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
2263 #ifdef HAVE_BRIDGE_FILTER
2264 #ifdef HAVE_NDO_BRIDGE_GETLINK_NLFLAGS
2265 static int igb_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2266 struct net_device *dev, u32 filter_mask,
2269 static int igb_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2270 struct net_device *dev, u32 filter_mask)
2271 #endif /* HAVE_NDO_BRIDGE_GETLINK_NLFLAGS */
2273 static int igb_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2274 struct net_device *dev)
2277 struct igb_adapter *adapter = netdev_priv(dev);
2280 if (!(adapter->vfs_allocated_count))
2283 if (adapter->flags & IGB_FLAG_LOOPBACK_ENABLE)
2284 mode = BRIDGE_MODE_VEB;
2286 mode = BRIDGE_MODE_VEPA;
2288 #ifdef HAVE_NDO_DFLT_BRIDGE_ADD_MASK
2289 #ifdef HAVE_NDO_BRIDGE_GETLINK_NLFLAGS
2290 #ifdef HAVE_NDO_BRIDGE_GETLINK_FILTER_MASK_VLAN_FILL
2291 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 0, 0,
2292 nlflags, filter_mask, NULL);
2294 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 0, 0, nlflags);
2295 #endif /* HAVE_NDO_BRIDGE_GETLINK_FILTER_MASK_VLAN_FILL */
2297 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 0, 0);
2298 #endif /* HAVE_NDO_BRIDGE_GETLINK_NLFLAGS */
2300 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
2301 #endif /* HAVE_NDO_DFLT_BRIDGE_ADD_MASK */
2303 #endif /* HAVE_BRIDGE_ATTRIBS */
2304 #endif /* NTF_SELF */
2306 #endif /* HAVE_NDO_SET_FEATURES */
2307 #ifdef HAVE_NET_DEVICE_OPS
2308 static const struct net_device_ops igb_netdev_ops = {
2309 .ndo_open = igb_open,
2310 .ndo_stop = igb_close,
2311 .ndo_start_xmit = igb_xmit_frame,
2312 .ndo_get_stats = igb_get_stats,
2313 .ndo_set_rx_mode = igb_set_rx_mode,
2314 .ndo_set_mac_address = igb_set_mac,
2315 .ndo_change_mtu = igb_change_mtu,
2316 .ndo_do_ioctl = igb_ioctl,
2317 .ndo_tx_timeout = igb_tx_timeout,
2318 .ndo_validate_addr = eth_validate_addr,
2319 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
2320 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
2322 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
2323 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
2324 #ifdef HAVE_VF_MIN_MAX_TXRATE
2325 .ndo_set_vf_rate = igb_ndo_set_vf_bw,
2326 #else /* HAVE_VF_MIN_MAX_TXRATE */
2327 .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
2328 #endif /* HAVE_VF_MIN_MAX_TXRATE */
2329 .ndo_get_vf_config = igb_ndo_get_vf_config,
2330 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
2331 .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
2332 #endif /* HAVE_VF_SPOOFCHK_CONFIGURE */
2333 #endif /* IFLA_VF_MAX */
2334 #ifdef CONFIG_NET_POLL_CONTROLLER
2335 .ndo_poll_controller = igb_netpoll,
2337 #ifdef HAVE_NDO_SET_FEATURES
2338 .ndo_fix_features = igb_fix_features,
2339 .ndo_set_features = igb_set_features,
2341 #ifdef HAVE_VLAN_RX_REGISTER
2342 .ndo_vlan_rx_register = igb_vlan_mode,
2344 #ifndef HAVE_RHEL6_NETDEV_OPS_EXT_FDB
2346 .ndo_fdb_add = igb_ndo_fdb_add,
2347 #ifndef USE_DEFAULT_FDB_DEL_DUMP
2348 .ndo_fdb_del = igb_ndo_fdb_del,
2349 .ndo_fdb_dump = igb_ndo_fdb_dump,
2351 #endif /* ! HAVE_RHEL6_NETDEV_OPS_EXT_FDB */
2352 #ifdef HAVE_BRIDGE_ATTRIBS
2353 .ndo_bridge_setlink = igb_ndo_bridge_setlink,
2354 .ndo_bridge_getlink = igb_ndo_bridge_getlink,
2355 #endif /* HAVE_BRIDGE_ATTRIBS */
2359 #ifdef CONFIG_IGB_VMDQ_NETDEV
2360 static const struct net_device_ops igb_vmdq_ops = {
2361 .ndo_open = &igb_vmdq_open,
2362 .ndo_stop = &igb_vmdq_close,
2363 .ndo_start_xmit = &igb_vmdq_xmit_frame,
2364 .ndo_get_stats = &igb_vmdq_get_stats,
2365 .ndo_set_rx_mode = &igb_vmdq_set_rx_mode,
2366 .ndo_validate_addr = eth_validate_addr,
2367 .ndo_set_mac_address = &igb_vmdq_set_mac,
2368 .ndo_change_mtu = &igb_vmdq_change_mtu,
2369 .ndo_tx_timeout = &igb_vmdq_tx_timeout,
2370 .ndo_vlan_rx_register = &igb_vmdq_vlan_rx_register,
2371 .ndo_vlan_rx_add_vid = &igb_vmdq_vlan_rx_add_vid,
2372 .ndo_vlan_rx_kill_vid = &igb_vmdq_vlan_rx_kill_vid,
2375 #endif /* CONFIG_IGB_VMDQ_NETDEV */
2376 #endif /* HAVE_NET_DEVICE_OPS */
2377 #ifdef CONFIG_IGB_VMDQ_NETDEV
2378 void igb_assign_vmdq_netdev_ops(struct net_device *vnetdev)
2380 #ifdef HAVE_NET_DEVICE_OPS
2381 vnetdev->netdev_ops = &igb_vmdq_ops;
2383 dev->open = &igb_vmdq_open;
2384 dev->stop = &igb_vmdq_close;
2385 dev->hard_start_xmit = &igb_vmdq_xmit_frame;
2386 dev->get_stats = &igb_vmdq_get_stats;
2387 #ifdef HAVE_SET_RX_MODE
2388 dev->set_rx_mode = &igb_vmdq_set_rx_mode;
2390 dev->set_multicast_list = &igb_vmdq_set_rx_mode;
2391 dev->set_mac_address = &igb_vmdq_set_mac;
2392 dev->change_mtu = &igb_vmdq_change_mtu;
2393 #ifdef HAVE_TX_TIMEOUT
2394 dev->tx_timeout = &igb_vmdq_tx_timeout;
2396 #if defined(NETIF_F_HW_VLAN_TX) || defined(NETIF_F_HW_VLAN_CTAG_TX)
2397 dev->vlan_rx_register = &igb_vmdq_vlan_rx_register;
2398 dev->vlan_rx_add_vid = &igb_vmdq_vlan_rx_add_vid;
2399 dev->vlan_rx_kill_vid = &igb_vmdq_vlan_rx_kill_vid;
2402 igb_vmdq_set_ethtool_ops(vnetdev);
2403 vnetdev->watchdog_timeo = 5 * HZ;
2407 int igb_init_vmdq_netdevs(struct igb_adapter *adapter)
2409 int pool, err = 0, base_queue;
2410 struct net_device *vnetdev;
2411 struct igb_vmdq_adapter *vmdq_adapter;
2413 for (pool = 1; pool < adapter->vmdq_pools; pool++) {
2414 int qpp = (!adapter->rss_queues ? 1 : adapter->rss_queues);
2415 base_queue = pool * qpp;
2416 vnetdev = alloc_etherdev(sizeof(struct igb_vmdq_adapter));
2421 vmdq_adapter = netdev_priv(vnetdev);
2422 vmdq_adapter->vnetdev = vnetdev;
2423 vmdq_adapter->real_adapter = adapter;
2424 vmdq_adapter->rx_ring = adapter->rx_ring[base_queue];
2425 vmdq_adapter->tx_ring = adapter->tx_ring[base_queue];
2426 igb_assign_vmdq_netdev_ops(vnetdev);
2427 snprintf(vnetdev->name, IFNAMSIZ, "%sv%d",
2428 adapter->netdev->name, pool);
2429 vnetdev->features = adapter->netdev->features;
2430 #ifdef HAVE_NETDEV_VLAN_FEATURES
2431 vnetdev->vlan_features = adapter->netdev->vlan_features;
2433 adapter->vmdq_netdev[pool-1] = vnetdev;
2434 err = register_netdev(vnetdev);
2441 int igb_remove_vmdq_netdevs(struct igb_adapter *adapter)
2445 for (pool = 1; pool < adapter->vmdq_pools; pool++) {
2446 unregister_netdev(adapter->vmdq_netdev[pool-1]);
2447 free_netdev(adapter->vmdq_netdev[pool-1]);
2448 adapter->vmdq_netdev[pool-1] = NULL;
2452 #endif /* CONFIG_IGB_VMDQ_NETDEV */
2455 * igb_set_fw_version - Configure version string for ethtool
2456 * @adapter: adapter struct
2459 static void igb_set_fw_version(struct igb_adapter *adapter)
2461 struct e1000_hw *hw = &adapter->hw;
2462 struct e1000_fw_version fw;
2464 e1000_get_fw_version(hw, &fw);
2466 switch (hw->mac.type) {
2469 if (!(e1000_get_flash_presence_i210(hw))) {
2470 snprintf(adapter->fw_version,
2471 sizeof(adapter->fw_version),
2473 fw.invm_major, fw.invm_minor, fw.invm_img_type);
2478 /* if option rom is valid, display its version too*/
2480 snprintf(adapter->fw_version,
2481 sizeof(adapter->fw_version),
2482 "%d.%d, 0x%08x, %d.%d.%d",
2483 fw.eep_major, fw.eep_minor, fw.etrack_id,
2484 fw.or_major, fw.or_build, fw.or_patch);
2487 if (fw.etrack_id != 0X0000) {
2488 snprintf(adapter->fw_version,
2489 sizeof(adapter->fw_version),
2491 fw.eep_major, fw.eep_minor, fw.etrack_id);
2493 snprintf(adapter->fw_version,
2494 sizeof(adapter->fw_version),
2496 fw.eep_major, fw.eep_minor, fw.eep_build);
2506 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2508 * @adapter: adapter struct
2510 static void igb_init_mas(struct igb_adapter *adapter)
2512 struct e1000_hw *hw = &adapter->hw;
2515 e1000_read_nvm(hw, NVM_COMPAT, 1, &eeprom_data);
2516 switch (hw->bus.func) {
2518 if (eeprom_data & IGB_MAS_ENABLE_0)
2519 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2522 if (eeprom_data & IGB_MAS_ENABLE_1)
2523 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2526 if (eeprom_data & IGB_MAS_ENABLE_2)
2527 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2530 if (eeprom_data & IGB_MAS_ENABLE_3)
2531 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2534 /* Shouldn't get here */
2535 dev_err(pci_dev_to_dev(adapter->pdev),
2536 "%s:AMS: Invalid port configuration, returning\n",
2537 adapter->netdev->name);
2543 * igb_probe - Device Initialization Routine
2544 * @pdev: PCI device information struct
2545 * @ent: entry in igb_pci_tbl
2547 * Returns 0 on success, negative on failure
2549 * igb_probe initializes an adapter identified by a pci_dev structure.
2550 * The OS initialization, configuring of the adapter private structure,
2551 * and a hardware reset occur.
2553 static int __devinit igb_probe(struct pci_dev *pdev,
2554 const struct pci_device_id *ent)
2556 struct net_device *netdev;
2557 struct igb_adapter *adapter;
2558 struct e1000_hw *hw;
2559 u16 eeprom_data = 0;
2560 u8 pba_str[E1000_PBANUM_LENGTH];
2562 static int global_quad_port_a; /* global quad port a indication */
2563 int i, err, pci_using_dac;
2564 static int cards_found;
2566 err = pci_enable_device_mem(pdev);
2571 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
2573 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
2577 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
2579 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
2581 IGB_ERR("No usable DMA configuration, "
2588 #ifndef HAVE_ASPM_QUIRKS
2589 /* 82575 requires that the pci-e link partner disable the L0s state */
2590 switch (pdev->device) {
2591 case E1000_DEV_ID_82575EB_COPPER:
2592 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2593 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2594 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
2599 #endif /* HAVE_ASPM_QUIRKS */
2600 err = pci_request_selected_regions(pdev,
2601 pci_select_bars(pdev,
2607 pci_enable_pcie_error_reporting(pdev);
2609 pci_set_master(pdev);
2613 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
2616 netdev = alloc_etherdev(sizeof(struct igb_adapter));
2617 #endif /* HAVE_TX_MQ */
2619 goto err_alloc_etherdev;
2621 SET_MODULE_OWNER(netdev);
2622 SET_NETDEV_DEV(netdev, &pdev->dev);
2624 pci_set_drvdata(pdev, netdev);
2625 adapter = netdev_priv(netdev);
2626 adapter->netdev = netdev;
2627 adapter->pdev = pdev;
2630 adapter->port_num = hw->bus.func;
2631 adapter->msg_enable = (1 << debug) - 1;
2634 err = pci_save_state(pdev);
2639 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2640 pci_resource_len(pdev, 0));
2644 #ifdef HAVE_NET_DEVICE_OPS
2645 netdev->netdev_ops = &igb_netdev_ops;
2646 #else /* HAVE_NET_DEVICE_OPS */
2647 netdev->open = &igb_open;
2648 netdev->stop = &igb_close;
2649 netdev->get_stats = &igb_get_stats;
2650 #ifdef HAVE_SET_RX_MODE
2651 netdev->set_rx_mode = &igb_set_rx_mode;
2653 netdev->set_multicast_list = &igb_set_rx_mode;
2654 netdev->set_mac_address = &igb_set_mac;
2655 netdev->change_mtu = &igb_change_mtu;
2656 netdev->do_ioctl = &igb_ioctl;
2657 #ifdef HAVE_TX_TIMEOUT
2658 netdev->tx_timeout = &igb_tx_timeout;
2660 netdev->vlan_rx_register = igb_vlan_mode;
2661 netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
2662 netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
2663 #ifdef CONFIG_NET_POLL_CONTROLLER
2664 netdev->poll_controller = igb_netpoll;
2666 netdev->hard_start_xmit = &igb_xmit_frame;
2667 #endif /* HAVE_NET_DEVICE_OPS */
2668 igb_set_ethtool_ops(netdev);
2669 #ifdef HAVE_TX_TIMEOUT
2670 netdev->watchdog_timeo = 5 * HZ;
2673 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2675 adapter->bd_number = cards_found;
2677 /* setup the private structure */
2678 err = igb_sw_init(adapter);
2682 e1000_get_bus_info(hw);
2684 hw->phy.autoneg_wait_to_complete = FALSE;
2685 hw->mac.adaptive_ifs = FALSE;
2687 /* Copper options */
2688 if (hw->phy.media_type == e1000_media_type_copper) {
2689 hw->phy.mdix = AUTO_ALL_MODES;
2690 hw->phy.disable_polarity_correction = FALSE;
2691 hw->phy.ms_type = e1000_ms_hw_default;
2694 if (e1000_check_reset_block(hw))
2695 dev_info(pci_dev_to_dev(pdev),
2696 "PHY reset is blocked due to SOL/IDER session.\n");
2699 * features is initialized to 0 in allocation, it might have bits
2700 * set by igb_sw_init so we should use an or instead of an
2703 netdev->features |= NETIF_F_SG |
2705 #ifdef NETIF_F_IPV6_CSUM
2713 #endif /* NETIF_F_TSO */
2714 #ifdef NETIF_F_RXHASH
2718 #ifdef NETIF_F_HW_VLAN_CTAG_RX
2719 NETIF_F_HW_VLAN_CTAG_RX |
2720 NETIF_F_HW_VLAN_CTAG_TX;
2722 NETIF_F_HW_VLAN_RX |
2726 if (hw->mac.type >= e1000_82576)
2727 netdev->features |= NETIF_F_SCTP_CSUM;
2729 #ifdef HAVE_NDO_SET_FEATURES
2730 /* copy netdev features into list of user selectable features */
2731 netdev->hw_features |= netdev->features;
2734 /* give us the option of enabling LRO later */
2735 netdev->hw_features |= NETIF_F_LRO;
2740 /* this is only needed on kernels prior to 2.6.39 */
2741 netdev->features |= NETIF_F_GRO;
2745 /* set this bit last since it cannot be part of hw_features */
2746 #ifdef NETIF_F_HW_VLAN_CTAG_FILTER
2747 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2749 netdev->features |= NETIF_F_HW_VLAN_FILTER;
2752 #ifdef HAVE_NETDEV_VLAN_FEATURES
2753 netdev->vlan_features |= NETIF_F_TSO |
2761 netdev->features |= NETIF_F_HIGHDMA;
2763 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
2765 if (adapter->dmac != IGB_DMAC_DISABLE)
2766 printk("%s: DMA Coalescing is enabled..\n", netdev->name);
2769 /* before reading the NVM, reset the controller to put the device in a
2770 * known good starting state */
2773 /* make sure the NVM is good */
2774 if (e1000_validate_nvm_checksum(hw) < 0) {
2775 dev_err(pci_dev_to_dev(pdev), "The NVM Checksum Is Not"
2781 /* copy the MAC address out of the NVM */
2782 if (e1000_read_mac_addr(hw))
2783 dev_err(pci_dev_to_dev(pdev), "NVM Read Error\n");
2784 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2785 #ifdef ETHTOOL_GPERMADDR
2786 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
2788 if (!is_valid_ether_addr(netdev->perm_addr)) {
2790 if (!is_valid_ether_addr(netdev->dev_addr)) {
2792 dev_err(pci_dev_to_dev(pdev), "Invalid MAC Address\n");
2797 memcpy(&adapter->mac_table[0].addr, hw->mac.addr, netdev->addr_len);
2798 adapter->mac_table[0].queue = adapter->vfs_allocated_count;
2799 adapter->mac_table[0].state = (IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE);
2800 igb_rar_set(adapter, 0);
2802 /* get firmware version for ethtool -i */
2803 igb_set_fw_version(adapter);
2805 /* Check if Media Autosense is enabled */
2806 if (hw->mac.type == e1000_82580)
2807 igb_init_mas(adapter);
2808 #ifdef HAVE_TIMER_SETUP
2809 timer_setup(&adapter->watchdog_timer, &igb_watchdog, 0);
2810 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
2811 timer_setup(&adapter->dma_err_timer, &igb_dma_err_timer, 0);
2812 timer_setup(&adapter->phy_info_timer, &igb_update_phy_info, 0);
2814 setup_timer(&adapter->watchdog_timer, &igb_watchdog,
2815 (unsigned long) adapter);
2816 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
2817 setup_timer(&adapter->dma_err_timer, &igb_dma_err_timer,
2818 (unsigned long) adapter);
2819 setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
2820 (unsigned long) adapter);
2823 INIT_WORK(&adapter->reset_task, igb_reset_task);
2824 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
2825 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
2826 INIT_WORK(&adapter->dma_err_task, igb_dma_err_task);
2828 /* Initialize link properties that are user-changeable */
2829 adapter->fc_autoneg = true;
2830 hw->mac.autoneg = true;
2831 hw->phy.autoneg_advertised = 0x2f;
2833 hw->fc.requested_mode = e1000_fc_default;
2834 hw->fc.current_mode = e1000_fc_default;
2836 e1000_validate_mdi_setting(hw);
2838 /* By default, support wake on port A */
2839 if (hw->bus.func == 0)
2840 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2842 /* Check the NVM for wake support for non-port A ports */
2843 if (hw->mac.type >= e1000_82580)
2844 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2845 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2847 else if (hw->bus.func == 1)
2848 e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
2850 if (eeprom_data & IGB_EEPROM_APME)
2851 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2853 /* now that we have the eeprom settings, apply the special cases where
2854 * the eeprom may be wrong or the board simply won't support wake on
2855 * lan on a particular port */
2856 switch (pdev->device) {
2857 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2858 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2860 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2861 case E1000_DEV_ID_82576_FIBER:
2862 case E1000_DEV_ID_82576_SERDES:
2863 /* Wake events only supported on port A for dual fiber
2864 * regardless of eeprom setting */
2865 if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1)
2866 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2868 case E1000_DEV_ID_82576_QUAD_COPPER:
2869 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
2870 /* if quad port adapter, disable WoL on all but port A */
2871 if (global_quad_port_a != 0)
2872 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2874 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2875 /* Reset for multiple quad port adapters */
2876 if (++global_quad_port_a == 4)
2877 global_quad_port_a = 0;
2880 /* If the device can't wake, don't set software support */
2881 if (!device_can_wakeup(&adapter->pdev->dev))
2882 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2886 /* initialize the wol settings based on the eeprom settings */
2887 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
2888 adapter->wol |= E1000_WUFC_MAG;
2890 /* Some vendors want WoL disabled by default, but still supported */
2891 if ((hw->mac.type == e1000_i350) &&
2892 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
2893 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2897 device_set_wakeup_enable(pci_dev_to_dev(adapter->pdev),
2898 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
2900 /* reset the hardware with the new settings */
2904 #ifdef HAVE_I2C_SUPPORT
2905 /* Init the I2C interface */
2906 err = igb_init_i2c(adapter);
2908 dev_err(&pdev->dev, "failed to init i2c interface\n");
2911 #endif /* HAVE_I2C_SUPPORT */
2913 /* let the f/w know that the h/w is now under the control of the
2915 igb_get_hw_control(adapter);
2917 strncpy(netdev->name, "eth%d", IFNAMSIZ);
2918 err = register_netdev(netdev);
2922 #ifdef CONFIG_IGB_VMDQ_NETDEV
2923 err = igb_init_vmdq_netdevs(adapter);
2927 /* carrier off reporting is important to ethtool even BEFORE open */
2928 netif_carrier_off(netdev);
2931 if (dca_add_requester(&pdev->dev) == E1000_SUCCESS) {
2932 adapter->flags |= IGB_FLAG_DCA_ENABLED;
2933 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
2934 igb_setup_dca(adapter);
2938 #ifdef HAVE_PTP_1588_CLOCK
2939 /* do hw tstamp init after resetting */
2940 igb_ptp_init(adapter);
2941 #endif /* HAVE_PTP_1588_CLOCK */
2943 dev_info(pci_dev_to_dev(pdev), "Intel(R) Gigabit Ethernet Network Connection\n");
2944 /* print bus type/speed/width info */
2945 dev_info(pci_dev_to_dev(pdev), "%s: (PCIe:%s:%s) ",
2947 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5GT/s" :
2948 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0GT/s" :
2949 (hw->mac.type == e1000_i354) ? "integrated" :
2951 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
2952 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
2953 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
2954 (hw->mac.type == e1000_i354) ? "integrated" :
2956 dev_info(pci_dev_to_dev(pdev), "%s: MAC: ", netdev->name);
2957 for (i = 0; i < 6; i++)
2958 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
2960 ret_val = e1000_read_pba_string(hw, pba_str, E1000_PBANUM_LENGTH);
2962 strncpy(pba_str, "Unknown", sizeof(pba_str) - 1);
2963 dev_info(pci_dev_to_dev(pdev), "%s: PBA No: %s\n", netdev->name,
2967 /* Initialize the thermal sensor on i350 devices. */
2968 if (hw->mac.type == e1000_i350) {
2969 if (hw->bus.func == 0) {
2973 * Read the NVM to determine if this i350 device
2974 * supports an external thermal sensor.
2976 e1000_read_nvm(hw, NVM_ETS_CFG, 1, &ets_word);
2977 if (ets_word != 0x0000 && ets_word != 0xFFFF)
2978 adapter->ets = true;
2980 adapter->ets = false;
2984 igb_sysfs_init(adapter);
2988 igb_procfs_init(adapter);
2989 #endif /* IGB_PROCFS */
2990 #endif /* IGB_HWMON */
2992 adapter->ets = false;
2995 if (hw->phy.media_type == e1000_media_type_copper) {
2996 switch (hw->mac.type) {
3000 /* Enable EEE for internal copper PHY devices */
3001 err = e1000_set_eee_i350(hw);
3003 (adapter->flags & IGB_FLAG_EEE))
3004 adapter->eee_advert =
3005 MDIO_EEE_100TX | MDIO_EEE_1000T;
3008 if ((E1000_READ_REG(hw, E1000_CTRL_EXT)) &
3009 (E1000_CTRL_EXT_LINK_MODE_SGMII)) {
3010 err = e1000_set_eee_i354(hw);
3012 (adapter->flags & IGB_FLAG_EEE))
3013 adapter->eee_advert =
3014 MDIO_EEE_100TX | MDIO_EEE_1000T;
3022 /* send driver version info to firmware */
3023 if (hw->mac.type >= e1000_i350)
3024 igb_init_fw(adapter);
3027 if (netdev->features & NETIF_F_LRO)
3028 dev_info(pci_dev_to_dev(pdev), "Internal LRO is enabled \n");
3030 dev_info(pci_dev_to_dev(pdev), "LRO is disabled \n");
3032 dev_info(pci_dev_to_dev(pdev),
3033 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
3034 adapter->msix_entries ? "MSI-X" :
3035 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
3036 adapter->num_rx_queues, adapter->num_tx_queues);
3040 pm_runtime_put_noidle(&pdev->dev);
3044 igb_release_hw_control(adapter);
3045 #ifdef HAVE_I2C_SUPPORT
3046 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
3047 #endif /* HAVE_I2C_SUPPORT */
3049 if (!e1000_check_reset_block(hw))
3050 e1000_phy_hw_reset(hw);
3052 if (hw->flash_address)
3053 iounmap(hw->flash_address);
3055 igb_clear_interrupt_scheme(adapter);
3056 igb_reset_sriov_capability(adapter);
3057 iounmap(hw->hw_addr);
3059 free_netdev(netdev);
3061 pci_release_selected_regions(pdev,
3062 pci_select_bars(pdev, IORESOURCE_MEM));
3065 pci_disable_device(pdev);
3068 #ifdef HAVE_I2C_SUPPORT
3070 * igb_remove_i2c - Cleanup I2C interface
3071 * @adapter: pointer to adapter structure
3074 static void igb_remove_i2c(struct igb_adapter *adapter)
3077 /* free the adapter bus structure */
3078 i2c_del_adapter(&adapter->i2c_adap);
3080 #endif /* HAVE_I2C_SUPPORT */
3083 * igb_remove - Device Removal Routine
3084 * @pdev: PCI device information struct
3086 * igb_remove is called by the PCI subsystem to alert the driver
3087 * that it should release a PCI device. The could be caused by a
3088 * Hot-Plug event, or because the driver is going to be removed from
3091 static void __devexit igb_remove(struct pci_dev *pdev)
3093 struct net_device *netdev = pci_get_drvdata(pdev);
3094 struct igb_adapter *adapter = netdev_priv(netdev);
3095 struct e1000_hw *hw = &adapter->hw;
3097 pm_runtime_get_noresume(&pdev->dev);
3098 #ifdef HAVE_I2C_SUPPORT
3099 igb_remove_i2c(adapter);
3100 #endif /* HAVE_I2C_SUPPORT */
3101 #ifdef HAVE_PTP_1588_CLOCK
3102 igb_ptp_stop(adapter);
3103 #endif /* HAVE_PTP_1588_CLOCK */
3105 /* flush_scheduled work may reschedule our watchdog task, so
3106 * explicitly disable watchdog tasks from being rescheduled */
3107 set_bit(__IGB_DOWN, &adapter->state);
3108 del_timer_sync(&adapter->watchdog_timer);
3109 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
3110 del_timer_sync(&adapter->dma_err_timer);
3111 del_timer_sync(&adapter->phy_info_timer);
3113 flush_scheduled_work();
3116 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
3117 dev_info(pci_dev_to_dev(pdev), "DCA disabled\n");
3118 dca_remove_requester(&pdev->dev);
3119 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
3120 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_DISABLE);
3124 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3125 * would have already happened in close and is redundant. */
3126 igb_release_hw_control(adapter);
3128 unregister_netdev(netdev);
3129 #ifdef CONFIG_IGB_VMDQ_NETDEV
3130 igb_remove_vmdq_netdevs(adapter);
3133 igb_clear_interrupt_scheme(adapter);
3134 igb_reset_sriov_capability(adapter);
3136 iounmap(hw->hw_addr);
3137 if (hw->flash_address)
3138 iounmap(hw->flash_address);
3139 pci_release_selected_regions(pdev,
3140 pci_select_bars(pdev, IORESOURCE_MEM));
3143 igb_sysfs_exit(adapter);
3146 igb_procfs_exit(adapter);
3147 #endif /* IGB_PROCFS */
3148 #endif /* IGB_HWMON */
3149 kfree(adapter->mac_table);
3150 kfree(adapter->shadow_vfta);
3151 free_netdev(netdev);
3153 pci_disable_pcie_error_reporting(pdev);
3155 pci_disable_device(pdev);
3159 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3160 * @adapter: board private structure to initialize
3162 * igb_sw_init initializes the Adapter private data structure.
3163 * Fields are initialized based on PCI device information and
3164 * OS network device settings (MTU size).
3166 static int igb_sw_init(struct igb_adapter *adapter)
3168 struct e1000_hw *hw = &adapter->hw;
3169 struct net_device *netdev = adapter->netdev;
3170 struct pci_dev *pdev = adapter->pdev;
3172 /* PCI config space info */
3174 hw->vendor_id = pdev->vendor;
3175 hw->device_id = pdev->device;
3176 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3177 hw->subsystem_device_id = pdev->subsystem_device;
3179 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3181 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
3183 /* set default ring sizes */
3184 adapter->tx_ring_count = IGB_DEFAULT_TXD;
3185 adapter->rx_ring_count = IGB_DEFAULT_RXD;
3187 /* set default work limits */
3188 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
3190 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3193 /* Initialize the hardware-specific values */
3194 if (e1000_setup_init_funcs(hw, TRUE)) {
3195 dev_err(pci_dev_to_dev(pdev), "Hardware Initialization Failure\n");
3199 adapter->mac_table = kzalloc(sizeof(struct igb_mac_addr) *
3200 hw->mac.rar_entry_count,
3203 /* Setup and initialize a copy of the hw vlan table array */
3204 adapter->shadow_vfta = kzalloc(sizeof(u32) * E1000_VFTA_ENTRIES,
3207 /* These calls may decrease the number of queues */
3208 if (hw->mac.type < e1000_i210) {
3209 igb_set_sriov_capability(adapter);
3212 if (igb_init_interrupt_scheme(adapter, true)) {
3213 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for queues\n");
3217 /* Explicitly disable IRQ since the NIC can be in any state. */
3218 igb_irq_disable(adapter);
3220 set_bit(__IGB_DOWN, &adapter->state);
3226 * igb_open - Called when a network interface is made active
3227 * @netdev: network interface device structure
3229 * Returns 0 on success, negative value on failure
3231 * The open entry point is called when a network interface is made
3232 * active by the system (IFF_UP). At this point all resources needed
3233 * for transmit and receive operations are allocated, the interrupt
3234 * handler is registered with the OS, the watchdog timer is started,
3235 * and the stack is notified that the interface is ready.
3237 static int __igb_open(struct net_device *netdev, bool resuming)
3239 struct igb_adapter *adapter = netdev_priv(netdev);
3240 struct e1000_hw *hw = &adapter->hw;
3241 #ifdef CONFIG_PM_RUNTIME
3242 struct pci_dev *pdev = adapter->pdev;
3243 #endif /* CONFIG_PM_RUNTIME */
3247 /* disallow open during test */
3248 if (test_bit(__IGB_TESTING, &adapter->state)) {
3253 #ifdef CONFIG_PM_RUNTIME
3255 pm_runtime_get_sync(&pdev->dev);
3256 #endif /* CONFIG_PM_RUNTIME */
3258 netif_carrier_off(netdev);
3260 /* allocate transmit descriptors */
3261 err = igb_setup_all_tx_resources(adapter);
3265 /* allocate receive descriptors */
3266 err = igb_setup_all_rx_resources(adapter);
3270 igb_power_up_link(adapter);
3272 /* before we allocate an interrupt, we must be ready to handle it.
3273 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3274 * as soon as we call pci_request_irq, so we have to setup our
3275 * clean_rx handler before we do so. */
3276 igb_configure(adapter);
3278 err = igb_request_irq(adapter);
3282 /* Notify the stack of the actual queue counts. */
3283 netif_set_real_num_tx_queues(netdev,
3284 adapter->vmdq_pools ? 1 :
3285 adapter->num_tx_queues);
3287 err = netif_set_real_num_rx_queues(netdev,
3288 adapter->vmdq_pools ? 1 :
3289 adapter->num_rx_queues);
3291 goto err_set_queues;
3293 /* From here on the code is the same as igb_up() */
3294 clear_bit(__IGB_DOWN, &adapter->state);
3296 for (i = 0; i < adapter->num_q_vectors; i++)
3297 napi_enable(&(adapter->q_vector[i]->napi));
3298 igb_configure_lli(adapter);
3300 /* Clear any pending interrupts. */
3301 E1000_READ_REG(hw, E1000_ICR);
3303 igb_irq_enable(adapter);
3305 /* notify VFs that reset has been completed */
3306 if (adapter->vfs_allocated_count) {
3307 u32 reg_data = E1000_READ_REG(hw, E1000_CTRL_EXT);
3308 reg_data |= E1000_CTRL_EXT_PFRSTD;
3309 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg_data);
3312 netif_tx_start_all_queues(netdev);
3314 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
3315 schedule_work(&adapter->dma_err_task);
3317 /* start the watchdog. */
3318 hw->mac.get_link_status = 1;
3319 schedule_work(&adapter->watchdog_task);
3321 return E1000_SUCCESS;
3324 igb_free_irq(adapter);
3326 igb_release_hw_control(adapter);
3327 igb_power_down_link(adapter);
3328 igb_free_all_rx_resources(adapter);
3330 igb_free_all_tx_resources(adapter);
3334 #ifdef CONFIG_PM_RUNTIME
3336 pm_runtime_put(&pdev->dev);
3337 #endif /* CONFIG_PM_RUNTIME */
3342 static int igb_open(struct net_device *netdev)
3344 return __igb_open(netdev, false);
3348 * igb_close - Disables a network interface
3349 * @netdev: network interface device structure
3351 * Returns 0, this is not allowed to fail
3353 * The close entry point is called when an interface is de-activated
3354 * by the OS. The hardware is still under the driver's control, but
3355 * needs to be disabled. A global MAC reset is issued to stop the
3356 * hardware, and all transmit and receive resources are freed.
3358 static int __igb_close(struct net_device *netdev, bool suspending)
3360 struct igb_adapter *adapter = netdev_priv(netdev);
3361 #ifdef CONFIG_PM_RUNTIME
3362 struct pci_dev *pdev = adapter->pdev;
3363 #endif /* CONFIG_PM_RUNTIME */
3365 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
3367 #ifdef CONFIG_PM_RUNTIME
3369 pm_runtime_get_sync(&pdev->dev);
3370 #endif /* CONFIG_PM_RUNTIME */
3374 igb_release_hw_control(adapter);
3376 igb_free_irq(adapter);
3378 igb_free_all_tx_resources(adapter);
3379 igb_free_all_rx_resources(adapter);
3381 #ifdef CONFIG_PM_RUNTIME
3383 pm_runtime_put_sync(&pdev->dev);
3384 #endif /* CONFIG_PM_RUNTIME */
3389 static int igb_close(struct net_device *netdev)
3391 return __igb_close(netdev, false);
3395 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
3396 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3398 * Return 0 on success, negative on failure
3400 int igb_setup_tx_resources(struct igb_ring *tx_ring)
3402 struct device *dev = tx_ring->dev;
3405 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3406 tx_ring->tx_buffer_info = vzalloc(size);
3407 if (!tx_ring->tx_buffer_info)
3410 /* round up to nearest 4K */
3411 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
3412 tx_ring->size = ALIGN(tx_ring->size, 4096);
3414 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
3415 &tx_ring->dma, GFP_KERNEL);
3420 tx_ring->next_to_use = 0;
3421 tx_ring->next_to_clean = 0;
3426 vfree(tx_ring->tx_buffer_info);
3428 "Unable to allocate memory for the transmit descriptor ring\n");
3433 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
3434 * (Descriptors) for all queues
3435 * @adapter: board private structure
3437 * Return 0 on success, negative on failure
3439 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
3441 struct pci_dev *pdev = adapter->pdev;
3444 for (i = 0; i < adapter->num_tx_queues; i++) {
3445 err = igb_setup_tx_resources(adapter->tx_ring[i]);
3447 dev_err(pci_dev_to_dev(pdev),
3448 "Allocation for Tx Queue %u failed\n", i);
3449 for (i--; i >= 0; i--)
3450 igb_free_tx_resources(adapter->tx_ring[i]);
3459 * igb_setup_tctl - configure the transmit control registers
3460 * @adapter: Board private structure
3462 void igb_setup_tctl(struct igb_adapter *adapter)
3464 struct e1000_hw *hw = &adapter->hw;
3467 /* disable queue 0 which is enabled by default on 82575 and 82576 */
3468 E1000_WRITE_REG(hw, E1000_TXDCTL(0), 0);
3470 /* Program the Transmit Control Register */
3471 tctl = E1000_READ_REG(hw, E1000_TCTL);
3472 tctl &= ~E1000_TCTL_CT;
3473 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3474 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3476 e1000_config_collision_dist(hw);
3478 /* Enable transmits */
3479 tctl |= E1000_TCTL_EN;
3481 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
3484 static u32 igb_tx_wthresh(struct igb_adapter *adapter)
3486 struct e1000_hw *hw = &adapter->hw;
3487 switch (hw->mac.type) {
3491 if (adapter->msix_entries)
3501 * igb_configure_tx_ring - Configure transmit ring after Reset
3502 * @adapter: board private structure
3503 * @ring: tx ring to configure
3505 * Configure a transmit ring after a reset.
3507 void igb_configure_tx_ring(struct igb_adapter *adapter,
3508 struct igb_ring *ring)
3510 struct e1000_hw *hw = &adapter->hw;
3512 u64 tdba = ring->dma;
3513 int reg_idx = ring->reg_idx;
3515 /* disable the queue */
3516 E1000_WRITE_REG(hw, E1000_TXDCTL(reg_idx), 0);
3517 E1000_WRITE_FLUSH(hw);
3520 E1000_WRITE_REG(hw, E1000_TDLEN(reg_idx),
3521 ring->count * sizeof(union e1000_adv_tx_desc));
3522 E1000_WRITE_REG(hw, E1000_TDBAL(reg_idx),
3523 tdba & 0x00000000ffffffffULL);
3524 E1000_WRITE_REG(hw, E1000_TDBAH(reg_idx), tdba >> 32);
3526 ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
3527 E1000_WRITE_REG(hw, E1000_TDH(reg_idx), 0);
3528 writel(0, ring->tail);
3530 txdctl |= IGB_TX_PTHRESH;
3531 txdctl |= IGB_TX_HTHRESH << 8;
3532 txdctl |= igb_tx_wthresh(adapter) << 16;
3534 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
3535 E1000_WRITE_REG(hw, E1000_TXDCTL(reg_idx), txdctl);
3539 * igb_configure_tx - Configure transmit Unit after Reset
3540 * @adapter: board private structure
3542 * Configure the Tx unit of the MAC after a reset.
3544 static void igb_configure_tx(struct igb_adapter *adapter)
3548 for (i = 0; i < adapter->num_tx_queues; i++)
3549 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
3553 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
3554 * @rx_ring: rx descriptor ring (for a specific queue) to setup
3556 * Returns 0 on success, negative on failure
3558 int igb_setup_rx_resources(struct igb_ring *rx_ring)
3560 struct device *dev = rx_ring->dev;
3563 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
3564 rx_ring->rx_buffer_info = vzalloc(size);
3565 if (!rx_ring->rx_buffer_info)
3568 desc_len = sizeof(union e1000_adv_rx_desc);
3570 /* Round up to nearest 4K */
3571 rx_ring->size = rx_ring->count * desc_len;
3572 rx_ring->size = ALIGN(rx_ring->size, 4096);
3574 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
3575 &rx_ring->dma, GFP_KERNEL);
3580 rx_ring->next_to_alloc = 0;
3581 rx_ring->next_to_clean = 0;
3582 rx_ring->next_to_use = 0;
3587 vfree(rx_ring->rx_buffer_info);
3588 rx_ring->rx_buffer_info = NULL;
3589 dev_err(dev, "Unable to allocate memory for the receive descriptor"
3595 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
3596 * (Descriptors) for all queues
3597 * @adapter: board private structure
3599 * Return 0 on success, negative on failure
3601 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
3603 struct pci_dev *pdev = adapter->pdev;
3606 for (i = 0; i < adapter->num_rx_queues; i++) {
3607 err = igb_setup_rx_resources(adapter->rx_ring[i]);
3609 dev_err(pci_dev_to_dev(pdev),
3610 "Allocation for Rx Queue %u failed\n", i);
3611 for (i--; i >= 0; i--)
3612 igb_free_rx_resources(adapter->rx_ring[i]);
3621 * igb_setup_mrqc - configure the multiple receive queue control registers
3622 * @adapter: Board private structure
3624 static void igb_setup_mrqc(struct igb_adapter *adapter)
3626 struct e1000_hw *hw = &adapter->hw;
3628 u32 j, num_rx_queues, shift = 0, shift2 = 0;
3629 static const u32 rsskey[10] = { 0xDA565A6D, 0xC20E5B25, 0x3D256741,
3630 0xB08FA343, 0xCB2BCAD0, 0xB4307BAE,
3631 0xA32DCB77, 0x0CF23080, 0x3BB7426A,
3634 /* Fill out hash function seeds */
3635 for (j = 0; j < 10; j++)
3636 E1000_WRITE_REG(hw, E1000_RSSRK(j), rsskey[j]);
3638 num_rx_queues = adapter->rss_queues;
3640 /* 82575 and 82576 supports 2 RSS queues for VMDq */
3641 switch (hw->mac.type) {
3643 if (adapter->vmdq_pools) {
3651 /* 82576 supports 2 RSS queues for SR-IOV */
3652 if (adapter->vfs_allocated_count || adapter->vmdq_pools) {
3662 * Populate the redirection table 4 entries at a time. To do this
3663 * we are generating the results for n and n+2 and then interleaving
3664 * those with the results with n+1 and n+3.
3666 for (j = 0; j < 32; j++) {
3667 /* first pass generates n and n+2 */
3668 u32 base = ((j * 0x00040004) + 0x00020000) * num_rx_queues;
3669 u32 reta = (base & 0x07800780) >> (7 - shift);
3671 /* second pass generates n+1 and n+3 */
3672 base += 0x00010001 * num_rx_queues;
3673 reta |= (base & 0x07800780) << (1 + shift);
3675 /* generate 2nd table for 82575 based parts */
3677 reta |= (0x01010101 * num_rx_queues) << shift2;
3679 E1000_WRITE_REG(hw, E1000_RETA(j), reta);
3683 * Disable raw packet checksumming so that RSS hash is placed in
3684 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
3685 * offloads as they are enabled by default
3687 rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
3688 rxcsum |= E1000_RXCSUM_PCSD;
3690 if (adapter->hw.mac.type >= e1000_82576)
3691 /* Enable Receive Checksum Offload for SCTP */
3692 rxcsum |= E1000_RXCSUM_CRCOFL;
3694 /* Don't need to set TUOFL or IPOFL, they default to 1 */
3695 E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
3697 /* Generate RSS hash based on packet types, TCP/UDP
3698 * port numbers and/or IPv4/v6 src and dst addresses
3700 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
3701 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3702 E1000_MRQC_RSS_FIELD_IPV6 |
3703 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3704 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
3706 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
3707 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
3708 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
3709 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
3711 /* If VMDq is enabled then we set the appropriate mode for that, else
3712 * we default to RSS so that an RSS hash is calculated per packet even
3713 * if we are only using one queue */
3714 if (adapter->vfs_allocated_count || adapter->vmdq_pools) {
3715 if (hw->mac.type > e1000_82575) {
3716 /* Set the default pool for the PF's first queue */
3717 u32 vtctl = E1000_READ_REG(hw, E1000_VT_CTL);
3718 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
3719 E1000_VT_CTL_DISABLE_DEF_POOL);
3720 vtctl |= adapter->vfs_allocated_count <<
3721 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
3722 E1000_WRITE_REG(hw, E1000_VT_CTL, vtctl);
3723 } else if (adapter->rss_queues > 1) {
3724 /* set default queue for pool 1 to queue 2 */
3725 E1000_WRITE_REG(hw, E1000_VT_CTL,
3726 adapter->rss_queues << 7);
3728 if (adapter->rss_queues > 1)
3729 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
3731 mrqc |= E1000_MRQC_ENABLE_VMDQ;
3733 mrqc |= E1000_MRQC_ENABLE_RSS_4Q;
3735 igb_vmm_control(adapter);
3737 E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
3741 * igb_setup_rctl - configure the receive control registers
3742 * @adapter: Board private structure
3744 void igb_setup_rctl(struct igb_adapter *adapter)
3746 struct e1000_hw *hw = &adapter->hw;
3749 rctl = E1000_READ_REG(hw, E1000_RCTL);
3751 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3752 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
3754 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
3755 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3758 * enable stripping of CRC. It's unlikely this will break BMC
3759 * redirection as it did with e1000. Newer features require
3760 * that the HW strips the CRC.
3762 rctl |= E1000_RCTL_SECRC;
3764 /* disable store bad packets and clear size bits. */
3765 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
3767 /* enable LPE to prevent packets larger than max_frame_size */
3768 rctl |= E1000_RCTL_LPE;
3770 /* disable queue 0 to prevent tail write w/o re-config */
3771 E1000_WRITE_REG(hw, E1000_RXDCTL(0), 0);
3773 /* Attention!!! For SR-IOV PF driver operations you must enable
3774 * queue drop for all VF and PF queues to prevent head of line blocking
3775 * if an un-trusted VF does not provide descriptors to hardware.
3777 if (adapter->vfs_allocated_count) {
3778 /* set all queue drop enable bits */
3779 E1000_WRITE_REG(hw, E1000_QDE, ALL_QUEUES);
3782 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3785 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
3788 struct e1000_hw *hw = &adapter->hw;
3791 /* if it isn't the PF check to see if VFs are enabled and
3792 * increase the size to support vlan tags */
3793 if (vfn < adapter->vfs_allocated_count &&
3794 adapter->vf_data[vfn].vlans_enabled)
3797 #ifdef CONFIG_IGB_VMDQ_NETDEV
3798 if (vfn >= adapter->vfs_allocated_count) {
3799 int queue = vfn - adapter->vfs_allocated_count;
3800 struct igb_vmdq_adapter *vadapter;
3802 vadapter = netdev_priv(adapter->vmdq_netdev[queue-1]);
3803 if (vadapter->vlgrp)
3807 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vfn));
3808 vmolr &= ~E1000_VMOLR_RLPML_MASK;
3809 vmolr |= size | E1000_VMOLR_LPE;
3810 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
3816 * igb_rlpml_set - set maximum receive packet size
3817 * @adapter: board private structure
3819 * Configure maximum receivable packet size.
3821 static void igb_rlpml_set(struct igb_adapter *adapter)
3823 u32 max_frame_size = adapter->max_frame_size;
3824 struct e1000_hw *hw = &adapter->hw;
3825 u16 pf_id = adapter->vfs_allocated_count;
3827 if (adapter->vmdq_pools && hw->mac.type != e1000_82575) {
3829 for (i = 0; i < adapter->vmdq_pools; i++)
3830 igb_set_vf_rlpml(adapter, max_frame_size, pf_id + i);
3832 * If we're in VMDQ or SR-IOV mode, then set global RLPML
3833 * to our max jumbo frame size, in case we need to enable
3834 * jumbo frames on one of the rings later.
3835 * This will not pass over-length frames into the default
3836 * queue because it's gated by the VMOLR.RLPML.
3838 max_frame_size = MAX_JUMBO_FRAME_SIZE;
3840 /* Set VF RLPML for the PF device. */
3841 if (adapter->vfs_allocated_count)
3842 igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
3844 E1000_WRITE_REG(hw, E1000_RLPML, max_frame_size);
3847 static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
3848 int vfn, bool enable)
3850 struct e1000_hw *hw = &adapter->hw;
3854 if (hw->mac.type < e1000_82576)
3857 if (hw->mac.type == e1000_i350)
3858 reg = hw->hw_addr + E1000_DVMOLR(vfn);
3860 reg = hw->hw_addr + E1000_VMOLR(vfn);
3864 val |= E1000_VMOLR_STRVLAN;
3866 val &= ~(E1000_VMOLR_STRVLAN);
3869 static inline void igb_set_vmolr(struct igb_adapter *adapter,
3872 struct e1000_hw *hw = &adapter->hw;
3876 * This register exists only on 82576 and newer so if we are older then
3877 * we should exit and do nothing
3879 if (hw->mac.type < e1000_82576)
3882 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vfn));
3885 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
3887 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
3889 /* clear all bits that might not be set */
3890 vmolr &= ~E1000_VMOLR_RSSE;
3892 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
3893 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
3895 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
3896 vmolr |= E1000_VMOLR_LPE; /* Accept long packets */
3898 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
3902 * igb_configure_rx_ring - Configure a receive ring after Reset
3903 * @adapter: board private structure
3904 * @ring: receive ring to be configured
3906 * Configure the Rx unit of the MAC after a reset.
3908 void igb_configure_rx_ring(struct igb_adapter *adapter,
3909 struct igb_ring *ring)
3911 struct e1000_hw *hw = &adapter->hw;
3912 u64 rdba = ring->dma;
3913 int reg_idx = ring->reg_idx;
3914 u32 srrctl = 0, rxdctl = 0;
3916 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
3918 * RLPML prevents us from receiving a frame larger than max_frame so
3919 * it is safe to just set the rx_buffer_len to max_frame without the
3920 * risk of an skb over panic.
3922 ring->rx_buffer_len = max_t(u32, adapter->max_frame_size,
3923 MAXIMUM_ETHERNET_VLAN_SIZE);
3926 /* disable the queue */
3927 E1000_WRITE_REG(hw, E1000_RXDCTL(reg_idx), 0);
3929 /* Set DMA base address registers */
3930 E1000_WRITE_REG(hw, E1000_RDBAL(reg_idx),
3931 rdba & 0x00000000ffffffffULL);
3932 E1000_WRITE_REG(hw, E1000_RDBAH(reg_idx), rdba >> 32);
3933 E1000_WRITE_REG(hw, E1000_RDLEN(reg_idx),
3934 ring->count * sizeof(union e1000_adv_rx_desc));
3936 /* initialize head and tail */
3937 ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
3938 E1000_WRITE_REG(hw, E1000_RDH(reg_idx), 0);
3939 writel(0, ring->tail);
3941 /* reset next-to- use/clean to place SW in sync with hardwdare */
3942 ring->next_to_clean = 0;
3943 ring->next_to_use = 0;
3944 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
3945 ring->next_to_alloc = 0;
3948 /* set descriptor configuration */
3949 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
3950 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
3951 srrctl |= IGB_RX_BUFSZ >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3952 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
3953 srrctl = ALIGN(ring->rx_buffer_len, 1024) >>
3954 E1000_SRRCTL_BSIZEPKT_SHIFT;
3955 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
3956 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3957 #ifdef HAVE_PTP_1588_CLOCK
3958 if (hw->mac.type >= e1000_82580)
3959 srrctl |= E1000_SRRCTL_TIMESTAMP;
3960 #endif /* HAVE_PTP_1588_CLOCK */
3962 * We should set the drop enable bit if:
3965 * Flow Control is disabled and number of RX queues > 1
3967 * This allows us to avoid head of line blocking for security
3968 * and performance reasons.
3970 if (adapter->vfs_allocated_count ||
3971 (adapter->num_rx_queues > 1 &&
3972 (hw->fc.requested_mode == e1000_fc_none ||
3973 hw->fc.requested_mode == e1000_fc_rx_pause)))
3974 srrctl |= E1000_SRRCTL_DROP_EN;
3976 E1000_WRITE_REG(hw, E1000_SRRCTL(reg_idx), srrctl);
3978 /* set filtering for VMDQ pools */
3979 igb_set_vmolr(adapter, reg_idx & 0x7, true);
3981 rxdctl |= IGB_RX_PTHRESH;
3982 rxdctl |= IGB_RX_HTHRESH << 8;
3983 rxdctl |= IGB_RX_WTHRESH << 16;
3985 /* enable receive descriptor fetching */
3986 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3987 E1000_WRITE_REG(hw, E1000_RXDCTL(reg_idx), rxdctl);
3991 * igb_configure_rx - Configure receive Unit after Reset
3992 * @adapter: board private structure
3994 * Configure the Rx unit of the MAC after a reset.
3996 static void igb_configure_rx(struct igb_adapter *adapter)
4000 /* set UTA to appropriate mode */
4001 igb_set_uta(adapter);
4003 igb_full_sync_mac_table(adapter);
4004 /* Setup the HW Rx Head and Tail Descriptor Pointers and
4005 * the Base and Length of the Rx Descriptor Ring */
4006 for (i = 0; i < adapter->num_rx_queues; i++)
4007 igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
4011 * igb_free_tx_resources - Free Tx Resources per Queue
4012 * @tx_ring: Tx descriptor ring for a specific queue
4014 * Free all transmit software resources
4016 void igb_free_tx_resources(struct igb_ring *tx_ring)
4018 igb_clean_tx_ring(tx_ring);
4020 vfree(tx_ring->tx_buffer_info);
4021 tx_ring->tx_buffer_info = NULL;
4023 /* if not set, then don't free */
4027 dma_free_coherent(tx_ring->dev, tx_ring->size,
4028 tx_ring->desc, tx_ring->dma);
4030 tx_ring->desc = NULL;
4034 * igb_free_all_tx_resources - Free Tx Resources for All Queues
4035 * @adapter: board private structure
4037 * Free all transmit software resources
4039 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
4043 for (i = 0; i < adapter->num_tx_queues; i++)
4044 igb_free_tx_resources(adapter->tx_ring[i]);
4047 void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
4048 struct igb_tx_buffer *tx_buffer)
4050 if (tx_buffer->skb) {
4051 dev_kfree_skb_any(tx_buffer->skb);
4052 if (dma_unmap_len(tx_buffer, len))
4053 dma_unmap_single(ring->dev,
4054 dma_unmap_addr(tx_buffer, dma),
4055 dma_unmap_len(tx_buffer, len),
4057 } else if (dma_unmap_len(tx_buffer, len)) {
4058 dma_unmap_page(ring->dev,
4059 dma_unmap_addr(tx_buffer, dma),
4060 dma_unmap_len(tx_buffer, len),
4063 tx_buffer->next_to_watch = NULL;
4064 tx_buffer->skb = NULL;
4065 dma_unmap_len_set(tx_buffer, len, 0);
4066 /* buffer_info must be completely set up in the transmit path */
4070 * igb_clean_tx_ring - Free Tx Buffers
4071 * @tx_ring: ring to be cleaned
4073 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
4075 struct igb_tx_buffer *buffer_info;
4079 if (!tx_ring->tx_buffer_info)
4081 /* Free all the Tx ring sk_buffs */
4083 for (i = 0; i < tx_ring->count; i++) {
4084 buffer_info = &tx_ring->tx_buffer_info[i];
4085 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
4088 netdev_tx_reset_queue(txring_txq(tx_ring));
4090 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
4091 memset(tx_ring->tx_buffer_info, 0, size);
4093 /* Zero out the descriptor ring */
4094 memset(tx_ring->desc, 0, tx_ring->size);
4096 tx_ring->next_to_use = 0;
4097 tx_ring->next_to_clean = 0;
4101 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
4102 * @adapter: board private structure
4104 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
4108 for (i = 0; i < adapter->num_tx_queues; i++)
4109 igb_clean_tx_ring(adapter->tx_ring[i]);
4113 * igb_free_rx_resources - Free Rx Resources
4114 * @rx_ring: ring to clean the resources from
4116 * Free all receive software resources
4118 void igb_free_rx_resources(struct igb_ring *rx_ring)
4120 igb_clean_rx_ring(rx_ring);
4122 vfree(rx_ring->rx_buffer_info);
4123 rx_ring->rx_buffer_info = NULL;
4125 /* if not set, then don't free */
4129 dma_free_coherent(rx_ring->dev, rx_ring->size,
4130 rx_ring->desc, rx_ring->dma);
4132 rx_ring->desc = NULL;
4136 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4137 * @adapter: board private structure
4139 * Free all receive software resources
4141 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
4145 for (i = 0; i < adapter->num_rx_queues; i++)
4146 igb_free_rx_resources(adapter->rx_ring[i]);
4150 * igb_clean_rx_ring - Free Rx Buffers per Queue
4151 * @rx_ring: ring to free buffers from
4153 void igb_clean_rx_ring(struct igb_ring *rx_ring)
4158 if (!rx_ring->rx_buffer_info)
4161 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
4163 dev_kfree_skb(rx_ring->skb);
4164 rx_ring->skb = NULL;
4167 /* Free all the Rx ring sk_buffs */
4168 for (i = 0; i < rx_ring->count; i++) {
4169 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
4170 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
4171 if (buffer_info->dma) {
4172 dma_unmap_single(rx_ring->dev,
4174 rx_ring->rx_buffer_len,
4176 buffer_info->dma = 0;
4179 if (buffer_info->skb) {
4180 dev_kfree_skb(buffer_info->skb);
4181 buffer_info->skb = NULL;
4184 if (!buffer_info->page)
4187 dma_unmap_page(rx_ring->dev,
4191 __free_page(buffer_info->page);
4193 buffer_info->page = NULL;
4197 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
4198 memset(rx_ring->rx_buffer_info, 0, size);
4200 /* Zero out the descriptor ring */
4201 memset(rx_ring->desc, 0, rx_ring->size);
4203 rx_ring->next_to_alloc = 0;
4204 rx_ring->next_to_clean = 0;
4205 rx_ring->next_to_use = 0;
4209 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4210 * @adapter: board private structure
4212 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
4216 for (i = 0; i < adapter->num_rx_queues; i++)
4217 igb_clean_rx_ring(adapter->rx_ring[i]);
4221 * igb_set_mac - Change the Ethernet Address of the NIC
4222 * @netdev: network interface device structure
4223 * @p: pointer to an address structure
4225 * Returns 0 on success, negative on failure
4227 static int igb_set_mac(struct net_device *netdev, void *p)
4229 struct igb_adapter *adapter = netdev_priv(netdev);
4230 struct e1000_hw *hw = &adapter->hw;
4231 struct sockaddr *addr = p;
4233 if (!is_valid_ether_addr(addr->sa_data))
4234 return -EADDRNOTAVAIL;
4236 igb_del_mac_filter(adapter, hw->mac.addr,
4237 adapter->vfs_allocated_count);
4238 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4239 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4241 /* set the correct pool for the new PF MAC address in entry 0 */
4242 return igb_add_mac_filter(adapter, hw->mac.addr,
4243 adapter->vfs_allocated_count);
4247 * igb_write_mc_addr_list - write multicast addresses to MTA
4248 * @netdev: network interface device structure
4250 * Writes multicast address list to the MTA hash table.
4251 * Returns: -ENOMEM on failure
4252 * 0 on no addresses written
4253 * X on writing X addresses to MTA
4255 int igb_write_mc_addr_list(struct net_device *netdev)
4257 struct igb_adapter *adapter = netdev_priv(netdev);
4258 struct e1000_hw *hw = &adapter->hw;
4259 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4260 struct netdev_hw_addr *ha;
4262 struct dev_mc_list *ha;
4266 #ifdef CONFIG_IGB_VMDQ_NETDEV
4269 count = netdev_mc_count(netdev);
4270 #ifdef CONFIG_IGB_VMDQ_NETDEV
4271 for (vm = 1; vm < adapter->vmdq_pools; vm++) {
4272 if (!adapter->vmdq_netdev[vm])
4274 if (!netif_running(adapter->vmdq_netdev[vm]))
4276 count += netdev_mc_count(adapter->vmdq_netdev[vm]);
4281 e1000_update_mc_addr_list(hw, NULL, 0);
4284 mta_list = kzalloc(count * 6, GFP_ATOMIC);
4288 /* The shared function expects a packed array of only addresses. */
4290 netdev_for_each_mc_addr(ha, netdev)
4291 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4292 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
4294 memcpy(mta_list + (i++ * ETH_ALEN), ha->dmi_addr, ETH_ALEN);
4296 #ifdef CONFIG_IGB_VMDQ_NETDEV
4297 for (vm = 1; vm < adapter->vmdq_pools; vm++) {
4298 if (!adapter->vmdq_netdev[vm])
4300 if (!netif_running(adapter->vmdq_netdev[vm]) ||
4301 !netdev_mc_count(adapter->vmdq_netdev[vm]))
4303 netdev_for_each_mc_addr(ha, adapter->vmdq_netdev[vm])
4304 #ifdef NETDEV_HW_ADDR_T_MULTICAST
4305 memcpy(mta_list + (i++ * ETH_ALEN),
4306 ha->addr, ETH_ALEN);
4308 memcpy(mta_list + (i++ * ETH_ALEN),
4309 ha->dmi_addr, ETH_ALEN);
4313 e1000_update_mc_addr_list(hw, mta_list, i);
4319 void igb_rar_set(struct igb_adapter *adapter, u32 index)
4321 u32 rar_low, rar_high;
4322 struct e1000_hw *hw = &adapter->hw;
4323 u8 *addr = adapter->mac_table[index].addr;
4324 /* HW expects these in little endian so we reverse the byte order
4325 * from network order (big endian) to little endian
4327 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4328 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4329 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4331 /* Indicate to hardware the Address is Valid. */
4332 if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE)
4333 rar_high |= E1000_RAH_AV;
4335 if (hw->mac.type == e1000_82575)
4336 rar_high |= E1000_RAH_POOL_1 * adapter->mac_table[index].queue;
4338 rar_high |= E1000_RAH_POOL_1 << adapter->mac_table[index].queue;
4340 E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
4341 E1000_WRITE_FLUSH(hw);
4342 E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
4343 E1000_WRITE_FLUSH(hw);
4346 void igb_full_sync_mac_table(struct igb_adapter *adapter)
4348 struct e1000_hw *hw = &adapter->hw;
4350 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4351 igb_rar_set(adapter, i);
4355 void igb_sync_mac_table(struct igb_adapter *adapter)
4357 struct e1000_hw *hw = &adapter->hw;
4359 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4360 if (adapter->mac_table[i].state & IGB_MAC_STATE_MODIFIED)
4361 igb_rar_set(adapter, i);
4362 adapter->mac_table[i].state &= ~(IGB_MAC_STATE_MODIFIED);
4366 int igb_available_rars(struct igb_adapter *adapter)
4368 struct e1000_hw *hw = &adapter->hw;
4371 for (i = 0; i < hw->mac.rar_entry_count; i++) {
4372 if (adapter->mac_table[i].state == 0)
4378 #ifdef HAVE_SET_RX_MODE
4380 * igb_write_uc_addr_list - write unicast addresses to RAR table
4381 * @netdev: network interface device structure
4383 * Writes unicast address list to the RAR table.
4384 * Returns: -ENOMEM on failure/insufficient address space
4385 * 0 on no addresses written
4386 * X on writing X addresses to the RAR table
4388 static int igb_write_uc_addr_list(struct net_device *netdev)
4390 struct igb_adapter *adapter = netdev_priv(netdev);
4391 unsigned int vfn = adapter->vfs_allocated_count;
4394 /* return ENOMEM indicating insufficient memory for addresses */
4395 if (netdev_uc_count(netdev) > igb_available_rars(adapter))
4397 if (!netdev_uc_empty(netdev)) {
4398 #ifdef NETDEV_HW_ADDR_T_UNICAST
4399 struct netdev_hw_addr *ha;
4401 struct dev_mc_list *ha;
4403 netdev_for_each_uc_addr(ha, netdev) {
4404 #ifdef NETDEV_HW_ADDR_T_UNICAST
4405 igb_del_mac_filter(adapter, ha->addr, vfn);
4406 igb_add_mac_filter(adapter, ha->addr, vfn);
4408 igb_del_mac_filter(adapter, ha->da_addr, vfn);
4409 igb_add_mac_filter(adapter, ha->da_addr, vfn);
4417 #endif /* HAVE_SET_RX_MODE */
4419 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
4420 * @netdev: network interface device structure
4422 * The set_rx_mode entry point is called whenever the unicast or multicast
4423 * address lists or the network interface flags are updated. This routine is
4424 * responsible for configuring the hardware for proper unicast, multicast,
4425 * promiscuous mode, and all-multi behavior.
4427 static void igb_set_rx_mode(struct net_device *netdev)
4429 struct igb_adapter *adapter = netdev_priv(netdev);
4430 struct e1000_hw *hw = &adapter->hw;
4431 unsigned int vfn = adapter->vfs_allocated_count;
4432 u32 rctl, vmolr = 0;
4435 /* Check for Promiscuous and All Multicast modes */
4436 rctl = E1000_READ_REG(hw, E1000_RCTL);
4438 /* clear the effected bits */
4439 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
4441 if (netdev->flags & IFF_PROMISC) {
4442 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
4443 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
4444 /* retain VLAN HW filtering if in VT mode */
4445 if (adapter->vfs_allocated_count || adapter->vmdq_pools)
4446 rctl |= E1000_RCTL_VFE;
4448 if (netdev->flags & IFF_ALLMULTI) {
4449 rctl |= E1000_RCTL_MPE;
4450 vmolr |= E1000_VMOLR_MPME;
4453 * Write addresses to the MTA, if the attempt fails
4454 * then we should just turn on promiscuous mode so
4455 * that we can at least receive multicast traffic
4457 count = igb_write_mc_addr_list(netdev);
4459 rctl |= E1000_RCTL_MPE;
4460 vmolr |= E1000_VMOLR_MPME;
4462 vmolr |= E1000_VMOLR_ROMPE;
4465 #ifdef HAVE_SET_RX_MODE
4467 * Write addresses to available RAR registers, if there is not
4468 * sufficient space to store all the addresses then enable
4469 * unicast promiscuous mode
4471 count = igb_write_uc_addr_list(netdev);
4473 rctl |= E1000_RCTL_UPE;
4474 vmolr |= E1000_VMOLR_ROPE;
4476 #endif /* HAVE_SET_RX_MODE */
4477 rctl |= E1000_RCTL_VFE;
4479 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4482 * In order to support SR-IOV and eventually VMDq it is necessary to set
4483 * the VMOLR to enable the appropriate modes. Without this workaround
4484 * we will have issues with VLAN tag stripping not being done for frames
4485 * that are only arriving because we are the default pool
4487 if (hw->mac.type < e1000_82576)
4490 vmolr |= E1000_READ_REG(hw, E1000_VMOLR(vfn)) &
4491 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
4492 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
4493 igb_restore_vf_multicasts(adapter);
4496 static void igb_check_wvbr(struct igb_adapter *adapter)
4498 struct e1000_hw *hw = &adapter->hw;
4501 switch (hw->mac.type) {
4504 if (!(wvbr = E1000_READ_REG(hw, E1000_WVBR)))
4511 adapter->wvbr |= wvbr;
4514 #define IGB_STAGGERED_QUEUE_OFFSET 8
4516 static void igb_spoof_check(struct igb_adapter *adapter)
4523 switch (adapter->hw.mac.type) {
4525 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4526 if (adapter->wvbr & (1 << j) ||
4527 adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
4528 DPRINTK(DRV, WARNING,
4529 "Spoof event(s) detected on VF %d\n", j);
4532 (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
4537 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4538 if (adapter->wvbr & (1 << j)) {
4539 DPRINTK(DRV, WARNING,
4540 "Spoof event(s) detected on VF %d\n", j);
4541 adapter->wvbr &= ~(1 << j);
4550 /* Need to wait a few seconds after link up to get diagnostic information from
4552 #ifdef HAVE_TIMER_SETUP
4553 static void igb_update_phy_info(struct timer_list *t)
4555 struct igb_adapter *adapter = from_timer(adapter, t, phy_info_timer);
4557 static void igb_update_phy_info(unsigned long data)
4559 struct igb_adapter *adapter = (struct igb_adapter *) data;
4561 e1000_get_phy_info(&adapter->hw);
4565 * igb_has_link - check shared code for link and determine up/down
4566 * @adapter: pointer to driver private info
4568 bool igb_has_link(struct igb_adapter *adapter)
4570 struct e1000_hw *hw = &adapter->hw;
4571 bool link_active = FALSE;
4573 /* get_link_status is set on LSC (link status) interrupt or
4574 * rx sequence error interrupt. get_link_status will stay
4575 * false until the e1000_check_for_link establishes link
4576 * for copper adapters ONLY
4578 switch (hw->phy.media_type) {
4579 case e1000_media_type_copper:
4580 if (!hw->mac.get_link_status)
4582 case e1000_media_type_internal_serdes:
4583 e1000_check_for_link(hw);
4584 link_active = !hw->mac.get_link_status;
4586 case e1000_media_type_unknown:
4591 if (((hw->mac.type == e1000_i210) ||
4592 (hw->mac.type == e1000_i211)) &&
4593 (hw->phy.id == I210_I_PHY_ID)) {
4594 if (!netif_carrier_ok(adapter->netdev)) {
4595 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4596 } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
4597 adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
4598 adapter->link_check_timeout = jiffies;
4606 * igb_watchdog - Timer Call-back
4607 * @data: pointer to adapter cast into an unsigned long
4609 #ifdef HAVE_TIMER_SETUP
4610 static void igb_watchdog(struct timer_list *t)
4612 struct igb_adapter *adapter = from_timer(adapter, t, watchdog_timer);
4614 static void igb_watchdog(unsigned long data)
4616 struct igb_adapter *adapter = (struct igb_adapter *)data;
4618 /* Do the rest outside of interrupt context */
4619 schedule_work(&adapter->watchdog_task);
4622 static void igb_watchdog_task(struct work_struct *work)
4624 struct igb_adapter *adapter = container_of(work,
4627 struct e1000_hw *hw = &adapter->hw;
4628 struct net_device *netdev = adapter->netdev;
4631 u32 thstat, ctrl_ext;
4634 link = igb_has_link(adapter);
4635 /* Force link down if we have fiber to swap to */
4636 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4637 if (hw->phy.media_type == e1000_media_type_copper) {
4638 connsw = E1000_READ_REG(hw, E1000_CONNSW);
4639 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
4644 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
4645 if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
4646 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4652 /* Perform a reset if the media type changed. */
4653 if (hw->dev_spec._82575.media_changed) {
4654 hw->dev_spec._82575.media_changed = false;
4655 adapter->flags |= IGB_FLAG_MEDIA_RESET;
4659 /* Cancel scheduled suspend requests. */
4660 pm_runtime_resume(netdev->dev.parent);
4662 if (!netif_carrier_ok(netdev)) {
4664 e1000_get_speed_and_duplex(hw,
4665 &adapter->link_speed,
4666 &adapter->link_duplex);
4668 ctrl = E1000_READ_REG(hw, E1000_CTRL);
4669 /* Links status message must follow this format */
4670 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
4671 "Flow Control: %s\n",
4673 adapter->link_speed,
4674 adapter->link_duplex == FULL_DUPLEX ?
4675 "Full Duplex" : "Half Duplex",
4676 ((ctrl & E1000_CTRL_TFCE) &&
4677 (ctrl & E1000_CTRL_RFCE)) ? "RX/TX":
4678 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
4679 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None")));
4680 /* adjust timeout factor according to speed/duplex */
4681 adapter->tx_timeout_factor = 1;
4682 switch (adapter->link_speed) {
4684 adapter->tx_timeout_factor = 14;
4687 /* maybe add some timeout factor ? */
4693 netif_carrier_on(netdev);
4694 netif_tx_wake_all_queues(netdev);
4696 igb_ping_all_vfs(adapter);
4698 igb_check_vf_rate_limit(adapter);
4699 #endif /* IFLA_VF_MAX */
4701 /* link state has changed, schedule phy info update */
4702 if (!test_bit(__IGB_DOWN, &adapter->state))
4703 mod_timer(&adapter->phy_info_timer,
4704 round_jiffies(jiffies + 2 * HZ));
4707 if (netif_carrier_ok(netdev)) {
4708 adapter->link_speed = 0;
4709 adapter->link_duplex = 0;
4710 /* check for thermal sensor event on i350 */
4711 if (hw->mac.type == e1000_i350) {
4712 thstat = E1000_READ_REG(hw, E1000_THSTAT);
4713 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
4714 if ((hw->phy.media_type ==
4715 e1000_media_type_copper) &&
4717 E1000_CTRL_EXT_LINK_MODE_SGMII)) {
4718 if (thstat & E1000_THSTAT_PWR_DOWN) {
4719 printk(KERN_ERR "igb: %s The "
4720 "network adapter was stopped "
4721 "because it overheated.\n",
4724 if (thstat & E1000_THSTAT_LINK_THROTTLE) {
4726 "igb: %s The network "
4727 "adapter supported "
4737 /* Links status message must follow this format */
4738 printk(KERN_INFO "igb: %s NIC Link is Down\n",
4740 netif_carrier_off(netdev);
4741 netif_tx_stop_all_queues(netdev);
4743 igb_ping_all_vfs(adapter);
4745 /* link state has changed, schedule phy info update */
4746 if (!test_bit(__IGB_DOWN, &adapter->state))
4747 mod_timer(&adapter->phy_info_timer,
4748 round_jiffies(jiffies + 2 * HZ));
4749 /* link is down, time to check for alternate media */
4750 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4751 igb_check_swap_media(adapter);
4752 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4753 schedule_work(&adapter->reset_task);
4754 /* return immediately */
4758 pm_schedule_suspend(netdev->dev.parent,
4761 /* also check for alternate media here */
4762 } else if (!netif_carrier_ok(netdev) &&
4763 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
4764 hw->mac.ops.power_up_serdes(hw);
4765 igb_check_swap_media(adapter);
4766 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4767 schedule_work(&adapter->reset_task);
4768 /* return immediately */
4774 igb_update_stats(adapter);
4776 for (i = 0; i < adapter->num_tx_queues; i++) {
4777 struct igb_ring *tx_ring = adapter->tx_ring[i];
4778 if (!netif_carrier_ok(netdev)) {
4779 /* We've lost link, so the controller stops DMA,
4780 * but we've got queued Tx work that's never going
4781 * to get done, so reset controller to flush Tx.
4782 * (Do the reset outside of interrupt context). */
4783 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
4784 adapter->tx_timeout_count++;
4785 schedule_work(&adapter->reset_task);
4786 /* return immediately since reset is imminent */
4791 /* Force detection of hung controller every watchdog period */
4792 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
4795 /* Cause software interrupt to ensure rx ring is cleaned */
4796 if (adapter->msix_entries) {
4798 for (i = 0; i < adapter->num_q_vectors; i++)
4799 eics |= adapter->q_vector[i]->eims_value;
4800 E1000_WRITE_REG(hw, E1000_EICS, eics);
4802 E1000_WRITE_REG(hw, E1000_ICS, E1000_ICS_RXDMT0);
4805 igb_spoof_check(adapter);
4807 /* Reset the timer */
4808 if (!test_bit(__IGB_DOWN, &adapter->state)) {
4809 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
4810 mod_timer(&adapter->watchdog_timer,
4811 round_jiffies(jiffies + HZ));
4813 mod_timer(&adapter->watchdog_timer,
4814 round_jiffies(jiffies + 2 * HZ));
4818 static void igb_dma_err_task(struct work_struct *work)
4820 struct igb_adapter *adapter = container_of(work,
4824 struct e1000_hw *hw = &adapter->hw;
4825 struct net_device *netdev = adapter->netdev;
4829 hgptc = E1000_READ_REG(hw, E1000_HGPTC);
4830 if (hgptc) /* If incrementing then no need for the check below */
4831 goto dma_timer_reset;
4833 * Check to see if a bad DMA write target from an errant or
4834 * malicious VF has caused a PCIe error. If so then we can
4835 * issue a VFLR to the offending VF(s) and then resume without
4836 * requesting a full slot reset.
4839 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
4840 ciaa = (vf << 16) | 0x80000000;
4841 /* 32 bit read so align, we really want status at offset 6 */
4842 ciaa |= PCI_COMMAND;
4843 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4844 ciad = E1000_READ_REG(hw, E1000_CIAD);
4846 /* disable debug mode asap after reading data */
4847 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4848 /* Get the upper 16 bits which will be the PCI status reg */
4850 if (ciad & (PCI_STATUS_REC_MASTER_ABORT |
4851 PCI_STATUS_REC_TARGET_ABORT |
4852 PCI_STATUS_SIG_SYSTEM_ERROR)) {
4853 netdev_err(netdev, "VF %d suffered error\n", vf);
4855 ciaa = (vf << 16) | 0x80000000;
4857 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4858 ciad = 0x00008000; /* VFLR */
4859 E1000_WRITE_REG(hw, E1000_CIAD, ciad);
4861 E1000_WRITE_REG(hw, E1000_CIAA, ciaa);
4865 /* Reset the timer */
4866 if (!test_bit(__IGB_DOWN, &adapter->state))
4867 mod_timer(&adapter->dma_err_timer,
4868 round_jiffies(jiffies + HZ / 10));
4872 * igb_dma_err_timer - Timer Call-back
4873 * @data: pointer to adapter cast into an unsigned long
4875 #ifdef HAVE_TIMER_SETUP
4876 static void igb_dma_err_timer(struct timer_list *t)
4878 struct igb_adapter *adapter = from_timer(adapter, t, dma_err_timer);
4880 static void igb_dma_err_timer(unsigned long data)
4882 struct igb_adapter *adapter = (struct igb_adapter *)data;
4884 /* Do the rest outside of interrupt context */
4885 schedule_work(&adapter->dma_err_task);
4888 enum latency_range {
4892 latency_invalid = 255
4896 * igb_update_ring_itr - update the dynamic ITR value based on packet size
4898 * Stores a new ITR value based on strictly on packet size. This
4899 * algorithm is less sophisticated than that used in igb_update_itr,
4900 * due to the difficulty of synchronizing statistics across multiple
4901 * receive rings. The divisors and thresholds used by this function
4902 * were determined based on theoretical maximum wire speed and testing
4903 * data, in order to minimize response time while increasing bulk
4905 * This functionality is controlled by the InterruptThrottleRate module
4906 * parameter (see igb_param.c)
4907 * NOTE: This function is called only when operating in a multiqueue
4908 * receive environment.
4909 * @q_vector: pointer to q_vector
4911 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
4913 int new_val = q_vector->itr_val;
4914 int avg_wire_size = 0;
4915 struct igb_adapter *adapter = q_vector->adapter;
4916 unsigned int packets;
4918 /* For non-gigabit speeds, just fix the interrupt rate at 4000
4919 * ints/sec - ITR timer value of 120 ticks.
4921 switch (adapter->link_speed) {
4924 new_val = IGB_4K_ITR;
4930 packets = q_vector->rx.total_packets;
4932 avg_wire_size = q_vector->rx.total_bytes / packets;
4934 packets = q_vector->tx.total_packets;
4936 avg_wire_size = max_t(u32, avg_wire_size,
4937 q_vector->tx.total_bytes / packets);
4939 /* if avg_wire_size isn't set no work was done */
4943 /* Add 24 bytes to size to account for CRC, preamble, and gap */
4944 avg_wire_size += 24;
4946 /* Don't starve jumbo frames */
4947 avg_wire_size = min(avg_wire_size, 3000);
4949 /* Give a little boost to mid-size frames */
4950 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
4951 new_val = avg_wire_size / 3;
4953 new_val = avg_wire_size / 2;
4955 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4956 if (new_val < IGB_20K_ITR &&
4957 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4958 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4959 new_val = IGB_20K_ITR;
4962 if (new_val != q_vector->itr_val) {
4963 q_vector->itr_val = new_val;
4964 q_vector->set_itr = 1;
4967 q_vector->rx.total_bytes = 0;
4968 q_vector->rx.total_packets = 0;
4969 q_vector->tx.total_bytes = 0;
4970 q_vector->tx.total_packets = 0;
4974 * igb_update_itr - update the dynamic ITR value based on statistics
4975 * Stores a new ITR value based on packets and byte
4976 * counts during the last interrupt. The advantage of per interrupt
4977 * computation is faster updates and more accurate ITR for the current
4978 * traffic pattern. Constants in this function were computed
4979 * based on theoretical maximum wire speed and thresholds were set based
4980 * on testing data as well as attempting to minimize response time
4981 * while increasing bulk throughput.
4982 * this functionality is controlled by the InterruptThrottleRate module
4983 * parameter (see igb_param.c)
4984 * NOTE: These calculations are only valid when operating in a single-
4985 * queue environment.
4986 * @q_vector: pointer to q_vector
4987 * @ring_container: ring info to update the itr for
4989 static void igb_update_itr(struct igb_q_vector *q_vector,
4990 struct igb_ring_container *ring_container)
4992 unsigned int packets = ring_container->total_packets;
4993 unsigned int bytes = ring_container->total_bytes;
4994 u8 itrval = ring_container->itr;
4996 /* no packets, exit with status unchanged */
5001 case lowest_latency:
5002 /* handle TSO and jumbo frames */
5003 if (bytes/packets > 8000)
5004 itrval = bulk_latency;
5005 else if ((packets < 5) && (bytes > 512))
5006 itrval = low_latency;
5008 case low_latency: /* 50 usec aka 20000 ints/s */
5009 if (bytes > 10000) {
5010 /* this if handles the TSO accounting */
5011 if (bytes/packets > 8000) {
5012 itrval = bulk_latency;
5013 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
5014 itrval = bulk_latency;
5015 } else if (packets > 35) {
5016 itrval = lowest_latency;
5018 } else if (bytes/packets > 2000) {
5019 itrval = bulk_latency;
5020 } else if (packets <= 2 && bytes < 512) {
5021 itrval = lowest_latency;
5024 case bulk_latency: /* 250 usec aka 4000 ints/s */
5025 if (bytes > 25000) {
5027 itrval = low_latency;
5028 } else if (bytes < 1500) {
5029 itrval = low_latency;
5034 /* clear work counters since we have the values we need */
5035 ring_container->total_bytes = 0;
5036 ring_container->total_packets = 0;
5038 /* write updated itr to ring container */
5039 ring_container->itr = itrval;
5042 static void igb_set_itr(struct igb_q_vector *q_vector)
5044 struct igb_adapter *adapter = q_vector->adapter;
5045 u32 new_itr = q_vector->itr_val;
5048 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
5049 switch (adapter->link_speed) {
5053 new_itr = IGB_4K_ITR;
5059 igb_update_itr(q_vector, &q_vector->tx);
5060 igb_update_itr(q_vector, &q_vector->rx);
5062 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
5064 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5065 if (current_itr == lowest_latency &&
5066 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
5067 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
5068 current_itr = low_latency;
5070 switch (current_itr) {
5071 /* counts and packets in update_itr are dependent on these numbers */
5072 case lowest_latency:
5073 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
5076 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
5079 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
5086 if (new_itr != q_vector->itr_val) {
5087 /* this attempts to bias the interrupt rate towards Bulk
5088 * by adding intermediate steps when interrupt rate is
5090 new_itr = new_itr > q_vector->itr_val ?
5091 max((new_itr * q_vector->itr_val) /
5092 (new_itr + (q_vector->itr_val >> 2)),
5095 /* Don't write the value here; it resets the adapter's
5096 * internal timer, and causes us to delay far longer than
5097 * we should between interrupts. Instead, we write the ITR
5098 * value at the beginning of the next interrupt so the timing
5099 * ends up being correct.
5101 q_vector->itr_val = new_itr;
5102 q_vector->set_itr = 1;
5106 void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
5107 u32 type_tucmd, u32 mss_l4len_idx)
5109 struct e1000_adv_tx_context_desc *context_desc;
5110 u16 i = tx_ring->next_to_use;
5112 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
5115 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
5117 /* set bits to identify this as an advanced context descriptor */
5118 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
5120 /* For 82575, context index must be unique per ring. */
5121 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5122 mss_l4len_idx |= tx_ring->reg_idx << 4;
5124 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
5125 context_desc->seqnum_seed = 0;
5126 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
5127 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
5130 static int igb_tso(struct igb_ring *tx_ring,
5131 struct igb_tx_buffer *first,
5135 struct sk_buff *skb = first->skb;
5136 u32 vlan_macip_lens, type_tucmd;
5137 u32 mss_l4len_idx, l4len;
5139 if (skb->ip_summed != CHECKSUM_PARTIAL)
5142 if (!skb_is_gso(skb))
5143 #endif /* NETIF_F_TSO */
5147 if (skb_header_cloned(skb)) {
5148 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5153 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5154 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5156 if (first->protocol == __constant_htons(ETH_P_IP)) {
5157 struct iphdr *iph = ip_hdr(skb);
5160 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5164 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5165 first->tx_flags |= IGB_TX_FLAGS_TSO |
5169 } else if (skb_is_gso_v6(skb)) {
5170 ipv6_hdr(skb)->payload_len = 0;
5171 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5172 &ipv6_hdr(skb)->daddr,
5174 first->tx_flags |= IGB_TX_FLAGS_TSO |
5179 /* compute header lengths */
5180 l4len = tcp_hdrlen(skb);
5181 *hdr_len = skb_transport_offset(skb) + l4len;
5183 /* update gso size and bytecount with header size */
5184 first->gso_segs = skb_shinfo(skb)->gso_segs;
5185 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5188 mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
5189 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
5191 /* VLAN MACLEN IPLEN */
5192 vlan_macip_lens = skb_network_header_len(skb);
5193 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5194 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5196 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5199 #endif /* NETIF_F_TSO */
5202 static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5204 struct sk_buff *skb = first->skb;
5205 u32 vlan_macip_lens = 0;
5206 u32 mss_l4len_idx = 0;
5209 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5210 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
5214 switch (first->protocol) {
5215 case __constant_htons(ETH_P_IP):
5216 vlan_macip_lens |= skb_network_header_len(skb);
5217 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5218 nexthdr = ip_hdr(skb)->protocol;
5220 #ifdef NETIF_F_IPV6_CSUM
5221 case __constant_htons(ETH_P_IPV6):
5222 vlan_macip_lens |= skb_network_header_len(skb);
5223 nexthdr = ipv6_hdr(skb)->nexthdr;
5227 if (unlikely(net_ratelimit())) {
5228 dev_warn(tx_ring->dev,
5229 "partial checksum but proto=%x!\n",
5237 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
5238 mss_l4len_idx = tcp_hdrlen(skb) <<
5239 E1000_ADVTXD_L4LEN_SHIFT;
5243 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
5244 mss_l4len_idx = sizeof(struct sctphdr) <<
5245 E1000_ADVTXD_L4LEN_SHIFT;
5249 mss_l4len_idx = sizeof(struct udphdr) <<
5250 E1000_ADVTXD_L4LEN_SHIFT;
5253 if (unlikely(net_ratelimit())) {
5254 dev_warn(tx_ring->dev,
5255 "partial checksum but l4 proto=%x!\n",
5261 /* update TX checksum flag */
5262 first->tx_flags |= IGB_TX_FLAGS_CSUM;
5265 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5266 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5268 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5271 #define IGB_SET_FLAG(_input, _flag, _result) \
5272 ((_flag <= _result) ? \
5273 ((u32)(_input & _flag) * (_result / _flag)) : \
5274 ((u32)(_input & _flag) / (_flag / _result)))
5276 static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
5278 /* set type for advanced descriptor with frame checksum insertion */
5279 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
5280 E1000_ADVTXD_DCMD_DEXT |
5281 E1000_ADVTXD_DCMD_IFCS;
5283 /* set HW vlan bit if vlan is present */
5284 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
5285 (E1000_ADVTXD_DCMD_VLE));
5287 /* set segmentation bits for TSO */
5288 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
5289 (E1000_ADVTXD_DCMD_TSE));
5291 /* set timestamp bit if present */
5292 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
5293 (E1000_ADVTXD_MAC_TSTAMP));
5298 static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
5299 union e1000_adv_tx_desc *tx_desc,
5300 u32 tx_flags, unsigned int paylen)
5302 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
5304 /* 82575 requires a unique index per ring */
5305 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5306 olinfo_status |= tx_ring->reg_idx << 4;
5308 /* insert L4 checksum */
5309 olinfo_status |= IGB_SET_FLAG(tx_flags,
5311 (E1000_TXD_POPTS_TXSM << 8));
5313 /* insert IPv4 checksum */
5314 olinfo_status |= IGB_SET_FLAG(tx_flags,
5316 (E1000_TXD_POPTS_IXSM << 8));
5318 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5321 static void igb_tx_map(struct igb_ring *tx_ring,
5322 struct igb_tx_buffer *first,
5325 struct sk_buff *skb = first->skb;
5326 struct igb_tx_buffer *tx_buffer;
5327 union e1000_adv_tx_desc *tx_desc;
5328 struct skb_frag_struct *frag;
5330 unsigned int data_len, size;
5331 u32 tx_flags = first->tx_flags;
5332 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
5333 u16 i = tx_ring->next_to_use;
5335 tx_desc = IGB_TX_DESC(tx_ring, i);
5337 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
5339 size = skb_headlen(skb);
5340 data_len = skb->data_len;
5342 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5346 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
5347 if (dma_mapping_error(tx_ring->dev, dma))
5350 /* record length, and DMA address */
5351 dma_unmap_len_set(tx_buffer, len, size);
5352 dma_unmap_addr_set(tx_buffer, dma, dma);
5354 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5356 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
5357 tx_desc->read.cmd_type_len =
5358 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
5362 if (i == tx_ring->count) {
5363 tx_desc = IGB_TX_DESC(tx_ring, 0);
5366 tx_desc->read.olinfo_status = 0;
5368 dma += IGB_MAX_DATA_PER_TXD;
5369 size -= IGB_MAX_DATA_PER_TXD;
5371 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5374 if (likely(!data_len))
5377 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
5381 if (i == tx_ring->count) {
5382 tx_desc = IGB_TX_DESC(tx_ring, 0);
5385 tx_desc->read.olinfo_status = 0;
5387 size = skb_frag_size(frag);
5390 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
5391 size, DMA_TO_DEVICE);
5393 tx_buffer = &tx_ring->tx_buffer_info[i];
5396 /* write last descriptor with RS and EOP bits */
5397 cmd_type |= size | IGB_TXD_DCMD;
5398 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
5400 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
5401 /* set the timestamp */
5402 first->time_stamp = jiffies;
5405 * Force memory writes to complete before letting h/w know there
5406 * are new descriptors to fetch. (Only applicable for weak-ordered
5407 * memory model archs, such as IA-64).
5409 * We also need this memory barrier to make certain all of the
5410 * status bits have been updated before next_to_watch is written.
5414 /* set next_to_watch value indicating a packet is present */
5415 first->next_to_watch = tx_desc;
5418 if (i == tx_ring->count)
5421 tx_ring->next_to_use = i;
5423 writel(i, tx_ring->tail);
5425 /* we need this if more than one processor can write to our tail
5426 * at a time, it syncronizes IO on IA64/Altix systems */
5432 dev_err(tx_ring->dev, "TX DMA map failed\n");
5434 /* clear dma mappings for failed tx_buffer_info map */
5436 tx_buffer = &tx_ring->tx_buffer_info[i];
5437 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer);
5438 if (tx_buffer == first)
5445 tx_ring->next_to_use = i;
5448 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5450 struct net_device *netdev = netdev_ring(tx_ring);
5452 if (netif_is_multiqueue(netdev))
5453 netif_stop_subqueue(netdev, ring_queue_index(tx_ring));
5455 netif_stop_queue(netdev);
5457 /* Herbert's original patch had:
5458 * smp_mb__after_netif_stop_queue();
5459 * but since that doesn't exist yet, just open code it. */
5462 /* We need to check again in a case another CPU has just
5463 * made room available. */
5464 if (igb_desc_unused(tx_ring) < size)
5468 if (netif_is_multiqueue(netdev))
5469 netif_wake_subqueue(netdev, ring_queue_index(tx_ring));
5471 netif_wake_queue(netdev);
5473 tx_ring->tx_stats.restart_queue++;
5478 static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5480 if (igb_desc_unused(tx_ring) >= size)
5482 return __igb_maybe_stop_tx(tx_ring, size);
5485 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
5486 struct igb_ring *tx_ring)
5488 struct igb_tx_buffer *first;
5491 #if PAGE_SIZE > IGB_MAX_DATA_PER_TXD
5494 u16 count = TXD_USE_COUNT(skb_headlen(skb));
5495 __be16 protocol = vlan_get_protocol(skb);
5499 * need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
5500 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
5501 * + 2 desc gap to keep tail from touching head,
5502 * + 1 desc for context descriptor,
5503 * otherwise try next time
5505 #if PAGE_SIZE > IGB_MAX_DATA_PER_TXD
5506 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
5507 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5509 count += skb_shinfo(skb)->nr_frags;
5511 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
5512 /* this is a hard error */
5513 return NETDEV_TX_BUSY;
5516 /* record the location of the first descriptor for this packet */
5517 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
5519 first->bytecount = skb->len;
5520 first->gso_segs = 1;
5522 skb_tx_timestamp(skb);
5524 #ifdef HAVE_PTP_1588_CLOCK
5525 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
5526 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5527 if (!adapter->ptp_tx_skb) {
5528 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5529 tx_flags |= IGB_TX_FLAGS_TSTAMP;
5531 adapter->ptp_tx_skb = skb_get(skb);
5532 adapter->ptp_tx_start = jiffies;
5533 if (adapter->hw.mac.type == e1000_82576)
5534 schedule_work(&adapter->ptp_tx_work);
5537 #endif /* HAVE_PTP_1588_CLOCK */
5539 if (vlan_tx_tag_present(skb)) {
5540 tx_flags |= IGB_TX_FLAGS_VLAN;
5541 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
5544 /* record initial flags and protocol */
5545 first->tx_flags = tx_flags;
5546 first->protocol = protocol;
5548 tso = igb_tso(tx_ring, first, &hdr_len);
5552 igb_tx_csum(tx_ring, first);
5554 igb_tx_map(tx_ring, first, hdr_len);
5556 #ifndef HAVE_TRANS_START_IN_QUEUE
5557 netdev_ring(tx_ring)->trans_start = jiffies;
5560 /* Make sure there is space in the ring for the next send. */
5561 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
5563 return NETDEV_TX_OK;
5566 igb_unmap_and_free_tx_resource(tx_ring, first);
5568 return NETDEV_TX_OK;
5572 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
5573 struct sk_buff *skb)
5575 unsigned int r_idx = skb->queue_mapping;
5577 if (r_idx >= adapter->num_tx_queues)
5578 r_idx = r_idx % adapter->num_tx_queues;
5580 return adapter->tx_ring[r_idx];
5583 #define igb_tx_queue_mapping(_adapter, _skb) (_adapter)->tx_ring[0]
5586 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
5587 struct net_device *netdev)
5589 struct igb_adapter *adapter = netdev_priv(netdev);
5591 if (test_bit(__IGB_DOWN, &adapter->state)) {
5592 dev_kfree_skb_any(skb);
5593 return NETDEV_TX_OK;
5596 if (skb->len <= 0) {
5597 dev_kfree_skb_any(skb);
5598 return NETDEV_TX_OK;
5602 * The minimum packet size with TCTL.PSP set is 17 so pad the skb
5603 * in order to meet this minimum size requirement.
5605 if (skb->len < 17) {
5606 if (skb_padto(skb, 17))
5607 return NETDEV_TX_OK;
5611 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
5615 * igb_tx_timeout - Respond to a Tx Hang
5616 * @netdev: network interface device structure
5618 static void igb_tx_timeout(struct net_device *netdev)
5620 struct igb_adapter *adapter = netdev_priv(netdev);
5621 struct e1000_hw *hw = &adapter->hw;
5623 /* Do the reset outside of interrupt context */
5624 adapter->tx_timeout_count++;
5626 if (hw->mac.type >= e1000_82580)
5627 hw->dev_spec._82575.global_device_reset = true;
5629 schedule_work(&adapter->reset_task);
5630 E1000_WRITE_REG(hw, E1000_EICS,
5631 (adapter->eims_enable_mask & ~adapter->eims_other));
5634 static void igb_reset_task(struct work_struct *work)
5636 struct igb_adapter *adapter;
5637 adapter = container_of(work, struct igb_adapter, reset_task);
5639 igb_reinit_locked(adapter);
5643 * igb_get_stats - Get System Network Statistics
5644 * @netdev: network interface device structure
5646 * Returns the address of the device statistics structure.
5647 * The statistics are updated here and also from the timer callback.
5649 static struct net_device_stats *igb_get_stats(struct net_device *netdev)
5651 struct igb_adapter *adapter = netdev_priv(netdev);
5653 if (!test_bit(__IGB_RESETTING, &adapter->state))
5654 igb_update_stats(adapter);
5656 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
5657 /* only return the current stats */
5658 return &netdev->stats;
5660 /* only return the current stats */
5661 return &adapter->net_stats;
5662 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
5666 * igb_change_mtu - Change the Maximum Transfer Unit
5667 * @netdev: network interface device structure
5668 * @new_mtu: new value for maximum frame size
5670 * Returns 0 on success, negative on failure
5672 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
5674 struct igb_adapter *adapter = netdev_priv(netdev);
5675 struct e1000_hw *hw = &adapter->hw;
5676 struct pci_dev *pdev = adapter->pdev;
5677 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
5679 if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
5680 dev_err(pci_dev_to_dev(pdev), "Invalid MTU setting\n");
5684 #define MAX_STD_JUMBO_FRAME_SIZE 9238
5685 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
5686 dev_err(pci_dev_to_dev(pdev), "MTU > 9216 not supported.\n");
5690 /* adjust max frame to be at least the size of a standard frame */
5691 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
5692 max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
5694 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
5695 usleep_range(1000, 2000);
5697 /* igb_down has a dependency on max_frame_size */
5698 adapter->max_frame_size = max_frame;
5700 if (netif_running(netdev))
5703 dev_info(pci_dev_to_dev(pdev), "changing MTU from %d to %d\n",
5704 netdev->mtu, new_mtu);
5705 netdev->mtu = new_mtu;
5706 hw->dev_spec._82575.mtu = new_mtu;
5708 if (netif_running(netdev))
5713 clear_bit(__IGB_RESETTING, &adapter->state);
5719 * igb_update_stats - Update the board statistics counters
5720 * @adapter: board private structure
5723 void igb_update_stats(struct igb_adapter *adapter)
5725 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
5726 struct net_device_stats *net_stats = &adapter->netdev->stats;
5728 struct net_device_stats *net_stats = &adapter->net_stats;
5729 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
5730 struct e1000_hw *hw = &adapter->hw;
5732 struct pci_dev *pdev = adapter->pdev;
5739 u32 flushed = 0, coal = 0;
5740 struct igb_q_vector *q_vector;
5743 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
5746 * Prevent stats update while adapter is being reset, or if the pci
5747 * connection is down.
5749 if (adapter->link_speed == 0)
5752 if (pci_channel_offline(pdev))
5757 for (i = 0; i < adapter->num_q_vectors; i++) {
5758 q_vector = adapter->q_vector[i];
5761 flushed += q_vector->lrolist.stats.flushed;
5762 coal += q_vector->lrolist.stats.coal;
5764 adapter->lro_stats.flushed = flushed;
5765 adapter->lro_stats.coal = coal;
5770 for (i = 0; i < adapter->num_rx_queues; i++) {
5771 u32 rqdpc_tmp = E1000_READ_REG(hw, E1000_RQDPC(i)) & 0x0FFF;
5772 struct igb_ring *ring = adapter->rx_ring[i];
5773 ring->rx_stats.drops += rqdpc_tmp;
5774 net_stats->rx_fifo_errors += rqdpc_tmp;
5775 #ifdef CONFIG_IGB_VMDQ_NETDEV
5776 if (!ring->vmdq_netdev) {
5777 bytes += ring->rx_stats.bytes;
5778 packets += ring->rx_stats.packets;
5781 bytes += ring->rx_stats.bytes;
5782 packets += ring->rx_stats.packets;
5786 net_stats->rx_bytes = bytes;
5787 net_stats->rx_packets = packets;
5791 for (i = 0; i < adapter->num_tx_queues; i++) {
5792 struct igb_ring *ring = adapter->tx_ring[i];
5793 #ifdef CONFIG_IGB_VMDQ_NETDEV
5794 if (!ring->vmdq_netdev) {
5795 bytes += ring->tx_stats.bytes;
5796 packets += ring->tx_stats.packets;
5799 bytes += ring->tx_stats.bytes;
5800 packets += ring->tx_stats.packets;
5803 net_stats->tx_bytes = bytes;
5804 net_stats->tx_packets = packets;
5806 /* read stats registers */
5807 adapter->stats.crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
5808 adapter->stats.gprc += E1000_READ_REG(hw, E1000_GPRC);
5809 adapter->stats.gorc += E1000_READ_REG(hw, E1000_GORCL);
5810 E1000_READ_REG(hw, E1000_GORCH); /* clear GORCL */
5811 adapter->stats.bprc += E1000_READ_REG(hw, E1000_BPRC);
5812 adapter->stats.mprc += E1000_READ_REG(hw, E1000_MPRC);
5813 adapter->stats.roc += E1000_READ_REG(hw, E1000_ROC);
5815 adapter->stats.prc64 += E1000_READ_REG(hw, E1000_PRC64);
5816 adapter->stats.prc127 += E1000_READ_REG(hw, E1000_PRC127);
5817 adapter->stats.prc255 += E1000_READ_REG(hw, E1000_PRC255);
5818 adapter->stats.prc511 += E1000_READ_REG(hw, E1000_PRC511);
5819 adapter->stats.prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
5820 adapter->stats.prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
5821 adapter->stats.symerrs += E1000_READ_REG(hw, E1000_SYMERRS);
5822 adapter->stats.sec += E1000_READ_REG(hw, E1000_SEC);
5824 mpc = E1000_READ_REG(hw, E1000_MPC);
5825 adapter->stats.mpc += mpc;
5826 net_stats->rx_fifo_errors += mpc;
5827 adapter->stats.scc += E1000_READ_REG(hw, E1000_SCC);
5828 adapter->stats.ecol += E1000_READ_REG(hw, E1000_ECOL);
5829 adapter->stats.mcc += E1000_READ_REG(hw, E1000_MCC);
5830 adapter->stats.latecol += E1000_READ_REG(hw, E1000_LATECOL);
5831 adapter->stats.dc += E1000_READ_REG(hw, E1000_DC);
5832 adapter->stats.rlec += E1000_READ_REG(hw, E1000_RLEC);
5833 adapter->stats.xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
5834 adapter->stats.xontxc += E1000_READ_REG(hw, E1000_XONTXC);
5835 adapter->stats.xoffrxc += E1000_READ_REG(hw, E1000_XOFFRXC);
5836 adapter->stats.xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
5837 adapter->stats.fcruc += E1000_READ_REG(hw, E1000_FCRUC);
5838 adapter->stats.gptc += E1000_READ_REG(hw, E1000_GPTC);
5839 adapter->stats.gotc += E1000_READ_REG(hw, E1000_GOTCL);
5840 E1000_READ_REG(hw, E1000_GOTCH); /* clear GOTCL */
5841 adapter->stats.rnbc += E1000_READ_REG(hw, E1000_RNBC);
5842 adapter->stats.ruc += E1000_READ_REG(hw, E1000_RUC);
5843 adapter->stats.rfc += E1000_READ_REG(hw, E1000_RFC);
5844 adapter->stats.rjc += E1000_READ_REG(hw, E1000_RJC);
5845 adapter->stats.tor += E1000_READ_REG(hw, E1000_TORH);
5846 adapter->stats.tot += E1000_READ_REG(hw, E1000_TOTH);
5847 adapter->stats.tpr += E1000_READ_REG(hw, E1000_TPR);
5849 adapter->stats.ptc64 += E1000_READ_REG(hw, E1000_PTC64);
5850 adapter->stats.ptc127 += E1000_READ_REG(hw, E1000_PTC127);
5851 adapter->stats.ptc255 += E1000_READ_REG(hw, E1000_PTC255);
5852 adapter->stats.ptc511 += E1000_READ_REG(hw, E1000_PTC511);
5853 adapter->stats.ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
5854 adapter->stats.ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
5856 adapter->stats.mptc += E1000_READ_REG(hw, E1000_MPTC);
5857 adapter->stats.bptc += E1000_READ_REG(hw, E1000_BPTC);
5859 adapter->stats.tpt += E1000_READ_REG(hw, E1000_TPT);
5860 adapter->stats.colc += E1000_READ_REG(hw, E1000_COLC);
5862 adapter->stats.algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
5863 /* read internal phy sepecific stats */
5864 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
5865 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
5866 adapter->stats.rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
5868 /* this stat has invalid values on i210/i211 */
5869 if ((hw->mac.type != e1000_i210) &&
5870 (hw->mac.type != e1000_i211))
5871 adapter->stats.tncrs += E1000_READ_REG(hw, E1000_TNCRS);
5873 adapter->stats.tsctc += E1000_READ_REG(hw, E1000_TSCTC);
5874 adapter->stats.tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
5876 adapter->stats.iac += E1000_READ_REG(hw, E1000_IAC);
5877 adapter->stats.icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
5878 adapter->stats.icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
5879 adapter->stats.icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
5880 adapter->stats.ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
5881 adapter->stats.ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
5882 adapter->stats.ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
5883 adapter->stats.ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
5884 adapter->stats.icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
5886 /* Fill out the OS statistics structure */
5887 net_stats->multicast = adapter->stats.mprc;
5888 net_stats->collisions = adapter->stats.colc;
5892 /* RLEC on some newer hardware can be incorrect so build
5893 * our own version based on RUC and ROC */
5894 net_stats->rx_errors = adapter->stats.rxerrc +
5895 adapter->stats.crcerrs + adapter->stats.algnerrc +
5896 adapter->stats.ruc + adapter->stats.roc +
5897 adapter->stats.cexterr;
5898 net_stats->rx_length_errors = adapter->stats.ruc +
5900 net_stats->rx_crc_errors = adapter->stats.crcerrs;
5901 net_stats->rx_frame_errors = adapter->stats.algnerrc;
5902 net_stats->rx_missed_errors = adapter->stats.mpc;
5905 net_stats->tx_errors = adapter->stats.ecol +
5906 adapter->stats.latecol;
5907 net_stats->tx_aborted_errors = adapter->stats.ecol;
5908 net_stats->tx_window_errors = adapter->stats.latecol;
5909 net_stats->tx_carrier_errors = adapter->stats.tncrs;
5911 /* Tx Dropped needs to be maintained elsewhere */
5914 if (hw->phy.media_type == e1000_media_type_copper) {
5915 if ((adapter->link_speed == SPEED_1000) &&
5916 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
5917 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
5918 adapter->phy_stats.idle_errors += phy_tmp;
5922 /* Management Stats */
5923 adapter->stats.mgptc += E1000_READ_REG(hw, E1000_MGTPTC);
5924 adapter->stats.mgprc += E1000_READ_REG(hw, E1000_MGTPRC);
5925 if (hw->mac.type > e1000_82580) {
5926 adapter->stats.o2bgptc += E1000_READ_REG(hw, E1000_O2BGPTC);
5927 adapter->stats.o2bspc += E1000_READ_REG(hw, E1000_O2BSPC);
5928 adapter->stats.b2ospc += E1000_READ_REG(hw, E1000_B2OSPC);
5929 adapter->stats.b2ogprc += E1000_READ_REG(hw, E1000_B2OGPRC);
5933 static irqreturn_t igb_msix_other(int irq, void *data)
5935 struct igb_adapter *adapter = data;
5936 struct e1000_hw *hw = &adapter->hw;
5937 u32 icr = E1000_READ_REG(hw, E1000_ICR);
5938 /* reading ICR causes bit 31 of EICR to be cleared */
5940 if (icr & E1000_ICR_DRSTA)
5941 schedule_work(&adapter->reset_task);
5943 if (icr & E1000_ICR_DOUTSYNC) {
5944 /* HW is reporting DMA is out of sync */
5945 adapter->stats.doosync++;
5946 /* The DMA Out of Sync is also indication of a spoof event
5947 * in IOV mode. Check the Wrong VM Behavior register to
5948 * see if it is really a spoof event. */
5949 igb_check_wvbr(adapter);
5952 /* Check for a mailbox event */
5953 if (icr & E1000_ICR_VMMB)
5954 igb_msg_task(adapter);
5956 if (icr & E1000_ICR_LSC) {
5957 hw->mac.get_link_status = 1;
5958 /* guard against interrupt when we're going down */
5959 if (!test_bit(__IGB_DOWN, &adapter->state))
5960 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5963 #ifdef HAVE_PTP_1588_CLOCK
5964 if (icr & E1000_ICR_TS) {
5965 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
5967 if (tsicr & E1000_TSICR_TXTS) {
5968 /* acknowledge the interrupt */
5969 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
5970 /* retrieve hardware timestamp */
5971 schedule_work(&adapter->ptp_tx_work);
5974 #endif /* HAVE_PTP_1588_CLOCK */
5976 /* Check for MDD event */
5977 if (icr & E1000_ICR_MDDET)
5978 igb_process_mdd_event(adapter);
5980 E1000_WRITE_REG(hw, E1000_EIMS, adapter->eims_other);
5985 static void igb_write_itr(struct igb_q_vector *q_vector)
5987 struct igb_adapter *adapter = q_vector->adapter;
5988 u32 itr_val = q_vector->itr_val & 0x7FFC;
5990 if (!q_vector->set_itr)
5996 if (adapter->hw.mac.type == e1000_82575)
5997 itr_val |= itr_val << 16;
5999 itr_val |= E1000_EITR_CNT_IGNR;
6001 writel(itr_val, q_vector->itr_register);
6002 q_vector->set_itr = 0;
6005 static irqreturn_t igb_msix_ring(int irq, void *data)
6007 struct igb_q_vector *q_vector = data;
6009 /* Write the ITR value calculated from the previous interrupt. */
6010 igb_write_itr(q_vector);
6012 napi_schedule(&q_vector->napi);
6018 static void igb_update_tx_dca(struct igb_adapter *adapter,
6019 struct igb_ring *tx_ring,
6022 struct e1000_hw *hw = &adapter->hw;
6023 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
6025 if (hw->mac.type != e1000_82575)
6026 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT_82576;
6029 * We can enable relaxed ordering for reads, but not writes when
6030 * DCA is enabled. This is due to a known issue in some chipsets
6031 * which will cause the DCA tag to be cleared.
6033 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
6034 E1000_DCA_TXCTRL_DATA_RRO_EN |
6035 E1000_DCA_TXCTRL_DESC_DCA_EN;
6037 E1000_WRITE_REG(hw, E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
6040 static void igb_update_rx_dca(struct igb_adapter *adapter,
6041 struct igb_ring *rx_ring,
6044 struct e1000_hw *hw = &adapter->hw;
6045 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
6047 if (hw->mac.type != e1000_82575)
6048 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT_82576;
6051 * We can enable relaxed ordering for reads, but not writes when
6052 * DCA is enabled. This is due to a known issue in some chipsets
6053 * which will cause the DCA tag to be cleared.
6055 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
6056 E1000_DCA_RXCTRL_DESC_DCA_EN;
6058 E1000_WRITE_REG(hw, E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
6061 static void igb_update_dca(struct igb_q_vector *q_vector)
6063 struct igb_adapter *adapter = q_vector->adapter;
6064 int cpu = get_cpu();
6066 if (q_vector->cpu == cpu)
6069 if (q_vector->tx.ring)
6070 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
6072 if (q_vector->rx.ring)
6073 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
6075 q_vector->cpu = cpu;
6080 static void igb_setup_dca(struct igb_adapter *adapter)
6082 struct e1000_hw *hw = &adapter->hw;
6085 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
6088 /* Always use CB2 mode, difference is masked in the CB driver. */
6089 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
6091 for (i = 0; i < adapter->num_q_vectors; i++) {
6092 adapter->q_vector[i]->cpu = -1;
6093 igb_update_dca(adapter->q_vector[i]);
6097 static int __igb_notify_dca(struct device *dev, void *data)
6099 struct net_device *netdev = dev_get_drvdata(dev);
6100 struct igb_adapter *adapter = netdev_priv(netdev);
6101 struct pci_dev *pdev = adapter->pdev;
6102 struct e1000_hw *hw = &adapter->hw;
6103 unsigned long event = *(unsigned long *)data;
6106 case DCA_PROVIDER_ADD:
6107 /* if already enabled, don't do it again */
6108 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
6110 if (dca_add_requester(dev) == E1000_SUCCESS) {
6111 adapter->flags |= IGB_FLAG_DCA_ENABLED;
6112 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
6113 igb_setup_dca(adapter);
6116 /* Fall Through since DCA is disabled. */
6117 case DCA_PROVIDER_REMOVE:
6118 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
6119 /* without this a class_device is left
6120 * hanging around in the sysfs model */
6121 dca_remove_requester(dev);
6122 dev_info(pci_dev_to_dev(pdev), "DCA disabled\n");
6123 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
6124 E1000_WRITE_REG(hw, E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_DISABLE);
6129 return E1000_SUCCESS;
6132 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
6137 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
6140 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6142 #endif /* IGB_DCA */
6144 static int igb_vf_configure(struct igb_adapter *adapter, int vf)
6146 unsigned char mac_addr[ETH_ALEN];
6148 random_ether_addr(mac_addr);
6149 igb_set_vf_mac(adapter, vf, mac_addr);
6152 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
6153 /* By default spoof check is enabled for all VFs */
6154 adapter->vf_data[vf].spoofchk_enabled = true;
6161 static void igb_ping_all_vfs(struct igb_adapter *adapter)
6163 struct e1000_hw *hw = &adapter->hw;
6167 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
6168 ping = E1000_PF_CONTROL_MSG;
6169 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
6170 ping |= E1000_VT_MSGTYPE_CTS;
6171 e1000_write_mbx(hw, &ping, 1, i);
6176 * igb_mta_set_ - Set multicast filter table address
6177 * @adapter: pointer to the adapter structure
6178 * @hash_value: determines the MTA register and bit to set
6180 * The multicast table address is a register array of 32-bit registers.
6181 * The hash_value is used to determine what register the bit is in, the
6182 * current value is read, the new bit is OR'd in and the new value is
6183 * written back into the register.
6185 void igb_mta_set(struct igb_adapter *adapter, u32 hash_value)
6187 struct e1000_hw *hw = &adapter->hw;
6188 u32 hash_bit, hash_reg, mta;
6191 * The MTA is a register array of 32-bit registers. It is
6192 * treated like an array of (32*mta_reg_count) bits. We want to
6193 * set bit BitArray[hash_value]. So we figure out what register
6194 * the bit is in, read it, OR in the new bit, then write
6195 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
6196 * mask to bits 31:5 of the hash value which gives us the
6197 * register we're modifying. The hash bit within that register
6198 * is determined by the lower 5 bits of the hash value.
6200 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
6201 hash_bit = hash_value & 0x1F;
6203 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
6205 mta |= (1 << hash_bit);
6207 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
6208 E1000_WRITE_FLUSH(hw);
6211 static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6214 struct e1000_hw *hw = &adapter->hw;
6215 u32 vmolr = E1000_READ_REG(hw, E1000_VMOLR(vf));
6216 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6218 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
6219 IGB_VF_FLAG_MULTI_PROMISC);
6220 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6222 #ifdef IGB_ENABLE_VF_PROMISC
6223 if (*msgbuf & E1000_VF_SET_PROMISC_UNICAST) {
6224 vmolr |= E1000_VMOLR_ROPE;
6225 vf_data->flags |= IGB_VF_FLAG_UNI_PROMISC;
6226 *msgbuf &= ~E1000_VF_SET_PROMISC_UNICAST;
6229 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
6230 vmolr |= E1000_VMOLR_MPME;
6231 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
6232 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
6235 * if we have hashes and we are clearing a multicast promisc
6236 * flag we need to write the hashes to the MTA as this step
6237 * was previously skipped
6239 if (vf_data->num_vf_mc_hashes > 30) {
6240 vmolr |= E1000_VMOLR_MPME;
6241 } else if (vf_data->num_vf_mc_hashes) {
6243 vmolr |= E1000_VMOLR_ROMPE;
6244 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6245 igb_mta_set(adapter, vf_data->vf_mc_hashes[j]);
6249 E1000_WRITE_REG(hw, E1000_VMOLR(vf), vmolr);
6251 /* there are flags left unprocessed, likely not supported */
6252 if (*msgbuf & E1000_VT_MSGINFO_MASK)
6259 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
6260 u32 *msgbuf, u32 vf)
6262 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6263 u16 *hash_list = (u16 *)&msgbuf[1];
6264 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6267 /* salt away the number of multicast addresses assigned
6268 * to this VF for later use to restore when the PF multi cast
6271 vf_data->num_vf_mc_hashes = n;
6273 /* only up to 30 hash values supported */
6277 /* store the hashes for later use */
6278 for (i = 0; i < n; i++)
6279 vf_data->vf_mc_hashes[i] = hash_list[i];
6281 /* Flush and reset the mta with the new values */
6282 igb_set_rx_mode(adapter->netdev);
6287 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
6289 struct e1000_hw *hw = &adapter->hw;
6290 struct vf_data_storage *vf_data;
6293 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6294 u32 vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
6295 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6297 vf_data = &adapter->vf_data[i];
6299 if ((vf_data->num_vf_mc_hashes > 30) ||
6300 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
6301 vmolr |= E1000_VMOLR_MPME;
6302 } else if (vf_data->num_vf_mc_hashes) {
6303 vmolr |= E1000_VMOLR_ROMPE;
6304 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6305 igb_mta_set(adapter, vf_data->vf_mc_hashes[j]);
6307 E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
6311 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
6313 struct e1000_hw *hw = &adapter->hw;
6314 u32 pool_mask, reg, vid;
6318 pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
6320 /* Find the vlan filter for this id */
6321 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6322 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6324 /* remove the vf from the pool */
6327 /* if pool is empty then remove entry from vfta */
6328 if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
6329 (reg & E1000_VLVF_VLANID_ENABLE)) {
6331 vid = reg & E1000_VLVF_VLANID_MASK;
6332 igb_vfta_set(adapter, vid, FALSE);
6335 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6338 adapter->vf_data[vf].vlans_enabled = 0;
6340 vlan_default = adapter->vf_data[vf].default_vf_vlan_id;
6342 igb_vlvf_set(adapter, vlan_default, true, vf);
6345 s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
6347 struct e1000_hw *hw = &adapter->hw;
6350 /* The vlvf table only exists on 82576 hardware and newer */
6351 if (hw->mac.type < e1000_82576)
6354 /* we only need to do this if VMDq is enabled */
6355 if (!adapter->vmdq_pools)
6358 /* Find the vlan filter for this id */
6359 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6360 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6361 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
6362 vid == (reg & E1000_VLVF_VLANID_MASK))
6367 if (i == E1000_VLVF_ARRAY_SIZE) {
6368 /* Did not find a matching VLAN ID entry that was
6369 * enabled. Search for a free filter entry, i.e.
6370 * one without the enable bit set
6372 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6373 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6374 if (!(reg & E1000_VLVF_VLANID_ENABLE))
6378 if (i < E1000_VLVF_ARRAY_SIZE) {
6379 /* Found an enabled/available entry */
6380 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
6382 /* if !enabled we need to set this up in vfta */
6383 if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
6384 /* add VID to filter table */
6385 igb_vfta_set(adapter, vid, TRUE);
6386 reg |= E1000_VLVF_VLANID_ENABLE;
6388 reg &= ~E1000_VLVF_VLANID_MASK;
6390 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6392 /* do not modify RLPML for PF devices */
6393 if (vf >= adapter->vfs_allocated_count)
6394 return E1000_SUCCESS;
6396 if (!adapter->vf_data[vf].vlans_enabled) {
6398 reg = E1000_READ_REG(hw, E1000_VMOLR(vf));
6399 size = reg & E1000_VMOLR_RLPML_MASK;
6401 reg &= ~E1000_VMOLR_RLPML_MASK;
6403 E1000_WRITE_REG(hw, E1000_VMOLR(vf), reg);
6406 adapter->vf_data[vf].vlans_enabled++;
6409 if (i < E1000_VLVF_ARRAY_SIZE) {
6410 /* remove vf from the pool */
6411 reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
6412 /* if pool is empty then remove entry from vfta */
6413 if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
6415 igb_vfta_set(adapter, vid, FALSE);
6417 E1000_WRITE_REG(hw, E1000_VLVF(i), reg);
6419 /* do not modify RLPML for PF devices */
6420 if (vf >= adapter->vfs_allocated_count)
6421 return E1000_SUCCESS;
6423 adapter->vf_data[vf].vlans_enabled--;
6424 if (!adapter->vf_data[vf].vlans_enabled) {
6426 reg = E1000_READ_REG(hw, E1000_VMOLR(vf));
6427 size = reg & E1000_VMOLR_RLPML_MASK;
6429 reg &= ~E1000_VMOLR_RLPML_MASK;
6431 E1000_WRITE_REG(hw, E1000_VMOLR(vf), reg);
6435 return E1000_SUCCESS;
6439 static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
6441 struct e1000_hw *hw = &adapter->hw;
6444 E1000_WRITE_REG(hw, E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
6446 E1000_WRITE_REG(hw, E1000_VMVIR(vf), 0);
6449 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
6450 #ifdef HAVE_VF_VLAN_PROTO
6451 int vf, u16 vlan, u8 qos, __be16 vlan_proto)
6453 int vf, u16 vlan, u8 qos)
6457 struct igb_adapter *adapter = netdev_priv(netdev);
6459 /* VLAN IDs accepted range 0-4094 */
6460 if ((vf >= adapter->vfs_allocated_count) || (vlan > VLAN_VID_MASK-1) || (qos > 7))
6463 #ifdef HAVE_VF_VLAN_PROTO
6464 if (vlan_proto != htons(ETH_P_8021Q))
6465 return -EPROTONOSUPPORT;
6469 err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
6472 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
6473 igb_set_vmolr(adapter, vf, !vlan);
6474 adapter->vf_data[vf].pf_vlan = vlan;
6475 adapter->vf_data[vf].pf_qos = qos;
6476 igb_set_vf_vlan_strip(adapter, vf, true);
6477 dev_info(&adapter->pdev->dev,
6478 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
6479 if (test_bit(__IGB_DOWN, &adapter->state)) {
6480 dev_warn(&adapter->pdev->dev,
6481 "The VF VLAN has been set,"
6482 " but the PF device is not up.\n");
6483 dev_warn(&adapter->pdev->dev,
6484 "Bring the PF device up before"
6485 " attempting to use the VF device.\n");
6488 if (adapter->vf_data[vf].pf_vlan)
6489 dev_info(&adapter->pdev->dev,
6490 "Clearing VLAN on VF %d\n", vf);
6491 igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
6493 igb_set_vmvir(adapter, vlan, vf);
6494 igb_set_vmolr(adapter, vf, true);
6495 igb_set_vf_vlan_strip(adapter, vf, false);
6496 adapter->vf_data[vf].pf_vlan = 0;
6497 adapter->vf_data[vf].pf_qos = 0;
6503 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
6504 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
6507 struct igb_adapter *adapter = netdev_priv(netdev);
6508 struct e1000_hw *hw = &adapter->hw;
6509 u32 dtxswc, reg_offset;
6511 if (!adapter->vfs_allocated_count)
6514 if (vf >= adapter->vfs_allocated_count)
6517 reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
6518 dtxswc = E1000_READ_REG(hw, reg_offset);
6520 dtxswc |= ((1 << vf) |
6521 (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
6523 dtxswc &= ~((1 << vf) |
6524 (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
6525 E1000_WRITE_REG(hw, reg_offset, dtxswc);
6527 adapter->vf_data[vf].spoofchk_enabled = setting;
6528 return E1000_SUCCESS;
6530 #endif /* HAVE_VF_SPOOFCHK_CONFIGURE */
6531 #endif /* IFLA_VF_MAX */
6533 static int igb_find_vlvf_entry(struct igb_adapter *adapter, int vid)
6535 struct e1000_hw *hw = &adapter->hw;
6539 /* Find the vlan filter for this id */
6540 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
6541 reg = E1000_READ_REG(hw, E1000_VLVF(i));
6542 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
6543 vid == (reg & E1000_VLVF_VLANID_MASK))
6547 if (i >= E1000_VLVF_ARRAY_SIZE)
6553 static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6555 struct e1000_hw *hw = &adapter->hw;
6556 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6557 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
6561 igb_set_vf_vlan_strip(adapter, vf, true);
6563 igb_set_vf_vlan_strip(adapter, vf, false);
6565 /* If in promiscuous mode we need to make sure the PF also has
6566 * the VLAN filter set.
6568 if (add && (adapter->netdev->flags & IFF_PROMISC))
6569 err = igb_vlvf_set(adapter, vid, add,
6570 adapter->vfs_allocated_count);
6574 err = igb_vlvf_set(adapter, vid, add, vf);
6579 /* Go through all the checks to see if the VLAN filter should
6580 * be wiped completely.
6582 if (!add && (adapter->netdev->flags & IFF_PROMISC)) {
6585 int regndx = igb_find_vlvf_entry(adapter, vid);
6588 /* See if any other pools are set for this VLAN filter
6589 * entry other than the PF.
6591 vlvf = bits = E1000_READ_REG(hw, E1000_VLVF(regndx));
6592 bits &= 1 << (E1000_VLVF_POOLSEL_SHIFT +
6593 adapter->vfs_allocated_count);
6594 /* If the filter was removed then ensure PF pool bit
6595 * is cleared if the PF only added itself to the pool
6596 * because the PF is in promiscuous mode.
6598 if ((vlvf & VLAN_VID_MASK) == vid &&
6599 #ifndef HAVE_VLAN_RX_REGISTER
6600 !test_bit(vid, adapter->active_vlans) &&
6603 igb_vlvf_set(adapter, vid, add,
6604 adapter->vfs_allocated_count);
6611 static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
6613 struct e1000_hw *hw = &adapter->hw;
6615 /* clear flags except flag that the PF has set the MAC */
6616 adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
6617 adapter->vf_data[vf].last_nack = jiffies;
6619 /* reset offloads to defaults */
6620 igb_set_vmolr(adapter, vf, true);
6622 /* reset vlans for device */
6623 igb_clear_vf_vfta(adapter, vf);
6625 if (adapter->vf_data[vf].pf_vlan)
6626 igb_ndo_set_vf_vlan(adapter->netdev, vf,
6627 adapter->vf_data[vf].pf_vlan,
6628 #ifdef HAVE_VF_VLAN_PROTO
6629 adapter->vf_data[vf].pf_qos,
6630 htons(ETH_P_8021Q));
6632 adapter->vf_data[vf].pf_qos);
6635 igb_clear_vf_vfta(adapter, vf);
6638 /* reset multicast table array for vf */
6639 adapter->vf_data[vf].num_vf_mc_hashes = 0;
6641 /* Flush and reset the mta with the new values */
6642 igb_set_rx_mode(adapter->netdev);
6645 * Reset the VFs TDWBAL and TDWBAH registers which are not
6648 E1000_WRITE_REG(hw, E1000_TDWBAH(vf), 0);
6649 E1000_WRITE_REG(hw, E1000_TDWBAL(vf), 0);
6650 if (hw->mac.type == e1000_82576) {
6651 E1000_WRITE_REG(hw, E1000_TDWBAH(IGB_MAX_VF_FUNCTIONS + vf), 0);
6652 E1000_WRITE_REG(hw, E1000_TDWBAL(IGB_MAX_VF_FUNCTIONS + vf), 0);
6656 static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
6658 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6660 /* generate a new mac address as we were hotplug removed/added */
6661 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
6662 random_ether_addr(vf_mac);
6664 /* process remaining reset events */
6665 igb_vf_reset(adapter, vf);
6668 static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
6670 struct e1000_hw *hw = &adapter->hw;
6671 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6673 u8 *addr = (u8 *)(&msgbuf[1]);
6675 /* process all the same items cleared in a function level reset */
6676 igb_vf_reset(adapter, vf);
6678 /* set vf mac address */
6679 igb_del_mac_filter(adapter, vf_mac, vf);
6680 igb_add_mac_filter(adapter, vf_mac, vf);
6682 /* enable transmit and receive for vf */
6683 reg = E1000_READ_REG(hw, E1000_VFTE);
6684 E1000_WRITE_REG(hw, E1000_VFTE, reg | (1 << vf));
6685 reg = E1000_READ_REG(hw, E1000_VFRE);
6686 E1000_WRITE_REG(hw, E1000_VFRE, reg | (1 << vf));
6688 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
6690 /* reply to reset with ack and vf mac address */
6691 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
6692 memcpy(addr, vf_mac, 6);
6693 e1000_write_mbx(hw, msgbuf, 3, vf);
6696 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
6699 * The VF MAC Address is stored in a packed array of bytes
6700 * starting at the second 32 bit word of the msg array
6702 unsigned char *addr = (unsigned char *)&msg[1];
6705 if (is_valid_ether_addr(addr))
6706 err = igb_set_vf_mac(adapter, vf, addr);
6711 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
6713 struct e1000_hw *hw = &adapter->hw;
6714 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6715 u32 msg = E1000_VT_MSGTYPE_NACK;
6717 /* if device isn't clear to send it shouldn't be reading either */
6718 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
6719 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6720 e1000_write_mbx(hw, &msg, 1, vf);
6721 vf_data->last_nack = jiffies;
6725 static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
6727 struct pci_dev *pdev = adapter->pdev;
6728 u32 msgbuf[E1000_VFMAILBOX_SIZE];
6729 struct e1000_hw *hw = &adapter->hw;
6730 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6733 retval = e1000_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
6736 dev_err(pci_dev_to_dev(pdev), "Error receiving message from VF\n");
6740 /* this is a message we already processed, do nothing */
6741 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
6745 * until the vf completes a reset it should not be
6746 * allowed to start any configuration.
6749 if (msgbuf[0] == E1000_VF_RESET) {
6750 igb_vf_reset_msg(adapter, vf);
6754 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
6755 msgbuf[0] = E1000_VT_MSGTYPE_NACK;
6756 if (time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6757 e1000_write_mbx(hw, msgbuf, 1, vf);
6758 vf_data->last_nack = jiffies;
6763 switch ((msgbuf[0] & 0xFFFF)) {
6764 case E1000_VF_SET_MAC_ADDR:
6766 #ifndef IGB_DISABLE_VF_MAC_SET
6767 if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
6768 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
6771 "VF %d attempted to override administratively "
6772 "set MAC address\nReload the VF driver to "
6773 "resume operations\n", vf);
6776 case E1000_VF_SET_PROMISC:
6777 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
6779 case E1000_VF_SET_MULTICAST:
6780 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
6782 case E1000_VF_SET_LPE:
6783 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
6785 case E1000_VF_SET_VLAN:
6788 if (vf_data->pf_vlan)
6790 "VF %d attempted to override administratively "
6791 "set VLAN tag\nReload the VF driver to "
6792 "resume operations\n", vf);
6795 retval = igb_set_vf_vlan(adapter, msgbuf, vf);
6798 dev_err(pci_dev_to_dev(pdev), "Unhandled Msg %08x\n", msgbuf[0]);
6799 retval = -E1000_ERR_MBX;
6803 /* notify the VF of the results of what it sent us */
6805 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
6807 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
6809 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
6811 e1000_write_mbx(hw, msgbuf, 1, vf);
6814 static void igb_msg_task(struct igb_adapter *adapter)
6816 struct e1000_hw *hw = &adapter->hw;
6819 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
6820 /* process any reset requests */
6821 if (!e1000_check_for_rst(hw, vf))
6822 igb_vf_reset_event(adapter, vf);
6824 /* process any messages pending */
6825 if (!e1000_check_for_msg(hw, vf))
6826 igb_rcv_msg_from_vf(adapter, vf);
6828 /* process any acks */
6829 if (!e1000_check_for_ack(hw, vf))
6830 igb_rcv_ack_from_vf(adapter, vf);
6835 * igb_set_uta - Set unicast filter table address
6836 * @adapter: board private structure
6838 * The unicast table address is a register array of 32-bit registers.
6839 * The table is meant to be used in a way similar to how the MTA is used
6840 * however due to certain limitations in the hardware it is necessary to
6841 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
6842 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
6844 static void igb_set_uta(struct igb_adapter *adapter)
6846 struct e1000_hw *hw = &adapter->hw;
6849 /* The UTA table only exists on 82576 hardware and newer */
6850 if (hw->mac.type < e1000_82576)
6853 /* we only need to do this if VMDq is enabled */
6854 if (!adapter->vmdq_pools)
6857 for (i = 0; i < hw->mac.uta_reg_count; i++)
6858 E1000_WRITE_REG_ARRAY(hw, E1000_UTA, i, ~0);
6862 * igb_intr_msi - Interrupt Handler
6863 * @irq: interrupt number
6864 * @data: pointer to a network interface device structure
6866 static irqreturn_t igb_intr_msi(int irq, void *data)
6868 struct igb_adapter *adapter = data;
6869 struct igb_q_vector *q_vector = adapter->q_vector[0];
6870 struct e1000_hw *hw = &adapter->hw;
6871 /* read ICR disables interrupts using IAM */
6872 u32 icr = E1000_READ_REG(hw, E1000_ICR);
6874 igb_write_itr(q_vector);
6876 if (icr & E1000_ICR_DRSTA)
6877 schedule_work(&adapter->reset_task);
6879 if (icr & E1000_ICR_DOUTSYNC) {
6880 /* HW is reporting DMA is out of sync */
6881 adapter->stats.doosync++;
6884 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6885 hw->mac.get_link_status = 1;
6886 if (!test_bit(__IGB_DOWN, &adapter->state))
6887 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6890 #ifdef HAVE_PTP_1588_CLOCK
6891 if (icr & E1000_ICR_TS) {
6892 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
6894 if (tsicr & E1000_TSICR_TXTS) {
6895 /* acknowledge the interrupt */
6896 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
6897 /* retrieve hardware timestamp */
6898 schedule_work(&adapter->ptp_tx_work);
6901 #endif /* HAVE_PTP_1588_CLOCK */
6903 napi_schedule(&q_vector->napi);
6909 * igb_intr - Legacy Interrupt Handler
6910 * @irq: interrupt number
6911 * @data: pointer to a network interface device structure
6913 static irqreturn_t igb_intr(int irq, void *data)
6915 struct igb_adapter *adapter = data;
6916 struct igb_q_vector *q_vector = adapter->q_vector[0];
6917 struct e1000_hw *hw = &adapter->hw;
6918 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
6919 * need for the IMC write */
6920 u32 icr = E1000_READ_REG(hw, E1000_ICR);
6922 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
6923 * not set, then the adapter didn't send an interrupt */
6924 if (!(icr & E1000_ICR_INT_ASSERTED))
6927 igb_write_itr(q_vector);
6929 if (icr & E1000_ICR_DRSTA)
6930 schedule_work(&adapter->reset_task);
6932 if (icr & E1000_ICR_DOUTSYNC) {
6933 /* HW is reporting DMA is out of sync */
6934 adapter->stats.doosync++;
6937 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6938 hw->mac.get_link_status = 1;
6939 /* guard against interrupt when we're going down */
6940 if (!test_bit(__IGB_DOWN, &adapter->state))
6941 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6944 #ifdef HAVE_PTP_1588_CLOCK
6945 if (icr & E1000_ICR_TS) {
6946 u32 tsicr = E1000_READ_REG(hw, E1000_TSICR);
6948 if (tsicr & E1000_TSICR_TXTS) {
6949 /* acknowledge the interrupt */
6950 E1000_WRITE_REG(hw, E1000_TSICR, E1000_TSICR_TXTS);
6951 /* retrieve hardware timestamp */
6952 schedule_work(&adapter->ptp_tx_work);
6955 #endif /* HAVE_PTP_1588_CLOCK */
6957 napi_schedule(&q_vector->napi);
6962 void igb_ring_irq_enable(struct igb_q_vector *q_vector)
6964 struct igb_adapter *adapter = q_vector->adapter;
6965 struct e1000_hw *hw = &adapter->hw;
6967 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
6968 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
6969 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
6970 igb_set_itr(q_vector);
6972 igb_update_ring_itr(q_vector);
6975 if (!test_bit(__IGB_DOWN, &adapter->state)) {
6976 if (adapter->msix_entries)
6977 E1000_WRITE_REG(hw, E1000_EIMS, q_vector->eims_value);
6979 igb_irq_enable(adapter);
6984 * igb_poll - NAPI Rx polling callback
6985 * @napi: napi polling structure
6986 * @budget: count of how many packets we should handle
6988 static int igb_poll(struct napi_struct *napi, int budget)
6990 struct igb_q_vector *q_vector = container_of(napi, struct igb_q_vector, napi);
6991 bool clean_complete = true;
6994 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
6995 igb_update_dca(q_vector);
6997 if (q_vector->tx.ring)
6998 clean_complete = igb_clean_tx_irq(q_vector);
7000 if (q_vector->rx.ring)
7001 clean_complete &= igb_clean_rx_irq(q_vector, budget);
7003 #ifndef HAVE_NETDEV_NAPI_LIST
7004 /* if netdev is disabled we need to stop polling */
7005 if (!netif_running(q_vector->adapter->netdev))
7006 clean_complete = true;
7009 /* If all work not completed, return budget and keep polling */
7010 if (!clean_complete)
7013 /* If not enough Rx work done, exit the polling mode */
7014 napi_complete(napi);
7015 igb_ring_irq_enable(q_vector);
7021 * igb_clean_tx_irq - Reclaim resources after transmit completes
7022 * @q_vector: pointer to q_vector containing needed info
7023 * returns TRUE if ring is completely cleaned
7025 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
7027 struct igb_adapter *adapter = q_vector->adapter;
7028 struct igb_ring *tx_ring = q_vector->tx.ring;
7029 struct igb_tx_buffer *tx_buffer;
7030 union e1000_adv_tx_desc *tx_desc;
7031 unsigned int total_bytes = 0, total_packets = 0;
7032 unsigned int budget = q_vector->tx.work_limit;
7033 unsigned int i = tx_ring->next_to_clean;
7035 if (test_bit(__IGB_DOWN, &adapter->state))
7038 tx_buffer = &tx_ring->tx_buffer_info[i];
7039 tx_desc = IGB_TX_DESC(tx_ring, i);
7040 i -= tx_ring->count;
7043 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
7045 /* if next_to_watch is not set then there is no work pending */
7049 /* prevent any other reads prior to eop_desc */
7050 read_barrier_depends();
7052 /* if DD is not set pending work has not been completed */
7053 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
7056 /* clear next_to_watch to prevent false hangs */
7057 tx_buffer->next_to_watch = NULL;
7059 /* update the statistics for this packet */
7060 total_bytes += tx_buffer->bytecount;
7061 total_packets += tx_buffer->gso_segs;
7064 dev_kfree_skb_any(tx_buffer->skb);
7066 /* unmap skb header data */
7067 dma_unmap_single(tx_ring->dev,
7068 dma_unmap_addr(tx_buffer, dma),
7069 dma_unmap_len(tx_buffer, len),
7072 /* clear tx_buffer data */
7073 tx_buffer->skb = NULL;
7074 dma_unmap_len_set(tx_buffer, len, 0);
7076 /* clear last DMA location and unmap remaining buffers */
7077 while (tx_desc != eop_desc) {
7082 i -= tx_ring->count;
7083 tx_buffer = tx_ring->tx_buffer_info;
7084 tx_desc = IGB_TX_DESC(tx_ring, 0);
7087 /* unmap any remaining paged data */
7088 if (dma_unmap_len(tx_buffer, len)) {
7089 dma_unmap_page(tx_ring->dev,
7090 dma_unmap_addr(tx_buffer, dma),
7091 dma_unmap_len(tx_buffer, len),
7093 dma_unmap_len_set(tx_buffer, len, 0);
7097 /* move us one more past the eop_desc for start of next pkt */
7102 i -= tx_ring->count;
7103 tx_buffer = tx_ring->tx_buffer_info;
7104 tx_desc = IGB_TX_DESC(tx_ring, 0);
7107 /* issue prefetch for next Tx descriptor */
7110 /* update budget accounting */
7112 } while (likely(budget));
7114 netdev_tx_completed_queue(txring_txq(tx_ring),
7115 total_packets, total_bytes);
7117 i += tx_ring->count;
7118 tx_ring->next_to_clean = i;
7119 tx_ring->tx_stats.bytes += total_bytes;
7120 tx_ring->tx_stats.packets += total_packets;
7121 q_vector->tx.total_bytes += total_bytes;
7122 q_vector->tx.total_packets += total_packets;
7125 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags) &&
7126 !(adapter->disable_hw_reset && adapter->tx_hang_detected)) {
7128 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
7130 struct e1000_hw *hw = &adapter->hw;
7132 /* Detect a transmit hang in hardware, this serializes the
7133 * check with the clearing of time_stamp and movement of i */
7134 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
7135 if (tx_buffer->next_to_watch &&
7136 time_after(jiffies, tx_buffer->time_stamp +
7137 (adapter->tx_timeout_factor * HZ))
7138 && !(E1000_READ_REG(hw, E1000_STATUS) &
7139 E1000_STATUS_TXOFF)) {
7141 /* detected Tx unit hang */
7143 adapter->tx_hang_detected = TRUE;
7144 if (adapter->disable_hw_reset) {
7145 DPRINTK(DRV, WARNING,
7146 "Deactivating netdev watchdog timer\n");
7147 if (del_timer(&netdev_ring(tx_ring)->watchdog_timer))
7148 dev_put(netdev_ring(tx_ring));
7149 #ifndef HAVE_NET_DEVICE_OPS
7150 netdev_ring(tx_ring)->tx_timeout = NULL;
7154 dev_err(tx_ring->dev,
7155 "Detected Tx Unit Hang\n"
7159 " next_to_use <%x>\n"
7160 " next_to_clean <%x>\n"
7161 "buffer_info[next_to_clean]\n"
7162 " time_stamp <%lx>\n"
7163 " next_to_watch <%p>\n"
7165 " desc.status <%x>\n",
7166 tx_ring->queue_index,
7167 E1000_READ_REG(hw, E1000_TDH(tx_ring->reg_idx)),
7168 readl(tx_ring->tail),
7169 tx_ring->next_to_use,
7170 tx_ring->next_to_clean,
7171 tx_buffer->time_stamp,
7172 tx_buffer->next_to_watch,
7174 tx_buffer->next_to_watch->wb.status);
7175 if (netif_is_multiqueue(netdev_ring(tx_ring)))
7176 netif_stop_subqueue(netdev_ring(tx_ring),
7177 ring_queue_index(tx_ring));
7179 netif_stop_queue(netdev_ring(tx_ring));
7181 /* we are about to reset, no point in enabling stuff */
7186 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7187 if (unlikely(total_packets &&
7188 netif_carrier_ok(netdev_ring(tx_ring)) &&
7189 igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
7190 /* Make sure that anybody stopping the queue after this
7191 * sees the new next_to_clean.
7194 if (netif_is_multiqueue(netdev_ring(tx_ring))) {
7195 if (__netif_subqueue_stopped(netdev_ring(tx_ring),
7196 ring_queue_index(tx_ring)) &&
7197 !(test_bit(__IGB_DOWN, &adapter->state))) {
7198 netif_wake_subqueue(netdev_ring(tx_ring),
7199 ring_queue_index(tx_ring));
7200 tx_ring->tx_stats.restart_queue++;
7203 if (netif_queue_stopped(netdev_ring(tx_ring)) &&
7204 !(test_bit(__IGB_DOWN, &adapter->state))) {
7205 netif_wake_queue(netdev_ring(tx_ring));
7206 tx_ring->tx_stats.restart_queue++;
7214 #ifdef HAVE_VLAN_RX_REGISTER
7216 * igb_receive_skb - helper function to handle rx indications
7217 * @q_vector: structure containing interrupt and ring information
7218 * @skb: packet to send up
7220 static void igb_receive_skb(struct igb_q_vector *q_vector,
7221 struct sk_buff *skb)
7223 struct vlan_group **vlgrp = netdev_priv(skb->dev);
7225 if (IGB_CB(skb)->vid) {
7227 vlan_gro_receive(&q_vector->napi, *vlgrp,
7228 IGB_CB(skb)->vid, skb);
7230 dev_kfree_skb_any(skb);
7233 napi_gro_receive(&q_vector->napi, skb);
7237 #endif /* HAVE_VLAN_RX_REGISTER */
7238 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7240 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7241 * @rx_ring: rx descriptor ring to store buffers on
7242 * @old_buff: donor buffer to have page reused
7244 * Synchronizes page for reuse by the adapter
7246 static void igb_reuse_rx_page(struct igb_ring *rx_ring,
7247 struct igb_rx_buffer *old_buff)
7249 struct igb_rx_buffer *new_buff;
7250 u16 nta = rx_ring->next_to_alloc;
7252 new_buff = &rx_ring->rx_buffer_info[nta];
7254 /* update, and store next to alloc */
7256 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
7258 /* transfer page from old buffer to new buffer */
7259 memcpy(new_buff, old_buff, sizeof(struct igb_rx_buffer));
7261 /* sync the buffer for use by the device */
7262 dma_sync_single_range_for_device(rx_ring->dev, old_buff->dma,
7263 old_buff->page_offset,
7268 static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
7270 unsigned int truesize)
7272 /* avoid re-using remote pages */
7273 if (unlikely(page_to_nid(page) != numa_node_id()))
7276 #if (PAGE_SIZE < 8192)
7277 /* if we are only owner of page we can reuse it */
7278 if (unlikely(page_count(page) != 1))
7281 /* flip page offset to other buffer */
7282 rx_buffer->page_offset ^= IGB_RX_BUFSZ;
7285 /* move offset up to the next cache line */
7286 rx_buffer->page_offset += truesize;
7288 if (rx_buffer->page_offset > (PAGE_SIZE - IGB_RX_BUFSZ))
7292 /* bump ref count on page before it is given to the stack */
7299 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
7300 * @rx_ring: rx descriptor ring to transact packets on
7301 * @rx_buffer: buffer containing page to add
7302 * @rx_desc: descriptor containing length of buffer written by hardware
7303 * @skb: sk_buff to place the data into
7305 * This function will add the data contained in rx_buffer->page to the skb.
7306 * This is done either through a direct copy if the data in the buffer is
7307 * less than the skb header size, otherwise it will just attach the page as
7308 * a frag to the skb.
7310 * The function will then update the page offset if necessary and return
7311 * true if the buffer can be reused by the adapter.
7313 static bool igb_add_rx_frag(struct igb_ring *rx_ring,
7314 struct igb_rx_buffer *rx_buffer,
7315 union e1000_adv_rx_desc *rx_desc,
7316 struct sk_buff *skb)
7318 struct page *page = rx_buffer->page;
7319 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
7320 #if (PAGE_SIZE < 8192)
7321 unsigned int truesize = IGB_RX_BUFSZ;
7323 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
7326 if ((size <= IGB_RX_HDR_LEN) && !skb_is_nonlinear(skb)) {
7327 unsigned char *va = page_address(page) + rx_buffer->page_offset;
7329 #ifdef HAVE_PTP_1588_CLOCK
7330 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
7331 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
7332 va += IGB_TS_HDR_LEN;
7333 size -= IGB_TS_HDR_LEN;
7335 #endif /* HAVE_PTP_1588_CLOCK */
7337 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
7339 /* we can reuse buffer as-is, just make sure it is local */
7340 if (likely(page_to_nid(page) == numa_node_id()))
7343 /* this page cannot be reused so discard it */
7348 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
7349 rx_buffer->page_offset, size, truesize);
7351 return igb_can_reuse_rx_page(rx_buffer, page, truesize);
7354 static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,
7355 union e1000_adv_rx_desc *rx_desc,
7356 struct sk_buff *skb)
7358 struct igb_rx_buffer *rx_buffer;
7361 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
7363 page = rx_buffer->page;
7367 void *page_addr = page_address(page) +
7368 rx_buffer->page_offset;
7370 /* prefetch first cache line of first page */
7371 prefetch(page_addr);
7372 #if L1_CACHE_BYTES < 128
7373 prefetch(page_addr + L1_CACHE_BYTES);
7376 /* allocate a skb to store the frags */
7377 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
7379 if (unlikely(!skb)) {
7380 rx_ring->rx_stats.alloc_failed++;
7385 * we will be copying header into skb->data in
7386 * pskb_may_pull so it is in our interest to prefetch
7387 * it now to avoid a possible cache miss
7389 prefetchw(skb->data);
7392 /* we are reusing so sync this buffer for CPU use */
7393 dma_sync_single_range_for_cpu(rx_ring->dev,
7395 rx_buffer->page_offset,
7399 /* pull page into skb */
7400 if (igb_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
7401 /* hand second half of page back to the ring */
7402 igb_reuse_rx_page(rx_ring, rx_buffer);
7404 /* we are not reusing the buffer so unmap it */
7405 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
7406 PAGE_SIZE, DMA_FROM_DEVICE);
7409 /* clear contents of rx_buffer */
7410 rx_buffer->page = NULL;
7416 static inline void igb_rx_checksum(struct igb_ring *ring,
7417 union e1000_adv_rx_desc *rx_desc,
7418 struct sk_buff *skb)
7420 skb_checksum_none_assert(skb);
7422 /* Ignore Checksum bit is set */
7423 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
7426 /* Rx checksum disabled via ethtool */
7427 if (!(netdev_ring(ring)->features & NETIF_F_RXCSUM))
7430 /* TCP/UDP checksum error bit is set */
7431 if (igb_test_staterr(rx_desc,
7432 E1000_RXDEXT_STATERR_TCPE |
7433 E1000_RXDEXT_STATERR_IPE)) {
7435 * work around errata with sctp packets where the TCPE aka
7436 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
7437 * packets, (aka let the stack check the crc32c)
7439 if (!((skb->len == 60) &&
7440 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags)))
7441 ring->rx_stats.csum_err++;
7443 /* let the stack verify checksum errors */
7446 /* It must be a TCP or UDP packet with a valid checksum */
7447 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
7448 E1000_RXD_STAT_UDPCS))
7449 skb->ip_summed = CHECKSUM_UNNECESSARY;
7452 #ifdef NETIF_F_RXHASH
7453 static inline void igb_rx_hash(struct igb_ring *ring,
7454 union e1000_adv_rx_desc *rx_desc,
7455 struct sk_buff *skb)
7457 if (netdev_ring(ring)->features & NETIF_F_RXHASH)
7458 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
7464 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7466 * igb_merge_active_tail - merge active tail into lro skb
7467 * @tail: pointer to active tail in frag_list
7469 * This function merges the length and data of an active tail into the
7470 * skb containing the frag_list. It resets the tail's pointer to the head,
7471 * but it leaves the heads pointer to tail intact.
7473 static inline struct sk_buff *igb_merge_active_tail(struct sk_buff *tail)
7475 struct sk_buff *head = IGB_CB(tail)->head;
7480 head->len += tail->len;
7481 head->data_len += tail->len;
7482 head->truesize += tail->len;
7484 IGB_CB(tail)->head = NULL;
7490 * igb_add_active_tail - adds an active tail into the skb frag_list
7491 * @head: pointer to the start of the skb
7492 * @tail: pointer to active tail to add to frag_list
7494 * This function adds an active tail to the end of the frag list. This tail
7495 * will still be receiving data so we cannot yet ad it's stats to the main
7496 * skb. That is done via igb_merge_active_tail.
7498 static inline void igb_add_active_tail(struct sk_buff *head, struct sk_buff *tail)
7500 struct sk_buff *old_tail = IGB_CB(head)->tail;
7503 igb_merge_active_tail(old_tail);
7504 old_tail->next = tail;
7506 skb_shinfo(head)->frag_list = tail;
7509 IGB_CB(tail)->head = head;
7510 IGB_CB(head)->tail = tail;
7512 IGB_CB(head)->append_cnt++;
7516 * igb_close_active_frag_list - cleanup pointers on a frag_list skb
7517 * @head: pointer to head of an active frag list
7519 * This function will clear the frag_tail_tracker pointer on an active
7520 * frag_list and returns true if the pointer was actually set
7522 static inline bool igb_close_active_frag_list(struct sk_buff *head)
7524 struct sk_buff *tail = IGB_CB(head)->tail;
7529 igb_merge_active_tail(tail);
7531 IGB_CB(head)->tail = NULL;
7536 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
7538 * igb_can_lro - returns true if packet is TCP/IPV4 and LRO is enabled
7539 * @adapter: board private structure
7540 * @rx_desc: pointer to the rx descriptor
7541 * @skb: pointer to the skb to be merged
7544 static inline bool igb_can_lro(struct igb_ring *rx_ring,
7545 union e1000_adv_rx_desc *rx_desc,
7546 struct sk_buff *skb)
7548 struct iphdr *iph = (struct iphdr *)skb->data;
7549 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
7551 /* verify hardware indicates this is IPv4/TCP */
7552 if((!(pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_TCP)) ||
7553 !(pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4))))
7556 /* .. and LRO is enabled */
7557 if (!(netdev_ring(rx_ring)->features & NETIF_F_LRO))
7560 /* .. and we are not in promiscuous mode */
7561 if (netdev_ring(rx_ring)->flags & IFF_PROMISC)
7564 /* .. and the header is large enough for us to read IP/TCP fields */
7565 if (!pskb_may_pull(skb, sizeof(struct igb_lrohdr)))
7568 /* .. and there are no VLANs on packet */
7569 if (skb->protocol != __constant_htons(ETH_P_IP))
7572 /* .. and we are version 4 with no options */
7573 if (*(u8 *)iph != 0x45)
7576 /* .. and the packet is not fragmented */
7577 if (iph->frag_off & htons(IP_MF | IP_OFFSET))
7580 /* .. and that next header is TCP */
7581 if (iph->protocol != IPPROTO_TCP)
7587 static inline struct igb_lrohdr *igb_lro_hdr(struct sk_buff *skb)
7589 return (struct igb_lrohdr *)skb->data;
7593 * igb_lro_flush - Indicate packets to upper layer.
7595 * Update IP and TCP header part of head skb if more than one
7596 * skb's chained and indicate packets to upper layer.
7598 static void igb_lro_flush(struct igb_q_vector *q_vector,
7599 struct sk_buff *skb)
7601 struct igb_lro_list *lrolist = &q_vector->lrolist;
7603 __skb_unlink(skb, &lrolist->active);
7605 if (IGB_CB(skb)->append_cnt) {
7606 struct igb_lrohdr *lroh = igb_lro_hdr(skb);
7608 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7609 /* close any active lro contexts */
7610 igb_close_active_frag_list(skb);
7613 /* incorporate ip header and re-calculate checksum */
7614 lroh->iph.tot_len = ntohs(skb->len);
7615 lroh->iph.check = 0;
7617 /* header length is 5 since we know no options exist */
7618 lroh->iph.check = ip_fast_csum((u8 *)lroh, 5);
7620 /* clear TCP checksum to indicate we are an LRO frame */
7623 /* incorporate latest timestamp into the tcp header */
7624 if (IGB_CB(skb)->tsecr) {
7625 lroh->ts[2] = IGB_CB(skb)->tsecr;
7626 lroh->ts[1] = htonl(IGB_CB(skb)->tsval);
7630 skb_shinfo(skb)->gso_size = IGB_CB(skb)->mss;
7631 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
7635 #ifdef HAVE_VLAN_RX_REGISTER
7636 igb_receive_skb(q_vector, skb);
7638 napi_gro_receive(&q_vector->napi, skb);
7640 lrolist->stats.flushed++;
7643 static void igb_lro_flush_all(struct igb_q_vector *q_vector)
7645 struct igb_lro_list *lrolist = &q_vector->lrolist;
7646 struct sk_buff *skb, *tmp;
7648 skb_queue_reverse_walk_safe(&lrolist->active, skb, tmp)
7649 igb_lro_flush(q_vector, skb);
7653 * igb_lro_header_ok - Main LRO function.
7655 static void igb_lro_header_ok(struct sk_buff *skb)
7657 struct igb_lrohdr *lroh = igb_lro_hdr(skb);
7658 u16 opt_bytes, data_len;
7660 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
7661 IGB_CB(skb)->tail = NULL;
7663 IGB_CB(skb)->tsecr = 0;
7664 IGB_CB(skb)->append_cnt = 0;
7665 IGB_CB(skb)->mss = 0;
7667 /* ensure that the checksum is valid */
7668 if (skb->ip_summed != CHECKSUM_UNNECESSARY)
7671 /* If we see CE codepoint in IP header, packet is not mergeable */
7672 if (INET_ECN_is_ce(ipv4_get_dsfield(&lroh->iph)))
7675 /* ensure no bits set besides ack or psh */
7676 if (lroh->th.fin || lroh->th.syn || lroh->th.rst ||
7677 lroh->th.urg || lroh->th.ece || lroh->th.cwr ||
7681 /* store the total packet length */
7682 data_len = ntohs(lroh->iph.tot_len);
7684 /* remove any padding from the end of the skb */
7685 __pskb_trim(skb, data_len);
7687 /* remove header length from data length */
7688 data_len -= sizeof(struct igb_lrohdr);
7691 * check for timestamps. Since the only option we handle are timestamps,
7692 * we only have to handle the simple case of aligned timestamps
7694 opt_bytes = (lroh->th.doff << 2) - sizeof(struct tcphdr);
7695 if (opt_bytes != 0) {
7696 if ((opt_bytes != TCPOLEN_TSTAMP_ALIGNED) ||
7697 !pskb_may_pull(skb, sizeof(struct igb_lrohdr) +
7698 TCPOLEN_TSTAMP_ALIGNED) ||
7699 (lroh->ts[0] != htonl((TCPOPT_NOP << 24) |
7700 (TCPOPT_NOP << 16) |
7701 (TCPOPT_TIMESTAMP << 8) |
7702 TCPOLEN_TIMESTAMP)) ||
7703 (lroh->ts[2] == 0)) {
7707 IGB_CB(skb)->tsval = ntohl(lroh->ts[1]);
7708 IGB_CB(skb)->tsecr = lroh->ts[2];
7710 data_len -= TCPOLEN_TSTAMP_ALIGNED;
7713 /* record data_len as mss for the packet */
7714 IGB_CB(skb)->mss = data_len;
7715 IGB_CB(skb)->next_seq = ntohl(lroh->th.seq);
7718 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7719 static void igb_merge_frags(struct sk_buff *lro_skb, struct sk_buff *new_skb)
7721 struct skb_shared_info *sh_info;
7722 struct skb_shared_info *new_skb_info;
7723 unsigned int data_len;
7725 sh_info = skb_shinfo(lro_skb);
7726 new_skb_info = skb_shinfo(new_skb);
7728 /* copy frags into the last skb */
7729 memcpy(sh_info->frags + sh_info->nr_frags,
7730 new_skb_info->frags,
7731 new_skb_info->nr_frags * sizeof(skb_frag_t));
7733 /* copy size data over */
7734 sh_info->nr_frags += new_skb_info->nr_frags;
7735 data_len = IGB_CB(new_skb)->mss;
7736 lro_skb->len += data_len;
7737 lro_skb->data_len += data_len;
7738 lro_skb->truesize += data_len;
7740 /* wipe record of data from new_skb */
7741 new_skb_info->nr_frags = 0;
7742 new_skb->len = new_skb->data_len = 0;
7743 dev_kfree_skb_any(new_skb);
7746 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
7748 * igb_lro_receive - if able, queue skb into lro chain
7749 * @q_vector: structure containing interrupt and ring information
7750 * @new_skb: pointer to current skb being checked
7752 * Checks whether the skb given is eligible for LRO and if that's
7753 * fine chains it to the existing lro_skb based on flowid. If an LRO for
7754 * the flow doesn't exist create one.
7756 static void igb_lro_receive(struct igb_q_vector *q_vector,
7757 struct sk_buff *new_skb)
7759 struct sk_buff *lro_skb;
7760 struct igb_lro_list *lrolist = &q_vector->lrolist;
7761 struct igb_lrohdr *lroh = igb_lro_hdr(new_skb);
7762 __be32 saddr = lroh->iph.saddr;
7763 __be32 daddr = lroh->iph.daddr;
7764 __be32 tcp_ports = *(__be32 *)&lroh->th;
7766 #ifdef HAVE_VLAN_RX_REGISTER
7767 u16 vid = IGB_CB(new_skb)->vid;
7769 u16 vid = new_skb->vlan_tci;
7772 igb_lro_header_ok(new_skb);
7775 * we have a packet that might be eligible for LRO,
7776 * so see if it matches anything we might expect
7778 skb_queue_walk(&lrolist->active, lro_skb) {
7779 if (*(__be32 *)&igb_lro_hdr(lro_skb)->th != tcp_ports ||
7780 igb_lro_hdr(lro_skb)->iph.saddr != saddr ||
7781 igb_lro_hdr(lro_skb)->iph.daddr != daddr)
7784 #ifdef HAVE_VLAN_RX_REGISTER
7785 if (IGB_CB(lro_skb)->vid != vid)
7787 if (lro_skb->vlan_tci != vid)
7791 /* out of order packet */
7792 if (IGB_CB(lro_skb)->next_seq != IGB_CB(new_skb)->next_seq) {
7793 igb_lro_flush(q_vector, lro_skb);
7794 IGB_CB(new_skb)->mss = 0;
7798 /* TCP timestamp options have changed */
7799 if (!IGB_CB(lro_skb)->tsecr != !IGB_CB(new_skb)->tsecr) {
7800 igb_lro_flush(q_vector, lro_skb);
7804 /* make sure timestamp values are increasing */
7805 if (IGB_CB(lro_skb)->tsecr &&
7806 IGB_CB(lro_skb)->tsval > IGB_CB(new_skb)->tsval) {
7807 igb_lro_flush(q_vector, lro_skb);
7808 IGB_CB(new_skb)->mss = 0;
7812 data_len = IGB_CB(new_skb)->mss;
7814 /* Check for all of the above below
7817 * resultant packet would be too large
7818 * new skb is larger than our current mss
7819 * data would remain in header
7820 * we would consume more frags then the sk_buff contains
7821 * ack sequence numbers changed
7822 * window size has changed
7824 if (data_len == 0 ||
7825 data_len > IGB_CB(lro_skb)->mss ||
7826 data_len > IGB_CB(lro_skb)->free ||
7827 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7828 data_len != new_skb->data_len ||
7829 skb_shinfo(new_skb)->nr_frags >=
7830 (MAX_SKB_FRAGS - skb_shinfo(lro_skb)->nr_frags) ||
7832 igb_lro_hdr(lro_skb)->th.ack_seq != lroh->th.ack_seq ||
7833 igb_lro_hdr(lro_skb)->th.window != lroh->th.window) {
7834 igb_lro_flush(q_vector, lro_skb);
7838 /* Remove IP and TCP header*/
7839 skb_pull(new_skb, new_skb->len - data_len);
7841 /* update timestamp and timestamp echo response */
7842 IGB_CB(lro_skb)->tsval = IGB_CB(new_skb)->tsval;
7843 IGB_CB(lro_skb)->tsecr = IGB_CB(new_skb)->tsecr;
7845 /* update sequence and free space */
7846 IGB_CB(lro_skb)->next_seq += data_len;
7847 IGB_CB(lro_skb)->free -= data_len;
7849 /* update append_cnt */
7850 IGB_CB(lro_skb)->append_cnt++;
7852 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
7853 /* if header is empty pull pages into current skb */
7854 igb_merge_frags(lro_skb, new_skb);
7856 /* chain this new skb in frag_list */
7857 igb_add_active_tail(lro_skb, new_skb);
7860 if ((data_len < IGB_CB(lro_skb)->mss) || lroh->th.psh ||
7861 skb_shinfo(lro_skb)->nr_frags == MAX_SKB_FRAGS) {
7862 igb_lro_hdr(lro_skb)->th.psh |= lroh->th.psh;
7863 igb_lro_flush(q_vector, lro_skb);
7866 lrolist->stats.coal++;
7870 if (IGB_CB(new_skb)->mss && !lroh->th.psh) {
7871 /* if we are at capacity flush the tail */
7872 if (skb_queue_len(&lrolist->active) >= IGB_LRO_MAX) {
7873 lro_skb = skb_peek_tail(&lrolist->active);
7875 igb_lro_flush(q_vector, lro_skb);
7878 /* update sequence and free space */
7879 IGB_CB(new_skb)->next_seq += IGB_CB(new_skb)->mss;
7880 IGB_CB(new_skb)->free = 65521 - new_skb->len;
7882 /* .. and insert at the front of the active list */
7883 __skb_queue_head(&lrolist->active, new_skb);
7885 lrolist->stats.coal++;
7889 /* packet not handled by any of the above, pass it to the stack */
7890 #ifdef HAVE_VLAN_RX_REGISTER
7891 igb_receive_skb(q_vector, new_skb);
7893 napi_gro_receive(&q_vector->napi, new_skb);
7897 #endif /* IGB_NO_LRO */
7899 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
7900 * @rx_ring: rx descriptor ring packet is being transacted on
7901 * @rx_desc: pointer to the EOP Rx descriptor
7902 * @skb: pointer to current skb being populated
7904 * This function checks the ring, descriptor, and packet information in
7905 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
7906 * other fields within the skb.
7908 static void igb_process_skb_fields(struct igb_ring *rx_ring,
7909 union e1000_adv_rx_desc *rx_desc,
7910 struct sk_buff *skb)
7912 struct net_device *dev = rx_ring->netdev;
7913 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
7915 #ifdef NETIF_F_RXHASH
7916 igb_rx_hash(rx_ring, rx_desc, skb);
7919 igb_rx_checksum(rx_ring, rx_desc, skb);
7921 /* update packet type stats */
7922 if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4))
7923 rx_ring->rx_stats.ipv4_packets++;
7924 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV4_EX))
7925 rx_ring->rx_stats.ipv4e_packets++;
7926 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV6))
7927 rx_ring->rx_stats.ipv6_packets++;
7928 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_IPV6_EX))
7929 rx_ring->rx_stats.ipv6e_packets++;
7930 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_TCP))
7931 rx_ring->rx_stats.tcp_packets++;
7932 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_UDP))
7933 rx_ring->rx_stats.udp_packets++;
7934 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_SCTP))
7935 rx_ring->rx_stats.sctp_packets++;
7936 else if (pkt_info & cpu_to_le16(E1000_RXDADV_PKTTYPE_NFS))
7937 rx_ring->rx_stats.nfs_packets++;
7939 #ifdef HAVE_PTP_1588_CLOCK
7940 igb_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
7941 #endif /* HAVE_PTP_1588_CLOCK */
7943 #ifdef NETIF_F_HW_VLAN_CTAG_RX
7944 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
7946 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
7948 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
7950 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
7951 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
7952 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
7954 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
7955 #ifdef HAVE_VLAN_RX_REGISTER
7956 IGB_CB(skb)->vid = vid;
7958 IGB_CB(skb)->vid = 0;
7961 #ifdef HAVE_VLAN_PROTOCOL
7962 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7964 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7971 skb_record_rx_queue(skb, rx_ring->queue_index);
7973 skb->protocol = eth_type_trans(skb, dev);
7977 * igb_is_non_eop - process handling of non-EOP buffers
7978 * @rx_ring: Rx ring being processed
7979 * @rx_desc: Rx descriptor for current buffer
7981 * This function updates next to clean. If the buffer is an EOP buffer
7982 * this function exits returning false, otherwise it will place the
7983 * sk_buff in the next buffer to be chained and return true indicating
7984 * that this is in fact a non-EOP buffer.
7986 static bool igb_is_non_eop(struct igb_ring *rx_ring,
7987 union e1000_adv_rx_desc *rx_desc)
7989 u32 ntc = rx_ring->next_to_clean + 1;
7991 /* fetch, update, and store next to clean */
7992 ntc = (ntc < rx_ring->count) ? ntc : 0;
7993 rx_ring->next_to_clean = ntc;
7995 prefetch(IGB_RX_DESC(rx_ring, ntc));
7997 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
8003 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8004 /* igb_clean_rx_irq -- * legacy */
8005 static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
8007 struct igb_ring *rx_ring = q_vector->rx.ring;
8008 unsigned int total_bytes = 0, total_packets = 0;
8009 u16 cleaned_count = igb_desc_unused(rx_ring);
8012 struct igb_rx_buffer *rx_buffer;
8013 union e1000_adv_rx_desc *rx_desc;
8014 struct sk_buff *skb;
8017 /* return some buffers to hardware, one at a time is too slow */
8018 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
8019 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8023 ntc = rx_ring->next_to_clean;
8024 rx_desc = IGB_RX_DESC(rx_ring, ntc);
8025 rx_buffer = &rx_ring->rx_buffer_info[ntc];
8027 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
8031 * This memory barrier is needed to keep us from reading
8032 * any other fields out of the rx_desc until we know the
8033 * RXD_STAT_DD bit is set
8037 skb = rx_buffer->skb;
8039 prefetch(skb->data);
8041 /* pull the header of the skb in */
8042 __skb_put(skb, le16_to_cpu(rx_desc->wb.upper.length));
8044 /* clear skb reference in buffer info structure */
8045 rx_buffer->skb = NULL;
8049 BUG_ON(igb_is_non_eop(rx_ring, rx_desc));
8051 dma_unmap_single(rx_ring->dev, rx_buffer->dma,
8052 rx_ring->rx_buffer_len,
8056 if (igb_test_staterr(rx_desc,
8057 E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
8058 dev_kfree_skb_any(skb);
8062 total_bytes += skb->len;
8064 /* populate checksum, timestamp, VLAN, and protocol */
8065 igb_process_skb_fields(rx_ring, rx_desc, skb);
8068 if (igb_can_lro(rx_ring, rx_desc, skb))
8069 igb_lro_receive(q_vector, skb);
8072 #ifdef HAVE_VLAN_RX_REGISTER
8073 igb_receive_skb(q_vector, skb);
8075 napi_gro_receive(&q_vector->napi, skb);
8079 netdev_ring(rx_ring)->last_rx = jiffies;
8082 /* update budget accounting */
8084 } while (likely(total_packets < budget));
8086 rx_ring->rx_stats.packets += total_packets;
8087 rx_ring->rx_stats.bytes += total_bytes;
8088 q_vector->rx.total_packets += total_packets;
8089 q_vector->rx.total_bytes += total_bytes;
8092 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8095 igb_lro_flush_all(q_vector);
8097 #endif /* IGB_NO_LRO */
8098 return total_packets < budget;
8100 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8102 * igb_get_headlen - determine size of header for LRO/GRO
8103 * @data: pointer to the start of the headers
8104 * @max_len: total length of section to find headers in
8106 * This function is meant to determine the length of headers that will
8107 * be recognized by hardware for LRO, and GRO offloads. The main
8108 * motivation of doing this is to only perform one pull for IPv4 TCP
8109 * packets so that we can do basic things like calculating the gso_size
8110 * based on the average data per packet.
8112 static unsigned int igb_get_headlen(unsigned char *data,
8113 unsigned int max_len)
8116 unsigned char *network;
8119 struct vlan_hdr *vlan;
8122 struct ipv6hdr *ipv6;
8125 u8 nexthdr = 0; /* default to not TCP */
8128 /* this should never happen, but better safe than sorry */
8129 if (max_len < ETH_HLEN)
8132 /* initialize network frame pointer */
8135 /* set first protocol and move network header forward */
8136 protocol = hdr.eth->h_proto;
8137 hdr.network += ETH_HLEN;
8139 /* handle any vlan tag if present */
8140 if (protocol == __constant_htons(ETH_P_8021Q)) {
8141 if ((hdr.network - data) > (max_len - VLAN_HLEN))
8144 protocol = hdr.vlan->h_vlan_encapsulated_proto;
8145 hdr.network += VLAN_HLEN;
8148 /* handle L3 protocols */
8149 if (protocol == __constant_htons(ETH_P_IP)) {
8150 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
8153 /* access ihl as a u8 to avoid unaligned access on ia64 */
8154 hlen = (hdr.network[0] & 0x0F) << 2;
8156 /* verify hlen meets minimum size requirements */
8157 if (hlen < sizeof(struct iphdr))
8158 return hdr.network - data;
8160 /* record next protocol if header is present */
8161 if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
8162 nexthdr = hdr.ipv4->protocol;
8164 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
8165 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
8168 /* record next protocol */
8169 nexthdr = hdr.ipv6->nexthdr;
8170 hlen = sizeof(struct ipv6hdr);
8171 #endif /* NETIF_F_TSO6 */
8173 return hdr.network - data;
8176 /* relocate pointer to start of L4 header */
8177 hdr.network += hlen;
8179 /* finally sort out TCP */
8180 if (nexthdr == IPPROTO_TCP) {
8181 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
8184 /* access doff as a u8 to avoid unaligned access on ia64 */
8185 hlen = (hdr.network[12] & 0xF0) >> 2;
8187 /* verify hlen meets minimum size requirements */
8188 if (hlen < sizeof(struct tcphdr))
8189 return hdr.network - data;
8191 hdr.network += hlen;
8192 } else if (nexthdr == IPPROTO_UDP) {
8193 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
8196 hdr.network += sizeof(struct udphdr);
8200 * If everything has gone correctly hdr.network should be the
8201 * data section of the packet and will be the end of the header.
8202 * If not then it probably represents the end of the last recognized
8205 if ((hdr.network - data) < max_len)
8206 return hdr.network - data;
8212 * igb_pull_tail - igb specific version of skb_pull_tail
8213 * @rx_ring: rx descriptor ring packet is being transacted on
8214 * @rx_desc: pointer to the EOP Rx descriptor
8215 * @skb: pointer to current skb being adjusted
8217 * This function is an igb specific version of __pskb_pull_tail. The
8218 * main difference between this version and the original function is that
8219 * this function can make several assumptions about the state of things
8220 * that allow for significant optimizations versus the standard function.
8221 * As a result we can do things like drop a frag and maintain an accurate
8222 * truesize for the skb.
8224 static void igb_pull_tail(struct igb_ring *rx_ring,
8225 union e1000_adv_rx_desc *rx_desc,
8226 struct sk_buff *skb)
8228 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
8230 unsigned int pull_len;
8233 * it is valid to use page_address instead of kmap since we are
8234 * working with pages allocated out of the lomem pool per
8235 * alloc_page(GFP_ATOMIC)
8237 va = skb_frag_address(frag);
8239 #ifdef HAVE_PTP_1588_CLOCK
8240 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
8241 /* retrieve timestamp from buffer */
8242 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
8244 /* update pointers to remove timestamp header */
8245 skb_frag_size_sub(frag, IGB_TS_HDR_LEN);
8246 frag->page_offset += IGB_TS_HDR_LEN;
8247 skb->data_len -= IGB_TS_HDR_LEN;
8248 skb->len -= IGB_TS_HDR_LEN;
8250 /* move va to start of packet data */
8251 va += IGB_TS_HDR_LEN;
8253 #endif /* HAVE_PTP_1588_CLOCK */
8256 * we need the header to contain the greater of either ETH_HLEN or
8257 * 60 bytes if the skb->len is less than 60 for skb_pad.
8259 pull_len = igb_get_headlen(va, IGB_RX_HDR_LEN);
8261 /* align pull length to size of long to optimize memcpy performance */
8262 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
8264 /* update all of the pointers */
8265 skb_frag_size_sub(frag, pull_len);
8266 frag->page_offset += pull_len;
8267 skb->data_len -= pull_len;
8268 skb->tail += pull_len;
8272 * igb_cleanup_headers - Correct corrupted or empty headers
8273 * @rx_ring: rx descriptor ring packet is being transacted on
8274 * @rx_desc: pointer to the EOP Rx descriptor
8275 * @skb: pointer to current skb being fixed
8277 * Address the case where we are pulling data in on pages only
8278 * and as such no data is present in the skb header.
8280 * In addition if skb is not at least 60 bytes we need to pad it so that
8281 * it is large enough to qualify as a valid Ethernet frame.
8283 * Returns true if an error was encountered and skb was freed.
8285 static bool igb_cleanup_headers(struct igb_ring *rx_ring,
8286 union e1000_adv_rx_desc *rx_desc,
8287 struct sk_buff *skb)
8290 if (unlikely((igb_test_staterr(rx_desc,
8291 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
8292 struct net_device *netdev = rx_ring->netdev;
8293 if (!(netdev->features & NETIF_F_RXALL)) {
8294 dev_kfree_skb_any(skb);
8299 /* place header in linear portion of buffer */
8300 if (skb_is_nonlinear(skb))
8301 igb_pull_tail(rx_ring, rx_desc, skb);
8303 /* if skb_pad returns an error the skb was freed */
8304 if (unlikely(skb->len < 60)) {
8305 int pad_len = 60 - skb->len;
8307 if (skb_pad(skb, pad_len))
8309 __skb_put(skb, pad_len);
8315 /* igb_clean_rx_irq -- * packet split */
8316 static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
8318 struct igb_ring *rx_ring = q_vector->rx.ring;
8319 struct sk_buff *skb = rx_ring->skb;
8320 unsigned int total_bytes = 0, total_packets = 0;
8321 u16 cleaned_count = igb_desc_unused(rx_ring);
8324 union e1000_adv_rx_desc *rx_desc;
8326 /* return some buffers to hardware, one at a time is too slow */
8327 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
8328 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8332 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
8334 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
8338 * This memory barrier is needed to keep us from reading
8339 * any other fields out of the rx_desc until we know the
8340 * RXD_STAT_DD bit is set
8344 /* retrieve a buffer from the ring */
8345 skb = igb_fetch_rx_buffer(rx_ring, rx_desc, skb);
8347 /* exit if we failed to retrieve a buffer */
8353 /* fetch next buffer in frame if non-eop */
8354 if (igb_is_non_eop(rx_ring, rx_desc))
8357 /* verify the packet layout is correct */
8358 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
8363 /* probably a little skewed due to removing CRC */
8364 total_bytes += skb->len;
8366 /* populate checksum, timestamp, VLAN, and protocol */
8367 igb_process_skb_fields(rx_ring, rx_desc, skb);
8370 if (igb_can_lro(rx_ring, rx_desc, skb))
8371 igb_lro_receive(q_vector, skb);
8374 #ifdef HAVE_VLAN_RX_REGISTER
8375 igb_receive_skb(q_vector, skb);
8377 napi_gro_receive(&q_vector->napi, skb);
8381 netdev_ring(rx_ring)->last_rx = jiffies;
8384 /* reset skb pointer */
8387 /* update budget accounting */
8389 } while (likely(total_packets < budget));
8391 /* place incomplete frames back on ring for completion */
8394 rx_ring->rx_stats.packets += total_packets;
8395 rx_ring->rx_stats.bytes += total_bytes;
8396 q_vector->rx.total_packets += total_packets;
8397 q_vector->rx.total_bytes += total_bytes;
8400 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8403 igb_lro_flush_all(q_vector);
8405 #endif /* IGB_NO_LRO */
8406 return total_packets < budget;
8408 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8410 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8411 static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring,
8412 struct igb_rx_buffer *bi)
8414 struct sk_buff *skb = bi->skb;
8415 dma_addr_t dma = bi->dma;
8421 skb = netdev_alloc_skb_ip_align(netdev_ring(rx_ring),
8422 rx_ring->rx_buffer_len);
8425 rx_ring->rx_stats.alloc_failed++;
8429 /* initialize skb for ring */
8430 skb_record_rx_queue(skb, ring_queue_index(rx_ring));
8433 dma = dma_map_single(rx_ring->dev, skb->data,
8434 rx_ring->rx_buffer_len, DMA_FROM_DEVICE);
8436 /* if mapping failed free memory back to system since
8437 * there isn't much point in holding memory we can't use
8439 if (dma_mapping_error(rx_ring->dev, dma)) {
8440 dev_kfree_skb_any(skb);
8443 rx_ring->rx_stats.alloc_failed++;
8451 #else /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8452 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
8453 struct igb_rx_buffer *bi)
8455 struct page *page = bi->page;
8458 /* since we are recycling buffers we should seldom need to alloc */
8462 /* alloc new page for storage */
8463 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
8464 if (unlikely(!page)) {
8465 rx_ring->rx_stats.alloc_failed++;
8469 /* map page for use */
8470 dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
8473 * if mapping failed free memory back to system since
8474 * there isn't much point in holding memory we can't use
8476 if (dma_mapping_error(rx_ring->dev, dma)) {
8479 rx_ring->rx_stats.alloc_failed++;
8485 bi->page_offset = 0;
8490 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8492 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
8493 * @adapter: address of board private structure
8495 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
8497 union e1000_adv_rx_desc *rx_desc;
8498 struct igb_rx_buffer *bi;
8499 u16 i = rx_ring->next_to_use;
8505 rx_desc = IGB_RX_DESC(rx_ring, i);
8506 bi = &rx_ring->rx_buffer_info[i];
8507 i -= rx_ring->count;
8510 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8511 if (!igb_alloc_mapped_skb(rx_ring, bi))
8513 if (!igb_alloc_mapped_page(rx_ring, bi))
8514 #endif /* CONFIG_IGB_DISABLE_PACKET_SPLIT */
8518 * Refresh the desc even if buffer_addrs didn't change
8519 * because each write-back erases this info.
8521 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
8522 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
8524 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
8531 rx_desc = IGB_RX_DESC(rx_ring, 0);
8532 bi = rx_ring->rx_buffer_info;
8533 i -= rx_ring->count;
8536 /* clear the hdr_addr for the next_to_use descriptor */
8537 rx_desc->read.hdr_addr = 0;
8540 } while (cleaned_count);
8542 i += rx_ring->count;
8544 if (rx_ring->next_to_use != i) {
8545 /* record the next descriptor to use */
8546 rx_ring->next_to_use = i;
8548 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
8549 /* update next to alloc since we have filled the ring */
8550 rx_ring->next_to_alloc = i;
8554 * Force memory writes to complete before letting h/w
8555 * know there are new descriptors to fetch. (Only
8556 * applicable for weak-ordered memory model archs,
8560 writel(i, rx_ring->tail);
8571 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8573 struct igb_adapter *adapter = netdev_priv(netdev);
8574 struct mii_ioctl_data *data = if_mii(ifr);
8576 if (adapter->hw.phy.media_type != e1000_media_type_copper)
8581 data->phy_id = adapter->hw.phy.addr;
8584 if (!capable(CAP_NET_ADMIN))
8586 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
8594 return E1000_SUCCESS;
8604 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8611 return igb_mii_ioctl(netdev, ifr, cmd);
8613 #ifdef HAVE_PTP_1588_CLOCK
8615 return igb_ptp_hwtstamp_ioctl(netdev, ifr, cmd);
8616 #endif /* HAVE_PTP_1588_CLOCK */
8617 #ifdef ETHTOOL_OPS_COMPAT
8619 return ethtool_ioctl(ifr);
8626 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8628 struct igb_adapter *adapter = hw->back;
8631 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
8633 return -E1000_ERR_CONFIG;
8635 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
8637 return E1000_SUCCESS;
8640 s32 e1000_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8642 struct igb_adapter *adapter = hw->back;
8645 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
8647 return -E1000_ERR_CONFIG;
8649 pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
8651 return E1000_SUCCESS;
8654 #ifdef HAVE_VLAN_RX_REGISTER
8655 static void igb_vlan_mode(struct net_device *netdev, struct vlan_group *vlgrp)
8657 void igb_vlan_mode(struct net_device *netdev, u32 features)
8660 struct igb_adapter *adapter = netdev_priv(netdev);
8661 struct e1000_hw *hw = &adapter->hw;
8664 #ifdef HAVE_VLAN_RX_REGISTER
8665 bool enable = !!vlgrp;
8667 igb_irq_disable(adapter);
8669 adapter->vlgrp = vlgrp;
8671 if (!test_bit(__IGB_DOWN, &adapter->state))
8672 igb_irq_enable(adapter);
8674 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8675 bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
8677 bool enable = !!(features & NETIF_F_HW_VLAN_RX);
8682 /* enable VLAN tag insert/strip */
8683 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8684 ctrl |= E1000_CTRL_VME;
8685 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8687 /* Disable CFI check */
8688 rctl = E1000_READ_REG(hw, E1000_RCTL);
8689 rctl &= ~E1000_RCTL_CFIEN;
8690 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
8692 /* disable VLAN tag insert/strip */
8693 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8694 ctrl &= ~E1000_CTRL_VME;
8695 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8698 #ifndef CONFIG_IGB_VMDQ_NETDEV
8699 for (i = 0; i < adapter->vmdq_pools; i++) {
8700 igb_set_vf_vlan_strip(adapter,
8701 adapter->vfs_allocated_count + i,
8706 igb_set_vf_vlan_strip(adapter,
8707 adapter->vfs_allocated_count,
8710 for (i = 1; i < adapter->vmdq_pools; i++) {
8711 #ifdef HAVE_VLAN_RX_REGISTER
8712 struct igb_vmdq_adapter *vadapter;
8713 vadapter = netdev_priv(adapter->vmdq_netdev[i-1]);
8714 enable = !!vadapter->vlgrp;
8716 struct net_device *vnetdev;
8717 vnetdev = adapter->vmdq_netdev[i-1];
8718 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8719 enable = !!(vnetdev->features & NETIF_F_HW_VLAN_CTAG_RX);
8721 enable = !!(vnetdev->features & NETIF_F_HW_VLAN_RX);
8724 igb_set_vf_vlan_strip(adapter,
8725 adapter->vfs_allocated_count + i,
8730 igb_rlpml_set(adapter);
8733 #ifdef HAVE_VLAN_PROTOCOL
8734 static int igb_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
8735 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
8736 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8737 static int igb_vlan_rx_add_vid(struct net_device *netdev,
8738 __always_unused __be16 proto, u16 vid)
8740 static int igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
8743 static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
8746 struct igb_adapter *adapter = netdev_priv(netdev);
8747 int pf_id = adapter->vfs_allocated_count;
8749 /* attempt to add filter to vlvf array */
8750 igb_vlvf_set(adapter, vid, TRUE, pf_id);
8752 /* add the filter since PF can receive vlans w/o entry in vlvf */
8753 igb_vfta_set(adapter, vid, TRUE);
8754 #ifndef HAVE_NETDEV_VLAN_FEATURES
8756 /* Copy feature flags from netdev to the vlan netdev for this vid.
8757 * This allows things like TSO to bubble down to our vlan device.
8758 * There is no need to update netdev for vlan 0 (DCB), since it
8759 * wouldn't has v_netdev.
8761 if (adapter->vlgrp) {
8762 struct vlan_group *vlgrp = adapter->vlgrp;
8763 struct net_device *v_netdev = vlan_group_get_device(vlgrp, vid);
8765 v_netdev->features |= netdev->features;
8766 vlan_group_set_device(vlgrp, vid, v_netdev);
8770 #ifndef HAVE_VLAN_RX_REGISTER
8772 set_bit(vid, adapter->active_vlans);
8774 #ifdef HAVE_INT_NDO_VLAN_RX_ADD_VID
8779 #ifdef HAVE_VLAN_PROTOCOL
8780 static int igb_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
8781 #elif defined HAVE_INT_NDO_VLAN_RX_ADD_VID
8782 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8783 static int igb_vlan_rx_kill_vid(struct net_device *netdev,
8784 __always_unused __be16 proto, u16 vid)
8786 static int igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
8789 static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
8792 struct igb_adapter *adapter = netdev_priv(netdev);
8793 int pf_id = adapter->vfs_allocated_count;
8796 #ifdef HAVE_VLAN_RX_REGISTER
8797 igb_irq_disable(adapter);
8799 vlan_group_set_device(adapter->vlgrp, vid, NULL);
8801 if (!test_bit(__IGB_DOWN, &adapter->state))
8802 igb_irq_enable(adapter);
8804 #endif /* HAVE_VLAN_RX_REGISTER */
8805 /* remove vlan from VLVF table array */
8806 err = igb_vlvf_set(adapter, vid, FALSE, pf_id);
8808 /* if vid was not present in VLVF just remove it from table */
8810 igb_vfta_set(adapter, vid, FALSE);
8811 #ifndef HAVE_VLAN_RX_REGISTER
8813 clear_bit(vid, adapter->active_vlans);
8815 #ifdef HAVE_INT_NDO_VLAN_RX_ADD_VID
8820 static void igb_restore_vlan(struct igb_adapter *adapter)
8822 #ifdef HAVE_VLAN_RX_REGISTER
8823 igb_vlan_mode(adapter->netdev, adapter->vlgrp);
8825 if (adapter->vlgrp) {
8827 for (vid = 0; vid < VLAN_N_VID; vid++) {
8828 if (!vlan_group_get_device(adapter->vlgrp, vid))
8830 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8831 igb_vlan_rx_add_vid(adapter->netdev,
8832 htons(ETH_P_8021Q), vid);
8834 igb_vlan_rx_add_vid(adapter->netdev, vid);
8841 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
8843 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
8844 #ifdef NETIF_F_HW_VLAN_CTAG_RX
8845 igb_vlan_rx_add_vid(adapter->netdev,
8846 htons(ETH_P_8021Q), vid);
8848 igb_vlan_rx_add_vid(adapter->netdev, vid);
8853 int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
8855 struct pci_dev *pdev = adapter->pdev;
8856 struct e1000_mac_info *mac = &adapter->hw.mac;
8860 /* SerDes device's does not support 10Mbps Full/duplex
8861 * and 100Mbps Half duplex
8863 if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
8865 case SPEED_10 + DUPLEX_HALF:
8866 case SPEED_10 + DUPLEX_FULL:
8867 case SPEED_100 + DUPLEX_HALF:
8868 dev_err(pci_dev_to_dev(pdev),
8869 "Unsupported Speed/Duplex configuration\n");
8877 case SPEED_10 + DUPLEX_HALF:
8878 mac->forced_speed_duplex = ADVERTISE_10_HALF;
8880 case SPEED_10 + DUPLEX_FULL:
8881 mac->forced_speed_duplex = ADVERTISE_10_FULL;
8883 case SPEED_100 + DUPLEX_HALF:
8884 mac->forced_speed_duplex = ADVERTISE_100_HALF;
8886 case SPEED_100 + DUPLEX_FULL:
8887 mac->forced_speed_duplex = ADVERTISE_100_FULL;
8889 case SPEED_1000 + DUPLEX_FULL:
8891 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
8893 case SPEED_1000 + DUPLEX_HALF: /* not supported */
8895 dev_err(pci_dev_to_dev(pdev), "Unsupported Speed/Duplex configuration\n");
8899 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
8900 adapter->hw.phy.mdix = AUTO_ALL_MODES;
8905 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
8908 struct net_device *netdev = pci_get_drvdata(pdev);
8909 struct igb_adapter *adapter = netdev_priv(netdev);
8910 struct e1000_hw *hw = &adapter->hw;
8911 u32 ctrl, rctl, status;
8912 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
8917 netif_device_detach(netdev);
8919 status = E1000_READ_REG(hw, E1000_STATUS);
8920 if (status & E1000_STATUS_LU)
8921 wufc &= ~E1000_WUFC_LNKC;
8923 if (netif_running(netdev))
8924 __igb_close(netdev, true);
8926 igb_clear_interrupt_scheme(adapter);
8929 retval = pci_save_state(pdev);
8935 igb_setup_rctl(adapter);
8936 igb_set_rx_mode(netdev);
8938 /* turn on all-multi mode if wake on multicast is enabled */
8939 if (wufc & E1000_WUFC_MC) {
8940 rctl = E1000_READ_REG(hw, E1000_RCTL);
8941 rctl |= E1000_RCTL_MPE;
8942 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
8945 ctrl = E1000_READ_REG(hw, E1000_CTRL);
8946 /* phy power management enable */
8947 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
8948 ctrl |= E1000_CTRL_ADVD3WUC;
8949 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8951 /* Allow time for pending master requests to run */
8952 e1000_disable_pcie_master(hw);
8954 E1000_WRITE_REG(hw, E1000_WUC, E1000_WUC_PME_EN);
8955 E1000_WRITE_REG(hw, E1000_WUFC, wufc);
8957 E1000_WRITE_REG(hw, E1000_WUC, 0);
8958 E1000_WRITE_REG(hw, E1000_WUFC, 0);
8961 *enable_wake = wufc || adapter->en_mng_pt;
8963 igb_power_down_link(adapter);
8965 igb_power_up_link(adapter);
8967 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8968 * would have already happened in close and is redundant. */
8969 igb_release_hw_control(adapter);
8971 pci_disable_device(pdev);
8977 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8978 static int igb_suspend(struct device *dev)
8980 static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
8981 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8983 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
8984 struct pci_dev *pdev = to_pci_dev(dev);
8985 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
8989 retval = __igb_shutdown(pdev, &wake, 0);
8994 pci_prepare_to_sleep(pdev);
8996 pci_wake_from_d3(pdev, false);
8997 pci_set_power_state(pdev, PCI_D3hot);
9003 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
9004 static int igb_resume(struct device *dev)
9006 static int igb_resume(struct pci_dev *pdev)
9007 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
9009 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
9010 struct pci_dev *pdev = to_pci_dev(dev);
9011 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
9012 struct net_device *netdev = pci_get_drvdata(pdev);
9013 struct igb_adapter *adapter = netdev_priv(netdev);
9014 struct e1000_hw *hw = &adapter->hw;
9017 pci_set_power_state(pdev, PCI_D0);
9018 pci_restore_state(pdev);
9019 pci_save_state(pdev);
9021 err = pci_enable_device_mem(pdev);
9023 dev_err(pci_dev_to_dev(pdev),
9024 "igb: Cannot enable PCI device from suspend\n");
9027 pci_set_master(pdev);
9029 pci_enable_wake(pdev, PCI_D3hot, 0);
9030 pci_enable_wake(pdev, PCI_D3cold, 0);
9032 if (igb_init_interrupt_scheme(adapter, true)) {
9033 dev_err(pci_dev_to_dev(pdev), "Unable to allocate memory for queues\n");
9039 /* let the f/w know that the h/w is now under the control of the
9041 igb_get_hw_control(adapter);
9043 E1000_WRITE_REG(hw, E1000_WUS, ~0);
9045 if (netdev->flags & IFF_UP) {
9047 err = __igb_open(netdev, true);
9053 netif_device_attach(netdev);
9058 #ifdef CONFIG_PM_RUNTIME
9059 #ifdef HAVE_SYSTEM_SLEEP_PM_OPS
9060 static int igb_runtime_idle(struct device *dev)
9062 struct pci_dev *pdev = to_pci_dev(dev);
9063 struct net_device *netdev = pci_get_drvdata(pdev);
9064 struct igb_adapter *adapter = netdev_priv(netdev);
9066 if (!igb_has_link(adapter))
9067 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
9072 static int igb_runtime_suspend(struct device *dev)
9074 struct pci_dev *pdev = to_pci_dev(dev);
9078 retval = __igb_shutdown(pdev, &wake, 1);
9083 pci_prepare_to_sleep(pdev);
9085 pci_wake_from_d3(pdev, false);
9086 pci_set_power_state(pdev, PCI_D3hot);
9092 static int igb_runtime_resume(struct device *dev)
9094 return igb_resume(dev);
9096 #endif /* HAVE_SYSTEM_SLEEP_PM_OPS */
9097 #endif /* CONFIG_PM_RUNTIME */
9098 #endif /* CONFIG_PM */
9100 #ifdef USE_REBOOT_NOTIFIER
9101 /* only want to do this for 2.4 kernels? */
9102 static int igb_notify_reboot(struct notifier_block *nb, unsigned long event,
9105 struct pci_dev *pdev = NULL;
9112 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
9113 if (pci_dev_driver(pdev) == &igb_driver) {
9114 __igb_shutdown(pdev, &wake, 0);
9115 if (event == SYS_POWER_OFF) {
9116 pci_wake_from_d3(pdev, wake);
9117 pci_set_power_state(pdev, PCI_D3hot);
9125 static void igb_shutdown(struct pci_dev *pdev)
9129 __igb_shutdown(pdev, &wake, 0);
9131 if (system_state == SYSTEM_POWER_OFF) {
9132 pci_wake_from_d3(pdev, wake);
9133 pci_set_power_state(pdev, PCI_D3hot);
9136 #endif /* USE_REBOOT_NOTIFIER */
9138 #ifdef CONFIG_NET_POLL_CONTROLLER
9140 * Polling 'interrupt' - used by things like netconsole to send skbs
9141 * without having to re-enable interrupts. It's not called while
9142 * the interrupt routine is executing.
9144 static void igb_netpoll(struct net_device *netdev)
9146 struct igb_adapter *adapter = netdev_priv(netdev);
9147 struct e1000_hw *hw = &adapter->hw;
9148 struct igb_q_vector *q_vector;
9151 for (i = 0; i < adapter->num_q_vectors; i++) {
9152 q_vector = adapter->q_vector[i];
9153 if (adapter->msix_entries)
9154 E1000_WRITE_REG(hw, E1000_EIMC, q_vector->eims_value);
9156 igb_irq_disable(adapter);
9157 napi_schedule(&q_vector->napi);
9160 #endif /* CONFIG_NET_POLL_CONTROLLER */
9163 #define E1000_DEV_ID_82576_VF 0x10CA
9165 * igb_io_error_detected - called when PCI error is detected
9166 * @pdev: Pointer to PCI device
9167 * @state: The current pci connection state
9169 * This function is called after a PCI bus error affecting
9170 * this device has been detected.
9172 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
9173 pci_channel_state_t state)
9175 struct net_device *netdev = pci_get_drvdata(pdev);
9176 struct igb_adapter *adapter = netdev_priv(netdev);
9178 #ifdef CONFIG_PCI_IOV__UNUSED
9179 struct pci_dev *bdev, *vfdev;
9180 u32 dw0, dw1, dw2, dw3;
9182 u16 req_id, pf_func;
9184 if (!(adapter->flags & IGB_FLAG_DETECT_BAD_DMA))
9185 goto skip_bad_vf_detection;
9187 bdev = pdev->bus->self;
9188 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
9189 bdev = bdev->bus->self;
9192 goto skip_bad_vf_detection;
9194 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
9196 goto skip_bad_vf_detection;
9198 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
9199 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
9200 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
9201 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
9204 /* On the 82576 if bit 7 of the requestor ID is set then it's a VF */
9205 if (!(req_id & 0x0080))
9206 goto skip_bad_vf_detection;
9208 pf_func = req_id & 0x01;
9209 if ((pf_func & 1) == (pdev->devfn & 1)) {
9211 vf = (req_id & 0x7F) >> 1;
9212 dev_err(pci_dev_to_dev(pdev),
9213 "VF %d has caused a PCIe error\n", vf);
9214 dev_err(pci_dev_to_dev(pdev),
9215 "TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9216 "%8.8x\tdw3: %8.8x\n",
9217 dw0, dw1, dw2, dw3);
9219 /* Find the pci device of the offending VF */
9220 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
9221 E1000_DEV_ID_82576_VF, NULL);
9223 if (vfdev->devfn == (req_id & 0xFF))
9225 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
9226 E1000_DEV_ID_82576_VF, vfdev);
9229 * There's a slim chance the VF could have been hot plugged,
9230 * so if it is no longer present we don't need to issue the
9231 * VFLR. Just clean up the AER in that case.
9234 dev_err(pci_dev_to_dev(pdev),
9235 "Issuing VFLR to VF %d\n", vf);
9236 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
9239 pci_cleanup_aer_uncorrect_error_status(pdev);
9243 * Even though the error may have occurred on the other port
9244 * we still need to increment the vf error reference count for
9245 * both ports because the I/O resume function will be called
9248 adapter->vferr_refcount++;
9250 return PCI_ERS_RESULT_RECOVERED;
9252 skip_bad_vf_detection:
9253 #endif /* CONFIG_PCI_IOV */
9255 netif_device_detach(netdev);
9257 if (state == pci_channel_io_perm_failure)
9258 return PCI_ERS_RESULT_DISCONNECT;
9260 if (netif_running(netdev))
9262 pci_disable_device(pdev);
9264 /* Request a slot slot reset. */
9265 return PCI_ERS_RESULT_NEED_RESET;
9269 * igb_io_slot_reset - called after the pci bus has been reset.
9270 * @pdev: Pointer to PCI device
9272 * Restart the card from scratch, as if from a cold-boot. Implementation
9273 * resembles the first-half of the igb_resume routine.
9275 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
9277 struct net_device *netdev = pci_get_drvdata(pdev);
9278 struct igb_adapter *adapter = netdev_priv(netdev);
9279 struct e1000_hw *hw = &adapter->hw;
9280 pci_ers_result_t result;
9282 if (pci_enable_device_mem(pdev)) {
9283 dev_err(pci_dev_to_dev(pdev),
9284 "Cannot re-enable PCI device after reset.\n");
9285 result = PCI_ERS_RESULT_DISCONNECT;
9287 pci_set_master(pdev);
9288 pci_restore_state(pdev);
9289 pci_save_state(pdev);
9291 pci_enable_wake(pdev, PCI_D3hot, 0);
9292 pci_enable_wake(pdev, PCI_D3cold, 0);
9294 schedule_work(&adapter->reset_task);
9295 E1000_WRITE_REG(hw, E1000_WUS, ~0);
9296 result = PCI_ERS_RESULT_RECOVERED;
9299 pci_cleanup_aer_uncorrect_error_status(pdev);
9305 * igb_io_resume - called when traffic can start flowing again.
9306 * @pdev: Pointer to PCI device
9308 * This callback is called when the error recovery driver tells us that
9309 * its OK to resume normal operation. Implementation resembles the
9310 * second-half of the igb_resume routine.
9312 static void igb_io_resume(struct pci_dev *pdev)
9314 struct net_device *netdev = pci_get_drvdata(pdev);
9315 struct igb_adapter *adapter = netdev_priv(netdev);
9317 if (adapter->vferr_refcount) {
9318 dev_info(pci_dev_to_dev(pdev), "Resuming after VF err\n");
9319 adapter->vferr_refcount--;
9323 if (netif_running(netdev)) {
9324 if (igb_up(adapter)) {
9325 dev_err(pci_dev_to_dev(pdev), "igb_up failed after reset\n");
9330 netif_device_attach(netdev);
9332 /* let the f/w know that the h/w is now under the control of the
9334 igb_get_hw_control(adapter);
9337 #endif /* HAVE_PCI_ERS */
9339 int igb_add_mac_filter(struct igb_adapter *adapter, u8 *addr, u16 queue)
9341 struct e1000_hw *hw = &adapter->hw;
9344 if (is_zero_ether_addr(addr))
9347 for (i = 0; i < hw->mac.rar_entry_count; i++) {
9348 if (adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE)
9350 adapter->mac_table[i].state = (IGB_MAC_STATE_MODIFIED |
9351 IGB_MAC_STATE_IN_USE);
9352 memcpy(adapter->mac_table[i].addr, addr, ETH_ALEN);
9353 adapter->mac_table[i].queue = queue;
9354 igb_sync_mac_table(adapter);
9359 int igb_del_mac_filter(struct igb_adapter *adapter, u8* addr, u16 queue)
9361 /* search table for addr, if found, set to 0 and sync */
9363 struct e1000_hw *hw = &adapter->hw;
9365 if (is_zero_ether_addr(addr))
9367 for (i = 0; i < hw->mac.rar_entry_count; i++) {
9368 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
9369 adapter->mac_table[i].queue == queue) {
9370 adapter->mac_table[i].state = IGB_MAC_STATE_MODIFIED;
9371 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
9372 adapter->mac_table[i].queue = 0;
9373 igb_sync_mac_table(adapter);
9379 static int igb_set_vf_mac(struct igb_adapter *adapter,
9380 int vf, unsigned char *mac_addr)
9382 igb_del_mac_filter(adapter, adapter->vf_data[vf].vf_mac_addresses, vf);
9383 memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
9385 igb_add_mac_filter(adapter, mac_addr, vf);
9391 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
9393 struct igb_adapter *adapter = netdev_priv(netdev);
9394 if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
9396 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
9397 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
9398 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
9399 " change effective.\n");
9400 if (test_bit(__IGB_DOWN, &adapter->state)) {
9401 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
9402 " but the PF device is not up.\n");
9403 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
9404 " attempting to use the VF device.\n");
9406 return igb_set_vf_mac(adapter, vf, mac);
9409 static int igb_link_mbps(int internal_link_speed)
9411 switch (internal_link_speed) {
9423 static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
9430 /* Calculate the rate factor values to set */
9431 rf_int = link_speed / tx_rate;
9432 rf_dec = (link_speed - (rf_int * tx_rate));
9433 rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
9435 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
9436 bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
9437 E1000_RTTBCNRC_RF_INT_MASK);
9438 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
9443 E1000_WRITE_REG(hw, E1000_RTTDQSEL, vf); /* vf X uses queue X */
9445 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
9446 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
9448 E1000_WRITE_REG(hw, E1000_RTTBCNRM(0), 0x14);
9449 E1000_WRITE_REG(hw, E1000_RTTBCNRC, bcnrc_val);
9452 static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
9454 int actual_link_speed, i;
9455 bool reset_rate = false;
9457 /* VF TX rate limit was not set */
9458 if ((adapter->vf_rate_link_speed == 0) ||
9459 (adapter->hw.mac.type != e1000_82576))
9462 actual_link_speed = igb_link_mbps(adapter->link_speed);
9463 if (actual_link_speed != adapter->vf_rate_link_speed) {
9465 adapter->vf_rate_link_speed = 0;
9466 dev_info(&adapter->pdev->dev,
9467 "Link speed has been changed. VF Transmit rate is disabled\n");
9470 for (i = 0; i < adapter->vfs_allocated_count; i++) {
9472 adapter->vf_data[i].tx_rate = 0;
9474 igb_set_vf_rate_limit(&adapter->hw, i,
9475 adapter->vf_data[i].tx_rate, actual_link_speed);
9479 #ifdef HAVE_VF_MIN_MAX_TXRATE
9480 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int min_tx_rate,
9482 #else /* HAVE_VF_MIN_MAX_TXRATE */
9483 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
9484 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9486 struct igb_adapter *adapter = netdev_priv(netdev);
9487 struct e1000_hw *hw = &adapter->hw;
9488 int actual_link_speed;
9490 if (hw->mac.type != e1000_82576)
9493 #ifdef HAVE_VF_MIN_MAX_TXRATE
9496 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9498 actual_link_speed = igb_link_mbps(adapter->link_speed);
9499 if ((vf >= adapter->vfs_allocated_count) ||
9500 (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) ||
9501 (tx_rate < 0) || (tx_rate > actual_link_speed))
9504 adapter->vf_rate_link_speed = actual_link_speed;
9505 adapter->vf_data[vf].tx_rate = (u16)tx_rate;
9506 igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
9511 static int igb_ndo_get_vf_config(struct net_device *netdev,
9512 int vf, struct ifla_vf_info *ivi)
9514 struct igb_adapter *adapter = netdev_priv(netdev);
9515 if (vf >= adapter->vfs_allocated_count)
9518 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
9519 #ifdef HAVE_VF_MIN_MAX_TXRATE
9520 ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
9521 ivi->min_tx_rate = 0;
9522 #else /* HAVE_VF_MIN_MAX_TXRATE */
9523 ivi->tx_rate = adapter->vf_data[vf].tx_rate;
9524 #endif /* HAVE_VF_MIN_MAX_TXRATE */
9525 ivi->vlan = adapter->vf_data[vf].pf_vlan;
9526 ivi->qos = adapter->vf_data[vf].pf_qos;
9527 #ifdef HAVE_VF_SPOOFCHK_CONFIGURE
9528 ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
9533 static void igb_vmm_control(struct igb_adapter *adapter)
9535 struct e1000_hw *hw = &adapter->hw;
9539 switch (hw->mac.type) {
9542 /* replication is not supported for 82575 */
9545 /* notify HW that the MAC is adding vlan tags */
9546 reg = E1000_READ_REG(hw, E1000_DTXCTL);
9547 reg |= (E1000_DTXCTL_VLAN_ADDED |
9548 E1000_DTXCTL_SPOOF_INT);
9549 E1000_WRITE_REG(hw, E1000_DTXCTL, reg);
9551 /* enable replication vlan tag stripping */
9552 reg = E1000_READ_REG(hw, E1000_RPLOLR);
9553 reg |= E1000_RPLOLR_STRVLAN;
9554 E1000_WRITE_REG(hw, E1000_RPLOLR, reg);
9557 /* none of the above registers are supported by i350 */
9561 /* Enable Malicious Driver Detection */
9562 if ((adapter->vfs_allocated_count) &&
9564 if (hw->mac.type == e1000_i350)
9565 igb_enable_mdd(adapter);
9568 /* enable replication and loopback support */
9569 count = adapter->vfs_allocated_count || adapter->vmdq_pools;
9570 if (adapter->flags & IGB_FLAG_LOOPBACK_ENABLE && count)
9571 e1000_vmdq_set_loopback_pf(hw, 1);
9572 e1000_vmdq_set_anti_spoofing_pf(hw,
9573 adapter->vfs_allocated_count || adapter->vmdq_pools,
9574 adapter->vfs_allocated_count);
9575 e1000_vmdq_set_replication_pf(hw, adapter->vfs_allocated_count ||
9576 adapter->vmdq_pools);
9579 static void igb_init_fw(struct igb_adapter *adapter)
9581 struct e1000_fw_drv_info fw_cmd;
9582 struct e1000_hw *hw = &adapter->hw;
9586 if (hw->mac.type == e1000_i210)
9587 mask = E1000_SWFW_EEP_SM;
9589 mask = E1000_SWFW_PHY0_SM;
9590 /* i211 parts do not support this feature */
9591 if (hw->mac.type == e1000_i211)
9592 hw->mac.arc_subsystem_valid = false;
9594 if (!hw->mac.ops.acquire_swfw_sync(hw, mask)) {
9595 for (i = 0; i <= FW_MAX_RETRIES; i++) {
9596 E1000_WRITE_REG(hw, E1000_FWSTS, E1000_FWSTS_FWRI);
9597 fw_cmd.hdr.cmd = FW_CMD_DRV_INFO;
9598 fw_cmd.hdr.buf_len = FW_CMD_DRV_INFO_LEN;
9599 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CMD_RESERVED;
9600 fw_cmd.port_num = hw->bus.func;
9601 fw_cmd.drv_version = FW_FAMILY_DRV_VER;
9602 fw_cmd.hdr.checksum = 0;
9603 fw_cmd.hdr.checksum = e1000_calculate_checksum((u8 *)&fw_cmd,
9605 fw_cmd.hdr.buf_len));
9606 e1000_host_interface_command(hw, (u8*)&fw_cmd,
9608 if (fw_cmd.hdr.cmd_or_resp.ret_status == FW_STATUS_SUCCESS)
9612 dev_warn(pci_dev_to_dev(adapter->pdev),
9613 "Unable to get semaphore, firmware init failed.\n");
9614 hw->mac.ops.release_swfw_sync(hw, mask);
9617 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
9619 struct e1000_hw *hw = &adapter->hw;
9624 if (hw->mac.type == e1000_i211)
9627 if (hw->mac.type > e1000_82580) {
9628 if (adapter->dmac != IGB_DMAC_DISABLE) {
9631 /* force threshold to 0. */
9632 E1000_WRITE_REG(hw, E1000_DMCTXTH, 0);
9635 * DMA Coalescing high water mark needs to be greater
9636 * than the Rx threshold. Set hwm to PBA - max frame
9637 * size in 16B units, capping it at PBA - 6KB.
9639 hwm = 64 * pba - adapter->max_frame_size / 16;
9640 if (hwm < 64 * (pba - 6))
9641 hwm = 64 * (pba - 6);
9642 reg = E1000_READ_REG(hw, E1000_FCRTC);
9643 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
9644 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
9645 & E1000_FCRTC_RTH_COAL_MASK);
9646 E1000_WRITE_REG(hw, E1000_FCRTC, reg);
9649 * Set the DMA Coalescing Rx threshold to PBA - 2 * max
9650 * frame size, capping it at PBA - 10KB.
9652 dmac_thr = pba - adapter->max_frame_size / 512;
9653 if (dmac_thr < pba - 10)
9654 dmac_thr = pba - 10;
9655 reg = E1000_READ_REG(hw, E1000_DMACR);
9656 reg &= ~E1000_DMACR_DMACTHR_MASK;
9657 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
9658 & E1000_DMACR_DMACTHR_MASK);
9660 /* transition to L0x or L1 if available..*/
9661 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
9663 /* Check if status is 2.5Gb backplane connection
9664 * before configuration of watchdog timer, which is
9665 * in msec values in 12.8usec intervals
9666 * watchdog timer= msec values in 32usec intervals
9667 * for non 2.5Gb connection
9669 if (hw->mac.type == e1000_i354) {
9670 status = E1000_READ_REG(hw, E1000_STATUS);
9671 if ((status & E1000_STATUS_2P5_SKU) &&
9672 (!(status & E1000_STATUS_2P5_SKU_OVER)))
9673 reg |= ((adapter->dmac * 5) >> 6);
9675 reg |= ((adapter->dmac) >> 5);
9677 reg |= ((adapter->dmac) >> 5);
9681 * Disable BMC-to-OS Watchdog enable
9682 * on devices that support OS-to-BMC
9684 if (hw->mac.type != e1000_i354)
9685 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
9686 E1000_WRITE_REG(hw, E1000_DMACR, reg);
9688 /* no lower threshold to disable coalescing(smart fifb)-UTRESH=0*/
9689 E1000_WRITE_REG(hw, E1000_DMCRTRH, 0);
9691 /* This sets the time to wait before requesting
9692 * transition to low power state to number of usecs
9693 * needed to receive 1 512 byte frame at gigabit
9694 * line rate. On i350 device, time to make transition
9695 * to Lx state is delayed by 4 usec with flush disable
9696 * bit set to avoid losing mailbox interrupts
9698 reg = E1000_READ_REG(hw, E1000_DMCTLX);
9699 if (hw->mac.type == e1000_i350)
9700 reg |= IGB_DMCTLX_DCFLUSH_DIS;
9702 /* in 2.5Gb connection, TTLX unit is 0.4 usec
9703 * which is 0x4*2 = 0xA. But delay is still 4 usec
9705 if (hw->mac.type == e1000_i354) {
9706 status = E1000_READ_REG(hw, E1000_STATUS);
9707 if ((status & E1000_STATUS_2P5_SKU) &&
9708 (!(status & E1000_STATUS_2P5_SKU_OVER)))
9715 E1000_WRITE_REG(hw, E1000_DMCTLX, reg);
9717 /* free space in tx packet buffer to wake from DMA coal */
9718 E1000_WRITE_REG(hw, E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
9719 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
9721 /* make low power state decision controlled by DMA coal */
9722 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
9723 reg &= ~E1000_PCIEMISC_LX_DECISION;
9724 E1000_WRITE_REG(hw, E1000_PCIEMISC, reg);
9725 } /* endif adapter->dmac is not disabled */
9726 } else if (hw->mac.type == e1000_82580) {
9727 u32 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
9728 E1000_WRITE_REG(hw, E1000_PCIEMISC,
9729 reg & ~E1000_PCIEMISC_LX_DECISION);
9730 E1000_WRITE_REG(hw, E1000_DMACR, 0);
9734 #ifdef HAVE_I2C_SUPPORT
9735 /* igb_read_i2c_byte - Reads 8 bit word over I2C
9736 * @hw: pointer to hardware structure
9737 * @byte_offset: byte offset to read
9738 * @dev_addr: device address
9741 * Performs byte read operation over I2C interface at
9742 * a specified device address.
9744 s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9745 u8 dev_addr, u8 *data)
9747 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9748 struct i2c_client *this_client = adapter->i2c_client;
9753 return E1000_ERR_I2C;
9755 swfw_mask = E1000_SWFW_PHY0_SM;
9757 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
9759 return E1000_ERR_SWFW_SYNC;
9761 status = i2c_smbus_read_byte_data(this_client, byte_offset);
9762 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9765 return E1000_ERR_I2C;
9768 return E1000_SUCCESS;
9772 /* igb_write_i2c_byte - Writes 8 bit word over I2C
9773 * @hw: pointer to hardware structure
9774 * @byte_offset: byte offset to write
9775 * @dev_addr: device address
9776 * @data: value to write
9778 * Performs byte write operation over I2C interface at
9779 * a specified device address.
9781 s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9782 u8 dev_addr, u8 data)
9784 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9785 struct i2c_client *this_client = adapter->i2c_client;
9787 u16 swfw_mask = E1000_SWFW_PHY0_SM;
9790 return E1000_ERR_I2C;
9792 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != E1000_SUCCESS)
9793 return E1000_ERR_SWFW_SYNC;
9794 status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
9795 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9798 return E1000_ERR_I2C;
9800 return E1000_SUCCESS;
9802 #endif /* HAVE_I2C_SUPPORT */
9807 * igb_probe - Device Initialization Routine
9808 * @pdev: PCI device information struct
9809 * @ent: entry in igb_pci_tbl
9811 * Returns 0 on success, negative on failure
9813 * igb_probe initializes an adapter identified by a pci_dev structure.
9814 * The OS initialization, configuring of the adapter private structure,
9815 * and a hardware reset occur.
9817 int igb_kni_probe(struct pci_dev *pdev,
9818 struct net_device **lad_dev)
9820 struct net_device *netdev;
9821 struct igb_adapter *adapter;
9822 struct e1000_hw *hw;
9823 u16 eeprom_data = 0;
9824 u8 pba_str[E1000_PBANUM_LENGTH];
9826 static int global_quad_port_a; /* global quad port a indication */
9827 int i, err, pci_using_dac = 0;
9828 static int cards_found;
9830 err = pci_enable_device_mem(pdev);
9836 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
9838 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(64));
9842 err = dma_set_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
9844 err = dma_set_coherent_mask(pci_dev_to_dev(pdev), DMA_BIT_MASK(32));
9846 IGB_ERR("No usable DMA configuration, "
9853 #ifndef HAVE_ASPM_QUIRKS
9854 /* 82575 requires that the pci-e link partner disable the L0s state */
9855 switch (pdev->device) {
9856 case E1000_DEV_ID_82575EB_COPPER:
9857 case E1000_DEV_ID_82575EB_FIBER_SERDES:
9858 case E1000_DEV_ID_82575GB_QUAD_COPPER:
9859 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
9864 #endif /* HAVE_ASPM_QUIRKS */
9865 err = pci_request_selected_regions(pdev,
9866 pci_select_bars(pdev,
9872 pci_enable_pcie_error_reporting(pdev);
9874 pci_set_master(pdev);
9879 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
9882 netdev = alloc_etherdev(sizeof(struct igb_adapter));
9883 #endif /* HAVE_TX_MQ */
9885 goto err_alloc_etherdev;
9887 SET_MODULE_OWNER(netdev);
9888 SET_NETDEV_DEV(netdev, &pdev->dev);
9890 //pci_set_drvdata(pdev, netdev);
9891 adapter = netdev_priv(netdev);
9892 adapter->netdev = netdev;
9893 adapter->pdev = pdev;
9896 adapter->port_num = hw->bus.func;
9897 adapter->msg_enable = (1 << debug) - 1;
9900 err = pci_save_state(pdev);
9905 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
9906 pci_resource_len(pdev, 0));
9910 #ifdef HAVE_NET_DEVICE_OPS
9911 netdev->netdev_ops = &igb_netdev_ops;
9912 #else /* HAVE_NET_DEVICE_OPS */
9913 netdev->open = &igb_open;
9914 netdev->stop = &igb_close;
9915 netdev->get_stats = &igb_get_stats;
9916 #ifdef HAVE_SET_RX_MODE
9917 netdev->set_rx_mode = &igb_set_rx_mode;
9919 netdev->set_multicast_list = &igb_set_rx_mode;
9920 netdev->set_mac_address = &igb_set_mac;
9921 netdev->change_mtu = &igb_change_mtu;
9922 netdev->do_ioctl = &igb_ioctl;
9923 #ifdef HAVE_TX_TIMEOUT
9924 netdev->tx_timeout = &igb_tx_timeout;
9926 netdev->vlan_rx_register = igb_vlan_mode;
9927 netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
9928 netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
9929 #ifdef CONFIG_NET_POLL_CONTROLLER
9930 netdev->poll_controller = igb_netpoll;
9932 netdev->hard_start_xmit = &igb_xmit_frame;
9933 #endif /* HAVE_NET_DEVICE_OPS */
9934 igb_set_ethtool_ops(netdev);
9935 #ifdef HAVE_TX_TIMEOUT
9936 netdev->watchdog_timeo = 5 * HZ;
9939 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
9941 adapter->bd_number = cards_found;
9943 /* setup the private structure */
9944 err = igb_sw_init(adapter);
9948 e1000_get_bus_info(hw);
9950 hw->phy.autoneg_wait_to_complete = FALSE;
9951 hw->mac.adaptive_ifs = FALSE;
9953 /* Copper options */
9954 if (hw->phy.media_type == e1000_media_type_copper) {
9955 hw->phy.mdix = AUTO_ALL_MODES;
9956 hw->phy.disable_polarity_correction = FALSE;
9957 hw->phy.ms_type = e1000_ms_hw_default;
9960 if (e1000_check_reset_block(hw))
9961 dev_info(pci_dev_to_dev(pdev),
9962 "PHY reset is blocked due to SOL/IDER session.\n");
9965 * features is initialized to 0 in allocation, it might have bits
9966 * set by igb_sw_init so we should use an or instead of an
9969 netdev->features |= NETIF_F_SG |
9971 #ifdef NETIF_F_IPV6_CSUM
9979 #endif /* NETIF_F_TSO */
9980 #ifdef NETIF_F_RXHASH
9984 #ifdef NETIF_F_HW_VLAN_CTAG_RX
9985 NETIF_F_HW_VLAN_CTAG_RX |
9986 NETIF_F_HW_VLAN_CTAG_TX;
9988 NETIF_F_HW_VLAN_RX |
9992 if (hw->mac.type >= e1000_82576)
9993 netdev->features |= NETIF_F_SCTP_CSUM;
9995 #ifdef HAVE_NDO_SET_FEATURES
9996 /* copy netdev features into list of user selectable features */
9997 netdev->hw_features |= netdev->features;
10000 /* give us the option of enabling LRO later */
10001 netdev->hw_features |= NETIF_F_LRO;
10006 /* this is only needed on kernels prior to 2.6.39 */
10007 netdev->features |= NETIF_F_GRO;
10011 /* set this bit last since it cannot be part of hw_features */
10012 #ifdef NETIF_F_HW_VLAN_CTAG_FILTER
10013 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
10015 netdev->features |= NETIF_F_HW_VLAN_FILTER;
10018 #ifdef HAVE_NETDEV_VLAN_FEATURES
10019 netdev->vlan_features |= NETIF_F_TSO |
10022 NETIF_F_IPV6_CSUM |
10027 netdev->features |= NETIF_F_HIGHDMA;
10030 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
10032 if (adapter->dmac != IGB_DMAC_DISABLE)
10033 printk("%s: DMA Coalescing is enabled..\n", netdev->name);
10036 /* before reading the NVM, reset the controller to put the device in a
10037 * known good starting state */
10038 e1000_reset_hw(hw);
10039 #endif /* NO_KNI */
10041 /* make sure the NVM is good */
10042 if (e1000_validate_nvm_checksum(hw) < 0) {
10043 dev_err(pci_dev_to_dev(pdev), "The NVM Checksum Is Not"
10049 /* copy the MAC address out of the NVM */
10050 if (e1000_read_mac_addr(hw))
10051 dev_err(pci_dev_to_dev(pdev), "NVM Read Error\n");
10052 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
10053 #ifdef ETHTOOL_GPERMADDR
10054 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
10056 if (!is_valid_ether_addr(netdev->perm_addr)) {
10058 if (!is_valid_ether_addr(netdev->dev_addr)) {
10060 dev_err(pci_dev_to_dev(pdev), "Invalid MAC Address\n");
10065 memcpy(&adapter->mac_table[0].addr, hw->mac.addr, netdev->addr_len);
10066 adapter->mac_table[0].queue = adapter->vfs_allocated_count;
10067 adapter->mac_table[0].state = (IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE);
10068 igb_rar_set(adapter, 0);
10070 /* get firmware version for ethtool -i */
10071 igb_set_fw_version(adapter);
10073 /* Check if Media Autosense is enabled */
10074 if (hw->mac.type == e1000_82580)
10075 igb_init_mas(adapter);
10078 #ifdef HAVE_TIMER_SETUP
10079 timer_setup(&adapter->watchdog_timer, &igb_watchdog, 0);
10080 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
10081 timer_setup(&adapter->dma_err_timer, &igb_dma_err_timer, 0);
10082 timer_setup(&adapter->phy_info_timer, &igb_update_phy_info, 0);
10084 setup_timer(&adapter->watchdog_timer, &igb_watchdog,
10085 (unsigned long) adapter);
10086 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
10087 setup_timer(&adapter->dma_err_timer, &igb_dma_err_timer,
10088 (unsigned long) adapter);
10089 setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
10090 (unsigned long) adapter);
10093 INIT_WORK(&adapter->reset_task, igb_reset_task);
10094 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
10095 if (adapter->flags & IGB_FLAG_DETECT_BAD_DMA)
10096 INIT_WORK(&adapter->dma_err_task, igb_dma_err_task);
10099 /* Initialize link properties that are user-changeable */
10100 adapter->fc_autoneg = true;
10101 hw->mac.autoneg = true;
10102 hw->phy.autoneg_advertised = 0x2f;
10104 hw->fc.requested_mode = e1000_fc_default;
10105 hw->fc.current_mode = e1000_fc_default;
10107 e1000_validate_mdi_setting(hw);
10109 /* By default, support wake on port A */
10110 if (hw->bus.func == 0)
10111 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10113 /* Check the NVM for wake support for non-port A ports */
10114 if (hw->mac.type >= e1000_82580)
10115 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
10116 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
10118 else if (hw->bus.func == 1)
10119 e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
10121 if (eeprom_data & IGB_EEPROM_APME)
10122 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10124 /* now that we have the eeprom settings, apply the special cases where
10125 * the eeprom may be wrong or the board simply won't support wake on
10126 * lan on a particular port */
10127 switch (pdev->device) {
10128 case E1000_DEV_ID_82575GB_QUAD_COPPER:
10129 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10131 case E1000_DEV_ID_82575EB_FIBER_SERDES:
10132 case E1000_DEV_ID_82576_FIBER:
10133 case E1000_DEV_ID_82576_SERDES:
10134 /* Wake events only supported on port A for dual fiber
10135 * regardless of eeprom setting */
10136 if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1)
10137 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10139 case E1000_DEV_ID_82576_QUAD_COPPER:
10140 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
10141 /* if quad port adapter, disable WoL on all but port A */
10142 if (global_quad_port_a != 0)
10143 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10145 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
10146 /* Reset for multiple quad port adapters */
10147 if (++global_quad_port_a == 4)
10148 global_quad_port_a = 0;
10151 /* If the device can't wake, don't set software support */
10152 if (!device_can_wakeup(&adapter->pdev->dev))
10153 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
10157 /* initialize the wol settings based on the eeprom settings */
10158 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
10159 adapter->wol |= E1000_WUFC_MAG;
10161 /* Some vendors want WoL disabled by default, but still supported */
10162 if ((hw->mac.type == e1000_i350) &&
10163 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
10164 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
10169 device_set_wakeup_enable(pci_dev_to_dev(adapter->pdev),
10170 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
10172 /* reset the hardware with the new settings */
10173 igb_reset(adapter);
10174 adapter->devrc = 0;
10176 #ifdef HAVE_I2C_SUPPORT
10177 /* Init the I2C interface */
10178 err = igb_init_i2c(adapter);
10180 dev_err(&pdev->dev, "failed to init i2c interface\n");
10183 #endif /* HAVE_I2C_SUPPORT */
10185 /* let the f/w know that the h/w is now under the control of the
10187 igb_get_hw_control(adapter);
10189 strncpy(netdev->name, "eth%d", IFNAMSIZ);
10190 err = register_netdev(netdev);
10194 #ifdef CONFIG_IGB_VMDQ_NETDEV
10195 err = igb_init_vmdq_netdevs(adapter);
10199 /* carrier off reporting is important to ethtool even BEFORE open */
10200 netif_carrier_off(netdev);
10203 if (dca_add_requester(&pdev->dev) == E1000_SUCCESS) {
10204 adapter->flags |= IGB_FLAG_DCA_ENABLED;
10205 dev_info(pci_dev_to_dev(pdev), "DCA enabled\n");
10206 igb_setup_dca(adapter);
10210 #ifdef HAVE_PTP_1588_CLOCK
10211 /* do hw tstamp init after resetting */
10212 igb_ptp_init(adapter);
10213 #endif /* HAVE_PTP_1588_CLOCK */
10215 #endif /* NO_KNI */
10216 dev_info(pci_dev_to_dev(pdev), "Intel(R) Gigabit Ethernet Network Connection\n");
10217 /* print bus type/speed/width info */
10218 dev_info(pci_dev_to_dev(pdev), "%s: (PCIe:%s:%s) ",
10220 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5GT/s" :
10221 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0GT/s" :
10222 (hw->mac.type == e1000_i354) ? "integrated" :
10224 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
10225 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
10226 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
10227 (hw->mac.type == e1000_i354) ? "integrated" :
10229 dev_info(pci_dev_to_dev(pdev), "%s: MAC: ", netdev->name);
10230 for (i = 0; i < 6; i++)
10231 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
10233 ret_val = e1000_read_pba_string(hw, pba_str, E1000_PBANUM_LENGTH);
10235 strncpy(pba_str, "Unknown", sizeof(pba_str) - 1);
10236 dev_info(pci_dev_to_dev(pdev), "%s: PBA No: %s\n", netdev->name,
10240 /* Initialize the thermal sensor on i350 devices. */
10241 if (hw->mac.type == e1000_i350) {
10242 if (hw->bus.func == 0) {
10246 * Read the NVM to determine if this i350 device
10247 * supports an external thermal sensor.
10249 e1000_read_nvm(hw, NVM_ETS_CFG, 1, &ets_word);
10250 if (ets_word != 0x0000 && ets_word != 0xFFFF)
10251 adapter->ets = true;
10253 adapter->ets = false;
10258 igb_sysfs_init(adapter);
10262 igb_procfs_init(adapter);
10263 #endif /* IGB_PROCFS */
10264 #endif /* IGB_HWMON */
10265 #endif /* NO_KNI */
10267 adapter->ets = false;
10270 if (hw->phy.media_type == e1000_media_type_copper) {
10271 switch (hw->mac.type) {
10275 /* Enable EEE for internal copper PHY devices */
10276 err = e1000_set_eee_i350(hw);
10278 (adapter->flags & IGB_FLAG_EEE))
10279 adapter->eee_advert =
10280 MDIO_EEE_100TX | MDIO_EEE_1000T;
10283 if ((E1000_READ_REG(hw, E1000_CTRL_EXT)) &
10284 (E1000_CTRL_EXT_LINK_MODE_SGMII)) {
10285 err = e1000_set_eee_i354(hw);
10287 (adapter->flags & IGB_FLAG_EEE))
10288 adapter->eee_advert =
10289 MDIO_EEE_100TX | MDIO_EEE_1000T;
10297 /* send driver version info to firmware */
10298 if (hw->mac.type >= e1000_i350)
10299 igb_init_fw(adapter);
10302 if (netdev->features & NETIF_F_LRO)
10303 dev_info(pci_dev_to_dev(pdev), "Internal LRO is enabled \n");
10305 dev_info(pci_dev_to_dev(pdev), "LRO is disabled \n");
10307 dev_info(pci_dev_to_dev(pdev),
10308 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
10309 adapter->msix_entries ? "MSI-X" :
10310 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
10311 adapter->num_rx_queues, adapter->num_tx_queues);
10316 pm_runtime_put_noidle(&pdev->dev);
10320 // igb_release_hw_control(adapter);
10321 #ifdef HAVE_I2C_SUPPORT
10322 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
10323 #endif /* HAVE_I2C_SUPPORT */
10325 // if (!e1000_check_reset_block(hw))
10326 // e1000_phy_hw_reset(hw);
10328 if (hw->flash_address)
10329 iounmap(hw->flash_address);
10331 // igb_clear_interrupt_scheme(adapter);
10332 // igb_reset_sriov_capability(adapter);
10333 iounmap(hw->hw_addr);
10335 free_netdev(netdev);
10336 err_alloc_etherdev:
10337 // pci_release_selected_regions(pdev,
10338 // pci_select_bars(pdev, IORESOURCE_MEM));
10341 pci_disable_device(pdev);
10346 void igb_kni_remove(struct pci_dev *pdev)
10348 pci_disable_device(pdev);