1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <net/ip6_checksum.h>
32 #include <linux/prefetch.h>
33 #include <linux/bitops.h>
34 #include <linux/if_vlan.h>
36 char e1000_driver_name[] = "e1000";
37 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
38 #define DRV_VERSION "7.3.21-k8-NAPI"
39 const char e1000_driver_version[] = DRV_VERSION;
40 static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 /* e1000_pci_tbl - PCI Device ID Table
44 * Last entry must be all 0s
47 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
49 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
50 INTEL_E1000_ETHERNET_DEVICE(0x1000),
51 INTEL_E1000_ETHERNET_DEVICE(0x1001),
52 INTEL_E1000_ETHERNET_DEVICE(0x1004),
53 INTEL_E1000_ETHERNET_DEVICE(0x1008),
54 INTEL_E1000_ETHERNET_DEVICE(0x1009),
55 INTEL_E1000_ETHERNET_DEVICE(0x100C),
56 INTEL_E1000_ETHERNET_DEVICE(0x100D),
57 INTEL_E1000_ETHERNET_DEVICE(0x100E),
58 INTEL_E1000_ETHERNET_DEVICE(0x100F),
59 INTEL_E1000_ETHERNET_DEVICE(0x1010),
60 INTEL_E1000_ETHERNET_DEVICE(0x1011),
61 INTEL_E1000_ETHERNET_DEVICE(0x1012),
62 INTEL_E1000_ETHERNET_DEVICE(0x1013),
63 INTEL_E1000_ETHERNET_DEVICE(0x1014),
64 INTEL_E1000_ETHERNET_DEVICE(0x1015),
65 INTEL_E1000_ETHERNET_DEVICE(0x1016),
66 INTEL_E1000_ETHERNET_DEVICE(0x1017),
67 INTEL_E1000_ETHERNET_DEVICE(0x1018),
68 INTEL_E1000_ETHERNET_DEVICE(0x1019),
69 INTEL_E1000_ETHERNET_DEVICE(0x101A),
70 INTEL_E1000_ETHERNET_DEVICE(0x101D),
71 INTEL_E1000_ETHERNET_DEVICE(0x101E),
72 INTEL_E1000_ETHERNET_DEVICE(0x1026),
73 INTEL_E1000_ETHERNET_DEVICE(0x1027),
74 INTEL_E1000_ETHERNET_DEVICE(0x1028),
75 INTEL_E1000_ETHERNET_DEVICE(0x1075),
76 INTEL_E1000_ETHERNET_DEVICE(0x1076),
77 INTEL_E1000_ETHERNET_DEVICE(0x1077),
78 INTEL_E1000_ETHERNET_DEVICE(0x1078),
79 INTEL_E1000_ETHERNET_DEVICE(0x1079),
80 INTEL_E1000_ETHERNET_DEVICE(0x107A),
81 INTEL_E1000_ETHERNET_DEVICE(0x107B),
82 INTEL_E1000_ETHERNET_DEVICE(0x107C),
83 INTEL_E1000_ETHERNET_DEVICE(0x108A),
84 INTEL_E1000_ETHERNET_DEVICE(0x1099),
85 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
86 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
87 /* required last entry */
91 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
93 int e1000_up(struct e1000_adapter *adapter);
94 void e1000_down(struct e1000_adapter *adapter);
95 void e1000_reinit_locked(struct e1000_adapter *adapter);
96 void e1000_reset(struct e1000_adapter *adapter);
97 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
98 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
99 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
100 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
101 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
102 struct e1000_tx_ring *txdr);
103 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
104 struct e1000_rx_ring *rxdr);
105 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
106 struct e1000_tx_ring *tx_ring);
107 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
108 struct e1000_rx_ring *rx_ring);
109 void e1000_update_stats(struct e1000_adapter *adapter);
111 static int e1000_init_module(void);
112 static void e1000_exit_module(void);
113 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
114 static void e1000_remove(struct pci_dev *pdev);
115 static int e1000_alloc_queues(struct e1000_adapter *adapter);
116 static int e1000_sw_init(struct e1000_adapter *adapter);
117 static int e1000_open(struct net_device *netdev);
118 static int e1000_close(struct net_device *netdev);
119 static void e1000_configure_tx(struct e1000_adapter *adapter);
120 static void e1000_configure_rx(struct e1000_adapter *adapter);
121 static void e1000_setup_rctl(struct e1000_adapter *adapter);
122 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
123 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
124 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
125 struct e1000_tx_ring *tx_ring);
126 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
127 struct e1000_rx_ring *rx_ring);
128 static void e1000_set_rx_mode(struct net_device *netdev);
129 static void e1000_update_phy_info_task(struct work_struct *work);
130 static void e1000_watchdog(struct work_struct *work);
131 static void e1000_82547_tx_fifo_stall_task(struct work_struct *work);
132 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
133 struct net_device *netdev);
134 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
135 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
136 static int e1000_set_mac(struct net_device *netdev, void *p);
137 static irqreturn_t e1000_intr(int irq, void *data);
138 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
139 struct e1000_tx_ring *tx_ring);
140 static int e1000_clean(struct napi_struct *napi, int budget);
141 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
142 struct e1000_rx_ring *rx_ring,
143 int *work_done, int work_to_do);
144 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
145 struct e1000_rx_ring *rx_ring,
146 int *work_done, int work_to_do);
147 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
148 struct e1000_rx_ring *rx_ring,
150 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring,
153 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
154 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
156 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
157 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
158 static void e1000_tx_timeout(struct net_device *dev);
159 static void e1000_reset_task(struct work_struct *work);
160 static void e1000_smartspeed(struct e1000_adapter *adapter);
161 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
162 struct sk_buff *skb);
164 static bool e1000_vlan_used(struct e1000_adapter *adapter);
165 static void e1000_vlan_mode(struct net_device *netdev,
166 netdev_features_t features);
167 static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
169 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
170 __be16 proto, u16 vid);
171 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
172 __be16 proto, u16 vid);
173 static void e1000_restore_vlan(struct e1000_adapter *adapter);
176 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
177 static int e1000_resume(struct pci_dev *pdev);
179 static void e1000_shutdown(struct pci_dev *pdev);
181 #ifdef CONFIG_NET_POLL_CONTROLLER
182 /* for netdump / net console */
183 static void e1000_netpoll (struct net_device *netdev);
186 #define COPYBREAK_DEFAULT 256
187 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
188 module_param(copybreak, uint, 0644);
189 MODULE_PARM_DESC(copybreak,
190 "Maximum size of packet that is copied to a new buffer on receive");
192 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
193 pci_channel_state_t state);
194 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
195 static void e1000_io_resume(struct pci_dev *pdev);
197 static const struct pci_error_handlers e1000_err_handler = {
198 .error_detected = e1000_io_error_detected,
199 .slot_reset = e1000_io_slot_reset,
200 .resume = e1000_io_resume,
203 static struct pci_driver e1000_driver = {
204 .name = e1000_driver_name,
205 .id_table = e1000_pci_tbl,
206 .probe = e1000_probe,
207 .remove = e1000_remove,
209 /* Power Management Hooks */
210 .suspend = e1000_suspend,
211 .resume = e1000_resume,
213 .shutdown = e1000_shutdown,
214 .err_handler = &e1000_err_handler
217 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
218 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
219 MODULE_LICENSE("GPL");
220 MODULE_VERSION(DRV_VERSION);
222 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
223 static int debug = -1;
224 module_param(debug, int, 0);
225 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
228 * e1000_get_hw_dev - return device
229 * used by hardware layer to print debugging information
232 struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
234 struct e1000_adapter *adapter = hw->back;
235 return adapter->netdev;
239 * e1000_init_module - Driver Registration Routine
241 * e1000_init_module is the first routine called when the driver is
242 * loaded. All it does is register with the PCI subsystem.
244 static int __init e1000_init_module(void)
247 pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
249 pr_info("%s\n", e1000_copyright);
251 ret = pci_register_driver(&e1000_driver);
252 if (copybreak != COPYBREAK_DEFAULT) {
254 pr_info("copybreak disabled\n");
256 pr_info("copybreak enabled for "
257 "packets <= %u bytes\n", copybreak);
262 module_init(e1000_init_module);
265 * e1000_exit_module - Driver Exit Cleanup Routine
267 * e1000_exit_module is called just before the driver is removed
270 static void __exit e1000_exit_module(void)
272 pci_unregister_driver(&e1000_driver);
275 module_exit(e1000_exit_module);
277 static int e1000_request_irq(struct e1000_adapter *adapter)
279 struct net_device *netdev = adapter->netdev;
280 irq_handler_t handler = e1000_intr;
281 int irq_flags = IRQF_SHARED;
284 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
287 e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
293 static void e1000_free_irq(struct e1000_adapter *adapter)
295 struct net_device *netdev = adapter->netdev;
297 free_irq(adapter->pdev->irq, netdev);
301 * e1000_irq_disable - Mask off interrupt generation on the NIC
302 * @adapter: board private structure
304 static void e1000_irq_disable(struct e1000_adapter *adapter)
306 struct e1000_hw *hw = &adapter->hw;
310 synchronize_irq(adapter->pdev->irq);
314 * e1000_irq_enable - Enable default interrupt generation settings
315 * @adapter: board private structure
317 static void e1000_irq_enable(struct e1000_adapter *adapter)
319 struct e1000_hw *hw = &adapter->hw;
321 ew32(IMS, IMS_ENABLE_MASK);
325 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
327 struct e1000_hw *hw = &adapter->hw;
328 struct net_device *netdev = adapter->netdev;
329 u16 vid = hw->mng_cookie.vlan_id;
330 u16 old_vid = adapter->mng_vlan_id;
332 if (!e1000_vlan_used(adapter))
335 if (!test_bit(vid, adapter->active_vlans)) {
336 if (hw->mng_cookie.status &
337 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
338 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
339 adapter->mng_vlan_id = vid;
341 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
343 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
345 !test_bit(old_vid, adapter->active_vlans))
346 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
349 adapter->mng_vlan_id = vid;
353 static void e1000_init_manageability(struct e1000_adapter *adapter)
355 struct e1000_hw *hw = &adapter->hw;
357 if (adapter->en_mng_pt) {
358 u32 manc = er32(MANC);
360 /* disable hardware interception of ARP */
361 manc &= ~(E1000_MANC_ARP_EN);
367 static void e1000_release_manageability(struct e1000_adapter *adapter)
369 struct e1000_hw *hw = &adapter->hw;
371 if (adapter->en_mng_pt) {
372 u32 manc = er32(MANC);
374 /* re-enable hardware interception of ARP */
375 manc |= E1000_MANC_ARP_EN;
382 * e1000_configure - configure the hardware for RX and TX
383 * @adapter = private board structure
385 static void e1000_configure(struct e1000_adapter *adapter)
387 struct net_device *netdev = adapter->netdev;
390 e1000_set_rx_mode(netdev);
392 e1000_restore_vlan(adapter);
393 e1000_init_manageability(adapter);
395 e1000_configure_tx(adapter);
396 e1000_setup_rctl(adapter);
397 e1000_configure_rx(adapter);
398 /* call E1000_DESC_UNUSED which always leaves
399 * at least 1 descriptor unused to make sure
400 * next_to_use != next_to_clean
402 for (i = 0; i < adapter->num_rx_queues; i++) {
403 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
404 adapter->alloc_rx_buf(adapter, ring,
405 E1000_DESC_UNUSED(ring));
409 int e1000_up(struct e1000_adapter *adapter)
411 struct e1000_hw *hw = &adapter->hw;
413 /* hardware has been reset, we need to reload some things */
414 e1000_configure(adapter);
416 clear_bit(__E1000_DOWN, &adapter->flags);
418 napi_enable(&adapter->napi);
420 e1000_irq_enable(adapter);
422 netif_wake_queue(adapter->netdev);
424 /* fire a link change interrupt to start the watchdog */
425 ew32(ICS, E1000_ICS_LSC);
430 * e1000_power_up_phy - restore link in case the phy was powered down
431 * @adapter: address of board private structure
433 * The phy may be powered down to save power and turn off link when the
434 * driver is unloaded and wake on lan is not enabled (among others)
435 * *** this routine MUST be followed by a call to e1000_reset ***
437 void e1000_power_up_phy(struct e1000_adapter *adapter)
439 struct e1000_hw *hw = &adapter->hw;
442 /* Just clear the power down bit to wake the phy back up */
443 if (hw->media_type == e1000_media_type_copper) {
444 /* according to the manual, the phy will retain its
445 * settings across a power-down/up cycle
447 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
448 mii_reg &= ~MII_CR_POWER_DOWN;
449 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
453 static void e1000_power_down_phy(struct e1000_adapter *adapter)
455 struct e1000_hw *hw = &adapter->hw;
457 /* Power down the PHY so no link is implied when interface is down *
458 * The PHY cannot be powered down if any of the following is true *
461 * (c) SoL/IDER session is active
463 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
464 hw->media_type == e1000_media_type_copper) {
467 switch (hw->mac_type) {
470 case e1000_82545_rev_3:
473 case e1000_82546_rev_3:
475 case e1000_82541_rev_2:
477 case e1000_82547_rev_2:
478 if (er32(MANC) & E1000_MANC_SMBUS_EN)
484 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
485 mii_reg |= MII_CR_POWER_DOWN;
486 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
493 static void e1000_down_and_stop(struct e1000_adapter *adapter)
495 set_bit(__E1000_DOWN, &adapter->flags);
497 /* Only kill reset task if adapter is not resetting */
498 if (!test_bit(__E1000_RESETTING, &adapter->flags))
499 cancel_work_sync(&adapter->reset_task);
501 cancel_delayed_work_sync(&adapter->watchdog_task);
502 cancel_delayed_work_sync(&adapter->phy_info_task);
503 cancel_delayed_work_sync(&adapter->fifo_stall_task);
506 void e1000_down(struct e1000_adapter *adapter)
508 struct e1000_hw *hw = &adapter->hw;
509 struct net_device *netdev = adapter->netdev;
513 /* disable receives in the hardware */
515 ew32(RCTL, rctl & ~E1000_RCTL_EN);
516 /* flush and sleep below */
518 netif_tx_disable(netdev);
520 /* disable transmits in the hardware */
522 tctl &= ~E1000_TCTL_EN;
524 /* flush both disables and wait for them to finish */
528 napi_disable(&adapter->napi);
530 e1000_irq_disable(adapter);
532 /* Setting DOWN must be after irq_disable to prevent
533 * a screaming interrupt. Setting DOWN also prevents
534 * tasks from rescheduling.
536 e1000_down_and_stop(adapter);
538 adapter->link_speed = 0;
539 adapter->link_duplex = 0;
540 netif_carrier_off(netdev);
542 e1000_reset(adapter);
543 e1000_clean_all_tx_rings(adapter);
544 e1000_clean_all_rx_rings(adapter);
547 void e1000_reinit_locked(struct e1000_adapter *adapter)
549 WARN_ON(in_interrupt());
550 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
554 clear_bit(__E1000_RESETTING, &adapter->flags);
557 void e1000_reset(struct e1000_adapter *adapter)
559 struct e1000_hw *hw = &adapter->hw;
560 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
561 bool legacy_pba_adjust = false;
564 /* Repartition Pba for greater than 9k mtu
565 * To take effect CTRL.RST is required.
568 switch (hw->mac_type) {
569 case e1000_82542_rev2_0:
570 case e1000_82542_rev2_1:
575 case e1000_82541_rev_2:
576 legacy_pba_adjust = true;
580 case e1000_82545_rev_3:
583 case e1000_82546_rev_3:
587 case e1000_82547_rev_2:
588 legacy_pba_adjust = true;
591 case e1000_undefined:
596 if (legacy_pba_adjust) {
597 if (hw->max_frame_size > E1000_RXBUFFER_8192)
598 pba -= 8; /* allocate more FIFO for Tx */
600 if (hw->mac_type == e1000_82547) {
601 adapter->tx_fifo_head = 0;
602 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
603 adapter->tx_fifo_size =
604 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
605 atomic_set(&adapter->tx_fifo_stall, 0);
607 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
608 /* adjust PBA for jumbo frames */
611 /* To maintain wire speed transmits, the Tx FIFO should be
612 * large enough to accommodate two full transmit packets,
613 * rounded up to the next 1KB and expressed in KB. Likewise,
614 * the Rx FIFO should be large enough to accommodate at least
615 * one full receive packet and is similarly rounded up and
619 /* upper 16 bits has Tx packet buffer allocation size in KB */
620 tx_space = pba >> 16;
621 /* lower 16 bits has Rx packet buffer allocation size in KB */
623 /* the Tx fifo also stores 16 bytes of information about the Tx
624 * but don't include ethernet FCS because hardware appends it
626 min_tx_space = (hw->max_frame_size +
627 sizeof(struct e1000_tx_desc) -
629 min_tx_space = ALIGN(min_tx_space, 1024);
631 /* software strips receive CRC, so leave room for it */
632 min_rx_space = hw->max_frame_size;
633 min_rx_space = ALIGN(min_rx_space, 1024);
636 /* If current Tx allocation is less than the min Tx FIFO size,
637 * and the min Tx FIFO size is less than the current Rx FIFO
638 * allocation, take space away from current Rx allocation
640 if (tx_space < min_tx_space &&
641 ((min_tx_space - tx_space) < pba)) {
642 pba = pba - (min_tx_space - tx_space);
644 /* PCI/PCIx hardware has PBA alignment constraints */
645 switch (hw->mac_type) {
646 case e1000_82545 ... e1000_82546_rev_3:
647 pba &= ~(E1000_PBA_8K - 1);
653 /* if short on Rx space, Rx wins and must trump Tx
654 * adjustment or use Early Receive if available
656 if (pba < min_rx_space)
663 /* flow control settings:
664 * The high water mark must be low enough to fit one full frame
665 * (or the size used for early receive) above it in the Rx FIFO.
666 * Set it to the lower of:
667 * - 90% of the Rx FIFO size, and
668 * - the full Rx FIFO size minus the early receive size (for parts
669 * with ERT support assuming ERT set to E1000_ERT_2048), or
670 * - the full Rx FIFO size minus one full frame
672 hwm = min(((pba << 10) * 9 / 10),
673 ((pba << 10) - hw->max_frame_size));
675 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
676 hw->fc_low_water = hw->fc_high_water - 8;
677 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
679 hw->fc = hw->original_fc;
681 /* Allow time for pending master requests to run */
683 if (hw->mac_type >= e1000_82544)
686 if (e1000_init_hw(hw))
687 e_dev_err("Hardware Error\n");
688 e1000_update_mng_vlan(adapter);
690 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
691 if (hw->mac_type >= e1000_82544 &&
693 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
694 u32 ctrl = er32(CTRL);
695 /* clear phy power management bit if we are in gig only mode,
696 * which if enabled will attempt negotiation to 100Mb, which
697 * can cause a loss of link at power off or driver unload
699 ctrl &= ~E1000_CTRL_SWDPIN3;
703 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
704 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
706 e1000_reset_adaptive(hw);
707 e1000_phy_get_info(hw, &adapter->phy_info);
709 e1000_release_manageability(adapter);
712 /* Dump the eeprom for users having checksum issues */
713 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
715 struct net_device *netdev = adapter->netdev;
716 struct ethtool_eeprom eeprom;
717 const struct ethtool_ops *ops = netdev->ethtool_ops;
720 u16 csum_old, csum_new = 0;
722 eeprom.len = ops->get_eeprom_len(netdev);
725 data = kmalloc(eeprom.len, GFP_KERNEL);
729 ops->get_eeprom(netdev, &eeprom, data);
731 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
732 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
733 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
734 csum_new += data[i] + (data[i + 1] << 8);
735 csum_new = EEPROM_SUM - csum_new;
737 pr_err("/*********************/\n");
738 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
739 pr_err("Calculated : 0x%04x\n", csum_new);
741 pr_err("Offset Values\n");
742 pr_err("======== ======\n");
743 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
745 pr_err("Include this output when contacting your support provider.\n");
746 pr_err("This is not a software error! Something bad happened to\n");
747 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
748 pr_err("result in further problems, possibly loss of data,\n");
749 pr_err("corruption or system hangs!\n");
750 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
751 pr_err("which is invalid and requires you to set the proper MAC\n");
752 pr_err("address manually before continuing to enable this network\n");
753 pr_err("device. Please inspect the EEPROM dump and report the\n");
754 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
755 pr_err("/*********************/\n");
761 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
762 * @pdev: PCI device information struct
764 * Return true if an adapter needs ioport resources
766 static int e1000_is_need_ioport(struct pci_dev *pdev)
768 switch (pdev->device) {
769 case E1000_DEV_ID_82540EM:
770 case E1000_DEV_ID_82540EM_LOM:
771 case E1000_DEV_ID_82540EP:
772 case E1000_DEV_ID_82540EP_LOM:
773 case E1000_DEV_ID_82540EP_LP:
774 case E1000_DEV_ID_82541EI:
775 case E1000_DEV_ID_82541EI_MOBILE:
776 case E1000_DEV_ID_82541ER:
777 case E1000_DEV_ID_82541ER_LOM:
778 case E1000_DEV_ID_82541GI:
779 case E1000_DEV_ID_82541GI_LF:
780 case E1000_DEV_ID_82541GI_MOBILE:
781 case E1000_DEV_ID_82544EI_COPPER:
782 case E1000_DEV_ID_82544EI_FIBER:
783 case E1000_DEV_ID_82544GC_COPPER:
784 case E1000_DEV_ID_82544GC_LOM:
785 case E1000_DEV_ID_82545EM_COPPER:
786 case E1000_DEV_ID_82545EM_FIBER:
787 case E1000_DEV_ID_82546EB_COPPER:
788 case E1000_DEV_ID_82546EB_FIBER:
789 case E1000_DEV_ID_82546EB_QUAD_COPPER:
796 static netdev_features_t e1000_fix_features(struct net_device *netdev,
797 netdev_features_t features)
799 /* Since there is no support for separate Rx/Tx vlan accel
800 * enable/disable make sure Tx flag is always in same state as Rx.
802 if (features & NETIF_F_HW_VLAN_CTAG_RX)
803 features |= NETIF_F_HW_VLAN_CTAG_TX;
805 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
810 static int e1000_set_features(struct net_device *netdev,
811 netdev_features_t features)
813 struct e1000_adapter *adapter = netdev_priv(netdev);
814 netdev_features_t changed = features ^ netdev->features;
816 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
817 e1000_vlan_mode(netdev, features);
819 if (!(changed & (NETIF_F_RXCSUM | NETIF_F_RXALL)))
822 netdev->features = features;
823 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
825 if (netif_running(netdev))
826 e1000_reinit_locked(adapter);
828 e1000_reset(adapter);
833 static const struct net_device_ops e1000_netdev_ops = {
834 .ndo_open = e1000_open,
835 .ndo_stop = e1000_close,
836 .ndo_start_xmit = e1000_xmit_frame,
837 .ndo_get_stats = e1000_get_stats,
838 .ndo_set_rx_mode = e1000_set_rx_mode,
839 .ndo_set_mac_address = e1000_set_mac,
840 .ndo_tx_timeout = e1000_tx_timeout,
841 .ndo_change_mtu = e1000_change_mtu,
842 .ndo_do_ioctl = e1000_ioctl,
843 .ndo_validate_addr = eth_validate_addr,
844 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
845 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
846 #ifdef CONFIG_NET_POLL_CONTROLLER
847 .ndo_poll_controller = e1000_netpoll,
849 .ndo_fix_features = e1000_fix_features,
850 .ndo_set_features = e1000_set_features,
854 * e1000_init_hw_struct - initialize members of hw struct
855 * @adapter: board private struct
856 * @hw: structure used by e1000_hw.c
858 * Factors out initialization of the e1000_hw struct to its own function
859 * that can be called very early at init (just after struct allocation).
860 * Fields are initialized based on PCI device information and
861 * OS network device settings (MTU size).
862 * Returns negative error codes if MAC type setup fails.
864 static int e1000_init_hw_struct(struct e1000_adapter *adapter,
867 struct pci_dev *pdev = adapter->pdev;
869 /* PCI config space info */
870 hw->vendor_id = pdev->vendor;
871 hw->device_id = pdev->device;
872 hw->subsystem_vendor_id = pdev->subsystem_vendor;
873 hw->subsystem_id = pdev->subsystem_device;
874 hw->revision_id = pdev->revision;
876 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
878 hw->max_frame_size = adapter->netdev->mtu +
879 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
880 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
882 /* identify the MAC */
883 if (e1000_set_mac_type(hw)) {
884 e_err(probe, "Unknown MAC Type\n");
888 switch (hw->mac_type) {
893 case e1000_82541_rev_2:
894 case e1000_82547_rev_2:
895 hw->phy_init_script = 1;
899 e1000_set_media_type(hw);
900 e1000_get_bus_info(hw);
902 hw->wait_autoneg_complete = false;
903 hw->tbi_compatibility_en = true;
904 hw->adaptive_ifs = true;
908 if (hw->media_type == e1000_media_type_copper) {
909 hw->mdix = AUTO_ALL_MODES;
910 hw->disable_polarity_correction = false;
911 hw->master_slave = E1000_MASTER_SLAVE;
918 * e1000_probe - Device Initialization Routine
919 * @pdev: PCI device information struct
920 * @ent: entry in e1000_pci_tbl
922 * Returns 0 on success, negative on failure
924 * e1000_probe initializes an adapter identified by a pci_dev structure.
925 * The OS initialization, configuring of the adapter private structure,
926 * and a hardware reset occur.
928 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
930 struct net_device *netdev;
931 struct e1000_adapter *adapter;
934 static int cards_found = 0;
935 static int global_quad_port_a = 0; /* global ksp3 port a indication */
936 int i, err, pci_using_dac;
939 u16 eeprom_apme_mask = E1000_EEPROM_APME;
940 int bars, need_ioport;
942 /* do not allocate ioport bars when not needed */
943 need_ioport = e1000_is_need_ioport(pdev);
945 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
946 err = pci_enable_device(pdev);
948 bars = pci_select_bars(pdev, IORESOURCE_MEM);
949 err = pci_enable_device_mem(pdev);
954 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
958 pci_set_master(pdev);
959 err = pci_save_state(pdev);
961 goto err_alloc_etherdev;
964 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
966 goto err_alloc_etherdev;
968 SET_NETDEV_DEV(netdev, &pdev->dev);
970 pci_set_drvdata(pdev, netdev);
971 adapter = netdev_priv(netdev);
972 adapter->netdev = netdev;
973 adapter->pdev = pdev;
974 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
975 adapter->bars = bars;
976 adapter->need_ioport = need_ioport;
982 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
986 if (adapter->need_ioport) {
987 for (i = BAR_1; i <= BAR_5; i++) {
988 if (pci_resource_len(pdev, i) == 0)
990 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
991 hw->io_base = pci_resource_start(pdev, i);
997 /* make ready for any if (hw->...) below */
998 err = e1000_init_hw_struct(adapter, hw);
1002 /* there is a workaround being applied below that limits
1003 * 64-bit DMA addresses to 64-bit hardware. There are some
1004 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
1007 if ((hw->bus_type == e1000_bus_type_pcix) &&
1008 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
1011 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1013 pr_err("No usable DMA config, aborting\n");
1018 netdev->netdev_ops = &e1000_netdev_ops;
1019 e1000_set_ethtool_ops(netdev);
1020 netdev->watchdog_timeo = 5 * HZ;
1021 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1023 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1025 adapter->bd_number = cards_found;
1027 /* setup the private structure */
1029 err = e1000_sw_init(adapter);
1034 if (hw->mac_type == e1000_ce4100) {
1035 hw->ce4100_gbe_mdio_base_virt =
1036 ioremap(pci_resource_start(pdev, BAR_1),
1037 pci_resource_len(pdev, BAR_1));
1039 if (!hw->ce4100_gbe_mdio_base_virt)
1040 goto err_mdio_ioremap;
1043 if (hw->mac_type >= e1000_82543) {
1044 netdev->hw_features = NETIF_F_SG |
1046 NETIF_F_HW_VLAN_CTAG_RX;
1047 netdev->features = NETIF_F_HW_VLAN_CTAG_TX |
1048 NETIF_F_HW_VLAN_CTAG_FILTER;
1051 if ((hw->mac_type >= e1000_82544) &&
1052 (hw->mac_type != e1000_82547))
1053 netdev->hw_features |= NETIF_F_TSO;
1055 netdev->priv_flags |= IFF_SUPP_NOFCS;
1057 netdev->features |= netdev->hw_features;
1058 netdev->hw_features |= (NETIF_F_RXCSUM |
1062 if (pci_using_dac) {
1063 netdev->features |= NETIF_F_HIGHDMA;
1064 netdev->vlan_features |= NETIF_F_HIGHDMA;
1067 netdev->vlan_features |= (NETIF_F_TSO |
1071 netdev->priv_flags |= IFF_UNICAST_FLT;
1073 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1075 /* initialize eeprom parameters */
1076 if (e1000_init_eeprom_params(hw)) {
1077 e_err(probe, "EEPROM initialization failed\n");
1081 /* before reading the EEPROM, reset the controller to
1082 * put the device in a known good starting state
1087 /* make sure the EEPROM is good */
1088 if (e1000_validate_eeprom_checksum(hw) < 0) {
1089 e_err(probe, "The EEPROM Checksum Is Not Valid\n");
1090 e1000_dump_eeprom(adapter);
1091 /* set MAC address to all zeroes to invalidate and temporary
1092 * disable this device for the user. This blocks regular
1093 * traffic while still permitting ethtool ioctls from reaching
1094 * the hardware as well as allowing the user to run the
1095 * interface after manually setting a hw addr using
1098 memset(hw->mac_addr, 0, netdev->addr_len);
1100 /* copy the MAC address out of the EEPROM */
1101 if (e1000_read_mac_addr(hw))
1102 e_err(probe, "EEPROM Read Error\n");
1104 /* don't block initalization here due to bad MAC address */
1105 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1107 if (!is_valid_ether_addr(netdev->dev_addr))
1108 e_err(probe, "Invalid MAC Address\n");
1111 INIT_DELAYED_WORK(&adapter->watchdog_task, e1000_watchdog);
1112 INIT_DELAYED_WORK(&adapter->fifo_stall_task,
1113 e1000_82547_tx_fifo_stall_task);
1114 INIT_DELAYED_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
1115 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1117 e1000_check_options(adapter);
1119 /* Initial Wake on LAN setting
1120 * If APM wake is enabled in the EEPROM,
1121 * enable the ACPI Magic Packet filter
1124 switch (hw->mac_type) {
1125 case e1000_82542_rev2_0:
1126 case e1000_82542_rev2_1:
1130 e1000_read_eeprom(hw,
1131 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1132 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1135 case e1000_82546_rev_3:
1136 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1137 e1000_read_eeprom(hw,
1138 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1143 e1000_read_eeprom(hw,
1144 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1147 if (eeprom_data & eeprom_apme_mask)
1148 adapter->eeprom_wol |= E1000_WUFC_MAG;
1150 /* now that we have the eeprom settings, apply the special cases
1151 * where the eeprom may be wrong or the board simply won't support
1152 * wake on lan on a particular port
1154 switch (pdev->device) {
1155 case E1000_DEV_ID_82546GB_PCIE:
1156 adapter->eeprom_wol = 0;
1158 case E1000_DEV_ID_82546EB_FIBER:
1159 case E1000_DEV_ID_82546GB_FIBER:
1160 /* Wake events only supported on port A for dual fiber
1161 * regardless of eeprom setting
1163 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1164 adapter->eeprom_wol = 0;
1166 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1167 /* if quad port adapter, disable WoL on all but port A */
1168 if (global_quad_port_a != 0)
1169 adapter->eeprom_wol = 0;
1171 adapter->quad_port_a = true;
1172 /* Reset for multiple quad port adapters */
1173 if (++global_quad_port_a == 4)
1174 global_quad_port_a = 0;
1178 /* initialize the wol settings based on the eeprom settings */
1179 adapter->wol = adapter->eeprom_wol;
1180 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1182 /* Auto detect PHY address */
1183 if (hw->mac_type == e1000_ce4100) {
1184 for (i = 0; i < 32; i++) {
1186 e1000_read_phy_reg(hw, PHY_ID2, &tmp);
1187 if (tmp == 0 || tmp == 0xFF) {
1196 /* reset the hardware with the new settings */
1197 e1000_reset(adapter);
1199 strcpy(netdev->name, "eth%d");
1200 err = register_netdev(netdev);
1204 e1000_vlan_filter_on_off(adapter, false);
1206 /* print bus type/speed/width info */
1207 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
1208 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1209 ((hw->bus_speed == e1000_bus_speed_133) ? 133 :
1210 (hw->bus_speed == e1000_bus_speed_120) ? 120 :
1211 (hw->bus_speed == e1000_bus_speed_100) ? 100 :
1212 (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33),
1213 ((hw->bus_width == e1000_bus_width_64) ? 64 : 32),
1216 /* carrier off reporting is important to ethtool even BEFORE open */
1217 netif_carrier_off(netdev);
1219 e_info(probe, "Intel(R) PRO/1000 Network Connection\n");
1226 e1000_phy_hw_reset(hw);
1228 if (hw->flash_address)
1229 iounmap(hw->flash_address);
1230 kfree(adapter->tx_ring);
1231 kfree(adapter->rx_ring);
1235 iounmap(hw->ce4100_gbe_mdio_base_virt);
1236 iounmap(hw->hw_addr);
1238 free_netdev(netdev);
1240 pci_release_selected_regions(pdev, bars);
1242 pci_disable_device(pdev);
1247 * e1000_remove - Device Removal Routine
1248 * @pdev: PCI device information struct
1250 * e1000_remove is called by the PCI subsystem to alert the driver
1251 * that it should release a PCI device. The could be caused by a
1252 * Hot-Plug event, or because the driver is going to be removed from
1255 static void e1000_remove(struct pci_dev *pdev)
1257 struct net_device *netdev = pci_get_drvdata(pdev);
1258 struct e1000_adapter *adapter = netdev_priv(netdev);
1259 struct e1000_hw *hw = &adapter->hw;
1261 e1000_down_and_stop(adapter);
1262 e1000_release_manageability(adapter);
1264 unregister_netdev(netdev);
1266 e1000_phy_hw_reset(hw);
1268 kfree(adapter->tx_ring);
1269 kfree(adapter->rx_ring);
1271 if (hw->mac_type == e1000_ce4100)
1272 iounmap(hw->ce4100_gbe_mdio_base_virt);
1273 iounmap(hw->hw_addr);
1274 if (hw->flash_address)
1275 iounmap(hw->flash_address);
1276 pci_release_selected_regions(pdev, adapter->bars);
1278 free_netdev(netdev);
1280 pci_disable_device(pdev);
1284 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1285 * @adapter: board private structure to initialize
1287 * e1000_sw_init initializes the Adapter private data structure.
1288 * e1000_init_hw_struct MUST be called before this function
1290 static int e1000_sw_init(struct e1000_adapter *adapter)
1292 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1294 adapter->num_tx_queues = 1;
1295 adapter->num_rx_queues = 1;
1297 if (e1000_alloc_queues(adapter)) {
1298 e_err(probe, "Unable to allocate memory for queues\n");
1302 /* Explicitly disable IRQ since the NIC can be in any state. */
1303 e1000_irq_disable(adapter);
1305 spin_lock_init(&adapter->stats_lock);
1307 set_bit(__E1000_DOWN, &adapter->flags);
1313 * e1000_alloc_queues - Allocate memory for all rings
1314 * @adapter: board private structure to initialize
1316 * We allocate one ring per queue at run-time since we don't know the
1317 * number of queues at compile-time.
1319 static int e1000_alloc_queues(struct e1000_adapter *adapter)
1321 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1322 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1323 if (!adapter->tx_ring)
1326 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1327 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1328 if (!adapter->rx_ring) {
1329 kfree(adapter->tx_ring);
1333 return E1000_SUCCESS;
1337 * e1000_open - Called when a network interface is made active
1338 * @netdev: network interface device structure
1340 * Returns 0 on success, negative value on failure
1342 * The open entry point is called when a network interface is made
1343 * active by the system (IFF_UP). At this point all resources needed
1344 * for transmit and receive operations are allocated, the interrupt
1345 * handler is registered with the OS, the watchdog task is started,
1346 * and the stack is notified that the interface is ready.
1348 static int e1000_open(struct net_device *netdev)
1350 struct e1000_adapter *adapter = netdev_priv(netdev);
1351 struct e1000_hw *hw = &adapter->hw;
1354 /* disallow open during test */
1355 if (test_bit(__E1000_TESTING, &adapter->flags))
1358 netif_carrier_off(netdev);
1360 /* allocate transmit descriptors */
1361 err = e1000_setup_all_tx_resources(adapter);
1365 /* allocate receive descriptors */
1366 err = e1000_setup_all_rx_resources(adapter);
1370 e1000_power_up_phy(adapter);
1372 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1373 if ((hw->mng_cookie.status &
1374 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1375 e1000_update_mng_vlan(adapter);
1378 /* before we allocate an interrupt, we must be ready to handle it.
1379 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1380 * as soon as we call pci_request_irq, so we have to setup our
1381 * clean_rx handler before we do so.
1383 e1000_configure(adapter);
1385 err = e1000_request_irq(adapter);
1389 /* From here on the code is the same as e1000_up() */
1390 clear_bit(__E1000_DOWN, &adapter->flags);
1392 napi_enable(&adapter->napi);
1394 e1000_irq_enable(adapter);
1396 netif_start_queue(netdev);
1398 /* fire a link status change interrupt to start the watchdog */
1399 ew32(ICS, E1000_ICS_LSC);
1401 return E1000_SUCCESS;
1404 e1000_power_down_phy(adapter);
1405 e1000_free_all_rx_resources(adapter);
1407 e1000_free_all_tx_resources(adapter);
1409 e1000_reset(adapter);
1415 * e1000_close - Disables a network interface
1416 * @netdev: network interface device structure
1418 * Returns 0, this is not allowed to fail
1420 * The close entry point is called when an interface is de-activated
1421 * by the OS. The hardware is still under the drivers control, but
1422 * needs to be disabled. A global MAC reset is issued to stop the
1423 * hardware, and all transmit and receive resources are freed.
1425 static int e1000_close(struct net_device *netdev)
1427 struct e1000_adapter *adapter = netdev_priv(netdev);
1428 struct e1000_hw *hw = &adapter->hw;
1429 int count = E1000_CHECK_RESET_COUNT;
1431 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
1432 usleep_range(10000, 20000);
1434 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1435 e1000_down(adapter);
1436 e1000_power_down_phy(adapter);
1437 e1000_free_irq(adapter);
1439 e1000_free_all_tx_resources(adapter);
1440 e1000_free_all_rx_resources(adapter);
1442 /* kill manageability vlan ID if supported, but not if a vlan with
1443 * the same ID is registered on the host OS (let 8021q kill it)
1445 if ((hw->mng_cookie.status &
1446 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1447 !test_bit(adapter->mng_vlan_id, adapter->active_vlans)) {
1448 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
1449 adapter->mng_vlan_id);
1456 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1457 * @adapter: address of board private structure
1458 * @start: address of beginning of memory
1459 * @len: length of memory
1461 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1464 struct e1000_hw *hw = &adapter->hw;
1465 unsigned long begin = (unsigned long)start;
1466 unsigned long end = begin + len;
1468 /* First rev 82545 and 82546 need to not allow any memory
1469 * write location to cross 64k boundary due to errata 23
1471 if (hw->mac_type == e1000_82545 ||
1472 hw->mac_type == e1000_ce4100 ||
1473 hw->mac_type == e1000_82546) {
1474 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1481 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1482 * @adapter: board private structure
1483 * @txdr: tx descriptor ring (for a specific queue) to setup
1485 * Return 0 on success, negative on failure
1487 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1488 struct e1000_tx_ring *txdr)
1490 struct pci_dev *pdev = adapter->pdev;
1493 size = sizeof(struct e1000_buffer) * txdr->count;
1494 txdr->buffer_info = vzalloc(size);
1495 if (!txdr->buffer_info)
1498 /* round up to nearest 4K */
1500 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1501 txdr->size = ALIGN(txdr->size, 4096);
1503 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1507 vfree(txdr->buffer_info);
1511 /* Fix for errata 23, can't cross 64kB boundary */
1512 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1513 void *olddesc = txdr->desc;
1514 dma_addr_t olddma = txdr->dma;
1515 e_err(tx_err, "txdr align check failed: %u bytes at %p\n",
1516 txdr->size, txdr->desc);
1517 /* Try again, without freeing the previous */
1518 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size,
1519 &txdr->dma, GFP_KERNEL);
1520 /* Failed allocation, critical failure */
1522 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1524 goto setup_tx_desc_die;
1527 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1529 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1531 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1533 e_err(probe, "Unable to allocate aligned memory "
1534 "for the transmit descriptor ring\n");
1535 vfree(txdr->buffer_info);
1538 /* Free old allocation, new allocation was successful */
1539 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1543 memset(txdr->desc, 0, txdr->size);
1545 txdr->next_to_use = 0;
1546 txdr->next_to_clean = 0;
1552 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1553 * (Descriptors) for all queues
1554 * @adapter: board private structure
1556 * Return 0 on success, negative on failure
1558 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1562 for (i = 0; i < adapter->num_tx_queues; i++) {
1563 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1565 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1566 for (i-- ; i >= 0; i--)
1567 e1000_free_tx_resources(adapter,
1568 &adapter->tx_ring[i]);
1577 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1578 * @adapter: board private structure
1580 * Configure the Tx unit of the MAC after a reset.
1582 static void e1000_configure_tx(struct e1000_adapter *adapter)
1585 struct e1000_hw *hw = &adapter->hw;
1586 u32 tdlen, tctl, tipg;
1589 /* Setup the HW Tx Head and Tail descriptor pointers */
1591 switch (adapter->num_tx_queues) {
1594 tdba = adapter->tx_ring[0].dma;
1595 tdlen = adapter->tx_ring[0].count *
1596 sizeof(struct e1000_tx_desc);
1598 ew32(TDBAH, (tdba >> 32));
1599 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1602 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ?
1603 E1000_TDH : E1000_82542_TDH);
1604 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ?
1605 E1000_TDT : E1000_82542_TDT);
1609 /* Set the default values for the Tx Inter Packet Gap timer */
1610 if ((hw->media_type == e1000_media_type_fiber ||
1611 hw->media_type == e1000_media_type_internal_serdes))
1612 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1614 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1616 switch (hw->mac_type) {
1617 case e1000_82542_rev2_0:
1618 case e1000_82542_rev2_1:
1619 tipg = DEFAULT_82542_TIPG_IPGT;
1620 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1621 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1624 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1625 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1628 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1629 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1632 /* Set the Tx Interrupt Delay register */
1634 ew32(TIDV, adapter->tx_int_delay);
1635 if (hw->mac_type >= e1000_82540)
1636 ew32(TADV, adapter->tx_abs_int_delay);
1638 /* Program the Transmit Control Register */
1641 tctl &= ~E1000_TCTL_CT;
1642 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1643 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1645 e1000_config_collision_dist(hw);
1647 /* Setup Transmit Descriptor Settings for eop descriptor */
1648 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1650 /* only set IDE if we are delaying interrupts using the timers */
1651 if (adapter->tx_int_delay)
1652 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1654 if (hw->mac_type < e1000_82543)
1655 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1657 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1659 /* Cache if we're 82544 running in PCI-X because we'll
1660 * need this to apply a workaround later in the send path.
1662 if (hw->mac_type == e1000_82544 &&
1663 hw->bus_type == e1000_bus_type_pcix)
1664 adapter->pcix_82544 = true;
1671 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1672 * @adapter: board private structure
1673 * @rxdr: rx descriptor ring (for a specific queue) to setup
1675 * Returns 0 on success, negative on failure
1677 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1678 struct e1000_rx_ring *rxdr)
1680 struct pci_dev *pdev = adapter->pdev;
1683 size = sizeof(struct e1000_buffer) * rxdr->count;
1684 rxdr->buffer_info = vzalloc(size);
1685 if (!rxdr->buffer_info)
1688 desc_len = sizeof(struct e1000_rx_desc);
1690 /* Round up to nearest 4K */
1692 rxdr->size = rxdr->count * desc_len;
1693 rxdr->size = ALIGN(rxdr->size, 4096);
1695 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1699 vfree(rxdr->buffer_info);
1703 /* Fix for errata 23, can't cross 64kB boundary */
1704 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1705 void *olddesc = rxdr->desc;
1706 dma_addr_t olddma = rxdr->dma;
1707 e_err(rx_err, "rxdr align check failed: %u bytes at %p\n",
1708 rxdr->size, rxdr->desc);
1709 /* Try again, without freeing the previous */
1710 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size,
1711 &rxdr->dma, GFP_KERNEL);
1712 /* Failed allocation, critical failure */
1714 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1716 goto setup_rx_desc_die;
1719 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1721 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1723 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1725 e_err(probe, "Unable to allocate aligned memory for "
1726 "the Rx descriptor ring\n");
1727 goto setup_rx_desc_die;
1729 /* Free old allocation, new allocation was successful */
1730 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1734 memset(rxdr->desc, 0, rxdr->size);
1736 rxdr->next_to_clean = 0;
1737 rxdr->next_to_use = 0;
1738 rxdr->rx_skb_top = NULL;
1744 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1745 * (Descriptors) for all queues
1746 * @adapter: board private structure
1748 * Return 0 on success, negative on failure
1750 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1754 for (i = 0; i < adapter->num_rx_queues; i++) {
1755 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1757 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1758 for (i-- ; i >= 0; i--)
1759 e1000_free_rx_resources(adapter,
1760 &adapter->rx_ring[i]);
1769 * e1000_setup_rctl - configure the receive control registers
1770 * @adapter: Board private structure
1772 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1774 struct e1000_hw *hw = &adapter->hw;
1779 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1781 rctl |= E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1782 E1000_RCTL_RDMTS_HALF |
1783 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1785 if (hw->tbi_compatibility_on == 1)
1786 rctl |= E1000_RCTL_SBP;
1788 rctl &= ~E1000_RCTL_SBP;
1790 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1791 rctl &= ~E1000_RCTL_LPE;
1793 rctl |= E1000_RCTL_LPE;
1795 /* Setup buffer sizes */
1796 rctl &= ~E1000_RCTL_SZ_4096;
1797 rctl |= E1000_RCTL_BSEX;
1798 switch (adapter->rx_buffer_len) {
1799 case E1000_RXBUFFER_2048:
1801 rctl |= E1000_RCTL_SZ_2048;
1802 rctl &= ~E1000_RCTL_BSEX;
1804 case E1000_RXBUFFER_4096:
1805 rctl |= E1000_RCTL_SZ_4096;
1807 case E1000_RXBUFFER_8192:
1808 rctl |= E1000_RCTL_SZ_8192;
1810 case E1000_RXBUFFER_16384:
1811 rctl |= E1000_RCTL_SZ_16384;
1815 /* This is useful for sniffing bad packets. */
1816 if (adapter->netdev->features & NETIF_F_RXALL) {
1817 /* UPE and MPE will be handled by normal PROMISC logic
1818 * in e1000e_set_rx_mode
1820 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
1821 E1000_RCTL_BAM | /* RX All Bcast Pkts */
1822 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
1824 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
1825 E1000_RCTL_DPF | /* Allow filtered pause */
1826 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
1827 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
1828 * and that breaks VLANs.
1836 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1837 * @adapter: board private structure
1839 * Configure the Rx unit of the MAC after a reset.
1841 static void e1000_configure_rx(struct e1000_adapter *adapter)
1844 struct e1000_hw *hw = &adapter->hw;
1845 u32 rdlen, rctl, rxcsum;
1847 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1848 rdlen = adapter->rx_ring[0].count *
1849 sizeof(struct e1000_rx_desc);
1850 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1851 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1853 rdlen = adapter->rx_ring[0].count *
1854 sizeof(struct e1000_rx_desc);
1855 adapter->clean_rx = e1000_clean_rx_irq;
1856 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1859 /* disable receives while setting up the descriptors */
1861 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1863 /* set the Receive Delay Timer Register */
1864 ew32(RDTR, adapter->rx_int_delay);
1866 if (hw->mac_type >= e1000_82540) {
1867 ew32(RADV, adapter->rx_abs_int_delay);
1868 if (adapter->itr_setting != 0)
1869 ew32(ITR, 1000000000 / (adapter->itr * 256));
1872 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1873 * the Base and Length of the Rx Descriptor Ring
1875 switch (adapter->num_rx_queues) {
1878 rdba = adapter->rx_ring[0].dma;
1880 ew32(RDBAH, (rdba >> 32));
1881 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1884 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ?
1885 E1000_RDH : E1000_82542_RDH);
1886 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ?
1887 E1000_RDT : E1000_82542_RDT);
1891 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1892 if (hw->mac_type >= e1000_82543) {
1893 rxcsum = er32(RXCSUM);
1894 if (adapter->rx_csum)
1895 rxcsum |= E1000_RXCSUM_TUOFL;
1897 /* don't need to clear IPPCSE as it defaults to 0 */
1898 rxcsum &= ~E1000_RXCSUM_TUOFL;
1899 ew32(RXCSUM, rxcsum);
1902 /* Enable Receives */
1903 ew32(RCTL, rctl | E1000_RCTL_EN);
1907 * e1000_free_tx_resources - Free Tx Resources per Queue
1908 * @adapter: board private structure
1909 * @tx_ring: Tx descriptor ring for a specific queue
1911 * Free all transmit software resources
1913 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1914 struct e1000_tx_ring *tx_ring)
1916 struct pci_dev *pdev = adapter->pdev;
1918 e1000_clean_tx_ring(adapter, tx_ring);
1920 vfree(tx_ring->buffer_info);
1921 tx_ring->buffer_info = NULL;
1923 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1926 tx_ring->desc = NULL;
1930 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1931 * @adapter: board private structure
1933 * Free all transmit software resources
1935 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1939 for (i = 0; i < adapter->num_tx_queues; i++)
1940 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1943 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1944 struct e1000_buffer *buffer_info)
1946 if (buffer_info->dma) {
1947 if (buffer_info->mapped_as_page)
1948 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1949 buffer_info->length, DMA_TO_DEVICE);
1951 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1952 buffer_info->length,
1954 buffer_info->dma = 0;
1956 if (buffer_info->skb) {
1957 dev_kfree_skb_any(buffer_info->skb);
1958 buffer_info->skb = NULL;
1960 buffer_info->time_stamp = 0;
1961 /* buffer_info must be completely set up in the transmit path */
1965 * e1000_clean_tx_ring - Free Tx Buffers
1966 * @adapter: board private structure
1967 * @tx_ring: ring to be cleaned
1969 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1970 struct e1000_tx_ring *tx_ring)
1972 struct e1000_hw *hw = &adapter->hw;
1973 struct e1000_buffer *buffer_info;
1977 /* Free all the Tx ring sk_buffs */
1979 for (i = 0; i < tx_ring->count; i++) {
1980 buffer_info = &tx_ring->buffer_info[i];
1981 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1984 netdev_reset_queue(adapter->netdev);
1985 size = sizeof(struct e1000_buffer) * tx_ring->count;
1986 memset(tx_ring->buffer_info, 0, size);
1988 /* Zero out the descriptor ring */
1990 memset(tx_ring->desc, 0, tx_ring->size);
1992 tx_ring->next_to_use = 0;
1993 tx_ring->next_to_clean = 0;
1994 tx_ring->last_tx_tso = false;
1996 writel(0, hw->hw_addr + tx_ring->tdh);
1997 writel(0, hw->hw_addr + tx_ring->tdt);
2001 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2002 * @adapter: board private structure
2004 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2008 for (i = 0; i < adapter->num_tx_queues; i++)
2009 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2013 * e1000_free_rx_resources - Free Rx Resources
2014 * @adapter: board private structure
2015 * @rx_ring: ring to clean the resources from
2017 * Free all receive software resources
2019 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2020 struct e1000_rx_ring *rx_ring)
2022 struct pci_dev *pdev = adapter->pdev;
2024 e1000_clean_rx_ring(adapter, rx_ring);
2026 vfree(rx_ring->buffer_info);
2027 rx_ring->buffer_info = NULL;
2029 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2032 rx_ring->desc = NULL;
2036 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2037 * @adapter: board private structure
2039 * Free all receive software resources
2041 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2045 for (i = 0; i < adapter->num_rx_queues; i++)
2046 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2050 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2051 * @adapter: board private structure
2052 * @rx_ring: ring to free buffers from
2054 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2055 struct e1000_rx_ring *rx_ring)
2057 struct e1000_hw *hw = &adapter->hw;
2058 struct e1000_buffer *buffer_info;
2059 struct pci_dev *pdev = adapter->pdev;
2063 /* Free all the Rx ring sk_buffs */
2064 for (i = 0; i < rx_ring->count; i++) {
2065 buffer_info = &rx_ring->buffer_info[i];
2066 if (buffer_info->dma &&
2067 adapter->clean_rx == e1000_clean_rx_irq) {
2068 dma_unmap_single(&pdev->dev, buffer_info->dma,
2069 buffer_info->length,
2071 } else if (buffer_info->dma &&
2072 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2073 dma_unmap_page(&pdev->dev, buffer_info->dma,
2074 buffer_info->length,
2078 buffer_info->dma = 0;
2079 if (buffer_info->page) {
2080 put_page(buffer_info->page);
2081 buffer_info->page = NULL;
2083 if (buffer_info->skb) {
2084 dev_kfree_skb(buffer_info->skb);
2085 buffer_info->skb = NULL;
2089 /* there also may be some cached data from a chained receive */
2090 if (rx_ring->rx_skb_top) {
2091 dev_kfree_skb(rx_ring->rx_skb_top);
2092 rx_ring->rx_skb_top = NULL;
2095 size = sizeof(struct e1000_buffer) * rx_ring->count;
2096 memset(rx_ring->buffer_info, 0, size);
2098 /* Zero out the descriptor ring */
2099 memset(rx_ring->desc, 0, rx_ring->size);
2101 rx_ring->next_to_clean = 0;
2102 rx_ring->next_to_use = 0;
2104 writel(0, hw->hw_addr + rx_ring->rdh);
2105 writel(0, hw->hw_addr + rx_ring->rdt);
2109 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2110 * @adapter: board private structure
2112 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2116 for (i = 0; i < adapter->num_rx_queues; i++)
2117 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2120 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2121 * and memory write and invalidate disabled for certain operations
2123 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2125 struct e1000_hw *hw = &adapter->hw;
2126 struct net_device *netdev = adapter->netdev;
2129 e1000_pci_clear_mwi(hw);
2132 rctl |= E1000_RCTL_RST;
2134 E1000_WRITE_FLUSH();
2137 if (netif_running(netdev))
2138 e1000_clean_all_rx_rings(adapter);
2141 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2143 struct e1000_hw *hw = &adapter->hw;
2144 struct net_device *netdev = adapter->netdev;
2148 rctl &= ~E1000_RCTL_RST;
2150 E1000_WRITE_FLUSH();
2153 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2154 e1000_pci_set_mwi(hw);
2156 if (netif_running(netdev)) {
2157 /* No need to loop, because 82542 supports only 1 queue */
2158 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2159 e1000_configure_rx(adapter);
2160 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2165 * e1000_set_mac - Change the Ethernet Address of the NIC
2166 * @netdev: network interface device structure
2167 * @p: pointer to an address structure
2169 * Returns 0 on success, negative on failure
2171 static int e1000_set_mac(struct net_device *netdev, void *p)
2173 struct e1000_adapter *adapter = netdev_priv(netdev);
2174 struct e1000_hw *hw = &adapter->hw;
2175 struct sockaddr *addr = p;
2177 if (!is_valid_ether_addr(addr->sa_data))
2178 return -EADDRNOTAVAIL;
2180 /* 82542 2.0 needs to be in reset to write receive address registers */
2182 if (hw->mac_type == e1000_82542_rev2_0)
2183 e1000_enter_82542_rst(adapter);
2185 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2186 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2188 e1000_rar_set(hw, hw->mac_addr, 0);
2190 if (hw->mac_type == e1000_82542_rev2_0)
2191 e1000_leave_82542_rst(adapter);
2197 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2198 * @netdev: network interface device structure
2200 * The set_rx_mode entry point is called whenever the unicast or multicast
2201 * address lists or the network interface flags are updated. This routine is
2202 * responsible for configuring the hardware for proper unicast, multicast,
2203 * promiscuous mode, and all-multi behavior.
2205 static void e1000_set_rx_mode(struct net_device *netdev)
2207 struct e1000_adapter *adapter = netdev_priv(netdev);
2208 struct e1000_hw *hw = &adapter->hw;
2209 struct netdev_hw_addr *ha;
2210 bool use_uc = false;
2213 int i, rar_entries = E1000_RAR_ENTRIES;
2214 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
2215 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2220 /* Check for Promiscuous and All Multicast modes */
2224 if (netdev->flags & IFF_PROMISC) {
2225 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2226 rctl &= ~E1000_RCTL_VFE;
2228 if (netdev->flags & IFF_ALLMULTI)
2229 rctl |= E1000_RCTL_MPE;
2231 rctl &= ~E1000_RCTL_MPE;
2232 /* Enable VLAN filter if there is a VLAN */
2233 if (e1000_vlan_used(adapter))
2234 rctl |= E1000_RCTL_VFE;
2237 if (netdev_uc_count(netdev) > rar_entries - 1) {
2238 rctl |= E1000_RCTL_UPE;
2239 } else if (!(netdev->flags & IFF_PROMISC)) {
2240 rctl &= ~E1000_RCTL_UPE;
2246 /* 82542 2.0 needs to be in reset to write receive address registers */
2248 if (hw->mac_type == e1000_82542_rev2_0)
2249 e1000_enter_82542_rst(adapter);
2251 /* load the first 14 addresses into the exact filters 1-14. Unicast
2252 * addresses take precedence to avoid disabling unicast filtering
2255 * RAR 0 is used for the station MAC address
2256 * if there are not 14 addresses, go ahead and clear the filters
2260 netdev_for_each_uc_addr(ha, netdev) {
2261 if (i == rar_entries)
2263 e1000_rar_set(hw, ha->addr, i++);
2266 netdev_for_each_mc_addr(ha, netdev) {
2267 if (i == rar_entries) {
2268 /* load any remaining addresses into the hash table */
2269 u32 hash_reg, hash_bit, mta;
2270 hash_value = e1000_hash_mc_addr(hw, ha->addr);
2271 hash_reg = (hash_value >> 5) & 0x7F;
2272 hash_bit = hash_value & 0x1F;
2273 mta = (1 << hash_bit);
2274 mcarray[hash_reg] |= mta;
2276 e1000_rar_set(hw, ha->addr, i++);
2280 for (; i < rar_entries; i++) {
2281 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2282 E1000_WRITE_FLUSH();
2283 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2284 E1000_WRITE_FLUSH();
2287 /* write the hash table completely, write from bottom to avoid
2288 * both stupid write combining chipsets, and flushing each write
2290 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2291 /* If we are on an 82544 has an errata where writing odd
2292 * offsets overwrites the previous even offset, but writing
2293 * backwards over the range solves the issue by always
2294 * writing the odd offset first
2296 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2298 E1000_WRITE_FLUSH();
2300 if (hw->mac_type == e1000_82542_rev2_0)
2301 e1000_leave_82542_rst(adapter);
2307 * e1000_update_phy_info_task - get phy info
2308 * @work: work struct contained inside adapter struct
2310 * Need to wait a few seconds after link up to get diagnostic information from
2313 static void e1000_update_phy_info_task(struct work_struct *work)
2315 struct e1000_adapter *adapter = container_of(work,
2316 struct e1000_adapter,
2317 phy_info_task.work);
2319 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2323 * e1000_82547_tx_fifo_stall_task - task to complete work
2324 * @work: work struct contained inside adapter struct
2326 static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
2328 struct e1000_adapter *adapter = container_of(work,
2329 struct e1000_adapter,
2330 fifo_stall_task.work);
2331 struct e1000_hw *hw = &adapter->hw;
2332 struct net_device *netdev = adapter->netdev;
2335 if (atomic_read(&adapter->tx_fifo_stall)) {
2336 if ((er32(TDT) == er32(TDH)) &&
2337 (er32(TDFT) == er32(TDFH)) &&
2338 (er32(TDFTS) == er32(TDFHS))) {
2340 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2341 ew32(TDFT, adapter->tx_head_addr);
2342 ew32(TDFH, adapter->tx_head_addr);
2343 ew32(TDFTS, adapter->tx_head_addr);
2344 ew32(TDFHS, adapter->tx_head_addr);
2346 E1000_WRITE_FLUSH();
2348 adapter->tx_fifo_head = 0;
2349 atomic_set(&adapter->tx_fifo_stall, 0);
2350 netif_wake_queue(netdev);
2351 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
2352 schedule_delayed_work(&adapter->fifo_stall_task, 1);
2357 bool e1000_has_link(struct e1000_adapter *adapter)
2359 struct e1000_hw *hw = &adapter->hw;
2360 bool link_active = false;
2362 /* get_link_status is set on LSC (link status) interrupt or rx
2363 * sequence error interrupt (except on intel ce4100).
2364 * get_link_status will stay false until the
2365 * e1000_check_for_link establishes link for copper adapters
2368 switch (hw->media_type) {
2369 case e1000_media_type_copper:
2370 if (hw->mac_type == e1000_ce4100)
2371 hw->get_link_status = 1;
2372 if (hw->get_link_status) {
2373 e1000_check_for_link(hw);
2374 link_active = !hw->get_link_status;
2379 case e1000_media_type_fiber:
2380 e1000_check_for_link(hw);
2381 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2383 case e1000_media_type_internal_serdes:
2384 e1000_check_for_link(hw);
2385 link_active = hw->serdes_has_link;
2395 * e1000_watchdog - work function
2396 * @work: work struct contained inside adapter struct
2398 static void e1000_watchdog(struct work_struct *work)
2400 struct e1000_adapter *adapter = container_of(work,
2401 struct e1000_adapter,
2402 watchdog_task.work);
2403 struct e1000_hw *hw = &adapter->hw;
2404 struct net_device *netdev = adapter->netdev;
2405 struct e1000_tx_ring *txdr = adapter->tx_ring;
2408 link = e1000_has_link(adapter);
2409 if ((netif_carrier_ok(netdev)) && link)
2413 if (!netif_carrier_ok(netdev)) {
2416 /* update snapshot of PHY registers on LSC */
2417 e1000_get_speed_and_duplex(hw,
2418 &adapter->link_speed,
2419 &adapter->link_duplex);
2422 pr_info("%s NIC Link is Up %d Mbps %s, "
2423 "Flow Control: %s\n",
2425 adapter->link_speed,
2426 adapter->link_duplex == FULL_DUPLEX ?
2427 "Full Duplex" : "Half Duplex",
2428 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2429 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2430 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2431 E1000_CTRL_TFCE) ? "TX" : "None")));
2433 /* adjust timeout factor according to speed/duplex */
2434 adapter->tx_timeout_factor = 1;
2435 switch (adapter->link_speed) {
2438 adapter->tx_timeout_factor = 16;
2442 /* maybe add some timeout factor ? */
2446 /* enable transmits in the hardware */
2448 tctl |= E1000_TCTL_EN;
2451 netif_carrier_on(netdev);
2452 if (!test_bit(__E1000_DOWN, &adapter->flags))
2453 schedule_delayed_work(&adapter->phy_info_task,
2455 adapter->smartspeed = 0;
2458 if (netif_carrier_ok(netdev)) {
2459 adapter->link_speed = 0;
2460 adapter->link_duplex = 0;
2461 pr_info("%s NIC Link is Down\n",
2463 netif_carrier_off(netdev);
2465 if (!test_bit(__E1000_DOWN, &adapter->flags))
2466 schedule_delayed_work(&adapter->phy_info_task,
2470 e1000_smartspeed(adapter);
2474 e1000_update_stats(adapter);
2476 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2477 adapter->tpt_old = adapter->stats.tpt;
2478 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2479 adapter->colc_old = adapter->stats.colc;
2481 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2482 adapter->gorcl_old = adapter->stats.gorcl;
2483 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2484 adapter->gotcl_old = adapter->stats.gotcl;
2486 e1000_update_adaptive(hw);
2488 if (!netif_carrier_ok(netdev)) {
2489 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2490 /* We've lost link, so the controller stops DMA,
2491 * but we've got queued Tx work that's never going
2492 * to get done, so reset controller to flush Tx.
2493 * (Do the reset outside of interrupt context).
2495 adapter->tx_timeout_count++;
2496 schedule_work(&adapter->reset_task);
2497 /* exit immediately since reset is imminent */
2502 /* Simple mode for Interrupt Throttle Rate (ITR) */
2503 if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) {
2504 /* Symmetric Tx/Rx gets a reduced ITR=2000;
2505 * Total asymmetrical Tx or Rx gets ITR=8000;
2506 * everyone else is between 2000-8000.
2508 u32 goc = (adapter->gotcl + adapter->gorcl) / 10000;
2509 u32 dif = (adapter->gotcl > adapter->gorcl ?
2510 adapter->gotcl - adapter->gorcl :
2511 adapter->gorcl - adapter->gotcl) / 10000;
2512 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2514 ew32(ITR, 1000000000 / (itr * 256));
2517 /* Cause software interrupt to ensure rx ring is cleaned */
2518 ew32(ICS, E1000_ICS_RXDMT0);
2520 /* Force detection of hung controller every watchdog period */
2521 adapter->detect_tx_hung = true;
2523 /* Reschedule the task */
2524 if (!test_bit(__E1000_DOWN, &adapter->flags))
2525 schedule_delayed_work(&adapter->watchdog_task, 2 * HZ);
2528 enum latency_range {
2532 latency_invalid = 255
2536 * e1000_update_itr - update the dynamic ITR value based on statistics
2537 * @adapter: pointer to adapter
2538 * @itr_setting: current adapter->itr
2539 * @packets: the number of packets during this measurement interval
2540 * @bytes: the number of bytes during this measurement interval
2542 * Stores a new ITR value based on packets and byte
2543 * counts during the last interrupt. The advantage of per interrupt
2544 * computation is faster updates and more accurate ITR for the current
2545 * traffic pattern. Constants in this function were computed
2546 * based on theoretical maximum wire speed and thresholds were set based
2547 * on testing data as well as attempting to minimize response time
2548 * while increasing bulk throughput.
2549 * this functionality is controlled by the InterruptThrottleRate module
2550 * parameter (see e1000_param.c)
2552 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2553 u16 itr_setting, int packets, int bytes)
2555 unsigned int retval = itr_setting;
2556 struct e1000_hw *hw = &adapter->hw;
2558 if (unlikely(hw->mac_type < e1000_82540))
2559 goto update_itr_done;
2562 goto update_itr_done;
2564 switch (itr_setting) {
2565 case lowest_latency:
2566 /* jumbo frames get bulk treatment*/
2567 if (bytes/packets > 8000)
2568 retval = bulk_latency;
2569 else if ((packets < 5) && (bytes > 512))
2570 retval = low_latency;
2572 case low_latency: /* 50 usec aka 20000 ints/s */
2573 if (bytes > 10000) {
2574 /* jumbo frames need bulk latency setting */
2575 if (bytes/packets > 8000)
2576 retval = bulk_latency;
2577 else if ((packets < 10) || ((bytes/packets) > 1200))
2578 retval = bulk_latency;
2579 else if ((packets > 35))
2580 retval = lowest_latency;
2581 } else if (bytes/packets > 2000)
2582 retval = bulk_latency;
2583 else if (packets <= 2 && bytes < 512)
2584 retval = lowest_latency;
2586 case bulk_latency: /* 250 usec aka 4000 ints/s */
2587 if (bytes > 25000) {
2589 retval = low_latency;
2590 } else if (bytes < 6000) {
2591 retval = low_latency;
2600 static void e1000_set_itr(struct e1000_adapter *adapter)
2602 struct e1000_hw *hw = &adapter->hw;
2604 u32 new_itr = adapter->itr;
2606 if (unlikely(hw->mac_type < e1000_82540))
2609 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2610 if (unlikely(adapter->link_speed != SPEED_1000)) {
2616 adapter->tx_itr = e1000_update_itr(adapter, adapter->tx_itr,
2617 adapter->total_tx_packets,
2618 adapter->total_tx_bytes);
2619 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2620 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2621 adapter->tx_itr = low_latency;
2623 adapter->rx_itr = e1000_update_itr(adapter, adapter->rx_itr,
2624 adapter->total_rx_packets,
2625 adapter->total_rx_bytes);
2626 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2627 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2628 adapter->rx_itr = low_latency;
2630 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2632 switch (current_itr) {
2633 /* counts and packets in update_itr are dependent on these numbers */
2634 case lowest_latency:
2638 new_itr = 20000; /* aka hwitr = ~200 */
2648 if (new_itr != adapter->itr) {
2649 /* this attempts to bias the interrupt rate towards Bulk
2650 * by adding intermediate steps when interrupt rate is
2653 new_itr = new_itr > adapter->itr ?
2654 min(adapter->itr + (new_itr >> 2), new_itr) :
2656 adapter->itr = new_itr;
2657 ew32(ITR, 1000000000 / (new_itr * 256));
2661 #define E1000_TX_FLAGS_CSUM 0x00000001
2662 #define E1000_TX_FLAGS_VLAN 0x00000002
2663 #define E1000_TX_FLAGS_TSO 0x00000004
2664 #define E1000_TX_FLAGS_IPV4 0x00000008
2665 #define E1000_TX_FLAGS_NO_FCS 0x00000010
2666 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2667 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2669 static int e1000_tso(struct e1000_adapter *adapter,
2670 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2672 struct e1000_context_desc *context_desc;
2673 struct e1000_buffer *buffer_info;
2676 u16 ipcse = 0, tucse, mss;
2677 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2680 if (skb_is_gso(skb)) {
2681 if (skb_header_cloned(skb)) {
2682 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2687 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2688 mss = skb_shinfo(skb)->gso_size;
2689 if (skb->protocol == htons(ETH_P_IP)) {
2690 struct iphdr *iph = ip_hdr(skb);
2693 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2697 cmd_length = E1000_TXD_CMD_IP;
2698 ipcse = skb_transport_offset(skb) - 1;
2699 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2700 ipv6_hdr(skb)->payload_len = 0;
2701 tcp_hdr(skb)->check =
2702 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2703 &ipv6_hdr(skb)->daddr,
2707 ipcss = skb_network_offset(skb);
2708 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2709 tucss = skb_transport_offset(skb);
2710 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2713 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2714 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2716 i = tx_ring->next_to_use;
2717 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2718 buffer_info = &tx_ring->buffer_info[i];
2720 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2721 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2722 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2723 context_desc->upper_setup.tcp_fields.tucss = tucss;
2724 context_desc->upper_setup.tcp_fields.tucso = tucso;
2725 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2726 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2727 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2728 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2730 buffer_info->time_stamp = jiffies;
2731 buffer_info->next_to_watch = i;
2733 if (++i == tx_ring->count) i = 0;
2734 tx_ring->next_to_use = i;
2741 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2742 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2744 struct e1000_context_desc *context_desc;
2745 struct e1000_buffer *buffer_info;
2748 u32 cmd_len = E1000_TXD_CMD_DEXT;
2750 if (skb->ip_summed != CHECKSUM_PARTIAL)
2753 switch (skb->protocol) {
2754 case cpu_to_be16(ETH_P_IP):
2755 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2756 cmd_len |= E1000_TXD_CMD_TCP;
2758 case cpu_to_be16(ETH_P_IPV6):
2759 /* XXX not handling all IPV6 headers */
2760 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2761 cmd_len |= E1000_TXD_CMD_TCP;
2764 if (unlikely(net_ratelimit()))
2765 e_warn(drv, "checksum_partial proto=%x!\n",
2770 css = skb_checksum_start_offset(skb);
2772 i = tx_ring->next_to_use;
2773 buffer_info = &tx_ring->buffer_info[i];
2774 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2776 context_desc->lower_setup.ip_config = 0;
2777 context_desc->upper_setup.tcp_fields.tucss = css;
2778 context_desc->upper_setup.tcp_fields.tucso =
2779 css + skb->csum_offset;
2780 context_desc->upper_setup.tcp_fields.tucse = 0;
2781 context_desc->tcp_seg_setup.data = 0;
2782 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2784 buffer_info->time_stamp = jiffies;
2785 buffer_info->next_to_watch = i;
2787 if (unlikely(++i == tx_ring->count)) i = 0;
2788 tx_ring->next_to_use = i;
2793 #define E1000_MAX_TXD_PWR 12
2794 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2796 static int e1000_tx_map(struct e1000_adapter *adapter,
2797 struct e1000_tx_ring *tx_ring,
2798 struct sk_buff *skb, unsigned int first,
2799 unsigned int max_per_txd, unsigned int nr_frags,
2802 struct e1000_hw *hw = &adapter->hw;
2803 struct pci_dev *pdev = adapter->pdev;
2804 struct e1000_buffer *buffer_info;
2805 unsigned int len = skb_headlen(skb);
2806 unsigned int offset = 0, size, count = 0, i;
2807 unsigned int f, bytecount, segs;
2809 i = tx_ring->next_to_use;
2812 buffer_info = &tx_ring->buffer_info[i];
2813 size = min(len, max_per_txd);
2814 /* Workaround for Controller erratum --
2815 * descriptor for non-tso packet in a linear SKB that follows a
2816 * tso gets written back prematurely before the data is fully
2817 * DMA'd to the controller
2819 if (!skb->data_len && tx_ring->last_tx_tso &&
2821 tx_ring->last_tx_tso = false;
2825 /* Workaround for premature desc write-backs
2826 * in TSO mode. Append 4-byte sentinel desc
2828 if (unlikely(mss && !nr_frags && size == len && size > 8))
2830 /* work-around for errata 10 and it applies
2831 * to all controllers in PCI-X mode
2832 * The fix is to make sure that the first descriptor of a
2833 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2835 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
2836 (size > 2015) && count == 0))
2839 /* Workaround for potential 82544 hang in PCI-X. Avoid
2840 * terminating buffers within evenly-aligned dwords.
2842 if (unlikely(adapter->pcix_82544 &&
2843 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2847 buffer_info->length = size;
2848 /* set time_stamp *before* dma to help avoid a possible race */
2849 buffer_info->time_stamp = jiffies;
2850 buffer_info->mapped_as_page = false;
2851 buffer_info->dma = dma_map_single(&pdev->dev,
2853 size, DMA_TO_DEVICE);
2854 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2856 buffer_info->next_to_watch = i;
2863 if (unlikely(i == tx_ring->count))
2868 for (f = 0; f < nr_frags; f++) {
2869 const struct skb_frag_struct *frag;
2871 frag = &skb_shinfo(skb)->frags[f];
2872 len = skb_frag_size(frag);
2876 unsigned long bufend;
2878 if (unlikely(i == tx_ring->count))
2881 buffer_info = &tx_ring->buffer_info[i];
2882 size = min(len, max_per_txd);
2883 /* Workaround for premature desc write-backs
2884 * in TSO mode. Append 4-byte sentinel desc
2886 if (unlikely(mss && f == (nr_frags-1) &&
2887 size == len && size > 8))
2889 /* Workaround for potential 82544 hang in PCI-X.
2890 * Avoid terminating buffers within evenly-aligned
2893 bufend = (unsigned long)
2894 page_to_phys(skb_frag_page(frag));
2895 bufend += offset + size - 1;
2896 if (unlikely(adapter->pcix_82544 &&
2901 buffer_info->length = size;
2902 buffer_info->time_stamp = jiffies;
2903 buffer_info->mapped_as_page = true;
2904 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
2905 offset, size, DMA_TO_DEVICE);
2906 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2908 buffer_info->next_to_watch = i;
2916 segs = skb_shinfo(skb)->gso_segs ?: 1;
2917 /* multiply data chunks by size of headers */
2918 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
2920 tx_ring->buffer_info[i].skb = skb;
2921 tx_ring->buffer_info[i].segs = segs;
2922 tx_ring->buffer_info[i].bytecount = bytecount;
2923 tx_ring->buffer_info[first].next_to_watch = i;
2928 dev_err(&pdev->dev, "TX DMA map failed\n");
2929 buffer_info->dma = 0;
2935 i += tx_ring->count;
2937 buffer_info = &tx_ring->buffer_info[i];
2938 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2944 static void e1000_tx_queue(struct e1000_adapter *adapter,
2945 struct e1000_tx_ring *tx_ring, int tx_flags,
2948 struct e1000_hw *hw = &adapter->hw;
2949 struct e1000_tx_desc *tx_desc = NULL;
2950 struct e1000_buffer *buffer_info;
2951 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2954 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2955 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2957 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2959 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2960 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2963 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2964 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2965 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2968 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2969 txd_lower |= E1000_TXD_CMD_VLE;
2970 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2973 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
2974 txd_lower &= ~(E1000_TXD_CMD_IFCS);
2976 i = tx_ring->next_to_use;
2979 buffer_info = &tx_ring->buffer_info[i];
2980 tx_desc = E1000_TX_DESC(*tx_ring, i);
2981 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2982 tx_desc->lower.data =
2983 cpu_to_le32(txd_lower | buffer_info->length);
2984 tx_desc->upper.data = cpu_to_le32(txd_upper);
2985 if (unlikely(++i == tx_ring->count)) i = 0;
2988 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2990 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
2991 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
2992 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
2994 /* Force memory writes to complete before letting h/w
2995 * know there are new descriptors to fetch. (Only
2996 * applicable for weak-ordered memory model archs,
3001 tx_ring->next_to_use = i;
3002 writel(i, hw->hw_addr + tx_ring->tdt);
3003 /* we need this if more than one processor can write to our tail
3004 * at a time, it synchronizes IO on IA64/Altix systems
3009 /* 82547 workaround to avoid controller hang in half-duplex environment.
3010 * The workaround is to avoid queuing a large packet that would span
3011 * the internal Tx FIFO ring boundary by notifying the stack to resend
3012 * the packet at a later time. This gives the Tx FIFO an opportunity to
3013 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3014 * to the beginning of the Tx FIFO.
3017 #define E1000_FIFO_HDR 0x10
3018 #define E1000_82547_PAD_LEN 0x3E0
3020 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3021 struct sk_buff *skb)
3023 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3024 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3026 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3028 if (adapter->link_duplex != HALF_DUPLEX)
3029 goto no_fifo_stall_required;
3031 if (atomic_read(&adapter->tx_fifo_stall))
3034 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3035 atomic_set(&adapter->tx_fifo_stall, 1);
3039 no_fifo_stall_required:
3040 adapter->tx_fifo_head += skb_fifo_len;
3041 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3042 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3046 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3048 struct e1000_adapter *adapter = netdev_priv(netdev);
3049 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3051 netif_stop_queue(netdev);
3052 /* Herbert's original patch had:
3053 * smp_mb__after_netif_stop_queue();
3054 * but since that doesn't exist yet, just open code it.
3058 /* We need to check again in a case another CPU has just
3059 * made room available.
3061 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3065 netif_start_queue(netdev);
3066 ++adapter->restart_queue;
3070 static int e1000_maybe_stop_tx(struct net_device *netdev,
3071 struct e1000_tx_ring *tx_ring, int size)
3073 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3075 return __e1000_maybe_stop_tx(netdev, size);
3078 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3079 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3080 struct net_device *netdev)
3082 struct e1000_adapter *adapter = netdev_priv(netdev);
3083 struct e1000_hw *hw = &adapter->hw;
3084 struct e1000_tx_ring *tx_ring;
3085 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3086 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3087 unsigned int tx_flags = 0;
3088 unsigned int len = skb_headlen(skb);
3089 unsigned int nr_frags;
3095 /* This goes back to the question of how to logically map a Tx queue
3096 * to a flow. Right now, performance is impacted slightly negatively
3097 * if using multiple Tx queues. If the stack breaks away from a
3098 * single qdisc implementation, we can look at this again.
3100 tx_ring = adapter->tx_ring;
3102 if (unlikely(skb->len <= 0)) {
3103 dev_kfree_skb_any(skb);
3104 return NETDEV_TX_OK;
3107 /* On PCI/PCI-X HW, if packet size is less than ETH_ZLEN,
3108 * packets may get corrupted during padding by HW.
3109 * To WA this issue, pad all small packets manually.
3111 if (skb->len < ETH_ZLEN) {
3112 if (skb_pad(skb, ETH_ZLEN - skb->len))
3113 return NETDEV_TX_OK;
3114 skb->len = ETH_ZLEN;
3115 skb_set_tail_pointer(skb, ETH_ZLEN);
3118 mss = skb_shinfo(skb)->gso_size;
3119 /* The controller does a simple calculation to
3120 * make sure there is enough room in the FIFO before
3121 * initiating the DMA for each buffer. The calc is:
3122 * 4 = ceil(buffer len/mss). To make sure we don't
3123 * overrun the FIFO, adjust the max buffer len if mss
3128 max_per_txd = min(mss << 2, max_per_txd);
3129 max_txd_pwr = fls(max_per_txd) - 1;
3131 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3132 if (skb->data_len && hdr_len == len) {
3133 switch (hw->mac_type) {
3134 unsigned int pull_size;
3136 /* Make sure we have room to chop off 4 bytes,
3137 * and that the end alignment will work out to
3138 * this hardware's requirements
3139 * NOTE: this is a TSO only workaround
3140 * if end byte alignment not correct move us
3141 * into the next dword
3143 if ((unsigned long)(skb_tail_pointer(skb) - 1)
3147 pull_size = min((unsigned int)4, skb->data_len);
3148 if (!__pskb_pull_tail(skb, pull_size)) {
3149 e_err(drv, "__pskb_pull_tail "
3151 dev_kfree_skb_any(skb);
3152 return NETDEV_TX_OK;
3154 len = skb_headlen(skb);
3163 /* reserve a descriptor for the offload context */
3164 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3168 /* Controller Erratum workaround */
3169 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3172 count += TXD_USE_COUNT(len, max_txd_pwr);
3174 if (adapter->pcix_82544)
3177 /* work-around for errata 10 and it applies to all controllers
3178 * in PCI-X mode, so add one more descriptor to the count
3180 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3184 nr_frags = skb_shinfo(skb)->nr_frags;
3185 for (f = 0; f < nr_frags; f++)
3186 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
3188 if (adapter->pcix_82544)
3191 /* need: count + 2 desc gap to keep tail from touching
3192 * head, otherwise try next time
3194 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3195 return NETDEV_TX_BUSY;
3197 if (unlikely((hw->mac_type == e1000_82547) &&
3198 (e1000_82547_fifo_workaround(adapter, skb)))) {
3199 netif_stop_queue(netdev);
3200 if (!test_bit(__E1000_DOWN, &adapter->flags))
3201 schedule_delayed_work(&adapter->fifo_stall_task, 1);
3202 return NETDEV_TX_BUSY;
3205 if (vlan_tx_tag_present(skb)) {
3206 tx_flags |= E1000_TX_FLAGS_VLAN;
3207 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3210 first = tx_ring->next_to_use;
3212 tso = e1000_tso(adapter, tx_ring, skb);
3214 dev_kfree_skb_any(skb);
3215 return NETDEV_TX_OK;
3219 if (likely(hw->mac_type != e1000_82544))
3220 tx_ring->last_tx_tso = true;
3221 tx_flags |= E1000_TX_FLAGS_TSO;
3222 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3223 tx_flags |= E1000_TX_FLAGS_CSUM;
3225 if (likely(skb->protocol == htons(ETH_P_IP)))
3226 tx_flags |= E1000_TX_FLAGS_IPV4;
3228 if (unlikely(skb->no_fcs))
3229 tx_flags |= E1000_TX_FLAGS_NO_FCS;
3231 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3235 netdev_sent_queue(netdev, skb->len);
3236 skb_tx_timestamp(skb);
3238 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3239 /* Make sure there is space in the ring for the next send. */
3240 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3243 dev_kfree_skb_any(skb);
3244 tx_ring->buffer_info[first].time_stamp = 0;
3245 tx_ring->next_to_use = first;
3248 return NETDEV_TX_OK;
3251 #define NUM_REGS 38 /* 1 based count */
3252 static void e1000_regdump(struct e1000_adapter *adapter)
3254 struct e1000_hw *hw = &adapter->hw;
3256 u32 *regs_buff = regs;
3259 static const char * const reg_name[] = {
3261 "RCTL", "RDLEN", "RDH", "RDT", "RDTR",
3262 "TCTL", "TDBAL", "TDBAH", "TDLEN", "TDH", "TDT",
3263 "TIDV", "TXDCTL", "TADV", "TARC0",
3264 "TDBAL1", "TDBAH1", "TDLEN1", "TDH1", "TDT1",
3266 "CTRL_EXT", "ERT", "RDBAL", "RDBAH",
3267 "TDFH", "TDFT", "TDFHS", "TDFTS", "TDFPC",
3268 "RDFH", "RDFT", "RDFHS", "RDFTS", "RDFPC"
3271 regs_buff[0] = er32(CTRL);
3272 regs_buff[1] = er32(STATUS);
3274 regs_buff[2] = er32(RCTL);
3275 regs_buff[3] = er32(RDLEN);
3276 regs_buff[4] = er32(RDH);
3277 regs_buff[5] = er32(RDT);
3278 regs_buff[6] = er32(RDTR);
3280 regs_buff[7] = er32(TCTL);
3281 regs_buff[8] = er32(TDBAL);
3282 regs_buff[9] = er32(TDBAH);
3283 regs_buff[10] = er32(TDLEN);
3284 regs_buff[11] = er32(TDH);
3285 regs_buff[12] = er32(TDT);
3286 regs_buff[13] = er32(TIDV);
3287 regs_buff[14] = er32(TXDCTL);
3288 regs_buff[15] = er32(TADV);
3289 regs_buff[16] = er32(TARC0);
3291 regs_buff[17] = er32(TDBAL1);
3292 regs_buff[18] = er32(TDBAH1);
3293 regs_buff[19] = er32(TDLEN1);
3294 regs_buff[20] = er32(TDH1);
3295 regs_buff[21] = er32(TDT1);
3296 regs_buff[22] = er32(TXDCTL1);
3297 regs_buff[23] = er32(TARC1);
3298 regs_buff[24] = er32(CTRL_EXT);
3299 regs_buff[25] = er32(ERT);
3300 regs_buff[26] = er32(RDBAL0);
3301 regs_buff[27] = er32(RDBAH0);
3302 regs_buff[28] = er32(TDFH);
3303 regs_buff[29] = er32(TDFT);
3304 regs_buff[30] = er32(TDFHS);
3305 regs_buff[31] = er32(TDFTS);
3306 regs_buff[32] = er32(TDFPC);
3307 regs_buff[33] = er32(RDFH);
3308 regs_buff[34] = er32(RDFT);
3309 regs_buff[35] = er32(RDFHS);
3310 regs_buff[36] = er32(RDFTS);
3311 regs_buff[37] = er32(RDFPC);
3313 pr_info("Register dump\n");
3314 for (i = 0; i < NUM_REGS; i++)
3315 pr_info("%-15s %08x\n", reg_name[i], regs_buff[i]);
3319 * e1000_dump: Print registers, tx ring and rx ring
3321 static void e1000_dump(struct e1000_adapter *adapter)
3323 /* this code doesn't handle multiple rings */
3324 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3325 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
3328 if (!netif_msg_hw(adapter))
3331 /* Print Registers */
3332 e1000_regdump(adapter);
3335 pr_info("TX Desc ring0 dump\n");
3337 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
3339 * Legacy Transmit Descriptor
3340 * +--------------------------------------------------------------+
3341 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
3342 * +--------------------------------------------------------------+
3343 * 8 | Special | CSS | Status | CMD | CSO | Length |
3344 * +--------------------------------------------------------------+
3345 * 63 48 47 36 35 32 31 24 23 16 15 0
3347 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
3348 * 63 48 47 40 39 32 31 16 15 8 7 0
3349 * +----------------------------------------------------------------+
3350 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
3351 * +----------------------------------------------------------------+
3352 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
3353 * +----------------------------------------------------------------+
3354 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3356 * Extended Data Descriptor (DTYP=0x1)
3357 * +----------------------------------------------------------------+
3358 * 0 | Buffer Address [63:0] |
3359 * +----------------------------------------------------------------+
3360 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
3361 * +----------------------------------------------------------------+
3362 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3364 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestmp bi->skb\n");
3365 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestmp bi->skb\n");
3367 if (!netif_msg_tx_done(adapter))
3368 goto rx_ring_summary;
3370 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
3371 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
3372 struct e1000_buffer *buffer_info = &tx_ring->buffer_info[i];
3373 struct my_u { __le64 a; __le64 b; };
3374 struct my_u *u = (struct my_u *)tx_desc;
3377 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
3379 else if (i == tx_ring->next_to_use)
3381 else if (i == tx_ring->next_to_clean)
3386 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p %s\n",
3387 ((le64_to_cpu(u->b) & (1<<20)) ? 'd' : 'c'), i,
3388 le64_to_cpu(u->a), le64_to_cpu(u->b),
3389 (u64)buffer_info->dma, buffer_info->length,
3390 buffer_info->next_to_watch,
3391 (u64)buffer_info->time_stamp, buffer_info->skb, type);
3396 pr_info("\nRX Desc ring dump\n");
3398 /* Legacy Receive Descriptor Format
3400 * +-----------------------------------------------------+
3401 * | Buffer Address [63:0] |
3402 * +-----------------------------------------------------+
3403 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
3404 * +-----------------------------------------------------+
3405 * 63 48 47 40 39 32 31 16 15 0
3407 pr_info("R[desc] [address 63:0 ] [vl er S cks ln] [bi->dma ] [bi->skb]\n");
3409 if (!netif_msg_rx_status(adapter))
3412 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
3413 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
3414 struct e1000_buffer *buffer_info = &rx_ring->buffer_info[i];
3415 struct my_u { __le64 a; __le64 b; };
3416 struct my_u *u = (struct my_u *)rx_desc;
3419 if (i == rx_ring->next_to_use)
3421 else if (i == rx_ring->next_to_clean)
3426 pr_info("R[0x%03X] %016llX %016llX %016llX %p %s\n",
3427 i, le64_to_cpu(u->a), le64_to_cpu(u->b),
3428 (u64)buffer_info->dma, buffer_info->skb, type);
3431 /* dump the descriptor caches */
3433 pr_info("Rx descriptor cache in 64bit format\n");
3434 for (i = 0x6000; i <= 0x63FF ; i += 0x10) {
3435 pr_info("R%04X: %08X|%08X %08X|%08X\n",
3437 readl(adapter->hw.hw_addr + i+4),
3438 readl(adapter->hw.hw_addr + i),
3439 readl(adapter->hw.hw_addr + i+12),
3440 readl(adapter->hw.hw_addr + i+8));
3443 pr_info("Tx descriptor cache in 64bit format\n");
3444 for (i = 0x7000; i <= 0x73FF ; i += 0x10) {
3445 pr_info("T%04X: %08X|%08X %08X|%08X\n",
3447 readl(adapter->hw.hw_addr + i+4),
3448 readl(adapter->hw.hw_addr + i),
3449 readl(adapter->hw.hw_addr + i+12),
3450 readl(adapter->hw.hw_addr + i+8));
3457 * e1000_tx_timeout - Respond to a Tx Hang
3458 * @netdev: network interface device structure
3460 static void e1000_tx_timeout(struct net_device *netdev)
3462 struct e1000_adapter *adapter = netdev_priv(netdev);
3464 /* Do the reset outside of interrupt context */
3465 adapter->tx_timeout_count++;
3466 schedule_work(&adapter->reset_task);
3469 static void e1000_reset_task(struct work_struct *work)
3471 struct e1000_adapter *adapter =
3472 container_of(work, struct e1000_adapter, reset_task);
3474 e_err(drv, "Reset adapter\n");
3475 e1000_reinit_locked(adapter);
3479 * e1000_get_stats - Get System Network Statistics
3480 * @netdev: network interface device structure
3482 * Returns the address of the device statistics structure.
3483 * The statistics are actually updated from the watchdog.
3485 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3487 /* only return the current stats */
3488 return &netdev->stats;
3492 * e1000_change_mtu - Change the Maximum Transfer Unit
3493 * @netdev: network interface device structure
3494 * @new_mtu: new value for maximum frame size
3496 * Returns 0 on success, negative on failure
3498 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3500 struct e1000_adapter *adapter = netdev_priv(netdev);
3501 struct e1000_hw *hw = &adapter->hw;
3502 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3504 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3505 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3506 e_err(probe, "Invalid MTU setting\n");
3510 /* Adapter-specific max frame size limits. */
3511 switch (hw->mac_type) {
3512 case e1000_undefined ... e1000_82542_rev2_1:
3513 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3514 e_err(probe, "Jumbo Frames not supported.\n");
3519 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3523 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3525 /* e1000_down has a dependency on max_frame_size */
3526 hw->max_frame_size = max_frame;
3527 if (netif_running(netdev))
3528 e1000_down(adapter);
3530 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3531 * means we reserve 2 more, this pushes us to allocate from the next
3533 * i.e. RXBUFFER_2048 --> size-4096 slab
3534 * however with the new *_jumbo_rx* routines, jumbo receives will use
3538 if (max_frame <= E1000_RXBUFFER_2048)
3539 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3541 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3542 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3543 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3544 adapter->rx_buffer_len = PAGE_SIZE;
3547 /* adjust allocation if LPE protects us, and we aren't using SBP */
3548 if (!hw->tbi_compatibility_on &&
3549 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3550 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3551 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3553 pr_info("%s changing MTU from %d to %d\n",
3554 netdev->name, netdev->mtu, new_mtu);
3555 netdev->mtu = new_mtu;
3557 if (netif_running(netdev))
3560 e1000_reset(adapter);
3562 clear_bit(__E1000_RESETTING, &adapter->flags);
3568 * e1000_update_stats - Update the board statistics counters
3569 * @adapter: board private structure
3571 void e1000_update_stats(struct e1000_adapter *adapter)
3573 struct net_device *netdev = adapter->netdev;
3574 struct e1000_hw *hw = &adapter->hw;
3575 struct pci_dev *pdev = adapter->pdev;
3576 unsigned long flags;
3579 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3581 /* Prevent stats update while adapter is being reset, or if the pci
3582 * connection is down.
3584 if (adapter->link_speed == 0)
3586 if (pci_channel_offline(pdev))
3589 spin_lock_irqsave(&adapter->stats_lock, flags);
3591 /* these counters are modified from e1000_tbi_adjust_stats,
3592 * called from the interrupt context, so they must only
3593 * be written while holding adapter->stats_lock
3596 adapter->stats.crcerrs += er32(CRCERRS);
3597 adapter->stats.gprc += er32(GPRC);
3598 adapter->stats.gorcl += er32(GORCL);
3599 adapter->stats.gorch += er32(GORCH);
3600 adapter->stats.bprc += er32(BPRC);
3601 adapter->stats.mprc += er32(MPRC);
3602 adapter->stats.roc += er32(ROC);
3604 adapter->stats.prc64 += er32(PRC64);
3605 adapter->stats.prc127 += er32(PRC127);
3606 adapter->stats.prc255 += er32(PRC255);
3607 adapter->stats.prc511 += er32(PRC511);
3608 adapter->stats.prc1023 += er32(PRC1023);
3609 adapter->stats.prc1522 += er32(PRC1522);
3611 adapter->stats.symerrs += er32(SYMERRS);
3612 adapter->stats.mpc += er32(MPC);
3613 adapter->stats.scc += er32(SCC);
3614 adapter->stats.ecol += er32(ECOL);
3615 adapter->stats.mcc += er32(MCC);
3616 adapter->stats.latecol += er32(LATECOL);
3617 adapter->stats.dc += er32(DC);
3618 adapter->stats.sec += er32(SEC);
3619 adapter->stats.rlec += er32(RLEC);
3620 adapter->stats.xonrxc += er32(XONRXC);
3621 adapter->stats.xontxc += er32(XONTXC);
3622 adapter->stats.xoffrxc += er32(XOFFRXC);
3623 adapter->stats.xofftxc += er32(XOFFTXC);
3624 adapter->stats.fcruc += er32(FCRUC);
3625 adapter->stats.gptc += er32(GPTC);
3626 adapter->stats.gotcl += er32(GOTCL);
3627 adapter->stats.gotch += er32(GOTCH);
3628 adapter->stats.rnbc += er32(RNBC);
3629 adapter->stats.ruc += er32(RUC);
3630 adapter->stats.rfc += er32(RFC);
3631 adapter->stats.rjc += er32(RJC);
3632 adapter->stats.torl += er32(TORL);
3633 adapter->stats.torh += er32(TORH);
3634 adapter->stats.totl += er32(TOTL);
3635 adapter->stats.toth += er32(TOTH);
3636 adapter->stats.tpr += er32(TPR);
3638 adapter->stats.ptc64 += er32(PTC64);
3639 adapter->stats.ptc127 += er32(PTC127);
3640 adapter->stats.ptc255 += er32(PTC255);
3641 adapter->stats.ptc511 += er32(PTC511);
3642 adapter->stats.ptc1023 += er32(PTC1023);
3643 adapter->stats.ptc1522 += er32(PTC1522);
3645 adapter->stats.mptc += er32(MPTC);
3646 adapter->stats.bptc += er32(BPTC);
3648 /* used for adaptive IFS */
3650 hw->tx_packet_delta = er32(TPT);
3651 adapter->stats.tpt += hw->tx_packet_delta;
3652 hw->collision_delta = er32(COLC);
3653 adapter->stats.colc += hw->collision_delta;
3655 if (hw->mac_type >= e1000_82543) {
3656 adapter->stats.algnerrc += er32(ALGNERRC);
3657 adapter->stats.rxerrc += er32(RXERRC);
3658 adapter->stats.tncrs += er32(TNCRS);
3659 adapter->stats.cexterr += er32(CEXTERR);
3660 adapter->stats.tsctc += er32(TSCTC);
3661 adapter->stats.tsctfc += er32(TSCTFC);
3664 /* Fill out the OS statistics structure */
3665 netdev->stats.multicast = adapter->stats.mprc;
3666 netdev->stats.collisions = adapter->stats.colc;
3670 /* RLEC on some newer hardware can be incorrect so build
3671 * our own version based on RUC and ROC
3673 netdev->stats.rx_errors = adapter->stats.rxerrc +
3674 adapter->stats.crcerrs + adapter->stats.algnerrc +
3675 adapter->stats.ruc + adapter->stats.roc +
3676 adapter->stats.cexterr;
3677 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3678 netdev->stats.rx_length_errors = adapter->stats.rlerrc;
3679 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3680 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3681 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3684 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3685 netdev->stats.tx_errors = adapter->stats.txerrc;
3686 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3687 netdev->stats.tx_window_errors = adapter->stats.latecol;
3688 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3689 if (hw->bad_tx_carr_stats_fd &&
3690 adapter->link_duplex == FULL_DUPLEX) {
3691 netdev->stats.tx_carrier_errors = 0;
3692 adapter->stats.tncrs = 0;
3695 /* Tx Dropped needs to be maintained elsewhere */
3698 if (hw->media_type == e1000_media_type_copper) {
3699 if ((adapter->link_speed == SPEED_1000) &&
3700 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3701 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3702 adapter->phy_stats.idle_errors += phy_tmp;
3705 if ((hw->mac_type <= e1000_82546) &&
3706 (hw->phy_type == e1000_phy_m88) &&
3707 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3708 adapter->phy_stats.receive_errors += phy_tmp;
3711 /* Management Stats */
3712 if (hw->has_smbus) {
3713 adapter->stats.mgptc += er32(MGTPTC);
3714 adapter->stats.mgprc += er32(MGTPRC);
3715 adapter->stats.mgpdc += er32(MGTPDC);
3718 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3722 * e1000_intr - Interrupt Handler
3723 * @irq: interrupt number
3724 * @data: pointer to a network interface device structure
3726 static irqreturn_t e1000_intr(int irq, void *data)
3728 struct net_device *netdev = data;
3729 struct e1000_adapter *adapter = netdev_priv(netdev);
3730 struct e1000_hw *hw = &adapter->hw;
3731 u32 icr = er32(ICR);
3733 if (unlikely((!icr)))
3734 return IRQ_NONE; /* Not our interrupt */
3736 /* we might have caused the interrupt, but the above
3737 * read cleared it, and just in case the driver is
3738 * down there is nothing to do so return handled
3740 if (unlikely(test_bit(__E1000_DOWN, &adapter->flags)))
3743 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3744 hw->get_link_status = 1;
3745 /* guard against interrupt when we're going down */
3746 if (!test_bit(__E1000_DOWN, &adapter->flags))
3747 schedule_delayed_work(&adapter->watchdog_task, 1);
3750 /* disable interrupts, without the synchronize_irq bit */
3752 E1000_WRITE_FLUSH();
3754 if (likely(napi_schedule_prep(&adapter->napi))) {
3755 adapter->total_tx_bytes = 0;
3756 adapter->total_tx_packets = 0;
3757 adapter->total_rx_bytes = 0;
3758 adapter->total_rx_packets = 0;
3759 __napi_schedule(&adapter->napi);
3761 /* this really should not happen! if it does it is basically a
3762 * bug, but not a hard error, so enable ints and continue
3764 if (!test_bit(__E1000_DOWN, &adapter->flags))
3765 e1000_irq_enable(adapter);
3772 * e1000_clean - NAPI Rx polling callback
3773 * @adapter: board private structure
3775 static int e1000_clean(struct napi_struct *napi, int budget)
3777 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
3779 int tx_clean_complete = 0, work_done = 0;
3781 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3783 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
3785 if (!tx_clean_complete)
3788 /* If budget not fully consumed, exit the polling mode */
3789 if (work_done < budget) {
3790 if (likely(adapter->itr_setting & 3))
3791 e1000_set_itr(adapter);
3792 napi_complete(napi);
3793 if (!test_bit(__E1000_DOWN, &adapter->flags))
3794 e1000_irq_enable(adapter);
3801 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3802 * @adapter: board private structure
3804 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3805 struct e1000_tx_ring *tx_ring)
3807 struct e1000_hw *hw = &adapter->hw;
3808 struct net_device *netdev = adapter->netdev;
3809 struct e1000_tx_desc *tx_desc, *eop_desc;
3810 struct e1000_buffer *buffer_info;
3811 unsigned int i, eop;
3812 unsigned int count = 0;
3813 unsigned int total_tx_bytes=0, total_tx_packets=0;
3814 unsigned int bytes_compl = 0, pkts_compl = 0;
3816 i = tx_ring->next_to_clean;
3817 eop = tx_ring->buffer_info[i].next_to_watch;
3818 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3820 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3821 (count < tx_ring->count)) {
3822 bool cleaned = false;
3823 rmb(); /* read buffer_info after eop_desc */
3824 for ( ; !cleaned; count++) {
3825 tx_desc = E1000_TX_DESC(*tx_ring, i);
3826 buffer_info = &tx_ring->buffer_info[i];
3827 cleaned = (i == eop);
3830 total_tx_packets += buffer_info->segs;
3831 total_tx_bytes += buffer_info->bytecount;
3832 if (buffer_info->skb) {
3833 bytes_compl += buffer_info->skb->len;
3838 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3839 tx_desc->upper.data = 0;
3841 if (unlikely(++i == tx_ring->count)) i = 0;
3844 eop = tx_ring->buffer_info[i].next_to_watch;
3845 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3848 tx_ring->next_to_clean = i;
3850 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
3852 #define TX_WAKE_THRESHOLD 32
3853 if (unlikely(count && netif_carrier_ok(netdev) &&
3854 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3855 /* Make sure that anybody stopping the queue after this
3856 * sees the new next_to_clean.
3860 if (netif_queue_stopped(netdev) &&
3861 !(test_bit(__E1000_DOWN, &adapter->flags))) {
3862 netif_wake_queue(netdev);
3863 ++adapter->restart_queue;
3867 if (adapter->detect_tx_hung) {
3868 /* Detect a transmit hang in hardware, this serializes the
3869 * check with the clearing of time_stamp and movement of i
3871 adapter->detect_tx_hung = false;
3872 if (tx_ring->buffer_info[eop].time_stamp &&
3873 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3874 (adapter->tx_timeout_factor * HZ)) &&
3875 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3877 /* detected Tx unit hang */
3878 e_err(drv, "Detected Tx Unit Hang\n"
3882 " next_to_use <%x>\n"
3883 " next_to_clean <%x>\n"
3884 "buffer_info[next_to_clean]\n"
3885 " time_stamp <%lx>\n"
3886 " next_to_watch <%x>\n"
3888 " next_to_watch.status <%x>\n",
3889 (unsigned long)(tx_ring - adapter->tx_ring),
3890 readl(hw->hw_addr + tx_ring->tdh),
3891 readl(hw->hw_addr + tx_ring->tdt),
3892 tx_ring->next_to_use,
3893 tx_ring->next_to_clean,
3894 tx_ring->buffer_info[eop].time_stamp,
3897 eop_desc->upper.fields.status);
3898 e1000_dump(adapter);
3899 netif_stop_queue(netdev);
3902 adapter->total_tx_bytes += total_tx_bytes;
3903 adapter->total_tx_packets += total_tx_packets;
3904 netdev->stats.tx_bytes += total_tx_bytes;
3905 netdev->stats.tx_packets += total_tx_packets;
3906 return count < tx_ring->count;
3910 * e1000_rx_checksum - Receive Checksum Offload for 82543
3911 * @adapter: board private structure
3912 * @status_err: receive descriptor status and error fields
3913 * @csum: receive descriptor csum field
3914 * @sk_buff: socket buffer with received data
3916 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3917 u32 csum, struct sk_buff *skb)
3919 struct e1000_hw *hw = &adapter->hw;
3920 u16 status = (u16)status_err;
3921 u8 errors = (u8)(status_err >> 24);
3923 skb_checksum_none_assert(skb);
3925 /* 82543 or newer only */
3926 if (unlikely(hw->mac_type < e1000_82543)) return;
3927 /* Ignore Checksum bit is set */
3928 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3929 /* TCP/UDP checksum error bit is set */
3930 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3931 /* let the stack verify checksum errors */
3932 adapter->hw_csum_err++;
3935 /* TCP/UDP Checksum has not been calculated */
3936 if (!(status & E1000_RXD_STAT_TCPCS))
3939 /* It must be a TCP or UDP packet with a valid checksum */
3940 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3941 /* TCP checksum is good */
3942 skb->ip_summed = CHECKSUM_UNNECESSARY;
3944 adapter->hw_csum_good++;
3948 * e1000_consume_page - helper function
3950 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
3955 skb->data_len += length;
3956 skb->truesize += PAGE_SIZE;
3960 * e1000_receive_skb - helper function to handle rx indications
3961 * @adapter: board private structure
3962 * @status: descriptor status field as written by hardware
3963 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3964 * @skb: pointer to sk_buff to be indicated to stack
3966 static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
3967 __le16 vlan, struct sk_buff *skb)
3969 skb->protocol = eth_type_trans(skb, adapter->netdev);
3971 if (status & E1000_RXD_STAT_VP) {
3972 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
3974 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
3976 napi_gro_receive(&adapter->napi, skb);
3980 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
3981 * @adapter: board private structure
3982 * @rx_ring: ring to clean
3983 * @work_done: amount of napi work completed this call
3984 * @work_to_do: max amount of work allowed for this call to do
3986 * the return value indicates whether actual cleaning was done, there
3987 * is no guarantee that everything was cleaned
3989 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
3990 struct e1000_rx_ring *rx_ring,
3991 int *work_done, int work_to_do)
3993 struct e1000_hw *hw = &adapter->hw;
3994 struct net_device *netdev = adapter->netdev;
3995 struct pci_dev *pdev = adapter->pdev;
3996 struct e1000_rx_desc *rx_desc, *next_rxd;
3997 struct e1000_buffer *buffer_info, *next_buffer;
3998 unsigned long irq_flags;
4001 int cleaned_count = 0;
4002 bool cleaned = false;
4003 unsigned int total_rx_bytes=0, total_rx_packets=0;
4005 i = rx_ring->next_to_clean;
4006 rx_desc = E1000_RX_DESC(*rx_ring, i);
4007 buffer_info = &rx_ring->buffer_info[i];
4009 while (rx_desc->status & E1000_RXD_STAT_DD) {
4010 struct sk_buff *skb;
4013 if (*work_done >= work_to_do)
4016 rmb(); /* read descriptor and rx_buffer_info after status DD */
4018 status = rx_desc->status;
4019 skb = buffer_info->skb;
4020 buffer_info->skb = NULL;
4022 if (++i == rx_ring->count) i = 0;
4023 next_rxd = E1000_RX_DESC(*rx_ring, i);
4026 next_buffer = &rx_ring->buffer_info[i];
4030 dma_unmap_page(&pdev->dev, buffer_info->dma,
4031 buffer_info->length, DMA_FROM_DEVICE);
4032 buffer_info->dma = 0;
4034 length = le16_to_cpu(rx_desc->length);
4036 /* errors is only valid for DD + EOP descriptors */
4037 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4038 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4042 mapped = page_address(buffer_info->page);
4043 last_byte = *(mapped + length - 1);
4044 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4046 spin_lock_irqsave(&adapter->stats_lock,
4048 e1000_tbi_adjust_stats(hw, &adapter->stats,
4050 spin_unlock_irqrestore(&adapter->stats_lock,
4054 if (netdev->features & NETIF_F_RXALL)
4056 /* recycle both page and skb */
4057 buffer_info->skb = skb;
4058 /* an error means any chain goes out the window
4061 if (rx_ring->rx_skb_top)
4062 dev_kfree_skb(rx_ring->rx_skb_top);
4063 rx_ring->rx_skb_top = NULL;
4068 #define rxtop rx_ring->rx_skb_top
4070 if (!(status & E1000_RXD_STAT_EOP)) {
4071 /* this descriptor is only the beginning (or middle) */
4073 /* this is the beginning of a chain */
4075 skb_fill_page_desc(rxtop, 0, buffer_info->page,
4078 /* this is the middle of a chain */
4079 skb_fill_page_desc(rxtop,
4080 skb_shinfo(rxtop)->nr_frags,
4081 buffer_info->page, 0, length);
4082 /* re-use the skb, only consumed the page */
4083 buffer_info->skb = skb;
4085 e1000_consume_page(buffer_info, rxtop, length);
4089 /* end of the chain */
4090 skb_fill_page_desc(rxtop,
4091 skb_shinfo(rxtop)->nr_frags,
4092 buffer_info->page, 0, length);
4093 /* re-use the current skb, we only consumed the
4096 buffer_info->skb = skb;
4099 e1000_consume_page(buffer_info, skb, length);
4101 /* no chain, got EOP, this buf is the packet
4102 * copybreak to save the put_page/alloc_page
4104 if (length <= copybreak &&
4105 skb_tailroom(skb) >= length) {
4107 vaddr = kmap_atomic(buffer_info->page);
4108 memcpy(skb_tail_pointer(skb), vaddr,
4110 kunmap_atomic(vaddr);
4111 /* re-use the page, so don't erase
4114 skb_put(skb, length);
4116 skb_fill_page_desc(skb, 0,
4117 buffer_info->page, 0,
4119 e1000_consume_page(buffer_info, skb,
4125 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4126 e1000_rx_checksum(adapter,
4128 ((u32)(rx_desc->errors) << 24),
4129 le16_to_cpu(rx_desc->csum), skb);
4131 total_rx_bytes += (skb->len - 4); /* don't count FCS */
4132 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4133 pskb_trim(skb, skb->len - 4);
4136 /* eth type trans needs skb->data to point to something */
4137 if (!pskb_may_pull(skb, ETH_HLEN)) {
4138 e_err(drv, "pskb_may_pull failed.\n");
4143 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4146 rx_desc->status = 0;
4148 /* return some buffers to hardware, one at a time is too slow */
4149 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4150 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4154 /* use prefetched values */
4156 buffer_info = next_buffer;
4158 rx_ring->next_to_clean = i;
4160 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4162 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4164 adapter->total_rx_packets += total_rx_packets;
4165 adapter->total_rx_bytes += total_rx_bytes;
4166 netdev->stats.rx_bytes += total_rx_bytes;
4167 netdev->stats.rx_packets += total_rx_packets;
4171 /* this should improve performance for small packets with large amounts
4172 * of reassembly being done in the stack
4174 static void e1000_check_copybreak(struct net_device *netdev,
4175 struct e1000_buffer *buffer_info,
4176 u32 length, struct sk_buff **skb)
4178 struct sk_buff *new_skb;
4180 if (length > copybreak)
4183 new_skb = netdev_alloc_skb_ip_align(netdev, length);
4187 skb_copy_to_linear_data_offset(new_skb, -NET_IP_ALIGN,
4188 (*skb)->data - NET_IP_ALIGN,
4189 length + NET_IP_ALIGN);
4190 /* save the skb in buffer_info as good */
4191 buffer_info->skb = *skb;
4196 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4197 * @adapter: board private structure
4198 * @rx_ring: ring to clean
4199 * @work_done: amount of napi work completed this call
4200 * @work_to_do: max amount of work allowed for this call to do
4202 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4203 struct e1000_rx_ring *rx_ring,
4204 int *work_done, int work_to_do)
4206 struct e1000_hw *hw = &adapter->hw;
4207 struct net_device *netdev = adapter->netdev;
4208 struct pci_dev *pdev = adapter->pdev;
4209 struct e1000_rx_desc *rx_desc, *next_rxd;
4210 struct e1000_buffer *buffer_info, *next_buffer;
4211 unsigned long flags;
4214 int cleaned_count = 0;
4215 bool cleaned = false;
4216 unsigned int total_rx_bytes=0, total_rx_packets=0;
4218 i = rx_ring->next_to_clean;
4219 rx_desc = E1000_RX_DESC(*rx_ring, i);
4220 buffer_info = &rx_ring->buffer_info[i];
4222 while (rx_desc->status & E1000_RXD_STAT_DD) {
4223 struct sk_buff *skb;
4226 if (*work_done >= work_to_do)
4229 rmb(); /* read descriptor and rx_buffer_info after status DD */
4231 status = rx_desc->status;
4232 skb = buffer_info->skb;
4233 buffer_info->skb = NULL;
4235 prefetch(skb->data - NET_IP_ALIGN);
4237 if (++i == rx_ring->count) i = 0;
4238 next_rxd = E1000_RX_DESC(*rx_ring, i);
4241 next_buffer = &rx_ring->buffer_info[i];
4245 dma_unmap_single(&pdev->dev, buffer_info->dma,
4246 buffer_info->length, DMA_FROM_DEVICE);
4247 buffer_info->dma = 0;
4249 length = le16_to_cpu(rx_desc->length);
4250 /* !EOP means multiple descriptors were used to store a single
4251 * packet, if thats the case we need to toss it. In fact, we
4252 * to toss every packet with the EOP bit clear and the next
4253 * frame that _does_ have the EOP bit set, as it is by
4254 * definition only a frame fragment
4256 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
4257 adapter->discarding = true;
4259 if (adapter->discarding) {
4260 /* All receives must fit into a single buffer */
4261 e_dbg("Receive packet consumed multiple buffers\n");
4263 buffer_info->skb = skb;
4264 if (status & E1000_RXD_STAT_EOP)
4265 adapter->discarding = false;
4269 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4270 u8 last_byte = *(skb->data + length - 1);
4271 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4273 spin_lock_irqsave(&adapter->stats_lock, flags);
4274 e1000_tbi_adjust_stats(hw, &adapter->stats,
4276 spin_unlock_irqrestore(&adapter->stats_lock,
4280 if (netdev->features & NETIF_F_RXALL)
4283 buffer_info->skb = skb;
4289 total_rx_bytes += (length - 4); /* don't count FCS */
4292 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4293 /* adjust length to remove Ethernet CRC, this must be
4294 * done after the TBI_ACCEPT workaround above
4298 e1000_check_copybreak(netdev, buffer_info, length, &skb);
4300 skb_put(skb, length);
4302 /* Receive Checksum Offload */
4303 e1000_rx_checksum(adapter,
4305 ((u32)(rx_desc->errors) << 24),
4306 le16_to_cpu(rx_desc->csum), skb);
4308 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4311 rx_desc->status = 0;
4313 /* return some buffers to hardware, one at a time is too slow */
4314 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4315 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4319 /* use prefetched values */
4321 buffer_info = next_buffer;
4323 rx_ring->next_to_clean = i;
4325 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4327 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4329 adapter->total_rx_packets += total_rx_packets;
4330 adapter->total_rx_bytes += total_rx_bytes;
4331 netdev->stats.rx_bytes += total_rx_bytes;
4332 netdev->stats.rx_packets += total_rx_packets;
4337 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4338 * @adapter: address of board private structure
4339 * @rx_ring: pointer to receive ring structure
4340 * @cleaned_count: number of buffers to allocate this pass
4343 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4344 struct e1000_rx_ring *rx_ring, int cleaned_count)
4346 struct net_device *netdev = adapter->netdev;
4347 struct pci_dev *pdev = adapter->pdev;
4348 struct e1000_rx_desc *rx_desc;
4349 struct e1000_buffer *buffer_info;
4350 struct sk_buff *skb;
4352 unsigned int bufsz = 256 - 16 /*for skb_reserve */ ;
4354 i = rx_ring->next_to_use;
4355 buffer_info = &rx_ring->buffer_info[i];
4357 while (cleaned_count--) {
4358 skb = buffer_info->skb;
4364 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4365 if (unlikely(!skb)) {
4366 /* Better luck next round */
4367 adapter->alloc_rx_buff_failed++;
4371 buffer_info->skb = skb;
4372 buffer_info->length = adapter->rx_buffer_len;
4374 /* allocate a new page if necessary */
4375 if (!buffer_info->page) {
4376 buffer_info->page = alloc_page(GFP_ATOMIC);
4377 if (unlikely(!buffer_info->page)) {
4378 adapter->alloc_rx_buff_failed++;
4383 if (!buffer_info->dma) {
4384 buffer_info->dma = dma_map_page(&pdev->dev,
4385 buffer_info->page, 0,
4386 buffer_info->length,
4388 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4389 put_page(buffer_info->page);
4391 buffer_info->page = NULL;
4392 buffer_info->skb = NULL;
4393 buffer_info->dma = 0;
4394 adapter->alloc_rx_buff_failed++;
4395 break; /* while !buffer_info->skb */
4399 rx_desc = E1000_RX_DESC(*rx_ring, i);
4400 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4402 if (unlikely(++i == rx_ring->count))
4404 buffer_info = &rx_ring->buffer_info[i];
4407 if (likely(rx_ring->next_to_use != i)) {
4408 rx_ring->next_to_use = i;
4409 if (unlikely(i-- == 0))
4410 i = (rx_ring->count - 1);
4412 /* Force memory writes to complete before letting h/w
4413 * know there are new descriptors to fetch. (Only
4414 * applicable for weak-ordered memory model archs,
4418 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4423 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4424 * @adapter: address of board private structure
4426 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4427 struct e1000_rx_ring *rx_ring,
4430 struct e1000_hw *hw = &adapter->hw;
4431 struct net_device *netdev = adapter->netdev;
4432 struct pci_dev *pdev = adapter->pdev;
4433 struct e1000_rx_desc *rx_desc;
4434 struct e1000_buffer *buffer_info;
4435 struct sk_buff *skb;
4437 unsigned int bufsz = adapter->rx_buffer_len;
4439 i = rx_ring->next_to_use;
4440 buffer_info = &rx_ring->buffer_info[i];
4442 while (cleaned_count--) {
4443 skb = buffer_info->skb;
4449 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4450 if (unlikely(!skb)) {
4451 /* Better luck next round */
4452 adapter->alloc_rx_buff_failed++;
4456 /* Fix for errata 23, can't cross 64kB boundary */
4457 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4458 struct sk_buff *oldskb = skb;
4459 e_err(rx_err, "skb align check failed: %u bytes at "
4460 "%p\n", bufsz, skb->data);
4461 /* Try again, without freeing the previous */
4462 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4463 /* Failed allocation, critical failure */
4465 dev_kfree_skb(oldskb);
4466 adapter->alloc_rx_buff_failed++;
4470 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4473 dev_kfree_skb(oldskb);
4474 adapter->alloc_rx_buff_failed++;
4475 break; /* while !buffer_info->skb */
4478 /* Use new allocation */
4479 dev_kfree_skb(oldskb);
4481 buffer_info->skb = skb;
4482 buffer_info->length = adapter->rx_buffer_len;
4484 buffer_info->dma = dma_map_single(&pdev->dev,
4486 buffer_info->length,
4488 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4490 buffer_info->skb = NULL;
4491 buffer_info->dma = 0;
4492 adapter->alloc_rx_buff_failed++;
4493 break; /* while !buffer_info->skb */
4496 /* XXX if it was allocated cleanly it will never map to a
4500 /* Fix for errata 23, can't cross 64kB boundary */
4501 if (!e1000_check_64k_bound(adapter,
4502 (void *)(unsigned long)buffer_info->dma,
4503 adapter->rx_buffer_len)) {
4504 e_err(rx_err, "dma align check failed: %u bytes at "
4505 "%p\n", adapter->rx_buffer_len,
4506 (void *)(unsigned long)buffer_info->dma);
4508 buffer_info->skb = NULL;
4510 dma_unmap_single(&pdev->dev, buffer_info->dma,
4511 adapter->rx_buffer_len,
4513 buffer_info->dma = 0;
4515 adapter->alloc_rx_buff_failed++;
4516 break; /* while !buffer_info->skb */
4518 rx_desc = E1000_RX_DESC(*rx_ring, i);
4519 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4521 if (unlikely(++i == rx_ring->count))
4523 buffer_info = &rx_ring->buffer_info[i];
4526 if (likely(rx_ring->next_to_use != i)) {
4527 rx_ring->next_to_use = i;
4528 if (unlikely(i-- == 0))
4529 i = (rx_ring->count - 1);
4531 /* Force memory writes to complete before letting h/w
4532 * know there are new descriptors to fetch. (Only
4533 * applicable for weak-ordered memory model archs,
4537 writel(i, hw->hw_addr + rx_ring->rdt);
4542 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4545 static void e1000_smartspeed(struct e1000_adapter *adapter)
4547 struct e1000_hw *hw = &adapter->hw;
4551 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4552 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4555 if (adapter->smartspeed == 0) {
4556 /* If Master/Slave config fault is asserted twice,
4557 * we assume back-to-back
4559 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4560 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4561 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4562 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4563 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4564 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4565 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4566 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4568 adapter->smartspeed++;
4569 if (!e1000_phy_setup_autoneg(hw) &&
4570 !e1000_read_phy_reg(hw, PHY_CTRL,
4572 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4573 MII_CR_RESTART_AUTO_NEG);
4574 e1000_write_phy_reg(hw, PHY_CTRL,
4579 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4580 /* If still no link, perhaps using 2/3 pair cable */
4581 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4582 phy_ctrl |= CR_1000T_MS_ENABLE;
4583 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4584 if (!e1000_phy_setup_autoneg(hw) &&
4585 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4586 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4587 MII_CR_RESTART_AUTO_NEG);
4588 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4591 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4592 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4593 adapter->smartspeed = 0;
4602 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4608 return e1000_mii_ioctl(netdev, ifr, cmd);
4620 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4623 struct e1000_adapter *adapter = netdev_priv(netdev);
4624 struct e1000_hw *hw = &adapter->hw;
4625 struct mii_ioctl_data *data = if_mii(ifr);
4628 unsigned long flags;
4630 if (hw->media_type != e1000_media_type_copper)
4635 data->phy_id = hw->phy_addr;
4638 spin_lock_irqsave(&adapter->stats_lock, flags);
4639 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4641 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4644 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4647 if (data->reg_num & ~(0x1F))
4649 mii_reg = data->val_in;
4650 spin_lock_irqsave(&adapter->stats_lock, flags);
4651 if (e1000_write_phy_reg(hw, data->reg_num,
4653 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4656 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4657 if (hw->media_type == e1000_media_type_copper) {
4658 switch (data->reg_num) {
4660 if (mii_reg & MII_CR_POWER_DOWN)
4662 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4664 hw->autoneg_advertised = 0x2F;
4669 else if (mii_reg & 0x2000)
4673 retval = e1000_set_spd_dplx(
4681 if (netif_running(adapter->netdev))
4682 e1000_reinit_locked(adapter);
4684 e1000_reset(adapter);
4686 case M88E1000_PHY_SPEC_CTRL:
4687 case M88E1000_EXT_PHY_SPEC_CTRL:
4688 if (e1000_phy_reset(hw))
4693 switch (data->reg_num) {
4695 if (mii_reg & MII_CR_POWER_DOWN)
4697 if (netif_running(adapter->netdev))
4698 e1000_reinit_locked(adapter);
4700 e1000_reset(adapter);
4708 return E1000_SUCCESS;
4711 void e1000_pci_set_mwi(struct e1000_hw *hw)
4713 struct e1000_adapter *adapter = hw->back;
4714 int ret_val = pci_set_mwi(adapter->pdev);
4717 e_err(probe, "Error in setting MWI\n");
4720 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4722 struct e1000_adapter *adapter = hw->back;
4724 pci_clear_mwi(adapter->pdev);
4727 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4729 struct e1000_adapter *adapter = hw->back;
4730 return pcix_get_mmrbc(adapter->pdev);
4733 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4735 struct e1000_adapter *adapter = hw->back;
4736 pcix_set_mmrbc(adapter->pdev, mmrbc);
4739 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4744 static bool e1000_vlan_used(struct e1000_adapter *adapter)
4748 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4753 static void __e1000_vlan_mode(struct e1000_adapter *adapter,
4754 netdev_features_t features)
4756 struct e1000_hw *hw = &adapter->hw;
4760 if (features & NETIF_F_HW_VLAN_CTAG_RX) {
4761 /* enable VLAN tag insert/strip */
4762 ctrl |= E1000_CTRL_VME;
4764 /* disable VLAN tag insert/strip */
4765 ctrl &= ~E1000_CTRL_VME;
4769 static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4772 struct e1000_hw *hw = &adapter->hw;
4775 if (!test_bit(__E1000_DOWN, &adapter->flags))
4776 e1000_irq_disable(adapter);
4778 __e1000_vlan_mode(adapter, adapter->netdev->features);
4780 /* enable VLAN receive filtering */
4782 rctl &= ~E1000_RCTL_CFIEN;
4783 if (!(adapter->netdev->flags & IFF_PROMISC))
4784 rctl |= E1000_RCTL_VFE;
4786 e1000_update_mng_vlan(adapter);
4788 /* disable VLAN receive filtering */
4790 rctl &= ~E1000_RCTL_VFE;
4794 if (!test_bit(__E1000_DOWN, &adapter->flags))
4795 e1000_irq_enable(adapter);
4798 static void e1000_vlan_mode(struct net_device *netdev,
4799 netdev_features_t features)
4801 struct e1000_adapter *adapter = netdev_priv(netdev);
4803 if (!test_bit(__E1000_DOWN, &adapter->flags))
4804 e1000_irq_disable(adapter);
4806 __e1000_vlan_mode(adapter, features);
4808 if (!test_bit(__E1000_DOWN, &adapter->flags))
4809 e1000_irq_enable(adapter);
4812 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
4813 __be16 proto, u16 vid)
4815 struct e1000_adapter *adapter = netdev_priv(netdev);
4816 struct e1000_hw *hw = &adapter->hw;
4819 if ((hw->mng_cookie.status &
4820 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4821 (vid == adapter->mng_vlan_id))
4824 if (!e1000_vlan_used(adapter))
4825 e1000_vlan_filter_on_off(adapter, true);
4827 /* add VID to filter table */
4828 index = (vid >> 5) & 0x7F;
4829 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4830 vfta |= (1 << (vid & 0x1F));
4831 e1000_write_vfta(hw, index, vfta);
4833 set_bit(vid, adapter->active_vlans);
4838 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
4839 __be16 proto, u16 vid)
4841 struct e1000_adapter *adapter = netdev_priv(netdev);
4842 struct e1000_hw *hw = &adapter->hw;
4845 if (!test_bit(__E1000_DOWN, &adapter->flags))
4846 e1000_irq_disable(adapter);
4847 if (!test_bit(__E1000_DOWN, &adapter->flags))
4848 e1000_irq_enable(adapter);
4850 /* remove VID from filter table */
4851 index = (vid >> 5) & 0x7F;
4852 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4853 vfta &= ~(1 << (vid & 0x1F));
4854 e1000_write_vfta(hw, index, vfta);
4856 clear_bit(vid, adapter->active_vlans);
4858 if (!e1000_vlan_used(adapter))
4859 e1000_vlan_filter_on_off(adapter, false);
4864 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4868 if (!e1000_vlan_used(adapter))
4871 e1000_vlan_filter_on_off(adapter, true);
4872 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4873 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
4876 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
4878 struct e1000_hw *hw = &adapter->hw;
4882 /* Make sure dplx is at most 1 bit and lsb of speed is not set
4883 * for the switch() below to work
4885 if ((spd & 1) || (dplx & ~1))
4888 /* Fiber NICs only allow 1000 gbps Full duplex */
4889 if ((hw->media_type == e1000_media_type_fiber) &&
4890 spd != SPEED_1000 &&
4891 dplx != DUPLEX_FULL)
4894 switch (spd + dplx) {
4895 case SPEED_10 + DUPLEX_HALF:
4896 hw->forced_speed_duplex = e1000_10_half;
4898 case SPEED_10 + DUPLEX_FULL:
4899 hw->forced_speed_duplex = e1000_10_full;
4901 case SPEED_100 + DUPLEX_HALF:
4902 hw->forced_speed_duplex = e1000_100_half;
4904 case SPEED_100 + DUPLEX_FULL:
4905 hw->forced_speed_duplex = e1000_100_full;
4907 case SPEED_1000 + DUPLEX_FULL:
4909 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4911 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4916 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
4917 hw->mdix = AUTO_ALL_MODES;
4922 e_err(probe, "Unsupported Speed/Duplex configuration\n");
4926 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4928 struct net_device *netdev = pci_get_drvdata(pdev);
4929 struct e1000_adapter *adapter = netdev_priv(netdev);
4930 struct e1000_hw *hw = &adapter->hw;
4931 u32 ctrl, ctrl_ext, rctl, status;
4932 u32 wufc = adapter->wol;
4937 netif_device_detach(netdev);
4939 if (netif_running(netdev)) {
4940 int count = E1000_CHECK_RESET_COUNT;
4942 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
4943 usleep_range(10000, 20000);
4945 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4946 e1000_down(adapter);
4950 retval = pci_save_state(pdev);
4955 status = er32(STATUS);
4956 if (status & E1000_STATUS_LU)
4957 wufc &= ~E1000_WUFC_LNKC;
4960 e1000_setup_rctl(adapter);
4961 e1000_set_rx_mode(netdev);
4965 /* turn on all-multi mode if wake on multicast is enabled */
4966 if (wufc & E1000_WUFC_MC)
4967 rctl |= E1000_RCTL_MPE;
4969 /* enable receives in the hardware */
4970 ew32(RCTL, rctl | E1000_RCTL_EN);
4972 if (hw->mac_type >= e1000_82540) {
4974 /* advertise wake from D3Cold */
4975 #define E1000_CTRL_ADVD3WUC 0x00100000
4976 /* phy power management enable */
4977 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4978 ctrl |= E1000_CTRL_ADVD3WUC |
4979 E1000_CTRL_EN_PHY_PWR_MGMT;
4983 if (hw->media_type == e1000_media_type_fiber ||
4984 hw->media_type == e1000_media_type_internal_serdes) {
4985 /* keep the laser running in D3 */
4986 ctrl_ext = er32(CTRL_EXT);
4987 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4988 ew32(CTRL_EXT, ctrl_ext);
4991 ew32(WUC, E1000_WUC_PME_EN);
4998 e1000_release_manageability(adapter);
5000 *enable_wake = !!wufc;
5002 /* make sure adapter isn't asleep if manageability is enabled */
5003 if (adapter->en_mng_pt)
5004 *enable_wake = true;
5006 if (netif_running(netdev))
5007 e1000_free_irq(adapter);
5009 pci_disable_device(pdev);
5015 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5020 retval = __e1000_shutdown(pdev, &wake);
5025 pci_prepare_to_sleep(pdev);
5027 pci_wake_from_d3(pdev, false);
5028 pci_set_power_state(pdev, PCI_D3hot);
5034 static int e1000_resume(struct pci_dev *pdev)
5036 struct net_device *netdev = pci_get_drvdata(pdev);
5037 struct e1000_adapter *adapter = netdev_priv(netdev);
5038 struct e1000_hw *hw = &adapter->hw;
5041 pci_set_power_state(pdev, PCI_D0);
5042 pci_restore_state(pdev);
5043 pci_save_state(pdev);
5045 if (adapter->need_ioport)
5046 err = pci_enable_device(pdev);
5048 err = pci_enable_device_mem(pdev);
5050 pr_err("Cannot enable PCI device from suspend\n");
5053 pci_set_master(pdev);
5055 pci_enable_wake(pdev, PCI_D3hot, 0);
5056 pci_enable_wake(pdev, PCI_D3cold, 0);
5058 if (netif_running(netdev)) {
5059 err = e1000_request_irq(adapter);
5064 e1000_power_up_phy(adapter);
5065 e1000_reset(adapter);
5068 e1000_init_manageability(adapter);
5070 if (netif_running(netdev))
5073 netif_device_attach(netdev);
5079 static void e1000_shutdown(struct pci_dev *pdev)
5083 __e1000_shutdown(pdev, &wake);
5085 if (system_state == SYSTEM_POWER_OFF) {
5086 pci_wake_from_d3(pdev, wake);
5087 pci_set_power_state(pdev, PCI_D3hot);
5091 #ifdef CONFIG_NET_POLL_CONTROLLER
5092 /* Polling 'interrupt' - used by things like netconsole to send skbs
5093 * without having to re-enable interrupts. It's not called while
5094 * the interrupt routine is executing.
5096 static void e1000_netpoll(struct net_device *netdev)
5098 struct e1000_adapter *adapter = netdev_priv(netdev);
5100 disable_irq(adapter->pdev->irq);
5101 e1000_intr(adapter->pdev->irq, netdev);
5102 enable_irq(adapter->pdev->irq);
5107 * e1000_io_error_detected - called when PCI error is detected
5108 * @pdev: Pointer to PCI device
5109 * @state: The current pci connection state
5111 * This function is called after a PCI bus error affecting
5112 * this device has been detected.
5114 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5115 pci_channel_state_t state)
5117 struct net_device *netdev = pci_get_drvdata(pdev);
5118 struct e1000_adapter *adapter = netdev_priv(netdev);
5120 netif_device_detach(netdev);
5122 if (state == pci_channel_io_perm_failure)
5123 return PCI_ERS_RESULT_DISCONNECT;
5125 if (netif_running(netdev))
5126 e1000_down(adapter);
5127 pci_disable_device(pdev);
5129 /* Request a slot slot reset. */
5130 return PCI_ERS_RESULT_NEED_RESET;
5134 * e1000_io_slot_reset - called after the pci bus has been reset.
5135 * @pdev: Pointer to PCI device
5137 * Restart the card from scratch, as if from a cold-boot. Implementation
5138 * resembles the first-half of the e1000_resume routine.
5140 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5142 struct net_device *netdev = pci_get_drvdata(pdev);
5143 struct e1000_adapter *adapter = netdev_priv(netdev);
5144 struct e1000_hw *hw = &adapter->hw;
5147 if (adapter->need_ioport)
5148 err = pci_enable_device(pdev);
5150 err = pci_enable_device_mem(pdev);
5152 pr_err("Cannot re-enable PCI device after reset.\n");
5153 return PCI_ERS_RESULT_DISCONNECT;
5155 pci_set_master(pdev);
5157 pci_enable_wake(pdev, PCI_D3hot, 0);
5158 pci_enable_wake(pdev, PCI_D3cold, 0);
5160 e1000_reset(adapter);
5163 return PCI_ERS_RESULT_RECOVERED;
5167 * e1000_io_resume - called when traffic can start flowing again.
5168 * @pdev: Pointer to PCI device
5170 * This callback is called when the error recovery driver tells us that
5171 * its OK to resume normal operation. Implementation resembles the
5172 * second-half of the e1000_resume routine.
5174 static void e1000_io_resume(struct pci_dev *pdev)
5176 struct net_device *netdev = pci_get_drvdata(pdev);
5177 struct e1000_adapter *adapter = netdev_priv(netdev);
5179 e1000_init_manageability(adapter);
5181 if (netif_running(netdev)) {
5182 if (e1000_up(adapter)) {
5183 pr_info("can't bring device back up after reset\n");
5188 netif_device_attach(netdev);