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 const struct pci_device_id 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 int e1000_open(struct net_device *netdev);
118 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 int e1000_change_mtu(struct net_device *netdev, int new_mtu);
135 static int e1000_set_mac(struct net_device *netdev, void *p);
136 static irqreturn_t e1000_intr(int irq, void *data);
137 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
138 struct e1000_tx_ring *tx_ring);
139 static int e1000_clean(struct napi_struct *napi, int budget);
140 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
143 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
145 int *work_done, int work_to_do);
146 static void e1000_alloc_dummy_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
151 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
152 struct e1000_rx_ring *rx_ring,
154 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
155 struct e1000_rx_ring *rx_ring,
157 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
158 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
160 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
161 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
162 static void e1000_tx_timeout(struct net_device *dev);
163 static void e1000_reset_task(struct work_struct *work);
164 static void e1000_smartspeed(struct e1000_adapter *adapter);
165 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
166 struct sk_buff *skb);
168 static bool e1000_vlan_used(struct e1000_adapter *adapter);
169 static void e1000_vlan_mode(struct net_device *netdev,
170 netdev_features_t features);
171 static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
173 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
174 __be16 proto, u16 vid);
175 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
176 __be16 proto, u16 vid);
177 static void e1000_restore_vlan(struct e1000_adapter *adapter);
180 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
181 static int e1000_resume(struct pci_dev *pdev);
183 static void e1000_shutdown(struct pci_dev *pdev);
185 #ifdef CONFIG_NET_POLL_CONTROLLER
186 /* for netdump / net console */
187 static void e1000_netpoll (struct net_device *netdev);
190 #define COPYBREAK_DEFAULT 256
191 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
192 module_param(copybreak, uint, 0644);
193 MODULE_PARM_DESC(copybreak,
194 "Maximum size of packet that is copied to a new buffer on receive");
196 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
197 pci_channel_state_t state);
198 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
199 static void e1000_io_resume(struct pci_dev *pdev);
201 static const struct pci_error_handlers e1000_err_handler = {
202 .error_detected = e1000_io_error_detected,
203 .slot_reset = e1000_io_slot_reset,
204 .resume = e1000_io_resume,
207 static struct pci_driver e1000_driver = {
208 .name = e1000_driver_name,
209 .id_table = e1000_pci_tbl,
210 .probe = e1000_probe,
211 .remove = e1000_remove,
213 /* Power Management Hooks */
214 .suspend = e1000_suspend,
215 .resume = e1000_resume,
217 .shutdown = e1000_shutdown,
218 .err_handler = &e1000_err_handler
221 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
222 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
223 MODULE_LICENSE("GPL");
224 MODULE_VERSION(DRV_VERSION);
226 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
227 static int debug = -1;
228 module_param(debug, int, 0);
229 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
232 * e1000_get_hw_dev - return device
233 * used by hardware layer to print debugging information
236 struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
238 struct e1000_adapter *adapter = hw->back;
239 return adapter->netdev;
243 * e1000_init_module - Driver Registration Routine
245 * e1000_init_module is the first routine called when the driver is
246 * loaded. All it does is register with the PCI subsystem.
248 static int __init e1000_init_module(void)
251 pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
253 pr_info("%s\n", e1000_copyright);
255 ret = pci_register_driver(&e1000_driver);
256 if (copybreak != COPYBREAK_DEFAULT) {
258 pr_info("copybreak disabled\n");
260 pr_info("copybreak enabled for "
261 "packets <= %u bytes\n", copybreak);
266 module_init(e1000_init_module);
269 * e1000_exit_module - Driver Exit Cleanup Routine
271 * e1000_exit_module is called just before the driver is removed
274 static void __exit e1000_exit_module(void)
276 pci_unregister_driver(&e1000_driver);
279 module_exit(e1000_exit_module);
281 static int e1000_request_irq(struct e1000_adapter *adapter)
283 struct net_device *netdev = adapter->netdev;
284 irq_handler_t handler = e1000_intr;
285 int irq_flags = IRQF_SHARED;
288 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
291 e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
297 static void e1000_free_irq(struct e1000_adapter *adapter)
299 struct net_device *netdev = adapter->netdev;
301 free_irq(adapter->pdev->irq, netdev);
305 * e1000_irq_disable - Mask off interrupt generation on the NIC
306 * @adapter: board private structure
308 static void e1000_irq_disable(struct e1000_adapter *adapter)
310 struct e1000_hw *hw = &adapter->hw;
314 synchronize_irq(adapter->pdev->irq);
318 * e1000_irq_enable - Enable default interrupt generation settings
319 * @adapter: board private structure
321 static void e1000_irq_enable(struct e1000_adapter *adapter)
323 struct e1000_hw *hw = &adapter->hw;
325 ew32(IMS, IMS_ENABLE_MASK);
329 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
331 struct e1000_hw *hw = &adapter->hw;
332 struct net_device *netdev = adapter->netdev;
333 u16 vid = hw->mng_cookie.vlan_id;
334 u16 old_vid = adapter->mng_vlan_id;
336 if (!e1000_vlan_used(adapter))
339 if (!test_bit(vid, adapter->active_vlans)) {
340 if (hw->mng_cookie.status &
341 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
342 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
343 adapter->mng_vlan_id = vid;
345 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
347 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
349 !test_bit(old_vid, adapter->active_vlans))
350 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
353 adapter->mng_vlan_id = vid;
357 static void e1000_init_manageability(struct e1000_adapter *adapter)
359 struct e1000_hw *hw = &adapter->hw;
361 if (adapter->en_mng_pt) {
362 u32 manc = er32(MANC);
364 /* disable hardware interception of ARP */
365 manc &= ~(E1000_MANC_ARP_EN);
371 static void e1000_release_manageability(struct e1000_adapter *adapter)
373 struct e1000_hw *hw = &adapter->hw;
375 if (adapter->en_mng_pt) {
376 u32 manc = er32(MANC);
378 /* re-enable hardware interception of ARP */
379 manc |= E1000_MANC_ARP_EN;
386 * e1000_configure - configure the hardware for RX and TX
387 * @adapter = private board structure
389 static void e1000_configure(struct e1000_adapter *adapter)
391 struct net_device *netdev = adapter->netdev;
394 e1000_set_rx_mode(netdev);
396 e1000_restore_vlan(adapter);
397 e1000_init_manageability(adapter);
399 e1000_configure_tx(adapter);
400 e1000_setup_rctl(adapter);
401 e1000_configure_rx(adapter);
402 /* call E1000_DESC_UNUSED which always leaves
403 * at least 1 descriptor unused to make sure
404 * next_to_use != next_to_clean
406 for (i = 0; i < adapter->num_rx_queues; i++) {
407 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
408 adapter->alloc_rx_buf(adapter, ring,
409 E1000_DESC_UNUSED(ring));
413 int e1000_up(struct e1000_adapter *adapter)
415 struct e1000_hw *hw = &adapter->hw;
417 /* hardware has been reset, we need to reload some things */
418 e1000_configure(adapter);
420 clear_bit(__E1000_DOWN, &adapter->flags);
422 napi_enable(&adapter->napi);
424 e1000_irq_enable(adapter);
426 netif_wake_queue(adapter->netdev);
428 /* fire a link change interrupt to start the watchdog */
429 ew32(ICS, E1000_ICS_LSC);
434 * e1000_power_up_phy - restore link in case the phy was powered down
435 * @adapter: address of board private structure
437 * The phy may be powered down to save power and turn off link when the
438 * driver is unloaded and wake on lan is not enabled (among others)
439 * *** this routine MUST be followed by a call to e1000_reset ***
441 void e1000_power_up_phy(struct e1000_adapter *adapter)
443 struct e1000_hw *hw = &adapter->hw;
446 /* Just clear the power down bit to wake the phy back up */
447 if (hw->media_type == e1000_media_type_copper) {
448 /* according to the manual, the phy will retain its
449 * settings across a power-down/up cycle
451 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
452 mii_reg &= ~MII_CR_POWER_DOWN;
453 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
457 static void e1000_power_down_phy(struct e1000_adapter *adapter)
459 struct e1000_hw *hw = &adapter->hw;
461 /* Power down the PHY so no link is implied when interface is down *
462 * The PHY cannot be powered down if any of the following is true *
465 * (c) SoL/IDER session is active
467 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
468 hw->media_type == e1000_media_type_copper) {
471 switch (hw->mac_type) {
474 case e1000_82545_rev_3:
477 case e1000_82546_rev_3:
479 case e1000_82541_rev_2:
481 case e1000_82547_rev_2:
482 if (er32(MANC) & E1000_MANC_SMBUS_EN)
488 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
489 mii_reg |= MII_CR_POWER_DOWN;
490 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
497 static void e1000_down_and_stop(struct e1000_adapter *adapter)
499 set_bit(__E1000_DOWN, &adapter->flags);
501 cancel_delayed_work_sync(&adapter->watchdog_task);
504 * Since the watchdog task can reschedule other tasks, we should cancel
505 * it first, otherwise we can run into the situation when a work is
506 * still running after the adapter has been turned down.
509 cancel_delayed_work_sync(&adapter->phy_info_task);
510 cancel_delayed_work_sync(&adapter->fifo_stall_task);
512 /* Only kill reset task if adapter is not resetting */
513 if (!test_bit(__E1000_RESETTING, &adapter->flags))
514 cancel_work_sync(&adapter->reset_task);
517 void e1000_down(struct e1000_adapter *adapter)
519 struct e1000_hw *hw = &adapter->hw;
520 struct net_device *netdev = adapter->netdev;
523 /* disable receives in the hardware */
525 ew32(RCTL, rctl & ~E1000_RCTL_EN);
526 /* flush and sleep below */
528 netif_tx_disable(netdev);
530 /* disable transmits in the hardware */
532 tctl &= ~E1000_TCTL_EN;
534 /* flush both disables and wait for them to finish */
538 /* Set the carrier off after transmits have been disabled in the
539 * hardware, to avoid race conditions with e1000_watchdog() (which
540 * may be running concurrently to us, checking for the carrier
541 * bit to decide whether it should enable transmits again). Such
542 * a race condition would result into transmission being disabled
543 * in the hardware until the next IFF_DOWN+IFF_UP cycle.
545 netif_carrier_off(netdev);
547 napi_disable(&adapter->napi);
549 e1000_irq_disable(adapter);
551 /* Setting DOWN must be after irq_disable to prevent
552 * a screaming interrupt. Setting DOWN also prevents
553 * tasks from rescheduling.
555 e1000_down_and_stop(adapter);
557 adapter->link_speed = 0;
558 adapter->link_duplex = 0;
560 e1000_reset(adapter);
561 e1000_clean_all_tx_rings(adapter);
562 e1000_clean_all_rx_rings(adapter);
565 void e1000_reinit_locked(struct e1000_adapter *adapter)
567 WARN_ON(in_interrupt());
568 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
572 clear_bit(__E1000_RESETTING, &adapter->flags);
575 void e1000_reset(struct e1000_adapter *adapter)
577 struct e1000_hw *hw = &adapter->hw;
578 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
579 bool legacy_pba_adjust = false;
582 /* Repartition Pba for greater than 9k mtu
583 * To take effect CTRL.RST is required.
586 switch (hw->mac_type) {
587 case e1000_82542_rev2_0:
588 case e1000_82542_rev2_1:
593 case e1000_82541_rev_2:
594 legacy_pba_adjust = true;
598 case e1000_82545_rev_3:
601 case e1000_82546_rev_3:
605 case e1000_82547_rev_2:
606 legacy_pba_adjust = true;
609 case e1000_undefined:
614 if (legacy_pba_adjust) {
615 if (hw->max_frame_size > E1000_RXBUFFER_8192)
616 pba -= 8; /* allocate more FIFO for Tx */
618 if (hw->mac_type == e1000_82547) {
619 adapter->tx_fifo_head = 0;
620 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
621 adapter->tx_fifo_size =
622 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
623 atomic_set(&adapter->tx_fifo_stall, 0);
625 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
626 /* adjust PBA for jumbo frames */
629 /* To maintain wire speed transmits, the Tx FIFO should be
630 * large enough to accommodate two full transmit packets,
631 * rounded up to the next 1KB and expressed in KB. Likewise,
632 * the Rx FIFO should be large enough to accommodate at least
633 * one full receive packet and is similarly rounded up and
637 /* upper 16 bits has Tx packet buffer allocation size in KB */
638 tx_space = pba >> 16;
639 /* lower 16 bits has Rx packet buffer allocation size in KB */
641 /* the Tx fifo also stores 16 bytes of information about the Tx
642 * but don't include ethernet FCS because hardware appends it
644 min_tx_space = (hw->max_frame_size +
645 sizeof(struct e1000_tx_desc) -
647 min_tx_space = ALIGN(min_tx_space, 1024);
649 /* software strips receive CRC, so leave room for it */
650 min_rx_space = hw->max_frame_size;
651 min_rx_space = ALIGN(min_rx_space, 1024);
654 /* If current Tx allocation is less than the min Tx FIFO size,
655 * and the min Tx FIFO size is less than the current Rx FIFO
656 * allocation, take space away from current Rx allocation
658 if (tx_space < min_tx_space &&
659 ((min_tx_space - tx_space) < pba)) {
660 pba = pba - (min_tx_space - tx_space);
662 /* PCI/PCIx hardware has PBA alignment constraints */
663 switch (hw->mac_type) {
664 case e1000_82545 ... e1000_82546_rev_3:
665 pba &= ~(E1000_PBA_8K - 1);
671 /* if short on Rx space, Rx wins and must trump Tx
672 * adjustment or use Early Receive if available
674 if (pba < min_rx_space)
681 /* flow control settings:
682 * The high water mark must be low enough to fit one full frame
683 * (or the size used for early receive) above it in the Rx FIFO.
684 * Set it to the lower of:
685 * - 90% of the Rx FIFO size, and
686 * - the full Rx FIFO size minus the early receive size (for parts
687 * with ERT support assuming ERT set to E1000_ERT_2048), or
688 * - the full Rx FIFO size minus one full frame
690 hwm = min(((pba << 10) * 9 / 10),
691 ((pba << 10) - hw->max_frame_size));
693 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
694 hw->fc_low_water = hw->fc_high_water - 8;
695 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
697 hw->fc = hw->original_fc;
699 /* Allow time for pending master requests to run */
701 if (hw->mac_type >= e1000_82544)
704 if (e1000_init_hw(hw))
705 e_dev_err("Hardware Error\n");
706 e1000_update_mng_vlan(adapter);
708 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
709 if (hw->mac_type >= e1000_82544 &&
711 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
712 u32 ctrl = er32(CTRL);
713 /* clear phy power management bit if we are in gig only mode,
714 * which if enabled will attempt negotiation to 100Mb, which
715 * can cause a loss of link at power off or driver unload
717 ctrl &= ~E1000_CTRL_SWDPIN3;
721 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
722 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
724 e1000_reset_adaptive(hw);
725 e1000_phy_get_info(hw, &adapter->phy_info);
727 e1000_release_manageability(adapter);
730 /* Dump the eeprom for users having checksum issues */
731 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
733 struct net_device *netdev = adapter->netdev;
734 struct ethtool_eeprom eeprom;
735 const struct ethtool_ops *ops = netdev->ethtool_ops;
738 u16 csum_old, csum_new = 0;
740 eeprom.len = ops->get_eeprom_len(netdev);
743 data = kmalloc(eeprom.len, GFP_KERNEL);
747 ops->get_eeprom(netdev, &eeprom, data);
749 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
750 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
751 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
752 csum_new += data[i] + (data[i + 1] << 8);
753 csum_new = EEPROM_SUM - csum_new;
755 pr_err("/*********************/\n");
756 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
757 pr_err("Calculated : 0x%04x\n", csum_new);
759 pr_err("Offset Values\n");
760 pr_err("======== ======\n");
761 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
763 pr_err("Include this output when contacting your support provider.\n");
764 pr_err("This is not a software error! Something bad happened to\n");
765 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
766 pr_err("result in further problems, possibly loss of data,\n");
767 pr_err("corruption or system hangs!\n");
768 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
769 pr_err("which is invalid and requires you to set the proper MAC\n");
770 pr_err("address manually before continuing to enable this network\n");
771 pr_err("device. Please inspect the EEPROM dump and report the\n");
772 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
773 pr_err("/*********************/\n");
779 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
780 * @pdev: PCI device information struct
782 * Return true if an adapter needs ioport resources
784 static int e1000_is_need_ioport(struct pci_dev *pdev)
786 switch (pdev->device) {
787 case E1000_DEV_ID_82540EM:
788 case E1000_DEV_ID_82540EM_LOM:
789 case E1000_DEV_ID_82540EP:
790 case E1000_DEV_ID_82540EP_LOM:
791 case E1000_DEV_ID_82540EP_LP:
792 case E1000_DEV_ID_82541EI:
793 case E1000_DEV_ID_82541EI_MOBILE:
794 case E1000_DEV_ID_82541ER:
795 case E1000_DEV_ID_82541ER_LOM:
796 case E1000_DEV_ID_82541GI:
797 case E1000_DEV_ID_82541GI_LF:
798 case E1000_DEV_ID_82541GI_MOBILE:
799 case E1000_DEV_ID_82544EI_COPPER:
800 case E1000_DEV_ID_82544EI_FIBER:
801 case E1000_DEV_ID_82544GC_COPPER:
802 case E1000_DEV_ID_82544GC_LOM:
803 case E1000_DEV_ID_82545EM_COPPER:
804 case E1000_DEV_ID_82545EM_FIBER:
805 case E1000_DEV_ID_82546EB_COPPER:
806 case E1000_DEV_ID_82546EB_FIBER:
807 case E1000_DEV_ID_82546EB_QUAD_COPPER:
814 static netdev_features_t e1000_fix_features(struct net_device *netdev,
815 netdev_features_t features)
817 /* Since there is no support for separate Rx/Tx vlan accel
818 * enable/disable make sure Tx flag is always in same state as Rx.
820 if (features & NETIF_F_HW_VLAN_CTAG_RX)
821 features |= NETIF_F_HW_VLAN_CTAG_TX;
823 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
828 static int e1000_set_features(struct net_device *netdev,
829 netdev_features_t features)
831 struct e1000_adapter *adapter = netdev_priv(netdev);
832 netdev_features_t changed = features ^ netdev->features;
834 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
835 e1000_vlan_mode(netdev, features);
837 if (!(changed & (NETIF_F_RXCSUM | NETIF_F_RXALL)))
840 netdev->features = features;
841 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
843 if (netif_running(netdev))
844 e1000_reinit_locked(adapter);
846 e1000_reset(adapter);
851 static const struct net_device_ops e1000_netdev_ops = {
852 .ndo_open = e1000_open,
853 .ndo_stop = e1000_close,
854 .ndo_start_xmit = e1000_xmit_frame,
855 .ndo_set_rx_mode = e1000_set_rx_mode,
856 .ndo_set_mac_address = e1000_set_mac,
857 .ndo_tx_timeout = e1000_tx_timeout,
858 .ndo_change_mtu = e1000_change_mtu,
859 .ndo_do_ioctl = e1000_ioctl,
860 .ndo_validate_addr = eth_validate_addr,
861 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
862 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
863 #ifdef CONFIG_NET_POLL_CONTROLLER
864 .ndo_poll_controller = e1000_netpoll,
866 .ndo_fix_features = e1000_fix_features,
867 .ndo_set_features = e1000_set_features,
871 * e1000_init_hw_struct - initialize members of hw struct
872 * @adapter: board private struct
873 * @hw: structure used by e1000_hw.c
875 * Factors out initialization of the e1000_hw struct to its own function
876 * that can be called very early at init (just after struct allocation).
877 * Fields are initialized based on PCI device information and
878 * OS network device settings (MTU size).
879 * Returns negative error codes if MAC type setup fails.
881 static int e1000_init_hw_struct(struct e1000_adapter *adapter,
884 struct pci_dev *pdev = adapter->pdev;
886 /* PCI config space info */
887 hw->vendor_id = pdev->vendor;
888 hw->device_id = pdev->device;
889 hw->subsystem_vendor_id = pdev->subsystem_vendor;
890 hw->subsystem_id = pdev->subsystem_device;
891 hw->revision_id = pdev->revision;
893 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
895 hw->max_frame_size = adapter->netdev->mtu +
896 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
897 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
899 /* identify the MAC */
900 if (e1000_set_mac_type(hw)) {
901 e_err(probe, "Unknown MAC Type\n");
905 switch (hw->mac_type) {
910 case e1000_82541_rev_2:
911 case e1000_82547_rev_2:
912 hw->phy_init_script = 1;
916 e1000_set_media_type(hw);
917 e1000_get_bus_info(hw);
919 hw->wait_autoneg_complete = false;
920 hw->tbi_compatibility_en = true;
921 hw->adaptive_ifs = true;
925 if (hw->media_type == e1000_media_type_copper) {
926 hw->mdix = AUTO_ALL_MODES;
927 hw->disable_polarity_correction = false;
928 hw->master_slave = E1000_MASTER_SLAVE;
935 * e1000_probe - Device Initialization Routine
936 * @pdev: PCI device information struct
937 * @ent: entry in e1000_pci_tbl
939 * Returns 0 on success, negative on failure
941 * e1000_probe initializes an adapter identified by a pci_dev structure.
942 * The OS initialization, configuring of the adapter private structure,
943 * and a hardware reset occur.
945 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
947 struct net_device *netdev;
948 struct e1000_adapter *adapter;
951 static int cards_found;
952 static int global_quad_port_a; /* global ksp3 port a indication */
953 int i, err, pci_using_dac;
956 u16 eeprom_apme_mask = E1000_EEPROM_APME;
957 int bars, need_ioport;
959 /* do not allocate ioport bars when not needed */
960 need_ioport = e1000_is_need_ioport(pdev);
962 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
963 err = pci_enable_device(pdev);
965 bars = pci_select_bars(pdev, IORESOURCE_MEM);
966 err = pci_enable_device_mem(pdev);
971 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
975 pci_set_master(pdev);
976 err = pci_save_state(pdev);
978 goto err_alloc_etherdev;
981 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
983 goto err_alloc_etherdev;
985 SET_NETDEV_DEV(netdev, &pdev->dev);
987 pci_set_drvdata(pdev, netdev);
988 adapter = netdev_priv(netdev);
989 adapter->netdev = netdev;
990 adapter->pdev = pdev;
991 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
992 adapter->bars = bars;
993 adapter->need_ioport = need_ioport;
999 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
1003 if (adapter->need_ioport) {
1004 for (i = BAR_1; i <= BAR_5; i++) {
1005 if (pci_resource_len(pdev, i) == 0)
1007 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1008 hw->io_base = pci_resource_start(pdev, i);
1014 /* make ready for any if (hw->...) below */
1015 err = e1000_init_hw_struct(adapter, hw);
1019 /* there is a workaround being applied below that limits
1020 * 64-bit DMA addresses to 64-bit hardware. There are some
1021 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
1024 if ((hw->bus_type == e1000_bus_type_pcix) &&
1025 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
1028 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1030 pr_err("No usable DMA config, aborting\n");
1035 netdev->netdev_ops = &e1000_netdev_ops;
1036 e1000_set_ethtool_ops(netdev);
1037 netdev->watchdog_timeo = 5 * HZ;
1038 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1040 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1042 adapter->bd_number = cards_found;
1044 /* setup the private structure */
1046 err = e1000_sw_init(adapter);
1051 if (hw->mac_type == e1000_ce4100) {
1052 hw->ce4100_gbe_mdio_base_virt =
1053 ioremap(pci_resource_start(pdev, BAR_1),
1054 pci_resource_len(pdev, BAR_1));
1056 if (!hw->ce4100_gbe_mdio_base_virt)
1057 goto err_mdio_ioremap;
1060 if (hw->mac_type >= e1000_82543) {
1061 netdev->hw_features = NETIF_F_SG |
1063 NETIF_F_HW_VLAN_CTAG_RX;
1064 netdev->features = NETIF_F_HW_VLAN_CTAG_TX |
1065 NETIF_F_HW_VLAN_CTAG_FILTER;
1068 if ((hw->mac_type >= e1000_82544) &&
1069 (hw->mac_type != e1000_82547))
1070 netdev->hw_features |= NETIF_F_TSO;
1072 netdev->priv_flags |= IFF_SUPP_NOFCS;
1074 netdev->features |= netdev->hw_features;
1075 netdev->hw_features |= (NETIF_F_RXCSUM |
1079 if (pci_using_dac) {
1080 netdev->features |= NETIF_F_HIGHDMA;
1081 netdev->vlan_features |= NETIF_F_HIGHDMA;
1084 netdev->vlan_features |= (NETIF_F_TSO |
1088 /* Do not set IFF_UNICAST_FLT for VMWare's 82545EM */
1089 if (hw->device_id != E1000_DEV_ID_82545EM_COPPER ||
1090 hw->subsystem_vendor_id != PCI_VENDOR_ID_VMWARE)
1091 netdev->priv_flags |= IFF_UNICAST_FLT;
1093 /* MTU range: 46 - 16110 */
1094 netdev->min_mtu = ETH_ZLEN - ETH_HLEN;
1095 netdev->max_mtu = MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
1097 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1099 /* initialize eeprom parameters */
1100 if (e1000_init_eeprom_params(hw)) {
1101 e_err(probe, "EEPROM initialization failed\n");
1105 /* before reading the EEPROM, reset the controller to
1106 * put the device in a known good starting state
1111 /* make sure the EEPROM is good */
1112 if (e1000_validate_eeprom_checksum(hw) < 0) {
1113 e_err(probe, "The EEPROM Checksum Is Not Valid\n");
1114 e1000_dump_eeprom(adapter);
1115 /* set MAC address to all zeroes to invalidate and temporary
1116 * disable this device for the user. This blocks regular
1117 * traffic while still permitting ethtool ioctls from reaching
1118 * the hardware as well as allowing the user to run the
1119 * interface after manually setting a hw addr using
1122 memset(hw->mac_addr, 0, netdev->addr_len);
1124 /* copy the MAC address out of the EEPROM */
1125 if (e1000_read_mac_addr(hw))
1126 e_err(probe, "EEPROM Read Error\n");
1128 /* don't block initialization here due to bad MAC address */
1129 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1131 if (!is_valid_ether_addr(netdev->dev_addr))
1132 e_err(probe, "Invalid MAC Address\n");
1135 INIT_DELAYED_WORK(&adapter->watchdog_task, e1000_watchdog);
1136 INIT_DELAYED_WORK(&adapter->fifo_stall_task,
1137 e1000_82547_tx_fifo_stall_task);
1138 INIT_DELAYED_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
1139 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1141 e1000_check_options(adapter);
1143 /* Initial Wake on LAN setting
1144 * If APM wake is enabled in the EEPROM,
1145 * enable the ACPI Magic Packet filter
1148 switch (hw->mac_type) {
1149 case e1000_82542_rev2_0:
1150 case e1000_82542_rev2_1:
1154 e1000_read_eeprom(hw,
1155 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1156 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1159 case e1000_82546_rev_3:
1160 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
1161 e1000_read_eeprom(hw,
1162 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1167 e1000_read_eeprom(hw,
1168 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1171 if (eeprom_data & eeprom_apme_mask)
1172 adapter->eeprom_wol |= E1000_WUFC_MAG;
1174 /* now that we have the eeprom settings, apply the special cases
1175 * where the eeprom may be wrong or the board simply won't support
1176 * wake on lan on a particular port
1178 switch (pdev->device) {
1179 case E1000_DEV_ID_82546GB_PCIE:
1180 adapter->eeprom_wol = 0;
1182 case E1000_DEV_ID_82546EB_FIBER:
1183 case E1000_DEV_ID_82546GB_FIBER:
1184 /* Wake events only supported on port A for dual fiber
1185 * regardless of eeprom setting
1187 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1188 adapter->eeprom_wol = 0;
1190 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1191 /* if quad port adapter, disable WoL on all but port A */
1192 if (global_quad_port_a != 0)
1193 adapter->eeprom_wol = 0;
1195 adapter->quad_port_a = true;
1196 /* Reset for multiple quad port adapters */
1197 if (++global_quad_port_a == 4)
1198 global_quad_port_a = 0;
1202 /* initialize the wol settings based on the eeprom settings */
1203 adapter->wol = adapter->eeprom_wol;
1204 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1206 /* Auto detect PHY address */
1207 if (hw->mac_type == e1000_ce4100) {
1208 for (i = 0; i < 32; i++) {
1210 e1000_read_phy_reg(hw, PHY_ID2, &tmp);
1212 if (tmp != 0 && tmp != 0xFF)
1220 /* reset the hardware with the new settings */
1221 e1000_reset(adapter);
1223 strcpy(netdev->name, "eth%d");
1224 err = register_netdev(netdev);
1228 e1000_vlan_filter_on_off(adapter, false);
1230 /* print bus type/speed/width info */
1231 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
1232 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1233 ((hw->bus_speed == e1000_bus_speed_133) ? 133 :
1234 (hw->bus_speed == e1000_bus_speed_120) ? 120 :
1235 (hw->bus_speed == e1000_bus_speed_100) ? 100 :
1236 (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33),
1237 ((hw->bus_width == e1000_bus_width_64) ? 64 : 32),
1240 /* carrier off reporting is important to ethtool even BEFORE open */
1241 netif_carrier_off(netdev);
1243 e_info(probe, "Intel(R) PRO/1000 Network Connection\n");
1250 e1000_phy_hw_reset(hw);
1252 if (hw->flash_address)
1253 iounmap(hw->flash_address);
1254 kfree(adapter->tx_ring);
1255 kfree(adapter->rx_ring);
1259 iounmap(hw->ce4100_gbe_mdio_base_virt);
1260 iounmap(hw->hw_addr);
1262 free_netdev(netdev);
1264 pci_release_selected_regions(pdev, bars);
1266 pci_disable_device(pdev);
1271 * e1000_remove - Device Removal Routine
1272 * @pdev: PCI device information struct
1274 * e1000_remove is called by the PCI subsystem to alert the driver
1275 * that it should release a PCI device. That could be caused by a
1276 * Hot-Plug event, or because the driver is going to be removed from
1279 static void e1000_remove(struct pci_dev *pdev)
1281 struct net_device *netdev = pci_get_drvdata(pdev);
1282 struct e1000_adapter *adapter = netdev_priv(netdev);
1283 struct e1000_hw *hw = &adapter->hw;
1285 e1000_down_and_stop(adapter);
1286 e1000_release_manageability(adapter);
1288 unregister_netdev(netdev);
1290 e1000_phy_hw_reset(hw);
1292 kfree(adapter->tx_ring);
1293 kfree(adapter->rx_ring);
1295 if (hw->mac_type == e1000_ce4100)
1296 iounmap(hw->ce4100_gbe_mdio_base_virt);
1297 iounmap(hw->hw_addr);
1298 if (hw->flash_address)
1299 iounmap(hw->flash_address);
1300 pci_release_selected_regions(pdev, adapter->bars);
1302 free_netdev(netdev);
1304 pci_disable_device(pdev);
1308 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1309 * @adapter: board private structure to initialize
1311 * e1000_sw_init initializes the Adapter private data structure.
1312 * e1000_init_hw_struct MUST be called before this function
1314 static int e1000_sw_init(struct e1000_adapter *adapter)
1316 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1318 adapter->num_tx_queues = 1;
1319 adapter->num_rx_queues = 1;
1321 if (e1000_alloc_queues(adapter)) {
1322 e_err(probe, "Unable to allocate memory for queues\n");
1326 /* Explicitly disable IRQ since the NIC can be in any state. */
1327 e1000_irq_disable(adapter);
1329 spin_lock_init(&adapter->stats_lock);
1331 set_bit(__E1000_DOWN, &adapter->flags);
1337 * e1000_alloc_queues - Allocate memory for all rings
1338 * @adapter: board private structure to initialize
1340 * We allocate one ring per queue at run-time since we don't know the
1341 * number of queues at compile-time.
1343 static int e1000_alloc_queues(struct e1000_adapter *adapter)
1345 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1346 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1347 if (!adapter->tx_ring)
1350 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1351 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1352 if (!adapter->rx_ring) {
1353 kfree(adapter->tx_ring);
1357 return E1000_SUCCESS;
1361 * e1000_open - Called when a network interface is made active
1362 * @netdev: network interface device structure
1364 * Returns 0 on success, negative value on failure
1366 * The open entry point is called when a network interface is made
1367 * active by the system (IFF_UP). At this point all resources needed
1368 * for transmit and receive operations are allocated, the interrupt
1369 * handler is registered with the OS, the watchdog task is started,
1370 * and the stack is notified that the interface is ready.
1372 int e1000_open(struct net_device *netdev)
1374 struct e1000_adapter *adapter = netdev_priv(netdev);
1375 struct e1000_hw *hw = &adapter->hw;
1378 /* disallow open during test */
1379 if (test_bit(__E1000_TESTING, &adapter->flags))
1382 netif_carrier_off(netdev);
1384 /* allocate transmit descriptors */
1385 err = e1000_setup_all_tx_resources(adapter);
1389 /* allocate receive descriptors */
1390 err = e1000_setup_all_rx_resources(adapter);
1394 e1000_power_up_phy(adapter);
1396 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1397 if ((hw->mng_cookie.status &
1398 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1399 e1000_update_mng_vlan(adapter);
1402 /* before we allocate an interrupt, we must be ready to handle it.
1403 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1404 * as soon as we call pci_request_irq, so we have to setup our
1405 * clean_rx handler before we do so.
1407 e1000_configure(adapter);
1409 err = e1000_request_irq(adapter);
1413 /* From here on the code is the same as e1000_up() */
1414 clear_bit(__E1000_DOWN, &adapter->flags);
1416 napi_enable(&adapter->napi);
1418 e1000_irq_enable(adapter);
1420 netif_start_queue(netdev);
1422 /* fire a link status change interrupt to start the watchdog */
1423 ew32(ICS, E1000_ICS_LSC);
1425 return E1000_SUCCESS;
1428 e1000_power_down_phy(adapter);
1429 e1000_free_all_rx_resources(adapter);
1431 e1000_free_all_tx_resources(adapter);
1433 e1000_reset(adapter);
1439 * e1000_close - Disables a network interface
1440 * @netdev: network interface device structure
1442 * Returns 0, this is not allowed to fail
1444 * The close entry point is called when an interface is de-activated
1445 * by the OS. The hardware is still under the drivers control, but
1446 * needs to be disabled. A global MAC reset is issued to stop the
1447 * hardware, and all transmit and receive resources are freed.
1449 int e1000_close(struct net_device *netdev)
1451 struct e1000_adapter *adapter = netdev_priv(netdev);
1452 struct e1000_hw *hw = &adapter->hw;
1453 int count = E1000_CHECK_RESET_COUNT;
1455 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
1456 usleep_range(10000, 20000);
1458 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1459 e1000_down(adapter);
1460 e1000_power_down_phy(adapter);
1461 e1000_free_irq(adapter);
1463 e1000_free_all_tx_resources(adapter);
1464 e1000_free_all_rx_resources(adapter);
1466 /* kill manageability vlan ID if supported, but not if a vlan with
1467 * the same ID is registered on the host OS (let 8021q kill it)
1469 if ((hw->mng_cookie.status &
1470 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1471 !test_bit(adapter->mng_vlan_id, adapter->active_vlans)) {
1472 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
1473 adapter->mng_vlan_id);
1480 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1481 * @adapter: address of board private structure
1482 * @start: address of beginning of memory
1483 * @len: length of memory
1485 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1488 struct e1000_hw *hw = &adapter->hw;
1489 unsigned long begin = (unsigned long)start;
1490 unsigned long end = begin + len;
1492 /* First rev 82545 and 82546 need to not allow any memory
1493 * write location to cross 64k boundary due to errata 23
1495 if (hw->mac_type == e1000_82545 ||
1496 hw->mac_type == e1000_ce4100 ||
1497 hw->mac_type == e1000_82546) {
1498 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1505 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1506 * @adapter: board private structure
1507 * @txdr: tx descriptor ring (for a specific queue) to setup
1509 * Return 0 on success, negative on failure
1511 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1512 struct e1000_tx_ring *txdr)
1514 struct pci_dev *pdev = adapter->pdev;
1517 size = sizeof(struct e1000_tx_buffer) * txdr->count;
1518 txdr->buffer_info = vzalloc(size);
1519 if (!txdr->buffer_info)
1522 /* round up to nearest 4K */
1524 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1525 txdr->size = ALIGN(txdr->size, 4096);
1527 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1531 vfree(txdr->buffer_info);
1535 /* Fix for errata 23, can't cross 64kB boundary */
1536 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1537 void *olddesc = txdr->desc;
1538 dma_addr_t olddma = txdr->dma;
1539 e_err(tx_err, "txdr align check failed: %u bytes at %p\n",
1540 txdr->size, txdr->desc);
1541 /* Try again, without freeing the previous */
1542 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size,
1543 &txdr->dma, GFP_KERNEL);
1544 /* Failed allocation, critical failure */
1546 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1548 goto setup_tx_desc_die;
1551 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1553 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1555 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1557 e_err(probe, "Unable to allocate aligned memory "
1558 "for the transmit descriptor ring\n");
1559 vfree(txdr->buffer_info);
1562 /* Free old allocation, new allocation was successful */
1563 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1567 memset(txdr->desc, 0, txdr->size);
1569 txdr->next_to_use = 0;
1570 txdr->next_to_clean = 0;
1576 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1577 * (Descriptors) for all queues
1578 * @adapter: board private structure
1580 * Return 0 on success, negative on failure
1582 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1586 for (i = 0; i < adapter->num_tx_queues; i++) {
1587 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1589 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1590 for (i-- ; i >= 0; i--)
1591 e1000_free_tx_resources(adapter,
1592 &adapter->tx_ring[i]);
1601 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1602 * @adapter: board private structure
1604 * Configure the Tx unit of the MAC after a reset.
1606 static void e1000_configure_tx(struct e1000_adapter *adapter)
1609 struct e1000_hw *hw = &adapter->hw;
1610 u32 tdlen, tctl, tipg;
1613 /* Setup the HW Tx Head and Tail descriptor pointers */
1615 switch (adapter->num_tx_queues) {
1618 tdba = adapter->tx_ring[0].dma;
1619 tdlen = adapter->tx_ring[0].count *
1620 sizeof(struct e1000_tx_desc);
1622 ew32(TDBAH, (tdba >> 32));
1623 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1626 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ?
1627 E1000_TDH : E1000_82542_TDH);
1628 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ?
1629 E1000_TDT : E1000_82542_TDT);
1633 /* Set the default values for the Tx Inter Packet Gap timer */
1634 if ((hw->media_type == e1000_media_type_fiber ||
1635 hw->media_type == e1000_media_type_internal_serdes))
1636 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1638 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1640 switch (hw->mac_type) {
1641 case e1000_82542_rev2_0:
1642 case e1000_82542_rev2_1:
1643 tipg = DEFAULT_82542_TIPG_IPGT;
1644 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1645 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1648 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1649 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1652 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1653 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1656 /* Set the Tx Interrupt Delay register */
1658 ew32(TIDV, adapter->tx_int_delay);
1659 if (hw->mac_type >= e1000_82540)
1660 ew32(TADV, adapter->tx_abs_int_delay);
1662 /* Program the Transmit Control Register */
1665 tctl &= ~E1000_TCTL_CT;
1666 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1667 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1669 e1000_config_collision_dist(hw);
1671 /* Setup Transmit Descriptor Settings for eop descriptor */
1672 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1674 /* only set IDE if we are delaying interrupts using the timers */
1675 if (adapter->tx_int_delay)
1676 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1678 if (hw->mac_type < e1000_82543)
1679 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1681 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1683 /* Cache if we're 82544 running in PCI-X because we'll
1684 * need this to apply a workaround later in the send path.
1686 if (hw->mac_type == e1000_82544 &&
1687 hw->bus_type == e1000_bus_type_pcix)
1688 adapter->pcix_82544 = true;
1695 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1696 * @adapter: board private structure
1697 * @rxdr: rx descriptor ring (for a specific queue) to setup
1699 * Returns 0 on success, negative on failure
1701 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1702 struct e1000_rx_ring *rxdr)
1704 struct pci_dev *pdev = adapter->pdev;
1707 size = sizeof(struct e1000_rx_buffer) * rxdr->count;
1708 rxdr->buffer_info = vzalloc(size);
1709 if (!rxdr->buffer_info)
1712 desc_len = sizeof(struct e1000_rx_desc);
1714 /* Round up to nearest 4K */
1716 rxdr->size = rxdr->count * desc_len;
1717 rxdr->size = ALIGN(rxdr->size, 4096);
1719 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1723 vfree(rxdr->buffer_info);
1727 /* Fix for errata 23, can't cross 64kB boundary */
1728 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1729 void *olddesc = rxdr->desc;
1730 dma_addr_t olddma = rxdr->dma;
1731 e_err(rx_err, "rxdr align check failed: %u bytes at %p\n",
1732 rxdr->size, rxdr->desc);
1733 /* Try again, without freeing the previous */
1734 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size,
1735 &rxdr->dma, GFP_KERNEL);
1736 /* Failed allocation, critical failure */
1738 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1740 goto setup_rx_desc_die;
1743 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1745 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1747 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1749 e_err(probe, "Unable to allocate aligned memory for "
1750 "the Rx descriptor ring\n");
1751 goto setup_rx_desc_die;
1753 /* Free old allocation, new allocation was successful */
1754 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1758 memset(rxdr->desc, 0, rxdr->size);
1760 rxdr->next_to_clean = 0;
1761 rxdr->next_to_use = 0;
1762 rxdr->rx_skb_top = NULL;
1768 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1769 * (Descriptors) for all queues
1770 * @adapter: board private structure
1772 * Return 0 on success, negative on failure
1774 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1778 for (i = 0; i < adapter->num_rx_queues; i++) {
1779 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1781 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1782 for (i-- ; i >= 0; i--)
1783 e1000_free_rx_resources(adapter,
1784 &adapter->rx_ring[i]);
1793 * e1000_setup_rctl - configure the receive control registers
1794 * @adapter: Board private structure
1796 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1798 struct e1000_hw *hw = &adapter->hw;
1803 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1805 rctl |= E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1806 E1000_RCTL_RDMTS_HALF |
1807 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1809 if (hw->tbi_compatibility_on == 1)
1810 rctl |= E1000_RCTL_SBP;
1812 rctl &= ~E1000_RCTL_SBP;
1814 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1815 rctl &= ~E1000_RCTL_LPE;
1817 rctl |= E1000_RCTL_LPE;
1819 /* Setup buffer sizes */
1820 rctl &= ~E1000_RCTL_SZ_4096;
1821 rctl |= E1000_RCTL_BSEX;
1822 switch (adapter->rx_buffer_len) {
1823 case E1000_RXBUFFER_2048:
1825 rctl |= E1000_RCTL_SZ_2048;
1826 rctl &= ~E1000_RCTL_BSEX;
1828 case E1000_RXBUFFER_4096:
1829 rctl |= E1000_RCTL_SZ_4096;
1831 case E1000_RXBUFFER_8192:
1832 rctl |= E1000_RCTL_SZ_8192;
1834 case E1000_RXBUFFER_16384:
1835 rctl |= E1000_RCTL_SZ_16384;
1839 /* This is useful for sniffing bad packets. */
1840 if (adapter->netdev->features & NETIF_F_RXALL) {
1841 /* UPE and MPE will be handled by normal PROMISC logic
1842 * in e1000e_set_rx_mode
1844 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
1845 E1000_RCTL_BAM | /* RX All Bcast Pkts */
1846 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
1848 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
1849 E1000_RCTL_DPF | /* Allow filtered pause */
1850 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
1851 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
1852 * and that breaks VLANs.
1860 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1861 * @adapter: board private structure
1863 * Configure the Rx unit of the MAC after a reset.
1865 static void e1000_configure_rx(struct e1000_adapter *adapter)
1868 struct e1000_hw *hw = &adapter->hw;
1869 u32 rdlen, rctl, rxcsum;
1871 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1872 rdlen = adapter->rx_ring[0].count *
1873 sizeof(struct e1000_rx_desc);
1874 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1875 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1877 rdlen = adapter->rx_ring[0].count *
1878 sizeof(struct e1000_rx_desc);
1879 adapter->clean_rx = e1000_clean_rx_irq;
1880 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1883 /* disable receives while setting up the descriptors */
1885 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1887 /* set the Receive Delay Timer Register */
1888 ew32(RDTR, adapter->rx_int_delay);
1890 if (hw->mac_type >= e1000_82540) {
1891 ew32(RADV, adapter->rx_abs_int_delay);
1892 if (adapter->itr_setting != 0)
1893 ew32(ITR, 1000000000 / (adapter->itr * 256));
1896 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1897 * the Base and Length of the Rx Descriptor Ring
1899 switch (adapter->num_rx_queues) {
1902 rdba = adapter->rx_ring[0].dma;
1904 ew32(RDBAH, (rdba >> 32));
1905 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1908 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ?
1909 E1000_RDH : E1000_82542_RDH);
1910 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ?
1911 E1000_RDT : E1000_82542_RDT);
1915 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1916 if (hw->mac_type >= e1000_82543) {
1917 rxcsum = er32(RXCSUM);
1918 if (adapter->rx_csum)
1919 rxcsum |= E1000_RXCSUM_TUOFL;
1921 /* don't need to clear IPPCSE as it defaults to 0 */
1922 rxcsum &= ~E1000_RXCSUM_TUOFL;
1923 ew32(RXCSUM, rxcsum);
1926 /* Enable Receives */
1927 ew32(RCTL, rctl | E1000_RCTL_EN);
1931 * e1000_free_tx_resources - Free Tx Resources per Queue
1932 * @adapter: board private structure
1933 * @tx_ring: Tx descriptor ring for a specific queue
1935 * Free all transmit software resources
1937 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1938 struct e1000_tx_ring *tx_ring)
1940 struct pci_dev *pdev = adapter->pdev;
1942 e1000_clean_tx_ring(adapter, tx_ring);
1944 vfree(tx_ring->buffer_info);
1945 tx_ring->buffer_info = NULL;
1947 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1950 tx_ring->desc = NULL;
1954 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1955 * @adapter: board private structure
1957 * Free all transmit software resources
1959 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1963 for (i = 0; i < adapter->num_tx_queues; i++)
1964 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1968 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1969 struct e1000_tx_buffer *buffer_info)
1971 if (buffer_info->dma) {
1972 if (buffer_info->mapped_as_page)
1973 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1974 buffer_info->length, DMA_TO_DEVICE);
1976 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1977 buffer_info->length,
1979 buffer_info->dma = 0;
1981 if (buffer_info->skb) {
1982 dev_kfree_skb_any(buffer_info->skb);
1983 buffer_info->skb = NULL;
1985 buffer_info->time_stamp = 0;
1986 /* buffer_info must be completely set up in the transmit path */
1990 * e1000_clean_tx_ring - Free Tx Buffers
1991 * @adapter: board private structure
1992 * @tx_ring: ring to be cleaned
1994 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1995 struct e1000_tx_ring *tx_ring)
1997 struct e1000_hw *hw = &adapter->hw;
1998 struct e1000_tx_buffer *buffer_info;
2002 /* Free all the Tx ring sk_buffs */
2004 for (i = 0; i < tx_ring->count; i++) {
2005 buffer_info = &tx_ring->buffer_info[i];
2006 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2009 netdev_reset_queue(adapter->netdev);
2010 size = sizeof(struct e1000_tx_buffer) * tx_ring->count;
2011 memset(tx_ring->buffer_info, 0, size);
2013 /* Zero out the descriptor ring */
2015 memset(tx_ring->desc, 0, tx_ring->size);
2017 tx_ring->next_to_use = 0;
2018 tx_ring->next_to_clean = 0;
2019 tx_ring->last_tx_tso = false;
2021 writel(0, hw->hw_addr + tx_ring->tdh);
2022 writel(0, hw->hw_addr + tx_ring->tdt);
2026 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2027 * @adapter: board private structure
2029 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2033 for (i = 0; i < adapter->num_tx_queues; i++)
2034 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2038 * e1000_free_rx_resources - Free Rx Resources
2039 * @adapter: board private structure
2040 * @rx_ring: ring to clean the resources from
2042 * Free all receive software resources
2044 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2045 struct e1000_rx_ring *rx_ring)
2047 struct pci_dev *pdev = adapter->pdev;
2049 e1000_clean_rx_ring(adapter, rx_ring);
2051 vfree(rx_ring->buffer_info);
2052 rx_ring->buffer_info = NULL;
2054 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2057 rx_ring->desc = NULL;
2061 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2062 * @adapter: board private structure
2064 * Free all receive software resources
2066 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2070 for (i = 0; i < adapter->num_rx_queues; i++)
2071 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2074 #define E1000_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
2075 static unsigned int e1000_frag_len(const struct e1000_adapter *a)
2077 return SKB_DATA_ALIGN(a->rx_buffer_len + E1000_HEADROOM) +
2078 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2081 static void *e1000_alloc_frag(const struct e1000_adapter *a)
2083 unsigned int len = e1000_frag_len(a);
2084 u8 *data = netdev_alloc_frag(len);
2087 data += E1000_HEADROOM;
2092 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2093 * @adapter: board private structure
2094 * @rx_ring: ring to free buffers from
2096 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2097 struct e1000_rx_ring *rx_ring)
2099 struct e1000_hw *hw = &adapter->hw;
2100 struct e1000_rx_buffer *buffer_info;
2101 struct pci_dev *pdev = adapter->pdev;
2105 /* Free all the Rx netfrags */
2106 for (i = 0; i < rx_ring->count; i++) {
2107 buffer_info = &rx_ring->buffer_info[i];
2108 if (adapter->clean_rx == e1000_clean_rx_irq) {
2109 if (buffer_info->dma)
2110 dma_unmap_single(&pdev->dev, buffer_info->dma,
2111 adapter->rx_buffer_len,
2113 if (buffer_info->rxbuf.data) {
2114 skb_free_frag(buffer_info->rxbuf.data);
2115 buffer_info->rxbuf.data = NULL;
2117 } else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2118 if (buffer_info->dma)
2119 dma_unmap_page(&pdev->dev, buffer_info->dma,
2120 adapter->rx_buffer_len,
2122 if (buffer_info->rxbuf.page) {
2123 put_page(buffer_info->rxbuf.page);
2124 buffer_info->rxbuf.page = NULL;
2128 buffer_info->dma = 0;
2131 /* there also may be some cached data from a chained receive */
2132 napi_free_frags(&adapter->napi);
2133 rx_ring->rx_skb_top = NULL;
2135 size = sizeof(struct e1000_rx_buffer) * rx_ring->count;
2136 memset(rx_ring->buffer_info, 0, size);
2138 /* Zero out the descriptor ring */
2139 memset(rx_ring->desc, 0, rx_ring->size);
2141 rx_ring->next_to_clean = 0;
2142 rx_ring->next_to_use = 0;
2144 writel(0, hw->hw_addr + rx_ring->rdh);
2145 writel(0, hw->hw_addr + rx_ring->rdt);
2149 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2150 * @adapter: board private structure
2152 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2156 for (i = 0; i < adapter->num_rx_queues; i++)
2157 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2160 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2161 * and memory write and invalidate disabled for certain operations
2163 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2165 struct e1000_hw *hw = &adapter->hw;
2166 struct net_device *netdev = adapter->netdev;
2169 e1000_pci_clear_mwi(hw);
2172 rctl |= E1000_RCTL_RST;
2174 E1000_WRITE_FLUSH();
2177 if (netif_running(netdev))
2178 e1000_clean_all_rx_rings(adapter);
2181 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2183 struct e1000_hw *hw = &adapter->hw;
2184 struct net_device *netdev = adapter->netdev;
2188 rctl &= ~E1000_RCTL_RST;
2190 E1000_WRITE_FLUSH();
2193 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2194 e1000_pci_set_mwi(hw);
2196 if (netif_running(netdev)) {
2197 /* No need to loop, because 82542 supports only 1 queue */
2198 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2199 e1000_configure_rx(adapter);
2200 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2205 * e1000_set_mac - Change the Ethernet Address of the NIC
2206 * @netdev: network interface device structure
2207 * @p: pointer to an address structure
2209 * Returns 0 on success, negative on failure
2211 static int e1000_set_mac(struct net_device *netdev, void *p)
2213 struct e1000_adapter *adapter = netdev_priv(netdev);
2214 struct e1000_hw *hw = &adapter->hw;
2215 struct sockaddr *addr = p;
2217 if (!is_valid_ether_addr(addr->sa_data))
2218 return -EADDRNOTAVAIL;
2220 /* 82542 2.0 needs to be in reset to write receive address registers */
2222 if (hw->mac_type == e1000_82542_rev2_0)
2223 e1000_enter_82542_rst(adapter);
2225 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2226 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2228 e1000_rar_set(hw, hw->mac_addr, 0);
2230 if (hw->mac_type == e1000_82542_rev2_0)
2231 e1000_leave_82542_rst(adapter);
2237 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2238 * @netdev: network interface device structure
2240 * The set_rx_mode entry point is called whenever the unicast or multicast
2241 * address lists or the network interface flags are updated. This routine is
2242 * responsible for configuring the hardware for proper unicast, multicast,
2243 * promiscuous mode, and all-multi behavior.
2245 static void e1000_set_rx_mode(struct net_device *netdev)
2247 struct e1000_adapter *adapter = netdev_priv(netdev);
2248 struct e1000_hw *hw = &adapter->hw;
2249 struct netdev_hw_addr *ha;
2250 bool use_uc = false;
2253 int i, rar_entries = E1000_RAR_ENTRIES;
2254 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
2255 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2260 /* Check for Promiscuous and All Multicast modes */
2264 if (netdev->flags & IFF_PROMISC) {
2265 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2266 rctl &= ~E1000_RCTL_VFE;
2268 if (netdev->flags & IFF_ALLMULTI)
2269 rctl |= E1000_RCTL_MPE;
2271 rctl &= ~E1000_RCTL_MPE;
2272 /* Enable VLAN filter if there is a VLAN */
2273 if (e1000_vlan_used(adapter))
2274 rctl |= E1000_RCTL_VFE;
2277 if (netdev_uc_count(netdev) > rar_entries - 1) {
2278 rctl |= E1000_RCTL_UPE;
2279 } else if (!(netdev->flags & IFF_PROMISC)) {
2280 rctl &= ~E1000_RCTL_UPE;
2286 /* 82542 2.0 needs to be in reset to write receive address registers */
2288 if (hw->mac_type == e1000_82542_rev2_0)
2289 e1000_enter_82542_rst(adapter);
2291 /* load the first 14 addresses into the exact filters 1-14. Unicast
2292 * addresses take precedence to avoid disabling unicast filtering
2295 * RAR 0 is used for the station MAC address
2296 * if there are not 14 addresses, go ahead and clear the filters
2300 netdev_for_each_uc_addr(ha, netdev) {
2301 if (i == rar_entries)
2303 e1000_rar_set(hw, ha->addr, i++);
2306 netdev_for_each_mc_addr(ha, netdev) {
2307 if (i == rar_entries) {
2308 /* load any remaining addresses into the hash table */
2309 u32 hash_reg, hash_bit, mta;
2310 hash_value = e1000_hash_mc_addr(hw, ha->addr);
2311 hash_reg = (hash_value >> 5) & 0x7F;
2312 hash_bit = hash_value & 0x1F;
2313 mta = (1 << hash_bit);
2314 mcarray[hash_reg] |= mta;
2316 e1000_rar_set(hw, ha->addr, i++);
2320 for (; i < rar_entries; i++) {
2321 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2322 E1000_WRITE_FLUSH();
2323 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2324 E1000_WRITE_FLUSH();
2327 /* write the hash table completely, write from bottom to avoid
2328 * both stupid write combining chipsets, and flushing each write
2330 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2331 /* If we are on an 82544 has an errata where writing odd
2332 * offsets overwrites the previous even offset, but writing
2333 * backwards over the range solves the issue by always
2334 * writing the odd offset first
2336 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2338 E1000_WRITE_FLUSH();
2340 if (hw->mac_type == e1000_82542_rev2_0)
2341 e1000_leave_82542_rst(adapter);
2347 * e1000_update_phy_info_task - get phy info
2348 * @work: work struct contained inside adapter struct
2350 * Need to wait a few seconds after link up to get diagnostic information from
2353 static void e1000_update_phy_info_task(struct work_struct *work)
2355 struct e1000_adapter *adapter = container_of(work,
2356 struct e1000_adapter,
2357 phy_info_task.work);
2359 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2363 * e1000_82547_tx_fifo_stall_task - task to complete work
2364 * @work: work struct contained inside adapter struct
2366 static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
2368 struct e1000_adapter *adapter = container_of(work,
2369 struct e1000_adapter,
2370 fifo_stall_task.work);
2371 struct e1000_hw *hw = &adapter->hw;
2372 struct net_device *netdev = adapter->netdev;
2375 if (atomic_read(&adapter->tx_fifo_stall)) {
2376 if ((er32(TDT) == er32(TDH)) &&
2377 (er32(TDFT) == er32(TDFH)) &&
2378 (er32(TDFTS) == er32(TDFHS))) {
2380 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2381 ew32(TDFT, adapter->tx_head_addr);
2382 ew32(TDFH, adapter->tx_head_addr);
2383 ew32(TDFTS, adapter->tx_head_addr);
2384 ew32(TDFHS, adapter->tx_head_addr);
2386 E1000_WRITE_FLUSH();
2388 adapter->tx_fifo_head = 0;
2389 atomic_set(&adapter->tx_fifo_stall, 0);
2390 netif_wake_queue(netdev);
2391 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
2392 schedule_delayed_work(&adapter->fifo_stall_task, 1);
2397 bool e1000_has_link(struct e1000_adapter *adapter)
2399 struct e1000_hw *hw = &adapter->hw;
2400 bool link_active = false;
2402 /* get_link_status is set on LSC (link status) interrupt or rx
2403 * sequence error interrupt (except on intel ce4100).
2404 * get_link_status will stay false until the
2405 * e1000_check_for_link establishes link for copper adapters
2408 switch (hw->media_type) {
2409 case e1000_media_type_copper:
2410 if (hw->mac_type == e1000_ce4100)
2411 hw->get_link_status = 1;
2412 if (hw->get_link_status) {
2413 e1000_check_for_link(hw);
2414 link_active = !hw->get_link_status;
2419 case e1000_media_type_fiber:
2420 e1000_check_for_link(hw);
2421 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2423 case e1000_media_type_internal_serdes:
2424 e1000_check_for_link(hw);
2425 link_active = hw->serdes_has_link;
2435 * e1000_watchdog - work function
2436 * @work: work struct contained inside adapter struct
2438 static void e1000_watchdog(struct work_struct *work)
2440 struct e1000_adapter *adapter = container_of(work,
2441 struct e1000_adapter,
2442 watchdog_task.work);
2443 struct e1000_hw *hw = &adapter->hw;
2444 struct net_device *netdev = adapter->netdev;
2445 struct e1000_tx_ring *txdr = adapter->tx_ring;
2448 link = e1000_has_link(adapter);
2449 if ((netif_carrier_ok(netdev)) && link)
2453 if (!netif_carrier_ok(netdev)) {
2456 /* update snapshot of PHY registers on LSC */
2457 e1000_get_speed_and_duplex(hw,
2458 &adapter->link_speed,
2459 &adapter->link_duplex);
2462 pr_info("%s NIC Link is Up %d Mbps %s, "
2463 "Flow Control: %s\n",
2465 adapter->link_speed,
2466 adapter->link_duplex == FULL_DUPLEX ?
2467 "Full Duplex" : "Half Duplex",
2468 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2469 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2470 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2471 E1000_CTRL_TFCE) ? "TX" : "None")));
2473 /* adjust timeout factor according to speed/duplex */
2474 adapter->tx_timeout_factor = 1;
2475 switch (adapter->link_speed) {
2478 adapter->tx_timeout_factor = 16;
2482 /* maybe add some timeout factor ? */
2486 /* enable transmits in the hardware */
2488 tctl |= E1000_TCTL_EN;
2491 netif_carrier_on(netdev);
2492 if (!test_bit(__E1000_DOWN, &adapter->flags))
2493 schedule_delayed_work(&adapter->phy_info_task,
2495 adapter->smartspeed = 0;
2498 if (netif_carrier_ok(netdev)) {
2499 adapter->link_speed = 0;
2500 adapter->link_duplex = 0;
2501 pr_info("%s NIC Link is Down\n",
2503 netif_carrier_off(netdev);
2505 if (!test_bit(__E1000_DOWN, &adapter->flags))
2506 schedule_delayed_work(&adapter->phy_info_task,
2510 e1000_smartspeed(adapter);
2514 e1000_update_stats(adapter);
2516 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2517 adapter->tpt_old = adapter->stats.tpt;
2518 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2519 adapter->colc_old = adapter->stats.colc;
2521 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2522 adapter->gorcl_old = adapter->stats.gorcl;
2523 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2524 adapter->gotcl_old = adapter->stats.gotcl;
2526 e1000_update_adaptive(hw);
2528 if (!netif_carrier_ok(netdev)) {
2529 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2530 /* We've lost link, so the controller stops DMA,
2531 * but we've got queued Tx work that's never going
2532 * to get done, so reset controller to flush Tx.
2533 * (Do the reset outside of interrupt context).
2535 adapter->tx_timeout_count++;
2536 schedule_work(&adapter->reset_task);
2537 /* exit immediately since reset is imminent */
2542 /* Simple mode for Interrupt Throttle Rate (ITR) */
2543 if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) {
2544 /* Symmetric Tx/Rx gets a reduced ITR=2000;
2545 * Total asymmetrical Tx or Rx gets ITR=8000;
2546 * everyone else is between 2000-8000.
2548 u32 goc = (adapter->gotcl + adapter->gorcl) / 10000;
2549 u32 dif = (adapter->gotcl > adapter->gorcl ?
2550 adapter->gotcl - adapter->gorcl :
2551 adapter->gorcl - adapter->gotcl) / 10000;
2552 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2554 ew32(ITR, 1000000000 / (itr * 256));
2557 /* Cause software interrupt to ensure rx ring is cleaned */
2558 ew32(ICS, E1000_ICS_RXDMT0);
2560 /* Force detection of hung controller every watchdog period */
2561 adapter->detect_tx_hung = true;
2563 /* Reschedule the task */
2564 if (!test_bit(__E1000_DOWN, &adapter->flags))
2565 schedule_delayed_work(&adapter->watchdog_task, 2 * HZ);
2568 enum latency_range {
2572 latency_invalid = 255
2576 * e1000_update_itr - update the dynamic ITR value based on statistics
2577 * @adapter: pointer to adapter
2578 * @itr_setting: current adapter->itr
2579 * @packets: the number of packets during this measurement interval
2580 * @bytes: the number of bytes during this measurement interval
2582 * Stores a new ITR value based on packets and byte
2583 * counts during the last interrupt. The advantage of per interrupt
2584 * computation is faster updates and more accurate ITR for the current
2585 * traffic pattern. Constants in this function were computed
2586 * based on theoretical maximum wire speed and thresholds were set based
2587 * on testing data as well as attempting to minimize response time
2588 * while increasing bulk throughput.
2589 * this functionality is controlled by the InterruptThrottleRate module
2590 * parameter (see e1000_param.c)
2592 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2593 u16 itr_setting, int packets, int bytes)
2595 unsigned int retval = itr_setting;
2596 struct e1000_hw *hw = &adapter->hw;
2598 if (unlikely(hw->mac_type < e1000_82540))
2599 goto update_itr_done;
2602 goto update_itr_done;
2604 switch (itr_setting) {
2605 case lowest_latency:
2606 /* jumbo frames get bulk treatment*/
2607 if (bytes/packets > 8000)
2608 retval = bulk_latency;
2609 else if ((packets < 5) && (bytes > 512))
2610 retval = low_latency;
2612 case low_latency: /* 50 usec aka 20000 ints/s */
2613 if (bytes > 10000) {
2614 /* jumbo frames need bulk latency setting */
2615 if (bytes/packets > 8000)
2616 retval = bulk_latency;
2617 else if ((packets < 10) || ((bytes/packets) > 1200))
2618 retval = bulk_latency;
2619 else if ((packets > 35))
2620 retval = lowest_latency;
2621 } else if (bytes/packets > 2000)
2622 retval = bulk_latency;
2623 else if (packets <= 2 && bytes < 512)
2624 retval = lowest_latency;
2626 case bulk_latency: /* 250 usec aka 4000 ints/s */
2627 if (bytes > 25000) {
2629 retval = low_latency;
2630 } else if (bytes < 6000) {
2631 retval = low_latency;
2640 static void e1000_set_itr(struct e1000_adapter *adapter)
2642 struct e1000_hw *hw = &adapter->hw;
2644 u32 new_itr = adapter->itr;
2646 if (unlikely(hw->mac_type < e1000_82540))
2649 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2650 if (unlikely(adapter->link_speed != SPEED_1000)) {
2656 adapter->tx_itr = e1000_update_itr(adapter, adapter->tx_itr,
2657 adapter->total_tx_packets,
2658 adapter->total_tx_bytes);
2659 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2660 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2661 adapter->tx_itr = low_latency;
2663 adapter->rx_itr = e1000_update_itr(adapter, adapter->rx_itr,
2664 adapter->total_rx_packets,
2665 adapter->total_rx_bytes);
2666 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2667 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2668 adapter->rx_itr = low_latency;
2670 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2672 switch (current_itr) {
2673 /* counts and packets in update_itr are dependent on these numbers */
2674 case lowest_latency:
2678 new_itr = 20000; /* aka hwitr = ~200 */
2688 if (new_itr != adapter->itr) {
2689 /* this attempts to bias the interrupt rate towards Bulk
2690 * by adding intermediate steps when interrupt rate is
2693 new_itr = new_itr > adapter->itr ?
2694 min(adapter->itr + (new_itr >> 2), new_itr) :
2696 adapter->itr = new_itr;
2697 ew32(ITR, 1000000000 / (new_itr * 256));
2701 #define E1000_TX_FLAGS_CSUM 0x00000001
2702 #define E1000_TX_FLAGS_VLAN 0x00000002
2703 #define E1000_TX_FLAGS_TSO 0x00000004
2704 #define E1000_TX_FLAGS_IPV4 0x00000008
2705 #define E1000_TX_FLAGS_NO_FCS 0x00000010
2706 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2707 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2709 static int e1000_tso(struct e1000_adapter *adapter,
2710 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2713 struct e1000_context_desc *context_desc;
2714 struct e1000_tx_buffer *buffer_info;
2717 u16 ipcse = 0, tucse, mss;
2718 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2720 if (skb_is_gso(skb)) {
2723 err = skb_cow_head(skb, 0);
2727 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2728 mss = skb_shinfo(skb)->gso_size;
2729 if (protocol == htons(ETH_P_IP)) {
2730 struct iphdr *iph = ip_hdr(skb);
2733 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2737 cmd_length = E1000_TXD_CMD_IP;
2738 ipcse = skb_transport_offset(skb) - 1;
2739 } else if (skb_is_gso_v6(skb)) {
2740 ipv6_hdr(skb)->payload_len = 0;
2741 tcp_hdr(skb)->check =
2742 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2743 &ipv6_hdr(skb)->daddr,
2747 ipcss = skb_network_offset(skb);
2748 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2749 tucss = skb_transport_offset(skb);
2750 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2753 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2754 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2756 i = tx_ring->next_to_use;
2757 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2758 buffer_info = &tx_ring->buffer_info[i];
2760 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2761 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2762 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2763 context_desc->upper_setup.tcp_fields.tucss = tucss;
2764 context_desc->upper_setup.tcp_fields.tucso = tucso;
2765 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2766 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2767 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2768 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2770 buffer_info->time_stamp = jiffies;
2771 buffer_info->next_to_watch = i;
2773 if (++i == tx_ring->count)
2776 tx_ring->next_to_use = i;
2783 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2784 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2787 struct e1000_context_desc *context_desc;
2788 struct e1000_tx_buffer *buffer_info;
2791 u32 cmd_len = E1000_TXD_CMD_DEXT;
2793 if (skb->ip_summed != CHECKSUM_PARTIAL)
2797 case cpu_to_be16(ETH_P_IP):
2798 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2799 cmd_len |= E1000_TXD_CMD_TCP;
2801 case cpu_to_be16(ETH_P_IPV6):
2802 /* XXX not handling all IPV6 headers */
2803 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2804 cmd_len |= E1000_TXD_CMD_TCP;
2807 if (unlikely(net_ratelimit()))
2808 e_warn(drv, "checksum_partial proto=%x!\n",
2813 css = skb_checksum_start_offset(skb);
2815 i = tx_ring->next_to_use;
2816 buffer_info = &tx_ring->buffer_info[i];
2817 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2819 context_desc->lower_setup.ip_config = 0;
2820 context_desc->upper_setup.tcp_fields.tucss = css;
2821 context_desc->upper_setup.tcp_fields.tucso =
2822 css + skb->csum_offset;
2823 context_desc->upper_setup.tcp_fields.tucse = 0;
2824 context_desc->tcp_seg_setup.data = 0;
2825 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2827 buffer_info->time_stamp = jiffies;
2828 buffer_info->next_to_watch = i;
2830 if (unlikely(++i == tx_ring->count))
2833 tx_ring->next_to_use = i;
2838 #define E1000_MAX_TXD_PWR 12
2839 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2841 static int e1000_tx_map(struct e1000_adapter *adapter,
2842 struct e1000_tx_ring *tx_ring,
2843 struct sk_buff *skb, unsigned int first,
2844 unsigned int max_per_txd, unsigned int nr_frags,
2847 struct e1000_hw *hw = &adapter->hw;
2848 struct pci_dev *pdev = adapter->pdev;
2849 struct e1000_tx_buffer *buffer_info;
2850 unsigned int len = skb_headlen(skb);
2851 unsigned int offset = 0, size, count = 0, i;
2852 unsigned int f, bytecount, segs;
2854 i = tx_ring->next_to_use;
2857 buffer_info = &tx_ring->buffer_info[i];
2858 size = min(len, max_per_txd);
2859 /* Workaround for Controller erratum --
2860 * descriptor for non-tso packet in a linear SKB that follows a
2861 * tso gets written back prematurely before the data is fully
2862 * DMA'd to the controller
2864 if (!skb->data_len && tx_ring->last_tx_tso &&
2866 tx_ring->last_tx_tso = false;
2870 /* Workaround for premature desc write-backs
2871 * in TSO mode. Append 4-byte sentinel desc
2873 if (unlikely(mss && !nr_frags && size == len && size > 8))
2875 /* work-around for errata 10 and it applies
2876 * to all controllers in PCI-X mode
2877 * The fix is to make sure that the first descriptor of a
2878 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2880 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
2881 (size > 2015) && count == 0))
2884 /* Workaround for potential 82544 hang in PCI-X. Avoid
2885 * terminating buffers within evenly-aligned dwords.
2887 if (unlikely(adapter->pcix_82544 &&
2888 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2892 buffer_info->length = size;
2893 /* set time_stamp *before* dma to help avoid a possible race */
2894 buffer_info->time_stamp = jiffies;
2895 buffer_info->mapped_as_page = false;
2896 buffer_info->dma = dma_map_single(&pdev->dev,
2898 size, DMA_TO_DEVICE);
2899 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2901 buffer_info->next_to_watch = i;
2908 if (unlikely(i == tx_ring->count))
2913 for (f = 0; f < nr_frags; f++) {
2914 const struct skb_frag_struct *frag;
2916 frag = &skb_shinfo(skb)->frags[f];
2917 len = skb_frag_size(frag);
2921 unsigned long bufend;
2923 if (unlikely(i == tx_ring->count))
2926 buffer_info = &tx_ring->buffer_info[i];
2927 size = min(len, max_per_txd);
2928 /* Workaround for premature desc write-backs
2929 * in TSO mode. Append 4-byte sentinel desc
2931 if (unlikely(mss && f == (nr_frags-1) &&
2932 size == len && size > 8))
2934 /* Workaround for potential 82544 hang in PCI-X.
2935 * Avoid terminating buffers within evenly-aligned
2938 bufend = (unsigned long)
2939 page_to_phys(skb_frag_page(frag));
2940 bufend += offset + size - 1;
2941 if (unlikely(adapter->pcix_82544 &&
2946 buffer_info->length = size;
2947 buffer_info->time_stamp = jiffies;
2948 buffer_info->mapped_as_page = true;
2949 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
2950 offset, size, DMA_TO_DEVICE);
2951 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2953 buffer_info->next_to_watch = i;
2961 segs = skb_shinfo(skb)->gso_segs ?: 1;
2962 /* multiply data chunks by size of headers */
2963 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
2965 tx_ring->buffer_info[i].skb = skb;
2966 tx_ring->buffer_info[i].segs = segs;
2967 tx_ring->buffer_info[i].bytecount = bytecount;
2968 tx_ring->buffer_info[first].next_to_watch = i;
2973 dev_err(&pdev->dev, "TX DMA map failed\n");
2974 buffer_info->dma = 0;
2980 i += tx_ring->count;
2982 buffer_info = &tx_ring->buffer_info[i];
2983 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2989 static void e1000_tx_queue(struct e1000_adapter *adapter,
2990 struct e1000_tx_ring *tx_ring, int tx_flags,
2993 struct e1000_tx_desc *tx_desc = NULL;
2994 struct e1000_tx_buffer *buffer_info;
2995 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2998 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2999 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3001 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3003 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3004 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3007 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3008 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3009 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3012 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3013 txd_lower |= E1000_TXD_CMD_VLE;
3014 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3017 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
3018 txd_lower &= ~(E1000_TXD_CMD_IFCS);
3020 i = tx_ring->next_to_use;
3023 buffer_info = &tx_ring->buffer_info[i];
3024 tx_desc = E1000_TX_DESC(*tx_ring, i);
3025 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3026 tx_desc->lower.data =
3027 cpu_to_le32(txd_lower | buffer_info->length);
3028 tx_desc->upper.data = cpu_to_le32(txd_upper);
3029 if (unlikely(++i == tx_ring->count))
3033 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3035 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
3036 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
3037 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
3039 /* Force memory writes to complete before letting h/w
3040 * know there are new descriptors to fetch. (Only
3041 * applicable for weak-ordered memory model archs,
3046 tx_ring->next_to_use = i;
3049 /* 82547 workaround to avoid controller hang in half-duplex environment.
3050 * The workaround is to avoid queuing a large packet that would span
3051 * the internal Tx FIFO ring boundary by notifying the stack to resend
3052 * the packet at a later time. This gives the Tx FIFO an opportunity to
3053 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3054 * to the beginning of the Tx FIFO.
3057 #define E1000_FIFO_HDR 0x10
3058 #define E1000_82547_PAD_LEN 0x3E0
3060 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3061 struct sk_buff *skb)
3063 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3064 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3066 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3068 if (adapter->link_duplex != HALF_DUPLEX)
3069 goto no_fifo_stall_required;
3071 if (atomic_read(&adapter->tx_fifo_stall))
3074 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3075 atomic_set(&adapter->tx_fifo_stall, 1);
3079 no_fifo_stall_required:
3080 adapter->tx_fifo_head += skb_fifo_len;
3081 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3082 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3086 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3088 struct e1000_adapter *adapter = netdev_priv(netdev);
3089 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3091 netif_stop_queue(netdev);
3092 /* Herbert's original patch had:
3093 * smp_mb__after_netif_stop_queue();
3094 * but since that doesn't exist yet, just open code it.
3098 /* We need to check again in a case another CPU has just
3099 * made room available.
3101 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3105 netif_start_queue(netdev);
3106 ++adapter->restart_queue;
3110 static int e1000_maybe_stop_tx(struct net_device *netdev,
3111 struct e1000_tx_ring *tx_ring, int size)
3113 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3115 return __e1000_maybe_stop_tx(netdev, size);
3118 #define TXD_USE_COUNT(S, X) (((S) + ((1 << (X)) - 1)) >> (X))
3119 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3120 struct net_device *netdev)
3122 struct e1000_adapter *adapter = netdev_priv(netdev);
3123 struct e1000_hw *hw = &adapter->hw;
3124 struct e1000_tx_ring *tx_ring;
3125 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3126 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3127 unsigned int tx_flags = 0;
3128 unsigned int len = skb_headlen(skb);
3129 unsigned int nr_frags;
3134 __be16 protocol = vlan_get_protocol(skb);
3136 /* This goes back to the question of how to logically map a Tx queue
3137 * to a flow. Right now, performance is impacted slightly negatively
3138 * if using multiple Tx queues. If the stack breaks away from a
3139 * single qdisc implementation, we can look at this again.
3141 tx_ring = adapter->tx_ring;
3143 /* On PCI/PCI-X HW, if packet size is less than ETH_ZLEN,
3144 * packets may get corrupted during padding by HW.
3145 * To WA this issue, pad all small packets manually.
3147 if (eth_skb_pad(skb))
3148 return NETDEV_TX_OK;
3150 mss = skb_shinfo(skb)->gso_size;
3151 /* The controller does a simple calculation to
3152 * make sure there is enough room in the FIFO before
3153 * initiating the DMA for each buffer. The calc is:
3154 * 4 = ceil(buffer len/mss). To make sure we don't
3155 * overrun the FIFO, adjust the max buffer len if mss
3160 max_per_txd = min(mss << 2, max_per_txd);
3161 max_txd_pwr = fls(max_per_txd) - 1;
3163 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3164 if (skb->data_len && hdr_len == len) {
3165 switch (hw->mac_type) {
3166 unsigned int pull_size;
3168 /* Make sure we have room to chop off 4 bytes,
3169 * and that the end alignment will work out to
3170 * this hardware's requirements
3171 * NOTE: this is a TSO only workaround
3172 * if end byte alignment not correct move us
3173 * into the next dword
3175 if ((unsigned long)(skb_tail_pointer(skb) - 1)
3179 pull_size = min((unsigned int)4, skb->data_len);
3180 if (!__pskb_pull_tail(skb, pull_size)) {
3181 e_err(drv, "__pskb_pull_tail "
3183 dev_kfree_skb_any(skb);
3184 return NETDEV_TX_OK;
3186 len = skb_headlen(skb);
3195 /* reserve a descriptor for the offload context */
3196 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3200 /* Controller Erratum workaround */
3201 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3204 count += TXD_USE_COUNT(len, max_txd_pwr);
3206 if (adapter->pcix_82544)
3209 /* work-around for errata 10 and it applies to all controllers
3210 * in PCI-X mode, so add one more descriptor to the count
3212 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3216 nr_frags = skb_shinfo(skb)->nr_frags;
3217 for (f = 0; f < nr_frags; f++)
3218 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
3220 if (adapter->pcix_82544)
3223 /* need: count + 2 desc gap to keep tail from touching
3224 * head, otherwise try next time
3226 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3227 return NETDEV_TX_BUSY;
3229 if (unlikely((hw->mac_type == e1000_82547) &&
3230 (e1000_82547_fifo_workaround(adapter, skb)))) {
3231 netif_stop_queue(netdev);
3232 if (!test_bit(__E1000_DOWN, &adapter->flags))
3233 schedule_delayed_work(&adapter->fifo_stall_task, 1);
3234 return NETDEV_TX_BUSY;
3237 if (skb_vlan_tag_present(skb)) {
3238 tx_flags |= E1000_TX_FLAGS_VLAN;
3239 tx_flags |= (skb_vlan_tag_get(skb) <<
3240 E1000_TX_FLAGS_VLAN_SHIFT);
3243 first = tx_ring->next_to_use;
3245 tso = e1000_tso(adapter, tx_ring, skb, protocol);
3247 dev_kfree_skb_any(skb);
3248 return NETDEV_TX_OK;
3252 if (likely(hw->mac_type != e1000_82544))
3253 tx_ring->last_tx_tso = true;
3254 tx_flags |= E1000_TX_FLAGS_TSO;
3255 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb, protocol)))
3256 tx_flags |= E1000_TX_FLAGS_CSUM;
3258 if (protocol == htons(ETH_P_IP))
3259 tx_flags |= E1000_TX_FLAGS_IPV4;
3261 if (unlikely(skb->no_fcs))
3262 tx_flags |= E1000_TX_FLAGS_NO_FCS;
3264 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3268 /* The descriptors needed is higher than other Intel drivers
3269 * due to a number of workarounds. The breakdown is below:
3270 * Data descriptors: MAX_SKB_FRAGS + 1
3271 * Context Descriptor: 1
3272 * Keep head from touching tail: 2
3275 int desc_needed = MAX_SKB_FRAGS + 7;
3277 netdev_sent_queue(netdev, skb->len);
3278 skb_tx_timestamp(skb);
3280 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3282 /* 82544 potentially requires twice as many data descriptors
3283 * in order to guarantee buffers don't end on evenly-aligned
3286 if (adapter->pcix_82544)
3287 desc_needed += MAX_SKB_FRAGS + 1;
3289 /* Make sure there is space in the ring for the next send. */
3290 e1000_maybe_stop_tx(netdev, tx_ring, desc_needed);
3292 if (!skb->xmit_more ||
3293 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
3294 writel(tx_ring->next_to_use, hw->hw_addr + tx_ring->tdt);
3295 /* we need this if more than one processor can write to
3296 * our tail at a time, it synchronizes IO on IA64/Altix
3302 dev_kfree_skb_any(skb);
3303 tx_ring->buffer_info[first].time_stamp = 0;
3304 tx_ring->next_to_use = first;
3307 return NETDEV_TX_OK;
3310 #define NUM_REGS 38 /* 1 based count */
3311 static void e1000_regdump(struct e1000_adapter *adapter)
3313 struct e1000_hw *hw = &adapter->hw;
3315 u32 *regs_buff = regs;
3318 static const char * const reg_name[] = {
3320 "RCTL", "RDLEN", "RDH", "RDT", "RDTR",
3321 "TCTL", "TDBAL", "TDBAH", "TDLEN", "TDH", "TDT",
3322 "TIDV", "TXDCTL", "TADV", "TARC0",
3323 "TDBAL1", "TDBAH1", "TDLEN1", "TDH1", "TDT1",
3325 "CTRL_EXT", "ERT", "RDBAL", "RDBAH",
3326 "TDFH", "TDFT", "TDFHS", "TDFTS", "TDFPC",
3327 "RDFH", "RDFT", "RDFHS", "RDFTS", "RDFPC"
3330 regs_buff[0] = er32(CTRL);
3331 regs_buff[1] = er32(STATUS);
3333 regs_buff[2] = er32(RCTL);
3334 regs_buff[3] = er32(RDLEN);
3335 regs_buff[4] = er32(RDH);
3336 regs_buff[5] = er32(RDT);
3337 regs_buff[6] = er32(RDTR);
3339 regs_buff[7] = er32(TCTL);
3340 regs_buff[8] = er32(TDBAL);
3341 regs_buff[9] = er32(TDBAH);
3342 regs_buff[10] = er32(TDLEN);
3343 regs_buff[11] = er32(TDH);
3344 regs_buff[12] = er32(TDT);
3345 regs_buff[13] = er32(TIDV);
3346 regs_buff[14] = er32(TXDCTL);
3347 regs_buff[15] = er32(TADV);
3348 regs_buff[16] = er32(TARC0);
3350 regs_buff[17] = er32(TDBAL1);
3351 regs_buff[18] = er32(TDBAH1);
3352 regs_buff[19] = er32(TDLEN1);
3353 regs_buff[20] = er32(TDH1);
3354 regs_buff[21] = er32(TDT1);
3355 regs_buff[22] = er32(TXDCTL1);
3356 regs_buff[23] = er32(TARC1);
3357 regs_buff[24] = er32(CTRL_EXT);
3358 regs_buff[25] = er32(ERT);
3359 regs_buff[26] = er32(RDBAL0);
3360 regs_buff[27] = er32(RDBAH0);
3361 regs_buff[28] = er32(TDFH);
3362 regs_buff[29] = er32(TDFT);
3363 regs_buff[30] = er32(TDFHS);
3364 regs_buff[31] = er32(TDFTS);
3365 regs_buff[32] = er32(TDFPC);
3366 regs_buff[33] = er32(RDFH);
3367 regs_buff[34] = er32(RDFT);
3368 regs_buff[35] = er32(RDFHS);
3369 regs_buff[36] = er32(RDFTS);
3370 regs_buff[37] = er32(RDFPC);
3372 pr_info("Register dump\n");
3373 for (i = 0; i < NUM_REGS; i++)
3374 pr_info("%-15s %08x\n", reg_name[i], regs_buff[i]);
3378 * e1000_dump: Print registers, tx ring and rx ring
3380 static void e1000_dump(struct e1000_adapter *adapter)
3382 /* this code doesn't handle multiple rings */
3383 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3384 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
3387 if (!netif_msg_hw(adapter))
3390 /* Print Registers */
3391 e1000_regdump(adapter);
3394 pr_info("TX Desc ring0 dump\n");
3396 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
3398 * Legacy Transmit Descriptor
3399 * +--------------------------------------------------------------+
3400 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
3401 * +--------------------------------------------------------------+
3402 * 8 | Special | CSS | Status | CMD | CSO | Length |
3403 * +--------------------------------------------------------------+
3404 * 63 48 47 36 35 32 31 24 23 16 15 0
3406 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
3407 * 63 48 47 40 39 32 31 16 15 8 7 0
3408 * +----------------------------------------------------------------+
3409 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
3410 * +----------------------------------------------------------------+
3411 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
3412 * +----------------------------------------------------------------+
3413 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3415 * Extended Data Descriptor (DTYP=0x1)
3416 * +----------------------------------------------------------------+
3417 * 0 | Buffer Address [63:0] |
3418 * +----------------------------------------------------------------+
3419 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
3420 * +----------------------------------------------------------------+
3421 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3423 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestmp bi->skb\n");
3424 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestmp bi->skb\n");
3426 if (!netif_msg_tx_done(adapter))
3427 goto rx_ring_summary;
3429 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
3430 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
3431 struct e1000_tx_buffer *buffer_info = &tx_ring->buffer_info[i];
3432 struct my_u { __le64 a; __le64 b; };
3433 struct my_u *u = (struct my_u *)tx_desc;
3436 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
3438 else if (i == tx_ring->next_to_use)
3440 else if (i == tx_ring->next_to_clean)
3445 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p %s\n",
3446 ((le64_to_cpu(u->b) & (1<<20)) ? 'd' : 'c'), i,
3447 le64_to_cpu(u->a), le64_to_cpu(u->b),
3448 (u64)buffer_info->dma, buffer_info->length,
3449 buffer_info->next_to_watch,
3450 (u64)buffer_info->time_stamp, buffer_info->skb, type);
3455 pr_info("\nRX Desc ring dump\n");
3457 /* Legacy Receive Descriptor Format
3459 * +-----------------------------------------------------+
3460 * | Buffer Address [63:0] |
3461 * +-----------------------------------------------------+
3462 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
3463 * +-----------------------------------------------------+
3464 * 63 48 47 40 39 32 31 16 15 0
3466 pr_info("R[desc] [address 63:0 ] [vl er S cks ln] [bi->dma ] [bi->skb]\n");
3468 if (!netif_msg_rx_status(adapter))
3471 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
3472 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
3473 struct e1000_rx_buffer *buffer_info = &rx_ring->buffer_info[i];
3474 struct my_u { __le64 a; __le64 b; };
3475 struct my_u *u = (struct my_u *)rx_desc;
3478 if (i == rx_ring->next_to_use)
3480 else if (i == rx_ring->next_to_clean)
3485 pr_info("R[0x%03X] %016llX %016llX %016llX %p %s\n",
3486 i, le64_to_cpu(u->a), le64_to_cpu(u->b),
3487 (u64)buffer_info->dma, buffer_info->rxbuf.data, type);
3490 /* dump the descriptor caches */
3492 pr_info("Rx descriptor cache in 64bit format\n");
3493 for (i = 0x6000; i <= 0x63FF ; i += 0x10) {
3494 pr_info("R%04X: %08X|%08X %08X|%08X\n",
3496 readl(adapter->hw.hw_addr + i+4),
3497 readl(adapter->hw.hw_addr + i),
3498 readl(adapter->hw.hw_addr + i+12),
3499 readl(adapter->hw.hw_addr + i+8));
3502 pr_info("Tx descriptor cache in 64bit format\n");
3503 for (i = 0x7000; i <= 0x73FF ; i += 0x10) {
3504 pr_info("T%04X: %08X|%08X %08X|%08X\n",
3506 readl(adapter->hw.hw_addr + i+4),
3507 readl(adapter->hw.hw_addr + i),
3508 readl(adapter->hw.hw_addr + i+12),
3509 readl(adapter->hw.hw_addr + i+8));
3516 * e1000_tx_timeout - Respond to a Tx Hang
3517 * @netdev: network interface device structure
3519 static void e1000_tx_timeout(struct net_device *netdev)
3521 struct e1000_adapter *adapter = netdev_priv(netdev);
3523 /* Do the reset outside of interrupt context */
3524 adapter->tx_timeout_count++;
3525 schedule_work(&adapter->reset_task);
3528 static void e1000_reset_task(struct work_struct *work)
3530 struct e1000_adapter *adapter =
3531 container_of(work, struct e1000_adapter, reset_task);
3533 e_err(drv, "Reset adapter\n");
3534 e1000_reinit_locked(adapter);
3538 * e1000_change_mtu - Change the Maximum Transfer Unit
3539 * @netdev: network interface device structure
3540 * @new_mtu: new value for maximum frame size
3542 * Returns 0 on success, negative on failure
3544 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3546 struct e1000_adapter *adapter = netdev_priv(netdev);
3547 struct e1000_hw *hw = &adapter->hw;
3548 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3550 /* Adapter-specific max frame size limits. */
3551 switch (hw->mac_type) {
3552 case e1000_undefined ... e1000_82542_rev2_1:
3553 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3554 e_err(probe, "Jumbo Frames not supported.\n");
3559 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3563 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3565 /* e1000_down has a dependency on max_frame_size */
3566 hw->max_frame_size = max_frame;
3567 if (netif_running(netdev)) {
3568 /* prevent buffers from being reallocated */
3569 adapter->alloc_rx_buf = e1000_alloc_dummy_rx_buffers;
3570 e1000_down(adapter);
3573 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3574 * means we reserve 2 more, this pushes us to allocate from the next
3576 * i.e. RXBUFFER_2048 --> size-4096 slab
3577 * however with the new *_jumbo_rx* routines, jumbo receives will use
3581 if (max_frame <= E1000_RXBUFFER_2048)
3582 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3584 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3585 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3586 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3587 adapter->rx_buffer_len = PAGE_SIZE;
3590 /* adjust allocation if LPE protects us, and we aren't using SBP */
3591 if (!hw->tbi_compatibility_on &&
3592 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3593 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3594 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3596 pr_info("%s changing MTU from %d to %d\n",
3597 netdev->name, netdev->mtu, new_mtu);
3598 netdev->mtu = new_mtu;
3600 if (netif_running(netdev))
3603 e1000_reset(adapter);
3605 clear_bit(__E1000_RESETTING, &adapter->flags);
3611 * e1000_update_stats - Update the board statistics counters
3612 * @adapter: board private structure
3614 void e1000_update_stats(struct e1000_adapter *adapter)
3616 struct net_device *netdev = adapter->netdev;
3617 struct e1000_hw *hw = &adapter->hw;
3618 struct pci_dev *pdev = adapter->pdev;
3619 unsigned long flags;
3622 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3624 /* Prevent stats update while adapter is being reset, or if the pci
3625 * connection is down.
3627 if (adapter->link_speed == 0)
3629 if (pci_channel_offline(pdev))
3632 spin_lock_irqsave(&adapter->stats_lock, flags);
3634 /* these counters are modified from e1000_tbi_adjust_stats,
3635 * called from the interrupt context, so they must only
3636 * be written while holding adapter->stats_lock
3639 adapter->stats.crcerrs += er32(CRCERRS);
3640 adapter->stats.gprc += er32(GPRC);
3641 adapter->stats.gorcl += er32(GORCL);
3642 adapter->stats.gorch += er32(GORCH);
3643 adapter->stats.bprc += er32(BPRC);
3644 adapter->stats.mprc += er32(MPRC);
3645 adapter->stats.roc += er32(ROC);
3647 adapter->stats.prc64 += er32(PRC64);
3648 adapter->stats.prc127 += er32(PRC127);
3649 adapter->stats.prc255 += er32(PRC255);
3650 adapter->stats.prc511 += er32(PRC511);
3651 adapter->stats.prc1023 += er32(PRC1023);
3652 adapter->stats.prc1522 += er32(PRC1522);
3654 adapter->stats.symerrs += er32(SYMERRS);
3655 adapter->stats.mpc += er32(MPC);
3656 adapter->stats.scc += er32(SCC);
3657 adapter->stats.ecol += er32(ECOL);
3658 adapter->stats.mcc += er32(MCC);
3659 adapter->stats.latecol += er32(LATECOL);
3660 adapter->stats.dc += er32(DC);
3661 adapter->stats.sec += er32(SEC);
3662 adapter->stats.rlec += er32(RLEC);
3663 adapter->stats.xonrxc += er32(XONRXC);
3664 adapter->stats.xontxc += er32(XONTXC);
3665 adapter->stats.xoffrxc += er32(XOFFRXC);
3666 adapter->stats.xofftxc += er32(XOFFTXC);
3667 adapter->stats.fcruc += er32(FCRUC);
3668 adapter->stats.gptc += er32(GPTC);
3669 adapter->stats.gotcl += er32(GOTCL);
3670 adapter->stats.gotch += er32(GOTCH);
3671 adapter->stats.rnbc += er32(RNBC);
3672 adapter->stats.ruc += er32(RUC);
3673 adapter->stats.rfc += er32(RFC);
3674 adapter->stats.rjc += er32(RJC);
3675 adapter->stats.torl += er32(TORL);
3676 adapter->stats.torh += er32(TORH);
3677 adapter->stats.totl += er32(TOTL);
3678 adapter->stats.toth += er32(TOTH);
3679 adapter->stats.tpr += er32(TPR);
3681 adapter->stats.ptc64 += er32(PTC64);
3682 adapter->stats.ptc127 += er32(PTC127);
3683 adapter->stats.ptc255 += er32(PTC255);
3684 adapter->stats.ptc511 += er32(PTC511);
3685 adapter->stats.ptc1023 += er32(PTC1023);
3686 adapter->stats.ptc1522 += er32(PTC1522);
3688 adapter->stats.mptc += er32(MPTC);
3689 adapter->stats.bptc += er32(BPTC);
3691 /* used for adaptive IFS */
3693 hw->tx_packet_delta = er32(TPT);
3694 adapter->stats.tpt += hw->tx_packet_delta;
3695 hw->collision_delta = er32(COLC);
3696 adapter->stats.colc += hw->collision_delta;
3698 if (hw->mac_type >= e1000_82543) {
3699 adapter->stats.algnerrc += er32(ALGNERRC);
3700 adapter->stats.rxerrc += er32(RXERRC);
3701 adapter->stats.tncrs += er32(TNCRS);
3702 adapter->stats.cexterr += er32(CEXTERR);
3703 adapter->stats.tsctc += er32(TSCTC);
3704 adapter->stats.tsctfc += er32(TSCTFC);
3707 /* Fill out the OS statistics structure */
3708 netdev->stats.multicast = adapter->stats.mprc;
3709 netdev->stats.collisions = adapter->stats.colc;
3713 /* RLEC on some newer hardware can be incorrect so build
3714 * our own version based on RUC and ROC
3716 netdev->stats.rx_errors = adapter->stats.rxerrc +
3717 adapter->stats.crcerrs + adapter->stats.algnerrc +
3718 adapter->stats.ruc + adapter->stats.roc +
3719 adapter->stats.cexterr;
3720 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3721 netdev->stats.rx_length_errors = adapter->stats.rlerrc;
3722 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3723 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3724 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3727 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3728 netdev->stats.tx_errors = adapter->stats.txerrc;
3729 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3730 netdev->stats.tx_window_errors = adapter->stats.latecol;
3731 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3732 if (hw->bad_tx_carr_stats_fd &&
3733 adapter->link_duplex == FULL_DUPLEX) {
3734 netdev->stats.tx_carrier_errors = 0;
3735 adapter->stats.tncrs = 0;
3738 /* Tx Dropped needs to be maintained elsewhere */
3741 if (hw->media_type == e1000_media_type_copper) {
3742 if ((adapter->link_speed == SPEED_1000) &&
3743 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3744 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3745 adapter->phy_stats.idle_errors += phy_tmp;
3748 if ((hw->mac_type <= e1000_82546) &&
3749 (hw->phy_type == e1000_phy_m88) &&
3750 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3751 adapter->phy_stats.receive_errors += phy_tmp;
3754 /* Management Stats */
3755 if (hw->has_smbus) {
3756 adapter->stats.mgptc += er32(MGTPTC);
3757 adapter->stats.mgprc += er32(MGTPRC);
3758 adapter->stats.mgpdc += er32(MGTPDC);
3761 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3765 * e1000_intr - Interrupt Handler
3766 * @irq: interrupt number
3767 * @data: pointer to a network interface device structure
3769 static irqreturn_t e1000_intr(int irq, void *data)
3771 struct net_device *netdev = data;
3772 struct e1000_adapter *adapter = netdev_priv(netdev);
3773 struct e1000_hw *hw = &adapter->hw;
3774 u32 icr = er32(ICR);
3776 if (unlikely((!icr)))
3777 return IRQ_NONE; /* Not our interrupt */
3779 /* we might have caused the interrupt, but the above
3780 * read cleared it, and just in case the driver is
3781 * down there is nothing to do so return handled
3783 if (unlikely(test_bit(__E1000_DOWN, &adapter->flags)))
3786 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3787 hw->get_link_status = 1;
3788 /* guard against interrupt when we're going down */
3789 if (!test_bit(__E1000_DOWN, &adapter->flags))
3790 schedule_delayed_work(&adapter->watchdog_task, 1);
3793 /* disable interrupts, without the synchronize_irq bit */
3795 E1000_WRITE_FLUSH();
3797 if (likely(napi_schedule_prep(&adapter->napi))) {
3798 adapter->total_tx_bytes = 0;
3799 adapter->total_tx_packets = 0;
3800 adapter->total_rx_bytes = 0;
3801 adapter->total_rx_packets = 0;
3802 __napi_schedule(&adapter->napi);
3804 /* this really should not happen! if it does it is basically a
3805 * bug, but not a hard error, so enable ints and continue
3807 if (!test_bit(__E1000_DOWN, &adapter->flags))
3808 e1000_irq_enable(adapter);
3815 * e1000_clean - NAPI Rx polling callback
3816 * @adapter: board private structure
3818 static int e1000_clean(struct napi_struct *napi, int budget)
3820 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
3822 int tx_clean_complete = 0, work_done = 0;
3824 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3826 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
3828 if (!tx_clean_complete)
3831 /* If budget not fully consumed, exit the polling mode */
3832 if (work_done < budget) {
3833 if (likely(adapter->itr_setting & 3))
3834 e1000_set_itr(adapter);
3835 napi_complete_done(napi, work_done);
3836 if (!test_bit(__E1000_DOWN, &adapter->flags))
3837 e1000_irq_enable(adapter);
3844 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3845 * @adapter: board private structure
3847 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3848 struct e1000_tx_ring *tx_ring)
3850 struct e1000_hw *hw = &adapter->hw;
3851 struct net_device *netdev = adapter->netdev;
3852 struct e1000_tx_desc *tx_desc, *eop_desc;
3853 struct e1000_tx_buffer *buffer_info;
3854 unsigned int i, eop;
3855 unsigned int count = 0;
3856 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
3857 unsigned int bytes_compl = 0, pkts_compl = 0;
3859 i = tx_ring->next_to_clean;
3860 eop = tx_ring->buffer_info[i].next_to_watch;
3861 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3863 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3864 (count < tx_ring->count)) {
3865 bool cleaned = false;
3866 dma_rmb(); /* read buffer_info after eop_desc */
3867 for ( ; !cleaned; count++) {
3868 tx_desc = E1000_TX_DESC(*tx_ring, i);
3869 buffer_info = &tx_ring->buffer_info[i];
3870 cleaned = (i == eop);
3873 total_tx_packets += buffer_info->segs;
3874 total_tx_bytes += buffer_info->bytecount;
3875 if (buffer_info->skb) {
3876 bytes_compl += buffer_info->skb->len;
3881 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3882 tx_desc->upper.data = 0;
3884 if (unlikely(++i == tx_ring->count))
3888 eop = tx_ring->buffer_info[i].next_to_watch;
3889 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3892 /* Synchronize with E1000_DESC_UNUSED called from e1000_xmit_frame,
3893 * which will reuse the cleaned buffers.
3895 smp_store_release(&tx_ring->next_to_clean, i);
3897 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
3899 #define TX_WAKE_THRESHOLD 32
3900 if (unlikely(count && netif_carrier_ok(netdev) &&
3901 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3902 /* Make sure that anybody stopping the queue after this
3903 * sees the new next_to_clean.
3907 if (netif_queue_stopped(netdev) &&
3908 !(test_bit(__E1000_DOWN, &adapter->flags))) {
3909 netif_wake_queue(netdev);
3910 ++adapter->restart_queue;
3914 if (adapter->detect_tx_hung) {
3915 /* Detect a transmit hang in hardware, this serializes the
3916 * check with the clearing of time_stamp and movement of i
3918 adapter->detect_tx_hung = false;
3919 if (tx_ring->buffer_info[eop].time_stamp &&
3920 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3921 (adapter->tx_timeout_factor * HZ)) &&
3922 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3924 /* detected Tx unit hang */
3925 e_err(drv, "Detected Tx Unit Hang\n"
3929 " next_to_use <%x>\n"
3930 " next_to_clean <%x>\n"
3931 "buffer_info[next_to_clean]\n"
3932 " time_stamp <%lx>\n"
3933 " next_to_watch <%x>\n"
3935 " next_to_watch.status <%x>\n",
3936 (unsigned long)(tx_ring - adapter->tx_ring),
3937 readl(hw->hw_addr + tx_ring->tdh),
3938 readl(hw->hw_addr + tx_ring->tdt),
3939 tx_ring->next_to_use,
3940 tx_ring->next_to_clean,
3941 tx_ring->buffer_info[eop].time_stamp,
3944 eop_desc->upper.fields.status);
3945 e1000_dump(adapter);
3946 netif_stop_queue(netdev);
3949 adapter->total_tx_bytes += total_tx_bytes;
3950 adapter->total_tx_packets += total_tx_packets;
3951 netdev->stats.tx_bytes += total_tx_bytes;
3952 netdev->stats.tx_packets += total_tx_packets;
3953 return count < tx_ring->count;
3957 * e1000_rx_checksum - Receive Checksum Offload for 82543
3958 * @adapter: board private structure
3959 * @status_err: receive descriptor status and error fields
3960 * @csum: receive descriptor csum field
3961 * @sk_buff: socket buffer with received data
3963 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3964 u32 csum, struct sk_buff *skb)
3966 struct e1000_hw *hw = &adapter->hw;
3967 u16 status = (u16)status_err;
3968 u8 errors = (u8)(status_err >> 24);
3970 skb_checksum_none_assert(skb);
3972 /* 82543 or newer only */
3973 if (unlikely(hw->mac_type < e1000_82543))
3975 /* Ignore Checksum bit is set */
3976 if (unlikely(status & E1000_RXD_STAT_IXSM))
3978 /* TCP/UDP checksum error bit is set */
3979 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3980 /* let the stack verify checksum errors */
3981 adapter->hw_csum_err++;
3984 /* TCP/UDP Checksum has not been calculated */
3985 if (!(status & E1000_RXD_STAT_TCPCS))
3988 /* It must be a TCP or UDP packet with a valid checksum */
3989 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3990 /* TCP checksum is good */
3991 skb->ip_summed = CHECKSUM_UNNECESSARY;
3993 adapter->hw_csum_good++;
3997 * e1000_consume_page - helper function for jumbo Rx path
3999 static void e1000_consume_page(struct e1000_rx_buffer *bi, struct sk_buff *skb,
4002 bi->rxbuf.page = NULL;
4004 skb->data_len += length;
4005 skb->truesize += PAGE_SIZE;
4009 * e1000_receive_skb - helper function to handle rx indications
4010 * @adapter: board private structure
4011 * @status: descriptor status field as written by hardware
4012 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4013 * @skb: pointer to sk_buff to be indicated to stack
4015 static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4016 __le16 vlan, struct sk_buff *skb)
4018 skb->protocol = eth_type_trans(skb, adapter->netdev);
4020 if (status & E1000_RXD_STAT_VP) {
4021 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4023 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
4025 napi_gro_receive(&adapter->napi, skb);
4029 * e1000_tbi_adjust_stats
4030 * @hw: Struct containing variables accessed by shared code
4031 * @frame_len: The length of the frame in question
4032 * @mac_addr: The Ethernet destination address of the frame in question
4034 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4036 static void e1000_tbi_adjust_stats(struct e1000_hw *hw,
4037 struct e1000_hw_stats *stats,
4038 u32 frame_len, const u8 *mac_addr)
4042 /* First adjust the frame length. */
4044 /* We need to adjust the statistics counters, since the hardware
4045 * counters overcount this packet as a CRC error and undercount
4046 * the packet as a good packet
4048 /* This packet should not be counted as a CRC error. */
4050 /* This packet does count as a Good Packet Received. */
4053 /* Adjust the Good Octets received counters */
4054 carry_bit = 0x80000000 & stats->gorcl;
4055 stats->gorcl += frame_len;
4056 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4057 * Received Count) was one before the addition,
4058 * AND it is zero after, then we lost the carry out,
4059 * need to add one to Gorch (Good Octets Received Count High).
4060 * This could be simplified if all environments supported
4063 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4065 /* Is this a broadcast or multicast? Check broadcast first,
4066 * since the test for a multicast frame will test positive on
4067 * a broadcast frame.
4069 if (is_broadcast_ether_addr(mac_addr))
4071 else if (is_multicast_ether_addr(mac_addr))
4074 if (frame_len == hw->max_frame_size) {
4075 /* In this case, the hardware has overcounted the number of
4082 /* Adjust the bin counters when the extra byte put the frame in the
4083 * wrong bin. Remember that the frame_len was adjusted above.
4085 if (frame_len == 64) {
4088 } else if (frame_len == 127) {
4091 } else if (frame_len == 255) {
4094 } else if (frame_len == 511) {
4097 } else if (frame_len == 1023) {
4100 } else if (frame_len == 1522) {
4105 static bool e1000_tbi_should_accept(struct e1000_adapter *adapter,
4106 u8 status, u8 errors,
4107 u32 length, const u8 *data)
4109 struct e1000_hw *hw = &adapter->hw;
4110 u8 last_byte = *(data + length - 1);
4112 if (TBI_ACCEPT(hw, status, errors, length, last_byte)) {
4113 unsigned long irq_flags;
4115 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
4116 e1000_tbi_adjust_stats(hw, &adapter->stats, length, data);
4117 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
4125 static struct sk_buff *e1000_alloc_rx_skb(struct e1000_adapter *adapter,
4128 struct sk_buff *skb = napi_alloc_skb(&adapter->napi, bufsz);
4131 adapter->alloc_rx_buff_failed++;
4136 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4137 * @adapter: board private structure
4138 * @rx_ring: ring to clean
4139 * @work_done: amount of napi work completed this call
4140 * @work_to_do: max amount of work allowed for this call to do
4142 * the return value indicates whether actual cleaning was done, there
4143 * is no guarantee that everything was cleaned
4145 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4146 struct e1000_rx_ring *rx_ring,
4147 int *work_done, int work_to_do)
4149 struct net_device *netdev = adapter->netdev;
4150 struct pci_dev *pdev = adapter->pdev;
4151 struct e1000_rx_desc *rx_desc, *next_rxd;
4152 struct e1000_rx_buffer *buffer_info, *next_buffer;
4155 int cleaned_count = 0;
4156 bool cleaned = false;
4157 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
4159 i = rx_ring->next_to_clean;
4160 rx_desc = E1000_RX_DESC(*rx_ring, i);
4161 buffer_info = &rx_ring->buffer_info[i];
4163 while (rx_desc->status & E1000_RXD_STAT_DD) {
4164 struct sk_buff *skb;
4167 if (*work_done >= work_to_do)
4170 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
4172 status = rx_desc->status;
4174 if (++i == rx_ring->count)
4177 next_rxd = E1000_RX_DESC(*rx_ring, i);
4180 next_buffer = &rx_ring->buffer_info[i];
4184 dma_unmap_page(&pdev->dev, buffer_info->dma,
4185 adapter->rx_buffer_len, DMA_FROM_DEVICE);
4186 buffer_info->dma = 0;
4188 length = le16_to_cpu(rx_desc->length);
4190 /* errors is only valid for DD + EOP descriptors */
4191 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4192 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4193 u8 *mapped = page_address(buffer_info->rxbuf.page);
4195 if (e1000_tbi_should_accept(adapter, status,
4199 } else if (netdev->features & NETIF_F_RXALL) {
4202 /* an error means any chain goes out the window
4205 if (rx_ring->rx_skb_top)
4206 dev_kfree_skb(rx_ring->rx_skb_top);
4207 rx_ring->rx_skb_top = NULL;
4212 #define rxtop rx_ring->rx_skb_top
4214 if (!(status & E1000_RXD_STAT_EOP)) {
4215 /* this descriptor is only the beginning (or middle) */
4217 /* this is the beginning of a chain */
4218 rxtop = napi_get_frags(&adapter->napi);
4222 skb_fill_page_desc(rxtop, 0,
4223 buffer_info->rxbuf.page,
4226 /* this is the middle of a chain */
4227 skb_fill_page_desc(rxtop,
4228 skb_shinfo(rxtop)->nr_frags,
4229 buffer_info->rxbuf.page, 0, length);
4231 e1000_consume_page(buffer_info, rxtop, length);
4235 /* end of the chain */
4236 skb_fill_page_desc(rxtop,
4237 skb_shinfo(rxtop)->nr_frags,
4238 buffer_info->rxbuf.page, 0, length);
4241 e1000_consume_page(buffer_info, skb, length);
4244 /* no chain, got EOP, this buf is the packet
4245 * copybreak to save the put_page/alloc_page
4247 p = buffer_info->rxbuf.page;
4248 if (length <= copybreak) {
4251 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4253 skb = e1000_alloc_rx_skb(adapter,
4258 vaddr = kmap_atomic(p);
4259 memcpy(skb_tail_pointer(skb), vaddr,
4261 kunmap_atomic(vaddr);
4262 /* re-use the page, so don't erase
4263 * buffer_info->rxbuf.page
4265 skb_put(skb, length);
4266 e1000_rx_checksum(adapter,
4267 status | rx_desc->errors << 24,
4268 le16_to_cpu(rx_desc->csum), skb);
4270 total_rx_bytes += skb->len;
4273 e1000_receive_skb(adapter, status,
4274 rx_desc->special, skb);
4277 skb = napi_get_frags(&adapter->napi);
4279 adapter->alloc_rx_buff_failed++;
4282 skb_fill_page_desc(skb, 0, p, 0,
4284 e1000_consume_page(buffer_info, skb,
4290 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4291 e1000_rx_checksum(adapter,
4293 ((u32)(rx_desc->errors) << 24),
4294 le16_to_cpu(rx_desc->csum), skb);
4296 total_rx_bytes += (skb->len - 4); /* don't count FCS */
4297 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4298 pskb_trim(skb, skb->len - 4);
4301 if (status & E1000_RXD_STAT_VP) {
4302 __le16 vlan = rx_desc->special;
4303 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4305 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
4308 napi_gro_frags(&adapter->napi);
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;
4336 /* this should improve performance for small packets with large amounts
4337 * of reassembly being done in the stack
4339 static struct sk_buff *e1000_copybreak(struct e1000_adapter *adapter,
4340 struct e1000_rx_buffer *buffer_info,
4341 u32 length, const void *data)
4343 struct sk_buff *skb;
4345 if (length > copybreak)
4348 skb = e1000_alloc_rx_skb(adapter, length);
4352 dma_sync_single_for_cpu(&adapter->pdev->dev, buffer_info->dma,
4353 length, DMA_FROM_DEVICE);
4355 skb_put_data(skb, data, length);
4361 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4362 * @adapter: board private structure
4363 * @rx_ring: ring to clean
4364 * @work_done: amount of napi work completed this call
4365 * @work_to_do: max amount of work allowed for this call to do
4367 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4368 struct e1000_rx_ring *rx_ring,
4369 int *work_done, int work_to_do)
4371 struct net_device *netdev = adapter->netdev;
4372 struct pci_dev *pdev = adapter->pdev;
4373 struct e1000_rx_desc *rx_desc, *next_rxd;
4374 struct e1000_rx_buffer *buffer_info, *next_buffer;
4377 int cleaned_count = 0;
4378 bool cleaned = false;
4379 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
4381 i = rx_ring->next_to_clean;
4382 rx_desc = E1000_RX_DESC(*rx_ring, i);
4383 buffer_info = &rx_ring->buffer_info[i];
4385 while (rx_desc->status & E1000_RXD_STAT_DD) {
4386 struct sk_buff *skb;
4390 if (*work_done >= work_to_do)
4393 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
4395 status = rx_desc->status;
4396 length = le16_to_cpu(rx_desc->length);
4398 data = buffer_info->rxbuf.data;
4400 skb = e1000_copybreak(adapter, buffer_info, length, data);
4402 unsigned int frag_len = e1000_frag_len(adapter);
4404 skb = build_skb(data - E1000_HEADROOM, frag_len);
4406 adapter->alloc_rx_buff_failed++;
4410 skb_reserve(skb, E1000_HEADROOM);
4411 dma_unmap_single(&pdev->dev, buffer_info->dma,
4412 adapter->rx_buffer_len,
4414 buffer_info->dma = 0;
4415 buffer_info->rxbuf.data = NULL;
4418 if (++i == rx_ring->count)
4421 next_rxd = E1000_RX_DESC(*rx_ring, i);
4424 next_buffer = &rx_ring->buffer_info[i];
4429 /* !EOP means multiple descriptors were used to store a single
4430 * packet, if thats the case we need to toss it. In fact, we
4431 * to toss every packet with the EOP bit clear and the next
4432 * frame that _does_ have the EOP bit set, as it is by
4433 * definition only a frame fragment
4435 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
4436 adapter->discarding = true;
4438 if (adapter->discarding) {
4439 /* All receives must fit into a single buffer */
4440 netdev_dbg(netdev, "Receive packet consumed multiple buffers\n");
4442 if (status & E1000_RXD_STAT_EOP)
4443 adapter->discarding = false;
4447 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4448 if (e1000_tbi_should_accept(adapter, status,
4452 } else if (netdev->features & NETIF_F_RXALL) {
4461 total_rx_bytes += (length - 4); /* don't count FCS */
4464 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4465 /* adjust length to remove Ethernet CRC, this must be
4466 * done after the TBI_ACCEPT workaround above
4470 if (buffer_info->rxbuf.data == NULL)
4471 skb_put(skb, length);
4472 else /* copybreak skb */
4473 skb_trim(skb, length);
4475 /* Receive Checksum Offload */
4476 e1000_rx_checksum(adapter,
4478 ((u32)(rx_desc->errors) << 24),
4479 le16_to_cpu(rx_desc->csum), skb);
4481 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4484 rx_desc->status = 0;
4486 /* return some buffers to hardware, one at a time is too slow */
4487 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4488 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4492 /* use prefetched values */
4494 buffer_info = next_buffer;
4496 rx_ring->next_to_clean = i;
4498 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4500 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4502 adapter->total_rx_packets += total_rx_packets;
4503 adapter->total_rx_bytes += total_rx_bytes;
4504 netdev->stats.rx_bytes += total_rx_bytes;
4505 netdev->stats.rx_packets += total_rx_packets;
4510 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4511 * @adapter: address of board private structure
4512 * @rx_ring: pointer to receive ring structure
4513 * @cleaned_count: number of buffers to allocate this pass
4516 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4517 struct e1000_rx_ring *rx_ring, int cleaned_count)
4519 struct pci_dev *pdev = adapter->pdev;
4520 struct e1000_rx_desc *rx_desc;
4521 struct e1000_rx_buffer *buffer_info;
4524 i = rx_ring->next_to_use;
4525 buffer_info = &rx_ring->buffer_info[i];
4527 while (cleaned_count--) {
4528 /* allocate a new page if necessary */
4529 if (!buffer_info->rxbuf.page) {
4530 buffer_info->rxbuf.page = alloc_page(GFP_ATOMIC);
4531 if (unlikely(!buffer_info->rxbuf.page)) {
4532 adapter->alloc_rx_buff_failed++;
4537 if (!buffer_info->dma) {
4538 buffer_info->dma = dma_map_page(&pdev->dev,
4539 buffer_info->rxbuf.page, 0,
4540 adapter->rx_buffer_len,
4542 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4543 put_page(buffer_info->rxbuf.page);
4544 buffer_info->rxbuf.page = NULL;
4545 buffer_info->dma = 0;
4546 adapter->alloc_rx_buff_failed++;
4551 rx_desc = E1000_RX_DESC(*rx_ring, i);
4552 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4554 if (unlikely(++i == rx_ring->count))
4556 buffer_info = &rx_ring->buffer_info[i];
4559 if (likely(rx_ring->next_to_use != i)) {
4560 rx_ring->next_to_use = i;
4561 if (unlikely(i-- == 0))
4562 i = (rx_ring->count - 1);
4564 /* Force memory writes to complete before letting h/w
4565 * know there are new descriptors to fetch. (Only
4566 * applicable for weak-ordered memory model archs,
4570 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4575 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4576 * @adapter: address of board private structure
4578 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4579 struct e1000_rx_ring *rx_ring,
4582 struct e1000_hw *hw = &adapter->hw;
4583 struct pci_dev *pdev = adapter->pdev;
4584 struct e1000_rx_desc *rx_desc;
4585 struct e1000_rx_buffer *buffer_info;
4587 unsigned int bufsz = adapter->rx_buffer_len;
4589 i = rx_ring->next_to_use;
4590 buffer_info = &rx_ring->buffer_info[i];
4592 while (cleaned_count--) {
4595 if (buffer_info->rxbuf.data)
4598 data = e1000_alloc_frag(adapter);
4600 /* Better luck next round */
4601 adapter->alloc_rx_buff_failed++;
4605 /* Fix for errata 23, can't cross 64kB boundary */
4606 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
4607 void *olddata = data;
4608 e_err(rx_err, "skb align check failed: %u bytes at "
4609 "%p\n", bufsz, data);
4610 /* Try again, without freeing the previous */
4611 data = e1000_alloc_frag(adapter);
4612 /* Failed allocation, critical failure */
4614 skb_free_frag(olddata);
4615 adapter->alloc_rx_buff_failed++;
4619 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
4621 skb_free_frag(data);
4622 skb_free_frag(olddata);
4623 adapter->alloc_rx_buff_failed++;
4627 /* Use new allocation */
4628 skb_free_frag(olddata);
4630 buffer_info->dma = dma_map_single(&pdev->dev,
4632 adapter->rx_buffer_len,
4634 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4635 skb_free_frag(data);
4636 buffer_info->dma = 0;
4637 adapter->alloc_rx_buff_failed++;
4641 /* XXX if it was allocated cleanly it will never map to a
4645 /* Fix for errata 23, can't cross 64kB boundary */
4646 if (!e1000_check_64k_bound(adapter,
4647 (void *)(unsigned long)buffer_info->dma,
4648 adapter->rx_buffer_len)) {
4649 e_err(rx_err, "dma align check failed: %u bytes at "
4650 "%p\n", adapter->rx_buffer_len,
4651 (void *)(unsigned long)buffer_info->dma);
4653 dma_unmap_single(&pdev->dev, buffer_info->dma,
4654 adapter->rx_buffer_len,
4657 skb_free_frag(data);
4658 buffer_info->rxbuf.data = NULL;
4659 buffer_info->dma = 0;
4661 adapter->alloc_rx_buff_failed++;
4664 buffer_info->rxbuf.data = data;
4666 rx_desc = E1000_RX_DESC(*rx_ring, i);
4667 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4669 if (unlikely(++i == rx_ring->count))
4671 buffer_info = &rx_ring->buffer_info[i];
4674 if (likely(rx_ring->next_to_use != i)) {
4675 rx_ring->next_to_use = i;
4676 if (unlikely(i-- == 0))
4677 i = (rx_ring->count - 1);
4679 /* Force memory writes to complete before letting h/w
4680 * know there are new descriptors to fetch. (Only
4681 * applicable for weak-ordered memory model archs,
4685 writel(i, hw->hw_addr + rx_ring->rdt);
4690 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4693 static void e1000_smartspeed(struct e1000_adapter *adapter)
4695 struct e1000_hw *hw = &adapter->hw;
4699 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4700 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4703 if (adapter->smartspeed == 0) {
4704 /* If Master/Slave config fault is asserted twice,
4705 * we assume back-to-back
4707 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4708 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4710 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4711 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4713 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4714 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4715 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4716 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4718 adapter->smartspeed++;
4719 if (!e1000_phy_setup_autoneg(hw) &&
4720 !e1000_read_phy_reg(hw, PHY_CTRL,
4722 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4723 MII_CR_RESTART_AUTO_NEG);
4724 e1000_write_phy_reg(hw, PHY_CTRL,
4729 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4730 /* If still no link, perhaps using 2/3 pair cable */
4731 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4732 phy_ctrl |= CR_1000T_MS_ENABLE;
4733 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4734 if (!e1000_phy_setup_autoneg(hw) &&
4735 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4736 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4737 MII_CR_RESTART_AUTO_NEG);
4738 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4741 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4742 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4743 adapter->smartspeed = 0;
4752 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4758 return e1000_mii_ioctl(netdev, ifr, cmd);
4770 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4773 struct e1000_adapter *adapter = netdev_priv(netdev);
4774 struct e1000_hw *hw = &adapter->hw;
4775 struct mii_ioctl_data *data = if_mii(ifr);
4778 unsigned long flags;
4780 if (hw->media_type != e1000_media_type_copper)
4785 data->phy_id = hw->phy_addr;
4788 spin_lock_irqsave(&adapter->stats_lock, flags);
4789 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4791 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4794 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4797 if (data->reg_num & ~(0x1F))
4799 mii_reg = data->val_in;
4800 spin_lock_irqsave(&adapter->stats_lock, flags);
4801 if (e1000_write_phy_reg(hw, data->reg_num,
4803 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4806 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4807 if (hw->media_type == e1000_media_type_copper) {
4808 switch (data->reg_num) {
4810 if (mii_reg & MII_CR_POWER_DOWN)
4812 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4814 hw->autoneg_advertised = 0x2F;
4819 else if (mii_reg & 0x2000)
4823 retval = e1000_set_spd_dplx(
4831 if (netif_running(adapter->netdev))
4832 e1000_reinit_locked(adapter);
4834 e1000_reset(adapter);
4836 case M88E1000_PHY_SPEC_CTRL:
4837 case M88E1000_EXT_PHY_SPEC_CTRL:
4838 if (e1000_phy_reset(hw))
4843 switch (data->reg_num) {
4845 if (mii_reg & MII_CR_POWER_DOWN)
4847 if (netif_running(adapter->netdev))
4848 e1000_reinit_locked(adapter);
4850 e1000_reset(adapter);
4858 return E1000_SUCCESS;
4861 void e1000_pci_set_mwi(struct e1000_hw *hw)
4863 struct e1000_adapter *adapter = hw->back;
4864 int ret_val = pci_set_mwi(adapter->pdev);
4867 e_err(probe, "Error in setting MWI\n");
4870 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4872 struct e1000_adapter *adapter = hw->back;
4874 pci_clear_mwi(adapter->pdev);
4877 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4879 struct e1000_adapter *adapter = hw->back;
4880 return pcix_get_mmrbc(adapter->pdev);
4883 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4885 struct e1000_adapter *adapter = hw->back;
4886 pcix_set_mmrbc(adapter->pdev, mmrbc);
4889 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4894 static bool e1000_vlan_used(struct e1000_adapter *adapter)
4898 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4903 static void __e1000_vlan_mode(struct e1000_adapter *adapter,
4904 netdev_features_t features)
4906 struct e1000_hw *hw = &adapter->hw;
4910 if (features & NETIF_F_HW_VLAN_CTAG_RX) {
4911 /* enable VLAN tag insert/strip */
4912 ctrl |= E1000_CTRL_VME;
4914 /* disable VLAN tag insert/strip */
4915 ctrl &= ~E1000_CTRL_VME;
4919 static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4922 struct e1000_hw *hw = &adapter->hw;
4925 if (!test_bit(__E1000_DOWN, &adapter->flags))
4926 e1000_irq_disable(adapter);
4928 __e1000_vlan_mode(adapter, adapter->netdev->features);
4930 /* enable VLAN receive filtering */
4932 rctl &= ~E1000_RCTL_CFIEN;
4933 if (!(adapter->netdev->flags & IFF_PROMISC))
4934 rctl |= E1000_RCTL_VFE;
4936 e1000_update_mng_vlan(adapter);
4938 /* disable VLAN receive filtering */
4940 rctl &= ~E1000_RCTL_VFE;
4944 if (!test_bit(__E1000_DOWN, &adapter->flags))
4945 e1000_irq_enable(adapter);
4948 static void e1000_vlan_mode(struct net_device *netdev,
4949 netdev_features_t features)
4951 struct e1000_adapter *adapter = netdev_priv(netdev);
4953 if (!test_bit(__E1000_DOWN, &adapter->flags))
4954 e1000_irq_disable(adapter);
4956 __e1000_vlan_mode(adapter, features);
4958 if (!test_bit(__E1000_DOWN, &adapter->flags))
4959 e1000_irq_enable(adapter);
4962 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
4963 __be16 proto, u16 vid)
4965 struct e1000_adapter *adapter = netdev_priv(netdev);
4966 struct e1000_hw *hw = &adapter->hw;
4969 if ((hw->mng_cookie.status &
4970 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4971 (vid == adapter->mng_vlan_id))
4974 if (!e1000_vlan_used(adapter))
4975 e1000_vlan_filter_on_off(adapter, true);
4977 /* add VID to filter table */
4978 index = (vid >> 5) & 0x7F;
4979 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4980 vfta |= (1 << (vid & 0x1F));
4981 e1000_write_vfta(hw, index, vfta);
4983 set_bit(vid, adapter->active_vlans);
4988 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
4989 __be16 proto, u16 vid)
4991 struct e1000_adapter *adapter = netdev_priv(netdev);
4992 struct e1000_hw *hw = &adapter->hw;
4995 if (!test_bit(__E1000_DOWN, &adapter->flags))
4996 e1000_irq_disable(adapter);
4997 if (!test_bit(__E1000_DOWN, &adapter->flags))
4998 e1000_irq_enable(adapter);
5000 /* remove VID from filter table */
5001 index = (vid >> 5) & 0x7F;
5002 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
5003 vfta &= ~(1 << (vid & 0x1F));
5004 e1000_write_vfta(hw, index, vfta);
5006 clear_bit(vid, adapter->active_vlans);
5008 if (!e1000_vlan_used(adapter))
5009 e1000_vlan_filter_on_off(adapter, false);
5014 static void e1000_restore_vlan(struct e1000_adapter *adapter)
5018 if (!e1000_vlan_used(adapter))
5021 e1000_vlan_filter_on_off(adapter, true);
5022 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
5023 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
5026 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
5028 struct e1000_hw *hw = &adapter->hw;
5032 /* Make sure dplx is at most 1 bit and lsb of speed is not set
5033 * for the switch() below to work
5035 if ((spd & 1) || (dplx & ~1))
5038 /* Fiber NICs only allow 1000 gbps Full duplex */
5039 if ((hw->media_type == e1000_media_type_fiber) &&
5040 spd != SPEED_1000 &&
5041 dplx != DUPLEX_FULL)
5044 switch (spd + dplx) {
5045 case SPEED_10 + DUPLEX_HALF:
5046 hw->forced_speed_duplex = e1000_10_half;
5048 case SPEED_10 + DUPLEX_FULL:
5049 hw->forced_speed_duplex = e1000_10_full;
5051 case SPEED_100 + DUPLEX_HALF:
5052 hw->forced_speed_duplex = e1000_100_half;
5054 case SPEED_100 + DUPLEX_FULL:
5055 hw->forced_speed_duplex = e1000_100_full;
5057 case SPEED_1000 + DUPLEX_FULL:
5059 hw->autoneg_advertised = ADVERTISE_1000_FULL;
5061 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5066 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
5067 hw->mdix = AUTO_ALL_MODES;
5072 e_err(probe, "Unsupported Speed/Duplex configuration\n");
5076 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
5078 struct net_device *netdev = pci_get_drvdata(pdev);
5079 struct e1000_adapter *adapter = netdev_priv(netdev);
5080 struct e1000_hw *hw = &adapter->hw;
5081 u32 ctrl, ctrl_ext, rctl, status;
5082 u32 wufc = adapter->wol;
5087 netif_device_detach(netdev);
5089 if (netif_running(netdev)) {
5090 int count = E1000_CHECK_RESET_COUNT;
5092 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
5093 usleep_range(10000, 20000);
5095 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
5096 e1000_down(adapter);
5100 retval = pci_save_state(pdev);
5105 status = er32(STATUS);
5106 if (status & E1000_STATUS_LU)
5107 wufc &= ~E1000_WUFC_LNKC;
5110 e1000_setup_rctl(adapter);
5111 e1000_set_rx_mode(netdev);
5115 /* turn on all-multi mode if wake on multicast is enabled */
5116 if (wufc & E1000_WUFC_MC)
5117 rctl |= E1000_RCTL_MPE;
5119 /* enable receives in the hardware */
5120 ew32(RCTL, rctl | E1000_RCTL_EN);
5122 if (hw->mac_type >= e1000_82540) {
5124 /* advertise wake from D3Cold */
5125 #define E1000_CTRL_ADVD3WUC 0x00100000
5126 /* phy power management enable */
5127 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5128 ctrl |= E1000_CTRL_ADVD3WUC |
5129 E1000_CTRL_EN_PHY_PWR_MGMT;
5133 if (hw->media_type == e1000_media_type_fiber ||
5134 hw->media_type == e1000_media_type_internal_serdes) {
5135 /* keep the laser running in D3 */
5136 ctrl_ext = er32(CTRL_EXT);
5137 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5138 ew32(CTRL_EXT, ctrl_ext);
5141 ew32(WUC, E1000_WUC_PME_EN);
5148 e1000_release_manageability(adapter);
5150 *enable_wake = !!wufc;
5152 /* make sure adapter isn't asleep if manageability is enabled */
5153 if (adapter->en_mng_pt)
5154 *enable_wake = true;
5156 if (netif_running(netdev))
5157 e1000_free_irq(adapter);
5159 pci_disable_device(pdev);
5165 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5170 retval = __e1000_shutdown(pdev, &wake);
5175 pci_prepare_to_sleep(pdev);
5177 pci_wake_from_d3(pdev, false);
5178 pci_set_power_state(pdev, PCI_D3hot);
5184 static int e1000_resume(struct pci_dev *pdev)
5186 struct net_device *netdev = pci_get_drvdata(pdev);
5187 struct e1000_adapter *adapter = netdev_priv(netdev);
5188 struct e1000_hw *hw = &adapter->hw;
5191 pci_set_power_state(pdev, PCI_D0);
5192 pci_restore_state(pdev);
5193 pci_save_state(pdev);
5195 if (adapter->need_ioport)
5196 err = pci_enable_device(pdev);
5198 err = pci_enable_device_mem(pdev);
5200 pr_err("Cannot enable PCI device from suspend\n");
5203 pci_set_master(pdev);
5205 pci_enable_wake(pdev, PCI_D3hot, 0);
5206 pci_enable_wake(pdev, PCI_D3cold, 0);
5208 if (netif_running(netdev)) {
5209 err = e1000_request_irq(adapter);
5214 e1000_power_up_phy(adapter);
5215 e1000_reset(adapter);
5218 e1000_init_manageability(adapter);
5220 if (netif_running(netdev))
5223 netif_device_attach(netdev);
5229 static void e1000_shutdown(struct pci_dev *pdev)
5233 __e1000_shutdown(pdev, &wake);
5235 if (system_state == SYSTEM_POWER_OFF) {
5236 pci_wake_from_d3(pdev, wake);
5237 pci_set_power_state(pdev, PCI_D3hot);
5241 #ifdef CONFIG_NET_POLL_CONTROLLER
5242 /* Polling 'interrupt' - used by things like netconsole to send skbs
5243 * without having to re-enable interrupts. It's not called while
5244 * the interrupt routine is executing.
5246 static void e1000_netpoll(struct net_device *netdev)
5248 struct e1000_adapter *adapter = netdev_priv(netdev);
5250 if (disable_hardirq(adapter->pdev->irq))
5251 e1000_intr(adapter->pdev->irq, netdev);
5252 enable_irq(adapter->pdev->irq);
5257 * e1000_io_error_detected - called when PCI error is detected
5258 * @pdev: Pointer to PCI device
5259 * @state: The current pci connection state
5261 * This function is called after a PCI bus error affecting
5262 * this device has been detected.
5264 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5265 pci_channel_state_t state)
5267 struct net_device *netdev = pci_get_drvdata(pdev);
5268 struct e1000_adapter *adapter = netdev_priv(netdev);
5270 netif_device_detach(netdev);
5272 if (state == pci_channel_io_perm_failure)
5273 return PCI_ERS_RESULT_DISCONNECT;
5275 if (netif_running(netdev))
5276 e1000_down(adapter);
5277 pci_disable_device(pdev);
5279 /* Request a slot slot reset. */
5280 return PCI_ERS_RESULT_NEED_RESET;
5284 * e1000_io_slot_reset - called after the pci bus has been reset.
5285 * @pdev: Pointer to PCI device
5287 * Restart the card from scratch, as if from a cold-boot. Implementation
5288 * resembles the first-half of the e1000_resume routine.
5290 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5292 struct net_device *netdev = pci_get_drvdata(pdev);
5293 struct e1000_adapter *adapter = netdev_priv(netdev);
5294 struct e1000_hw *hw = &adapter->hw;
5297 if (adapter->need_ioport)
5298 err = pci_enable_device(pdev);
5300 err = pci_enable_device_mem(pdev);
5302 pr_err("Cannot re-enable PCI device after reset.\n");
5303 return PCI_ERS_RESULT_DISCONNECT;
5305 pci_set_master(pdev);
5307 pci_enable_wake(pdev, PCI_D3hot, 0);
5308 pci_enable_wake(pdev, PCI_D3cold, 0);
5310 e1000_reset(adapter);
5313 return PCI_ERS_RESULT_RECOVERED;
5317 * e1000_io_resume - called when traffic can start flowing again.
5318 * @pdev: Pointer to PCI device
5320 * This callback is called when the error recovery driver tells us that
5321 * its OK to resume normal operation. Implementation resembles the
5322 * second-half of the e1000_resume routine.
5324 static void e1000_io_resume(struct pci_dev *pdev)
5326 struct net_device *netdev = pci_get_drvdata(pdev);
5327 struct e1000_adapter *adapter = netdev_priv(netdev);
5329 e1000_init_manageability(adapter);
5331 if (netif_running(netdev)) {
5332 if (e1000_up(adapter)) {
5333 pr_info("can't bring device back up after reset\n");
5338 netif_device_attach(netdev);