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 char e1000_driver_name[] = "e1000";
33 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
34 #define DRV_VERSION "7.3.21-k3-NAPI"
35 const char e1000_driver_version[] = DRV_VERSION;
36 static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
38 /* e1000_pci_tbl - PCI Device ID Table
40 * Last entry must be all 0s
43 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
45 static struct pci_device_id e1000_pci_tbl[] = {
46 INTEL_E1000_ETHERNET_DEVICE(0x1000),
47 INTEL_E1000_ETHERNET_DEVICE(0x1001),
48 INTEL_E1000_ETHERNET_DEVICE(0x1004),
49 INTEL_E1000_ETHERNET_DEVICE(0x1008),
50 INTEL_E1000_ETHERNET_DEVICE(0x1009),
51 INTEL_E1000_ETHERNET_DEVICE(0x100C),
52 INTEL_E1000_ETHERNET_DEVICE(0x100D),
53 INTEL_E1000_ETHERNET_DEVICE(0x100E),
54 INTEL_E1000_ETHERNET_DEVICE(0x100F),
55 INTEL_E1000_ETHERNET_DEVICE(0x1010),
56 INTEL_E1000_ETHERNET_DEVICE(0x1011),
57 INTEL_E1000_ETHERNET_DEVICE(0x1012),
58 INTEL_E1000_ETHERNET_DEVICE(0x1013),
59 INTEL_E1000_ETHERNET_DEVICE(0x1014),
60 INTEL_E1000_ETHERNET_DEVICE(0x1015),
61 INTEL_E1000_ETHERNET_DEVICE(0x1016),
62 INTEL_E1000_ETHERNET_DEVICE(0x1017),
63 INTEL_E1000_ETHERNET_DEVICE(0x1018),
64 INTEL_E1000_ETHERNET_DEVICE(0x1019),
65 INTEL_E1000_ETHERNET_DEVICE(0x101A),
66 INTEL_E1000_ETHERNET_DEVICE(0x101D),
67 INTEL_E1000_ETHERNET_DEVICE(0x101E),
68 INTEL_E1000_ETHERNET_DEVICE(0x1026),
69 INTEL_E1000_ETHERNET_DEVICE(0x1027),
70 INTEL_E1000_ETHERNET_DEVICE(0x1028),
71 INTEL_E1000_ETHERNET_DEVICE(0x1075),
72 INTEL_E1000_ETHERNET_DEVICE(0x1076),
73 INTEL_E1000_ETHERNET_DEVICE(0x1077),
74 INTEL_E1000_ETHERNET_DEVICE(0x1078),
75 INTEL_E1000_ETHERNET_DEVICE(0x1079),
76 INTEL_E1000_ETHERNET_DEVICE(0x107A),
77 INTEL_E1000_ETHERNET_DEVICE(0x107B),
78 INTEL_E1000_ETHERNET_DEVICE(0x107C),
79 INTEL_E1000_ETHERNET_DEVICE(0x108A),
80 INTEL_E1000_ETHERNET_DEVICE(0x1099),
81 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
82 /* required last entry */
86 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
88 int e1000_up(struct e1000_adapter *adapter);
89 void e1000_down(struct e1000_adapter *adapter);
90 void e1000_reinit_locked(struct e1000_adapter *adapter);
91 void e1000_reset(struct e1000_adapter *adapter);
92 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
93 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
94 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
95 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
96 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
97 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
98 struct e1000_tx_ring *txdr);
99 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
100 struct e1000_rx_ring *rxdr);
101 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
102 struct e1000_tx_ring *tx_ring);
103 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
104 struct e1000_rx_ring *rx_ring);
105 void e1000_update_stats(struct e1000_adapter *adapter);
107 static int e1000_init_module(void);
108 static void e1000_exit_module(void);
109 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
110 static void __devexit e1000_remove(struct pci_dev *pdev);
111 static int e1000_alloc_queues(struct e1000_adapter *adapter);
112 static int e1000_sw_init(struct e1000_adapter *adapter);
113 static int e1000_open(struct net_device *netdev);
114 static int e1000_close(struct net_device *netdev);
115 static void e1000_configure_tx(struct e1000_adapter *adapter);
116 static void e1000_configure_rx(struct e1000_adapter *adapter);
117 static void e1000_setup_rctl(struct e1000_adapter *adapter);
118 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
119 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
120 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
121 struct e1000_tx_ring *tx_ring);
122 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
123 struct e1000_rx_ring *rx_ring);
124 static void e1000_set_rx_mode(struct net_device *netdev);
125 static void e1000_update_phy_info(unsigned long data);
126 static void e1000_watchdog(unsigned long data);
127 static void e1000_82547_tx_fifo_stall(unsigned long data);
128 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
129 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
130 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
131 static int e1000_set_mac(struct net_device *netdev, void *p);
132 static irqreturn_t e1000_intr(int irq, void *data);
133 static irqreturn_t e1000_intr_msi(int irq, void *data);
134 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
135 struct e1000_tx_ring *tx_ring);
136 static int e1000_clean(struct napi_struct *napi, int budget);
137 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
138 struct e1000_rx_ring *rx_ring,
139 int *work_done, int work_to_do);
140 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
143 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
146 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
149 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
150 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
152 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
153 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
154 static void e1000_tx_timeout(struct net_device *dev);
155 static void e1000_reset_task(struct work_struct *work);
156 static void e1000_smartspeed(struct e1000_adapter *adapter);
157 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
158 struct sk_buff *skb);
160 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
161 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
162 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
163 static void e1000_restore_vlan(struct e1000_adapter *adapter);
166 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
167 static int e1000_resume(struct pci_dev *pdev);
169 static void e1000_shutdown(struct pci_dev *pdev);
171 #ifdef CONFIG_NET_POLL_CONTROLLER
172 /* for netdump / net console */
173 static void e1000_netpoll (struct net_device *netdev);
176 #define COPYBREAK_DEFAULT 256
177 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
178 module_param(copybreak, uint, 0644);
179 MODULE_PARM_DESC(copybreak,
180 "Maximum size of packet that is copied to a new buffer on receive");
182 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
183 pci_channel_state_t state);
184 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
185 static void e1000_io_resume(struct pci_dev *pdev);
187 static struct pci_error_handlers e1000_err_handler = {
188 .error_detected = e1000_io_error_detected,
189 .slot_reset = e1000_io_slot_reset,
190 .resume = e1000_io_resume,
193 static struct pci_driver e1000_driver = {
194 .name = e1000_driver_name,
195 .id_table = e1000_pci_tbl,
196 .probe = e1000_probe,
197 .remove = __devexit_p(e1000_remove),
199 /* Power Managment Hooks */
200 .suspend = e1000_suspend,
201 .resume = e1000_resume,
203 .shutdown = e1000_shutdown,
204 .err_handler = &e1000_err_handler
207 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
208 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
209 MODULE_LICENSE("GPL");
210 MODULE_VERSION(DRV_VERSION);
212 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
213 module_param(debug, int, 0);
214 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
217 * e1000_init_module - Driver Registration Routine
219 * e1000_init_module is the first routine called when the driver is
220 * loaded. All it does is register with the PCI subsystem.
223 static int __init e1000_init_module(void)
226 printk(KERN_INFO "%s - version %s\n",
227 e1000_driver_string, e1000_driver_version);
229 printk(KERN_INFO "%s\n", e1000_copyright);
231 ret = pci_register_driver(&e1000_driver);
232 if (copybreak != COPYBREAK_DEFAULT) {
234 printk(KERN_INFO "e1000: copybreak disabled\n");
236 printk(KERN_INFO "e1000: copybreak enabled for "
237 "packets <= %u bytes\n", copybreak);
242 module_init(e1000_init_module);
245 * e1000_exit_module - Driver Exit Cleanup Routine
247 * e1000_exit_module is called just before the driver is removed
251 static void __exit e1000_exit_module(void)
253 pci_unregister_driver(&e1000_driver);
256 module_exit(e1000_exit_module);
258 static int e1000_request_irq(struct e1000_adapter *adapter)
260 struct e1000_hw *hw = &adapter->hw;
261 struct net_device *netdev = adapter->netdev;
262 irq_handler_t handler = e1000_intr;
263 int irq_flags = IRQF_SHARED;
266 if (hw->mac_type >= e1000_82571) {
267 adapter->have_msi = !pci_enable_msi(adapter->pdev);
268 if (adapter->have_msi) {
269 handler = e1000_intr_msi;
274 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
277 if (adapter->have_msi)
278 pci_disable_msi(adapter->pdev);
280 "Unable to allocate interrupt Error: %d\n", err);
286 static void e1000_free_irq(struct e1000_adapter *adapter)
288 struct net_device *netdev = adapter->netdev;
290 free_irq(adapter->pdev->irq, netdev);
292 if (adapter->have_msi)
293 pci_disable_msi(adapter->pdev);
297 * e1000_irq_disable - Mask off interrupt generation on the NIC
298 * @adapter: board private structure
301 static void e1000_irq_disable(struct e1000_adapter *adapter)
303 struct e1000_hw *hw = &adapter->hw;
307 synchronize_irq(adapter->pdev->irq);
311 * e1000_irq_enable - Enable default interrupt generation settings
312 * @adapter: board private structure
315 static void e1000_irq_enable(struct e1000_adapter *adapter)
317 struct e1000_hw *hw = &adapter->hw;
319 ew32(IMS, IMS_ENABLE_MASK);
323 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
325 struct e1000_hw *hw = &adapter->hw;
326 struct net_device *netdev = adapter->netdev;
327 u16 vid = hw->mng_cookie.vlan_id;
328 u16 old_vid = adapter->mng_vlan_id;
329 if (adapter->vlgrp) {
330 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
331 if (hw->mng_cookie.status &
332 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
333 e1000_vlan_rx_add_vid(netdev, vid);
334 adapter->mng_vlan_id = vid;
336 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
338 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
340 !vlan_group_get_device(adapter->vlgrp, old_vid))
341 e1000_vlan_rx_kill_vid(netdev, old_vid);
343 adapter->mng_vlan_id = vid;
348 * e1000_release_hw_control - release control of the h/w to f/w
349 * @adapter: address of board private structure
351 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
352 * For ASF and Pass Through versions of f/w this means that the
353 * driver is no longer loaded. For AMT version (only with 82573) i
354 * of the f/w this means that the network i/f is closed.
358 static void e1000_release_hw_control(struct e1000_adapter *adapter)
362 struct e1000_hw *hw = &adapter->hw;
364 /* Let firmware taken over control of h/w */
365 switch (hw->mac_type) {
368 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
372 case e1000_80003es2lan:
374 ctrl_ext = er32(CTRL_EXT);
375 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
383 * e1000_get_hw_control - get control of the h/w from f/w
384 * @adapter: address of board private structure
386 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
387 * For ASF and Pass Through versions of f/w this means that
388 * the driver is loaded. For AMT version (only with 82573)
389 * of the f/w this means that the network i/f is open.
393 static void e1000_get_hw_control(struct e1000_adapter *adapter)
397 struct e1000_hw *hw = &adapter->hw;
399 /* Let firmware know the driver has taken over */
400 switch (hw->mac_type) {
403 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
407 case e1000_80003es2lan:
409 ctrl_ext = er32(CTRL_EXT);
410 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
417 static void e1000_init_manageability(struct e1000_adapter *adapter)
419 struct e1000_hw *hw = &adapter->hw;
421 if (adapter->en_mng_pt) {
422 u32 manc = er32(MANC);
424 /* disable hardware interception of ARP */
425 manc &= ~(E1000_MANC_ARP_EN);
427 /* enable receiving management packets to the host */
428 /* this will probably generate destination unreachable messages
429 * from the host OS, but the packets will be handled on SMBUS */
430 if (hw->has_manc2h) {
431 u32 manc2h = er32(MANC2H);
433 manc |= E1000_MANC_EN_MNG2HOST;
434 #define E1000_MNG2HOST_PORT_623 (1 << 5)
435 #define E1000_MNG2HOST_PORT_664 (1 << 6)
436 manc2h |= E1000_MNG2HOST_PORT_623;
437 manc2h |= E1000_MNG2HOST_PORT_664;
438 ew32(MANC2H, manc2h);
445 static void e1000_release_manageability(struct e1000_adapter *adapter)
447 struct e1000_hw *hw = &adapter->hw;
449 if (adapter->en_mng_pt) {
450 u32 manc = er32(MANC);
452 /* re-enable hardware interception of ARP */
453 manc |= E1000_MANC_ARP_EN;
456 manc &= ~E1000_MANC_EN_MNG2HOST;
458 /* don't explicitly have to mess with MANC2H since
459 * MANC has an enable disable that gates MANC2H */
466 * e1000_configure - configure the hardware for RX and TX
467 * @adapter = private board structure
469 static void e1000_configure(struct e1000_adapter *adapter)
471 struct net_device *netdev = adapter->netdev;
474 e1000_set_rx_mode(netdev);
476 e1000_restore_vlan(adapter);
477 e1000_init_manageability(adapter);
479 e1000_configure_tx(adapter);
480 e1000_setup_rctl(adapter);
481 e1000_configure_rx(adapter);
482 /* call E1000_DESC_UNUSED which always leaves
483 * at least 1 descriptor unused to make sure
484 * next_to_use != next_to_clean */
485 for (i = 0; i < adapter->num_rx_queues; i++) {
486 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
487 adapter->alloc_rx_buf(adapter, ring,
488 E1000_DESC_UNUSED(ring));
491 adapter->tx_queue_len = netdev->tx_queue_len;
494 int e1000_up(struct e1000_adapter *adapter)
496 struct e1000_hw *hw = &adapter->hw;
498 /* hardware has been reset, we need to reload some things */
499 e1000_configure(adapter);
501 clear_bit(__E1000_DOWN, &adapter->flags);
503 napi_enable(&adapter->napi);
505 e1000_irq_enable(adapter);
507 netif_wake_queue(adapter->netdev);
509 /* fire a link change interrupt to start the watchdog */
510 ew32(ICS, E1000_ICS_LSC);
515 * e1000_power_up_phy - restore link in case the phy was powered down
516 * @adapter: address of board private structure
518 * The phy may be powered down to save power and turn off link when the
519 * driver is unloaded and wake on lan is not enabled (among others)
520 * *** this routine MUST be followed by a call to e1000_reset ***
524 void e1000_power_up_phy(struct e1000_adapter *adapter)
526 struct e1000_hw *hw = &adapter->hw;
529 /* Just clear the power down bit to wake the phy back up */
530 if (hw->media_type == e1000_media_type_copper) {
531 /* according to the manual, the phy will retain its
532 * settings across a power-down/up cycle */
533 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
534 mii_reg &= ~MII_CR_POWER_DOWN;
535 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
539 static void e1000_power_down_phy(struct e1000_adapter *adapter)
541 struct e1000_hw *hw = &adapter->hw;
543 /* Power down the PHY so no link is implied when interface is down *
544 * The PHY cannot be powered down if any of the following is true *
547 * (c) SoL/IDER session is active */
548 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
549 hw->media_type == e1000_media_type_copper) {
552 switch (hw->mac_type) {
555 case e1000_82545_rev_3:
557 case e1000_82546_rev_3:
559 case e1000_82541_rev_2:
561 case e1000_82547_rev_2:
562 if (er32(MANC) & E1000_MANC_SMBUS_EN)
568 case e1000_80003es2lan:
570 if (e1000_check_mng_mode(hw) ||
571 e1000_check_phy_reset_block(hw))
577 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
578 mii_reg |= MII_CR_POWER_DOWN;
579 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
586 void e1000_down(struct e1000_adapter *adapter)
588 struct e1000_hw *hw = &adapter->hw;
589 struct net_device *netdev = adapter->netdev;
592 /* signal that we're down so the interrupt handler does not
593 * reschedule our watchdog timer */
594 set_bit(__E1000_DOWN, &adapter->flags);
596 /* disable receives in the hardware */
598 ew32(RCTL, rctl & ~E1000_RCTL_EN);
599 /* flush and sleep below */
601 /* can be netif_tx_disable when NETIF_F_LLTX is removed */
602 netif_stop_queue(netdev);
604 /* disable transmits in the hardware */
606 tctl &= ~E1000_TCTL_EN;
608 /* flush both disables and wait for them to finish */
612 napi_disable(&adapter->napi);
614 e1000_irq_disable(adapter);
616 del_timer_sync(&adapter->tx_fifo_stall_timer);
617 del_timer_sync(&adapter->watchdog_timer);
618 del_timer_sync(&adapter->phy_info_timer);
620 netdev->tx_queue_len = adapter->tx_queue_len;
621 adapter->link_speed = 0;
622 adapter->link_duplex = 0;
623 netif_carrier_off(netdev);
625 e1000_reset(adapter);
626 e1000_clean_all_tx_rings(adapter);
627 e1000_clean_all_rx_rings(adapter);
630 void e1000_reinit_locked(struct e1000_adapter *adapter)
632 WARN_ON(in_interrupt());
633 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
637 clear_bit(__E1000_RESETTING, &adapter->flags);
640 void e1000_reset(struct e1000_adapter *adapter)
642 struct e1000_hw *hw = &adapter->hw;
643 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
644 bool legacy_pba_adjust = false;
647 /* Repartition Pba for greater than 9k mtu
648 * To take effect CTRL.RST is required.
651 switch (hw->mac_type) {
652 case e1000_82542_rev2_0:
653 case e1000_82542_rev2_1:
658 case e1000_82541_rev_2:
659 legacy_pba_adjust = true;
663 case e1000_82545_rev_3:
665 case e1000_82546_rev_3:
669 case e1000_82547_rev_2:
670 legacy_pba_adjust = true;
675 case e1000_80003es2lan:
683 case e1000_undefined:
688 if (legacy_pba_adjust) {
689 if (hw->max_frame_size > E1000_RXBUFFER_8192)
690 pba -= 8; /* allocate more FIFO for Tx */
692 if (hw->mac_type == e1000_82547) {
693 adapter->tx_fifo_head = 0;
694 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
695 adapter->tx_fifo_size =
696 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
697 atomic_set(&adapter->tx_fifo_stall, 0);
699 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
700 /* adjust PBA for jumbo frames */
703 /* To maintain wire speed transmits, the Tx FIFO should be
704 * large enough to accommodate two full transmit packets,
705 * rounded up to the next 1KB and expressed in KB. Likewise,
706 * the Rx FIFO should be large enough to accommodate at least
707 * one full receive packet and is similarly rounded up and
708 * expressed in KB. */
710 /* upper 16 bits has Tx packet buffer allocation size in KB */
711 tx_space = pba >> 16;
712 /* lower 16 bits has Rx packet buffer allocation size in KB */
715 * the tx fifo also stores 16 bytes of information about the tx
716 * but don't include ethernet FCS because hardware appends it
718 min_tx_space = (hw->max_frame_size +
719 sizeof(struct e1000_tx_desc) -
721 min_tx_space = ALIGN(min_tx_space, 1024);
723 /* software strips receive CRC, so leave room for it */
724 min_rx_space = hw->max_frame_size;
725 min_rx_space = ALIGN(min_rx_space, 1024);
728 /* If current Tx allocation is less than the min Tx FIFO size,
729 * and the min Tx FIFO size is less than the current Rx FIFO
730 * allocation, take space away from current Rx allocation */
731 if (tx_space < min_tx_space &&
732 ((min_tx_space - tx_space) < pba)) {
733 pba = pba - (min_tx_space - tx_space);
735 /* PCI/PCIx hardware has PBA alignment constraints */
736 switch (hw->mac_type) {
737 case e1000_82545 ... e1000_82546_rev_3:
738 pba &= ~(E1000_PBA_8K - 1);
744 /* if short on rx space, rx wins and must trump tx
745 * adjustment or use Early Receive if available */
746 if (pba < min_rx_space) {
747 switch (hw->mac_type) {
749 /* ERT enabled in e1000_configure_rx */
762 * flow control settings:
763 * The high water mark must be low enough to fit one full frame
764 * (or the size used for early receive) above it in the Rx FIFO.
765 * Set it to the lower of:
766 * - 90% of the Rx FIFO size, and
767 * - the full Rx FIFO size minus the early receive size (for parts
768 * with ERT support assuming ERT set to E1000_ERT_2048), or
769 * - the full Rx FIFO size minus one full frame
771 hwm = min(((pba << 10) * 9 / 10),
772 ((pba << 10) - hw->max_frame_size));
774 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
775 hw->fc_low_water = hw->fc_high_water - 8;
776 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
778 hw->fc = hw->original_fc;
780 /* Allow time for pending master requests to run */
782 if (hw->mac_type >= e1000_82544)
785 if (e1000_init_hw(hw))
786 DPRINTK(PROBE, ERR, "Hardware Error\n");
787 e1000_update_mng_vlan(adapter);
789 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
790 if (hw->mac_type >= e1000_82544 &&
791 hw->mac_type <= e1000_82547_rev_2 &&
793 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
794 u32 ctrl = er32(CTRL);
795 /* clear phy power management bit if we are in gig only mode,
796 * which if enabled will attempt negotiation to 100Mb, which
797 * can cause a loss of link at power off or driver unload */
798 ctrl &= ~E1000_CTRL_SWDPIN3;
802 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
803 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
805 e1000_reset_adaptive(hw);
806 e1000_phy_get_info(hw, &adapter->phy_info);
808 if (!adapter->smart_power_down &&
809 (hw->mac_type == e1000_82571 ||
810 hw->mac_type == e1000_82572)) {
812 /* speed up time to link by disabling smart power down, ignore
813 * the return value of this function because there is nothing
814 * different we would do if it failed */
815 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
817 phy_data &= ~IGP02E1000_PM_SPD;
818 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
822 e1000_release_manageability(adapter);
826 * Dump the eeprom for users having checksum issues
828 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
830 struct net_device *netdev = adapter->netdev;
831 struct ethtool_eeprom eeprom;
832 const struct ethtool_ops *ops = netdev->ethtool_ops;
835 u16 csum_old, csum_new = 0;
837 eeprom.len = ops->get_eeprom_len(netdev);
840 data = kmalloc(eeprom.len, GFP_KERNEL);
842 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
847 ops->get_eeprom(netdev, &eeprom, data);
849 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
850 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
851 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
852 csum_new += data[i] + (data[i + 1] << 8);
853 csum_new = EEPROM_SUM - csum_new;
855 printk(KERN_ERR "/*********************/\n");
856 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
857 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
859 printk(KERN_ERR "Offset Values\n");
860 printk(KERN_ERR "======== ======\n");
861 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
863 printk(KERN_ERR "Include this output when contacting your support "
865 printk(KERN_ERR "This is not a software error! Something bad "
866 "happened to your hardware or\n");
867 printk(KERN_ERR "EEPROM image. Ignoring this "
868 "problem could result in further problems,\n");
869 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
870 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
871 "which is invalid\n");
872 printk(KERN_ERR "and requires you to set the proper MAC "
873 "address manually before continuing\n");
874 printk(KERN_ERR "to enable this network device.\n");
875 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
876 "to your hardware vendor\n");
877 printk(KERN_ERR "or Intel Customer Support.\n");
878 printk(KERN_ERR "/*********************/\n");
884 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
885 * @pdev: PCI device information struct
887 * Return true if an adapter needs ioport resources
889 static int e1000_is_need_ioport(struct pci_dev *pdev)
891 switch (pdev->device) {
892 case E1000_DEV_ID_82540EM:
893 case E1000_DEV_ID_82540EM_LOM:
894 case E1000_DEV_ID_82540EP:
895 case E1000_DEV_ID_82540EP_LOM:
896 case E1000_DEV_ID_82540EP_LP:
897 case E1000_DEV_ID_82541EI:
898 case E1000_DEV_ID_82541EI_MOBILE:
899 case E1000_DEV_ID_82541ER:
900 case E1000_DEV_ID_82541ER_LOM:
901 case E1000_DEV_ID_82541GI:
902 case E1000_DEV_ID_82541GI_LF:
903 case E1000_DEV_ID_82541GI_MOBILE:
904 case E1000_DEV_ID_82544EI_COPPER:
905 case E1000_DEV_ID_82544EI_FIBER:
906 case E1000_DEV_ID_82544GC_COPPER:
907 case E1000_DEV_ID_82544GC_LOM:
908 case E1000_DEV_ID_82545EM_COPPER:
909 case E1000_DEV_ID_82545EM_FIBER:
910 case E1000_DEV_ID_82546EB_COPPER:
911 case E1000_DEV_ID_82546EB_FIBER:
912 case E1000_DEV_ID_82546EB_QUAD_COPPER:
919 static const struct net_device_ops e1000_netdev_ops = {
920 .ndo_open = e1000_open,
921 .ndo_stop = e1000_close,
922 .ndo_start_xmit = e1000_xmit_frame,
923 .ndo_get_stats = e1000_get_stats,
924 .ndo_set_rx_mode = e1000_set_rx_mode,
925 .ndo_set_mac_address = e1000_set_mac,
926 .ndo_tx_timeout = e1000_tx_timeout,
927 .ndo_change_mtu = e1000_change_mtu,
928 .ndo_do_ioctl = e1000_ioctl,
929 .ndo_validate_addr = eth_validate_addr,
931 .ndo_vlan_rx_register = e1000_vlan_rx_register,
932 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
933 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
934 #ifdef CONFIG_NET_POLL_CONTROLLER
935 .ndo_poll_controller = e1000_netpoll,
940 * e1000_probe - Device Initialization Routine
941 * @pdev: PCI device information struct
942 * @ent: entry in e1000_pci_tbl
944 * Returns 0 on success, negative on failure
946 * e1000_probe initializes an adapter identified by a pci_dev structure.
947 * The OS initialization, configuring of the adapter private structure,
948 * and a hardware reset occur.
950 static int __devinit e1000_probe(struct pci_dev *pdev,
951 const struct pci_device_id *ent)
953 struct net_device *netdev;
954 struct e1000_adapter *adapter;
957 static int cards_found = 0;
958 static int global_quad_port_a = 0; /* global ksp3 port a indication */
959 int i, err, pci_using_dac;
961 u16 eeprom_apme_mask = E1000_EEPROM_APME;
962 int bars, need_ioport;
964 /* do not allocate ioport bars when not needed */
965 need_ioport = e1000_is_need_ioport(pdev);
967 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
968 err = pci_enable_device(pdev);
970 bars = pci_select_bars(pdev, IORESOURCE_MEM);
971 err = pci_enable_device_mem(pdev);
976 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
977 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
980 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
982 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
984 E1000_ERR("No usable DMA configuration, "
992 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
996 pci_set_master(pdev);
999 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
1001 goto err_alloc_etherdev;
1003 SET_NETDEV_DEV(netdev, &pdev->dev);
1005 pci_set_drvdata(pdev, netdev);
1006 adapter = netdev_priv(netdev);
1007 adapter->netdev = netdev;
1008 adapter->pdev = pdev;
1009 adapter->msg_enable = (1 << debug) - 1;
1010 adapter->bars = bars;
1011 adapter->need_ioport = need_ioport;
1017 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
1021 if (adapter->need_ioport) {
1022 for (i = BAR_1; i <= BAR_5; i++) {
1023 if (pci_resource_len(pdev, i) == 0)
1025 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1026 hw->io_base = pci_resource_start(pdev, i);
1032 netdev->netdev_ops = &e1000_netdev_ops;
1033 e1000_set_ethtool_ops(netdev);
1034 netdev->watchdog_timeo = 5 * HZ;
1035 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1037 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1039 adapter->bd_number = cards_found;
1041 /* setup the private structure */
1043 err = e1000_sw_init(adapter);
1048 /* Flash BAR mapping must happen after e1000_sw_init
1049 * because it depends on mac_type */
1050 if ((hw->mac_type == e1000_ich8lan) &&
1051 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
1052 hw->flash_address = pci_ioremap_bar(pdev, 1);
1053 if (!hw->flash_address)
1057 if (e1000_check_phy_reset_block(hw))
1058 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1060 if (hw->mac_type >= e1000_82543) {
1061 netdev->features = NETIF_F_SG |
1063 NETIF_F_HW_VLAN_TX |
1064 NETIF_F_HW_VLAN_RX |
1065 NETIF_F_HW_VLAN_FILTER;
1066 if (hw->mac_type == e1000_ich8lan)
1067 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
1070 if ((hw->mac_type >= e1000_82544) &&
1071 (hw->mac_type != e1000_82547))
1072 netdev->features |= NETIF_F_TSO;
1074 if (hw->mac_type > e1000_82547_rev_2)
1075 netdev->features |= NETIF_F_TSO6;
1077 netdev->features |= NETIF_F_HIGHDMA;
1079 netdev->vlan_features |= NETIF_F_TSO;
1080 netdev->vlan_features |= NETIF_F_TSO6;
1081 netdev->vlan_features |= NETIF_F_HW_CSUM;
1082 netdev->vlan_features |= NETIF_F_SG;
1084 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1086 /* initialize eeprom parameters */
1087 if (e1000_init_eeprom_params(hw)) {
1088 E1000_ERR("EEPROM initialization failed\n");
1092 /* before reading the EEPROM, reset the controller to
1093 * put the device in a known good starting state */
1097 /* make sure the EEPROM is good */
1098 if (e1000_validate_eeprom_checksum(hw) < 0) {
1099 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1100 e1000_dump_eeprom(adapter);
1102 * set MAC address to all zeroes to invalidate and temporary
1103 * disable this device for the user. This blocks regular
1104 * traffic while still permitting ethtool ioctls from reaching
1105 * the hardware as well as allowing the user to run the
1106 * interface after manually setting a hw addr using
1109 memset(hw->mac_addr, 0, netdev->addr_len);
1111 /* copy the MAC address out of the EEPROM */
1112 if (e1000_read_mac_addr(hw))
1113 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1115 /* don't block initalization here due to bad MAC address */
1116 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1117 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
1119 if (!is_valid_ether_addr(netdev->perm_addr))
1120 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1122 e1000_get_bus_info(hw);
1124 init_timer(&adapter->tx_fifo_stall_timer);
1125 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1126 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
1128 init_timer(&adapter->watchdog_timer);
1129 adapter->watchdog_timer.function = &e1000_watchdog;
1130 adapter->watchdog_timer.data = (unsigned long) adapter;
1132 init_timer(&adapter->phy_info_timer);
1133 adapter->phy_info_timer.function = &e1000_update_phy_info;
1134 adapter->phy_info_timer.data = (unsigned long)adapter;
1136 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1138 e1000_check_options(adapter);
1140 /* Initial Wake on LAN setting
1141 * If APM wake is enabled in the EEPROM,
1142 * enable the ACPI Magic Packet filter
1145 switch (hw->mac_type) {
1146 case e1000_82542_rev2_0:
1147 case e1000_82542_rev2_1:
1151 e1000_read_eeprom(hw,
1152 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1153 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1156 e1000_read_eeprom(hw,
1157 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1158 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1161 case e1000_82546_rev_3:
1163 case e1000_80003es2lan:
1164 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1165 e1000_read_eeprom(hw,
1166 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1171 e1000_read_eeprom(hw,
1172 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1175 if (eeprom_data & eeprom_apme_mask)
1176 adapter->eeprom_wol |= E1000_WUFC_MAG;
1178 /* now that we have the eeprom settings, apply the special cases
1179 * where the eeprom may be wrong or the board simply won't support
1180 * wake on lan on a particular port */
1181 switch (pdev->device) {
1182 case E1000_DEV_ID_82546GB_PCIE:
1183 adapter->eeprom_wol = 0;
1185 case E1000_DEV_ID_82546EB_FIBER:
1186 case E1000_DEV_ID_82546GB_FIBER:
1187 case E1000_DEV_ID_82571EB_FIBER:
1188 /* Wake events only supported on port A for dual fiber
1189 * regardless of eeprom setting */
1190 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1191 adapter->eeprom_wol = 0;
1193 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1194 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1195 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1196 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1197 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1198 /* if quad port adapter, disable WoL on all but port A */
1199 if (global_quad_port_a != 0)
1200 adapter->eeprom_wol = 0;
1202 adapter->quad_port_a = 1;
1203 /* Reset for multiple quad port adapters */
1204 if (++global_quad_port_a == 4)
1205 global_quad_port_a = 0;
1209 /* initialize the wol settings based on the eeprom settings */
1210 adapter->wol = adapter->eeprom_wol;
1211 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1213 /* print bus type/speed/width info */
1214 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1215 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1216 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1217 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1218 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1219 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1220 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1221 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1222 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1223 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1224 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1227 printk("%pM\n", netdev->dev_addr);
1229 if (hw->bus_type == e1000_bus_type_pci_express) {
1230 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1231 "longer be supported by this driver in the future.\n",
1232 pdev->vendor, pdev->device);
1233 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1234 "driver instead.\n");
1237 /* reset the hardware with the new settings */
1238 e1000_reset(adapter);
1240 /* If the controller is 82573 and f/w is AMT, do not set
1241 * DRV_LOAD until the interface is up. For all other cases,
1242 * let the f/w know that the h/w is now under the control
1244 if (hw->mac_type != e1000_82573 ||
1245 !e1000_check_mng_mode(hw))
1246 e1000_get_hw_control(adapter);
1248 strcpy(netdev->name, "eth%d");
1249 err = register_netdev(netdev);
1253 /* carrier off reporting is important to ethtool even BEFORE open */
1254 netif_carrier_off(netdev);
1256 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1262 e1000_release_hw_control(adapter);
1264 if (!e1000_check_phy_reset_block(hw))
1265 e1000_phy_hw_reset(hw);
1267 if (hw->flash_address)
1268 iounmap(hw->flash_address);
1270 kfree(adapter->tx_ring);
1271 kfree(adapter->rx_ring);
1273 iounmap(hw->hw_addr);
1275 free_netdev(netdev);
1277 pci_release_selected_regions(pdev, bars);
1280 pci_disable_device(pdev);
1285 * e1000_remove - Device Removal Routine
1286 * @pdev: PCI device information struct
1288 * e1000_remove is called by the PCI subsystem to alert the driver
1289 * that it should release a PCI device. The could be caused by a
1290 * Hot-Plug event, or because the driver is going to be removed from
1294 static void __devexit e1000_remove(struct pci_dev *pdev)
1296 struct net_device *netdev = pci_get_drvdata(pdev);
1297 struct e1000_adapter *adapter = netdev_priv(netdev);
1298 struct e1000_hw *hw = &adapter->hw;
1300 cancel_work_sync(&adapter->reset_task);
1302 e1000_release_manageability(adapter);
1304 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1305 * would have already happened in close and is redundant. */
1306 e1000_release_hw_control(adapter);
1308 unregister_netdev(netdev);
1310 if (!e1000_check_phy_reset_block(hw))
1311 e1000_phy_hw_reset(hw);
1313 kfree(adapter->tx_ring);
1314 kfree(adapter->rx_ring);
1316 iounmap(hw->hw_addr);
1317 if (hw->flash_address)
1318 iounmap(hw->flash_address);
1319 pci_release_selected_regions(pdev, adapter->bars);
1321 free_netdev(netdev);
1323 pci_disable_device(pdev);
1327 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1328 * @adapter: board private structure to initialize
1330 * e1000_sw_init initializes the Adapter private data structure.
1331 * Fields are initialized based on PCI device information and
1332 * OS network device settings (MTU size).
1335 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1337 struct e1000_hw *hw = &adapter->hw;
1338 struct net_device *netdev = adapter->netdev;
1339 struct pci_dev *pdev = adapter->pdev;
1341 /* PCI config space info */
1343 hw->vendor_id = pdev->vendor;
1344 hw->device_id = pdev->device;
1345 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1346 hw->subsystem_id = pdev->subsystem_device;
1347 hw->revision_id = pdev->revision;
1349 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1351 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1352 hw->max_frame_size = netdev->mtu +
1353 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1354 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1356 /* identify the MAC */
1358 if (e1000_set_mac_type(hw)) {
1359 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1363 switch (hw->mac_type) {
1368 case e1000_82541_rev_2:
1369 case e1000_82547_rev_2:
1370 hw->phy_init_script = 1;
1374 e1000_set_media_type(hw);
1376 hw->wait_autoneg_complete = false;
1377 hw->tbi_compatibility_en = true;
1378 hw->adaptive_ifs = true;
1380 /* Copper options */
1382 if (hw->media_type == e1000_media_type_copper) {
1383 hw->mdix = AUTO_ALL_MODES;
1384 hw->disable_polarity_correction = false;
1385 hw->master_slave = E1000_MASTER_SLAVE;
1388 adapter->num_tx_queues = 1;
1389 adapter->num_rx_queues = 1;
1391 if (e1000_alloc_queues(adapter)) {
1392 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1396 /* Explicitly disable IRQ since the NIC can be in any state. */
1397 e1000_irq_disable(adapter);
1399 spin_lock_init(&adapter->stats_lock);
1401 set_bit(__E1000_DOWN, &adapter->flags);
1407 * e1000_alloc_queues - Allocate memory for all rings
1408 * @adapter: board private structure to initialize
1410 * We allocate one ring per queue at run-time since we don't know the
1411 * number of queues at compile-time.
1414 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1416 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1417 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1418 if (!adapter->tx_ring)
1421 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1422 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1423 if (!adapter->rx_ring) {
1424 kfree(adapter->tx_ring);
1428 return E1000_SUCCESS;
1432 * e1000_open - Called when a network interface is made active
1433 * @netdev: network interface device structure
1435 * Returns 0 on success, negative value on failure
1437 * The open entry point is called when a network interface is made
1438 * active by the system (IFF_UP). At this point all resources needed
1439 * for transmit and receive operations are allocated, the interrupt
1440 * handler is registered with the OS, the watchdog timer is started,
1441 * and the stack is notified that the interface is ready.
1444 static int e1000_open(struct net_device *netdev)
1446 struct e1000_adapter *adapter = netdev_priv(netdev);
1447 struct e1000_hw *hw = &adapter->hw;
1450 /* disallow open during test */
1451 if (test_bit(__E1000_TESTING, &adapter->flags))
1454 netif_carrier_off(netdev);
1456 /* allocate transmit descriptors */
1457 err = e1000_setup_all_tx_resources(adapter);
1461 /* allocate receive descriptors */
1462 err = e1000_setup_all_rx_resources(adapter);
1466 e1000_power_up_phy(adapter);
1468 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1469 if ((hw->mng_cookie.status &
1470 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1471 e1000_update_mng_vlan(adapter);
1474 /* If AMT is enabled, let the firmware know that the network
1475 * interface is now open */
1476 if (hw->mac_type == e1000_82573 &&
1477 e1000_check_mng_mode(hw))
1478 e1000_get_hw_control(adapter);
1480 /* before we allocate an interrupt, we must be ready to handle it.
1481 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1482 * as soon as we call pci_request_irq, so we have to setup our
1483 * clean_rx handler before we do so. */
1484 e1000_configure(adapter);
1486 err = e1000_request_irq(adapter);
1490 /* From here on the code is the same as e1000_up() */
1491 clear_bit(__E1000_DOWN, &adapter->flags);
1493 napi_enable(&adapter->napi);
1495 e1000_irq_enable(adapter);
1497 netif_start_queue(netdev);
1499 /* fire a link status change interrupt to start the watchdog */
1500 ew32(ICS, E1000_ICS_LSC);
1502 return E1000_SUCCESS;
1505 e1000_release_hw_control(adapter);
1506 e1000_power_down_phy(adapter);
1507 e1000_free_all_rx_resources(adapter);
1509 e1000_free_all_tx_resources(adapter);
1511 e1000_reset(adapter);
1517 * e1000_close - Disables a network interface
1518 * @netdev: network interface device structure
1520 * Returns 0, this is not allowed to fail
1522 * The close entry point is called when an interface is de-activated
1523 * by the OS. The hardware is still under the drivers control, but
1524 * needs to be disabled. A global MAC reset is issued to stop the
1525 * hardware, and all transmit and receive resources are freed.
1528 static int e1000_close(struct net_device *netdev)
1530 struct e1000_adapter *adapter = netdev_priv(netdev);
1531 struct e1000_hw *hw = &adapter->hw;
1533 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1534 e1000_down(adapter);
1535 e1000_power_down_phy(adapter);
1536 e1000_free_irq(adapter);
1538 e1000_free_all_tx_resources(adapter);
1539 e1000_free_all_rx_resources(adapter);
1541 /* kill manageability vlan ID if supported, but not if a vlan with
1542 * the same ID is registered on the host OS (let 8021q kill it) */
1543 if ((hw->mng_cookie.status &
1544 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1546 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1547 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1550 /* If AMT is enabled, let the firmware know that the network
1551 * interface is now closed */
1552 if (hw->mac_type == e1000_82573 &&
1553 e1000_check_mng_mode(hw))
1554 e1000_release_hw_control(adapter);
1560 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1561 * @adapter: address of board private structure
1562 * @start: address of beginning of memory
1563 * @len: length of memory
1565 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1568 struct e1000_hw *hw = &adapter->hw;
1569 unsigned long begin = (unsigned long)start;
1570 unsigned long end = begin + len;
1572 /* First rev 82545 and 82546 need to not allow any memory
1573 * write location to cross 64k boundary due to errata 23 */
1574 if (hw->mac_type == e1000_82545 ||
1575 hw->mac_type == e1000_82546) {
1576 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1583 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1584 * @adapter: board private structure
1585 * @txdr: tx descriptor ring (for a specific queue) to setup
1587 * Return 0 on success, negative on failure
1590 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1591 struct e1000_tx_ring *txdr)
1593 struct pci_dev *pdev = adapter->pdev;
1596 size = sizeof(struct e1000_buffer) * txdr->count;
1597 txdr->buffer_info = vmalloc(size);
1598 if (!txdr->buffer_info) {
1600 "Unable to allocate memory for the transmit descriptor ring\n");
1603 memset(txdr->buffer_info, 0, size);
1605 /* round up to nearest 4K */
1607 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1608 txdr->size = ALIGN(txdr->size, 4096);
1610 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1613 vfree(txdr->buffer_info);
1615 "Unable to allocate memory for the transmit descriptor ring\n");
1619 /* Fix for errata 23, can't cross 64kB boundary */
1620 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1621 void *olddesc = txdr->desc;
1622 dma_addr_t olddma = txdr->dma;
1623 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1624 "at %p\n", txdr->size, txdr->desc);
1625 /* Try again, without freeing the previous */
1626 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1627 /* Failed allocation, critical failure */
1629 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1630 goto setup_tx_desc_die;
1633 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1635 pci_free_consistent(pdev, txdr->size, txdr->desc,
1637 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1639 "Unable to allocate aligned memory "
1640 "for the transmit descriptor ring\n");
1641 vfree(txdr->buffer_info);
1644 /* Free old allocation, new allocation was successful */
1645 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1648 memset(txdr->desc, 0, txdr->size);
1650 txdr->next_to_use = 0;
1651 txdr->next_to_clean = 0;
1657 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1658 * (Descriptors) for all queues
1659 * @adapter: board private structure
1661 * Return 0 on success, negative on failure
1664 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1668 for (i = 0; i < adapter->num_tx_queues; i++) {
1669 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1672 "Allocation for Tx Queue %u failed\n", i);
1673 for (i-- ; i >= 0; i--)
1674 e1000_free_tx_resources(adapter,
1675 &adapter->tx_ring[i]);
1684 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1685 * @adapter: board private structure
1687 * Configure the Tx unit of the MAC after a reset.
1690 static void e1000_configure_tx(struct e1000_adapter *adapter)
1693 struct e1000_hw *hw = &adapter->hw;
1694 u32 tdlen, tctl, tipg, tarc;
1697 /* Setup the HW Tx Head and Tail descriptor pointers */
1699 switch (adapter->num_tx_queues) {
1702 tdba = adapter->tx_ring[0].dma;
1703 tdlen = adapter->tx_ring[0].count *
1704 sizeof(struct e1000_tx_desc);
1706 ew32(TDBAH, (tdba >> 32));
1707 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1710 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1711 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1715 /* Set the default values for the Tx Inter Packet Gap timer */
1716 if (hw->mac_type <= e1000_82547_rev_2 &&
1717 (hw->media_type == e1000_media_type_fiber ||
1718 hw->media_type == e1000_media_type_internal_serdes))
1719 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1721 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1723 switch (hw->mac_type) {
1724 case e1000_82542_rev2_0:
1725 case e1000_82542_rev2_1:
1726 tipg = DEFAULT_82542_TIPG_IPGT;
1727 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1728 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1730 case e1000_80003es2lan:
1731 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1732 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1735 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1736 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1739 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1740 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1743 /* Set the Tx Interrupt Delay register */
1745 ew32(TIDV, adapter->tx_int_delay);
1746 if (hw->mac_type >= e1000_82540)
1747 ew32(TADV, adapter->tx_abs_int_delay);
1749 /* Program the Transmit Control Register */
1752 tctl &= ~E1000_TCTL_CT;
1753 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1754 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1756 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1758 /* set the speed mode bit, we'll clear it if we're not at
1759 * gigabit link later */
1762 } else if (hw->mac_type == e1000_80003es2lan) {
1771 e1000_config_collision_dist(hw);
1773 /* Setup Transmit Descriptor Settings for eop descriptor */
1774 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1776 /* only set IDE if we are delaying interrupts using the timers */
1777 if (adapter->tx_int_delay)
1778 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1780 if (hw->mac_type < e1000_82543)
1781 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1783 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1785 /* Cache if we're 82544 running in PCI-X because we'll
1786 * need this to apply a workaround later in the send path. */
1787 if (hw->mac_type == e1000_82544 &&
1788 hw->bus_type == e1000_bus_type_pcix)
1789 adapter->pcix_82544 = 1;
1796 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1797 * @adapter: board private structure
1798 * @rxdr: rx descriptor ring (for a specific queue) to setup
1800 * Returns 0 on success, negative on failure
1803 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1804 struct e1000_rx_ring *rxdr)
1806 struct e1000_hw *hw = &adapter->hw;
1807 struct pci_dev *pdev = adapter->pdev;
1810 size = sizeof(struct e1000_buffer) * rxdr->count;
1811 rxdr->buffer_info = vmalloc(size);
1812 if (!rxdr->buffer_info) {
1814 "Unable to allocate memory for the receive descriptor ring\n");
1817 memset(rxdr->buffer_info, 0, size);
1819 if (hw->mac_type <= e1000_82547_rev_2)
1820 desc_len = sizeof(struct e1000_rx_desc);
1822 desc_len = sizeof(union e1000_rx_desc_packet_split);
1824 /* Round up to nearest 4K */
1826 rxdr->size = rxdr->count * desc_len;
1827 rxdr->size = ALIGN(rxdr->size, 4096);
1829 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1833 "Unable to allocate memory for the receive descriptor ring\n");
1835 vfree(rxdr->buffer_info);
1839 /* Fix for errata 23, can't cross 64kB boundary */
1840 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1841 void *olddesc = rxdr->desc;
1842 dma_addr_t olddma = rxdr->dma;
1843 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1844 "at %p\n", rxdr->size, rxdr->desc);
1845 /* Try again, without freeing the previous */
1846 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1847 /* Failed allocation, critical failure */
1849 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1851 "Unable to allocate memory "
1852 "for the receive descriptor ring\n");
1853 goto setup_rx_desc_die;
1856 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1858 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1860 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1862 "Unable to allocate aligned memory "
1863 "for the receive descriptor ring\n");
1864 goto setup_rx_desc_die;
1866 /* Free old allocation, new allocation was successful */
1867 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1870 memset(rxdr->desc, 0, rxdr->size);
1872 rxdr->next_to_clean = 0;
1873 rxdr->next_to_use = 0;
1874 rxdr->rx_skb_top = NULL;
1880 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1881 * (Descriptors) for all queues
1882 * @adapter: board private structure
1884 * Return 0 on success, negative on failure
1887 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1891 for (i = 0; i < adapter->num_rx_queues; i++) {
1892 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1895 "Allocation for Rx Queue %u failed\n", i);
1896 for (i-- ; i >= 0; i--)
1897 e1000_free_rx_resources(adapter,
1898 &adapter->rx_ring[i]);
1907 * e1000_setup_rctl - configure the receive control registers
1908 * @adapter: Board private structure
1910 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1912 struct e1000_hw *hw = &adapter->hw;
1917 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1919 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1920 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1921 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1923 if (hw->tbi_compatibility_on == 1)
1924 rctl |= E1000_RCTL_SBP;
1926 rctl &= ~E1000_RCTL_SBP;
1928 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1929 rctl &= ~E1000_RCTL_LPE;
1931 rctl |= E1000_RCTL_LPE;
1933 /* Setup buffer sizes */
1934 rctl &= ~E1000_RCTL_SZ_4096;
1935 rctl |= E1000_RCTL_BSEX;
1936 switch (adapter->rx_buffer_len) {
1937 case E1000_RXBUFFER_256:
1938 rctl |= E1000_RCTL_SZ_256;
1939 rctl &= ~E1000_RCTL_BSEX;
1941 case E1000_RXBUFFER_512:
1942 rctl |= E1000_RCTL_SZ_512;
1943 rctl &= ~E1000_RCTL_BSEX;
1945 case E1000_RXBUFFER_1024:
1946 rctl |= E1000_RCTL_SZ_1024;
1947 rctl &= ~E1000_RCTL_BSEX;
1949 case E1000_RXBUFFER_2048:
1951 rctl |= E1000_RCTL_SZ_2048;
1952 rctl &= ~E1000_RCTL_BSEX;
1954 case E1000_RXBUFFER_4096:
1955 rctl |= E1000_RCTL_SZ_4096;
1957 case E1000_RXBUFFER_8192:
1958 rctl |= E1000_RCTL_SZ_8192;
1960 case E1000_RXBUFFER_16384:
1961 rctl |= E1000_RCTL_SZ_16384;
1969 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1970 * @adapter: board private structure
1972 * Configure the Rx unit of the MAC after a reset.
1975 static void e1000_configure_rx(struct e1000_adapter *adapter)
1978 struct e1000_hw *hw = &adapter->hw;
1979 u32 rdlen, rctl, rxcsum, ctrl_ext;
1981 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1982 rdlen = adapter->rx_ring[0].count *
1983 sizeof(struct e1000_rx_desc);
1984 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1985 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1987 rdlen = adapter->rx_ring[0].count *
1988 sizeof(struct e1000_rx_desc);
1989 adapter->clean_rx = e1000_clean_rx_irq;
1990 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1993 /* disable receives while setting up the descriptors */
1995 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1997 /* set the Receive Delay Timer Register */
1998 ew32(RDTR, adapter->rx_int_delay);
2000 if (hw->mac_type >= e1000_82540) {
2001 ew32(RADV, adapter->rx_abs_int_delay);
2002 if (adapter->itr_setting != 0)
2003 ew32(ITR, 1000000000 / (adapter->itr * 256));
2006 if (hw->mac_type >= e1000_82571) {
2007 ctrl_ext = er32(CTRL_EXT);
2008 /* Reset delay timers after every interrupt */
2009 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2010 /* Auto-Mask interrupts upon ICR access */
2011 ctrl_ext |= E1000_CTRL_EXT_IAME;
2012 ew32(IAM, 0xffffffff);
2013 ew32(CTRL_EXT, ctrl_ext);
2014 E1000_WRITE_FLUSH();
2017 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2018 * the Base and Length of the Rx Descriptor Ring */
2019 switch (adapter->num_rx_queues) {
2022 rdba = adapter->rx_ring[0].dma;
2024 ew32(RDBAH, (rdba >> 32));
2025 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2028 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2029 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
2033 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2034 if (hw->mac_type >= e1000_82543) {
2035 rxcsum = er32(RXCSUM);
2036 if (adapter->rx_csum)
2037 rxcsum |= E1000_RXCSUM_TUOFL;
2039 /* don't need to clear IPPCSE as it defaults to 0 */
2040 rxcsum &= ~E1000_RXCSUM_TUOFL;
2041 ew32(RXCSUM, rxcsum);
2044 /* Enable Receives */
2049 * e1000_free_tx_resources - Free Tx Resources per Queue
2050 * @adapter: board private structure
2051 * @tx_ring: Tx descriptor ring for a specific queue
2053 * Free all transmit software resources
2056 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2057 struct e1000_tx_ring *tx_ring)
2059 struct pci_dev *pdev = adapter->pdev;
2061 e1000_clean_tx_ring(adapter, tx_ring);
2063 vfree(tx_ring->buffer_info);
2064 tx_ring->buffer_info = NULL;
2066 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2068 tx_ring->desc = NULL;
2072 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2073 * @adapter: board private structure
2075 * Free all transmit software resources
2078 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
2082 for (i = 0; i < adapter->num_tx_queues; i++)
2083 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
2086 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2087 struct e1000_buffer *buffer_info)
2089 buffer_info->dma = 0;
2090 if (buffer_info->skb) {
2091 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
2093 dev_kfree_skb_any(buffer_info->skb);
2094 buffer_info->skb = NULL;
2096 buffer_info->time_stamp = 0;
2097 /* buffer_info must be completely set up in the transmit path */
2101 * e1000_clean_tx_ring - Free Tx Buffers
2102 * @adapter: board private structure
2103 * @tx_ring: ring to be cleaned
2106 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2107 struct e1000_tx_ring *tx_ring)
2109 struct e1000_hw *hw = &adapter->hw;
2110 struct e1000_buffer *buffer_info;
2114 /* Free all the Tx ring sk_buffs */
2116 for (i = 0; i < tx_ring->count; i++) {
2117 buffer_info = &tx_ring->buffer_info[i];
2118 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2121 size = sizeof(struct e1000_buffer) * tx_ring->count;
2122 memset(tx_ring->buffer_info, 0, size);
2124 /* Zero out the descriptor ring */
2126 memset(tx_ring->desc, 0, tx_ring->size);
2128 tx_ring->next_to_use = 0;
2129 tx_ring->next_to_clean = 0;
2130 tx_ring->last_tx_tso = 0;
2132 writel(0, hw->hw_addr + tx_ring->tdh);
2133 writel(0, hw->hw_addr + tx_ring->tdt);
2137 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2138 * @adapter: board private structure
2141 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2145 for (i = 0; i < adapter->num_tx_queues; i++)
2146 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2150 * e1000_free_rx_resources - Free Rx Resources
2151 * @adapter: board private structure
2152 * @rx_ring: ring to clean the resources from
2154 * Free all receive software resources
2157 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2158 struct e1000_rx_ring *rx_ring)
2160 struct pci_dev *pdev = adapter->pdev;
2162 e1000_clean_rx_ring(adapter, rx_ring);
2164 vfree(rx_ring->buffer_info);
2165 rx_ring->buffer_info = NULL;
2167 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2169 rx_ring->desc = NULL;
2173 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2174 * @adapter: board private structure
2176 * Free all receive software resources
2179 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2183 for (i = 0; i < adapter->num_rx_queues; i++)
2184 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2188 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2189 * @adapter: board private structure
2190 * @rx_ring: ring to free buffers from
2193 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2194 struct e1000_rx_ring *rx_ring)
2196 struct e1000_hw *hw = &adapter->hw;
2197 struct e1000_buffer *buffer_info;
2198 struct pci_dev *pdev = adapter->pdev;
2202 /* Free all the Rx ring sk_buffs */
2203 for (i = 0; i < rx_ring->count; i++) {
2204 buffer_info = &rx_ring->buffer_info[i];
2205 if (buffer_info->dma &&
2206 adapter->clean_rx == e1000_clean_rx_irq) {
2207 pci_unmap_single(pdev, buffer_info->dma,
2208 buffer_info->length,
2209 PCI_DMA_FROMDEVICE);
2210 } else if (buffer_info->dma &&
2211 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2212 pci_unmap_page(pdev, buffer_info->dma,
2213 buffer_info->length,
2214 PCI_DMA_FROMDEVICE);
2217 buffer_info->dma = 0;
2218 if (buffer_info->page) {
2219 put_page(buffer_info->page);
2220 buffer_info->page = NULL;
2222 if (buffer_info->skb) {
2223 dev_kfree_skb(buffer_info->skb);
2224 buffer_info->skb = NULL;
2228 /* there also may be some cached data from a chained receive */
2229 if (rx_ring->rx_skb_top) {
2230 dev_kfree_skb(rx_ring->rx_skb_top);
2231 rx_ring->rx_skb_top = NULL;
2234 size = sizeof(struct e1000_buffer) * rx_ring->count;
2235 memset(rx_ring->buffer_info, 0, size);
2237 /* Zero out the descriptor ring */
2238 memset(rx_ring->desc, 0, rx_ring->size);
2240 rx_ring->next_to_clean = 0;
2241 rx_ring->next_to_use = 0;
2243 writel(0, hw->hw_addr + rx_ring->rdh);
2244 writel(0, hw->hw_addr + rx_ring->rdt);
2248 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2249 * @adapter: board private structure
2252 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2256 for (i = 0; i < adapter->num_rx_queues; i++)
2257 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2260 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2261 * and memory write and invalidate disabled for certain operations
2263 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2265 struct e1000_hw *hw = &adapter->hw;
2266 struct net_device *netdev = adapter->netdev;
2269 e1000_pci_clear_mwi(hw);
2272 rctl |= E1000_RCTL_RST;
2274 E1000_WRITE_FLUSH();
2277 if (netif_running(netdev))
2278 e1000_clean_all_rx_rings(adapter);
2281 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2283 struct e1000_hw *hw = &adapter->hw;
2284 struct net_device *netdev = adapter->netdev;
2288 rctl &= ~E1000_RCTL_RST;
2290 E1000_WRITE_FLUSH();
2293 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2294 e1000_pci_set_mwi(hw);
2296 if (netif_running(netdev)) {
2297 /* No need to loop, because 82542 supports only 1 queue */
2298 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2299 e1000_configure_rx(adapter);
2300 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2305 * e1000_set_mac - Change the Ethernet Address of the NIC
2306 * @netdev: network interface device structure
2307 * @p: pointer to an address structure
2309 * Returns 0 on success, negative on failure
2312 static int e1000_set_mac(struct net_device *netdev, void *p)
2314 struct e1000_adapter *adapter = netdev_priv(netdev);
2315 struct e1000_hw *hw = &adapter->hw;
2316 struct sockaddr *addr = p;
2318 if (!is_valid_ether_addr(addr->sa_data))
2319 return -EADDRNOTAVAIL;
2321 /* 82542 2.0 needs to be in reset to write receive address registers */
2323 if (hw->mac_type == e1000_82542_rev2_0)
2324 e1000_enter_82542_rst(adapter);
2326 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2327 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2329 e1000_rar_set(hw, hw->mac_addr, 0);
2331 /* With 82571 controllers, LAA may be overwritten (with the default)
2332 * due to controller reset from the other port. */
2333 if (hw->mac_type == e1000_82571) {
2334 /* activate the work around */
2335 hw->laa_is_present = 1;
2337 /* Hold a copy of the LAA in RAR[14] This is done so that
2338 * between the time RAR[0] gets clobbered and the time it
2339 * gets fixed (in e1000_watchdog), the actual LAA is in one
2340 * of the RARs and no incoming packets directed to this port
2341 * are dropped. Eventaully the LAA will be in RAR[0] and
2343 e1000_rar_set(hw, hw->mac_addr,
2344 E1000_RAR_ENTRIES - 1);
2347 if (hw->mac_type == e1000_82542_rev2_0)
2348 e1000_leave_82542_rst(adapter);
2354 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2355 * @netdev: network interface device structure
2357 * The set_rx_mode entry point is called whenever the unicast or multicast
2358 * address lists or the network interface flags are updated. This routine is
2359 * responsible for configuring the hardware for proper unicast, multicast,
2360 * promiscuous mode, and all-multi behavior.
2363 static void e1000_set_rx_mode(struct net_device *netdev)
2365 struct e1000_adapter *adapter = netdev_priv(netdev);
2366 struct e1000_hw *hw = &adapter->hw;
2367 struct netdev_hw_addr *ha;
2368 bool use_uc = false;
2369 struct dev_addr_list *mc_ptr;
2372 int i, rar_entries = E1000_RAR_ENTRIES;
2373 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2374 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2375 E1000_NUM_MTA_REGISTERS;
2376 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2379 DPRINTK(PROBE, ERR, "memory allocation failed\n");
2383 if (hw->mac_type == e1000_ich8lan)
2384 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2386 /* reserve RAR[14] for LAA over-write work-around */
2387 if (hw->mac_type == e1000_82571)
2390 /* Check for Promiscuous and All Multicast modes */
2394 if (netdev->flags & IFF_PROMISC) {
2395 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2396 rctl &= ~E1000_RCTL_VFE;
2398 if (netdev->flags & IFF_ALLMULTI) {
2399 rctl |= E1000_RCTL_MPE;
2401 rctl &= ~E1000_RCTL_MPE;
2403 if (adapter->hw.mac_type != e1000_ich8lan)
2404 rctl |= E1000_RCTL_VFE;
2407 if (netdev->uc.count > rar_entries - 1) {
2408 rctl |= E1000_RCTL_UPE;
2409 } else if (!(netdev->flags & IFF_PROMISC)) {
2410 rctl &= ~E1000_RCTL_UPE;
2416 /* 82542 2.0 needs to be in reset to write receive address registers */
2418 if (hw->mac_type == e1000_82542_rev2_0)
2419 e1000_enter_82542_rst(adapter);
2421 /* load the first 14 addresses into the exact filters 1-14. Unicast
2422 * addresses take precedence to avoid disabling unicast filtering
2425 * RAR 0 is used for the station MAC adddress
2426 * if there are not 14 addresses, go ahead and clear the filters
2427 * -- with 82571 controllers only 0-13 entries are filled here
2431 list_for_each_entry(ha, &netdev->uc.list, list) {
2432 if (i == rar_entries)
2434 e1000_rar_set(hw, ha->addr, i++);
2437 WARN_ON(i == rar_entries);
2439 mc_ptr = netdev->mc_list;
2441 for (; i < rar_entries; i++) {
2443 e1000_rar_set(hw, mc_ptr->da_addr, i);
2444 mc_ptr = mc_ptr->next;
2446 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2447 E1000_WRITE_FLUSH();
2448 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2449 E1000_WRITE_FLUSH();
2453 /* load any remaining addresses into the hash table */
2455 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2456 u32 hash_reg, hash_bit, mta;
2457 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
2458 hash_reg = (hash_value >> 5) & 0x7F;
2459 hash_bit = hash_value & 0x1F;
2460 mta = (1 << hash_bit);
2461 mcarray[hash_reg] |= mta;
2464 /* write the hash table completely, write from bottom to avoid
2465 * both stupid write combining chipsets, and flushing each write */
2466 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2468 * If we are on an 82544 has an errata where writing odd
2469 * offsets overwrites the previous even offset, but writing
2470 * backwards over the range solves the issue by always
2471 * writing the odd offset first
2473 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2475 E1000_WRITE_FLUSH();
2477 if (hw->mac_type == e1000_82542_rev2_0)
2478 e1000_leave_82542_rst(adapter);
2483 /* Need to wait a few seconds after link up to get diagnostic information from
2486 static void e1000_update_phy_info(unsigned long data)
2488 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2489 struct e1000_hw *hw = &adapter->hw;
2490 e1000_phy_get_info(hw, &adapter->phy_info);
2494 * e1000_82547_tx_fifo_stall - Timer Call-back
2495 * @data: pointer to adapter cast into an unsigned long
2498 static void e1000_82547_tx_fifo_stall(unsigned long data)
2500 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2501 struct e1000_hw *hw = &adapter->hw;
2502 struct net_device *netdev = adapter->netdev;
2505 if (atomic_read(&adapter->tx_fifo_stall)) {
2506 if ((er32(TDT) == er32(TDH)) &&
2507 (er32(TDFT) == er32(TDFH)) &&
2508 (er32(TDFTS) == er32(TDFHS))) {
2510 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2511 ew32(TDFT, adapter->tx_head_addr);
2512 ew32(TDFH, adapter->tx_head_addr);
2513 ew32(TDFTS, adapter->tx_head_addr);
2514 ew32(TDFHS, adapter->tx_head_addr);
2516 E1000_WRITE_FLUSH();
2518 adapter->tx_fifo_head = 0;
2519 atomic_set(&adapter->tx_fifo_stall, 0);
2520 netif_wake_queue(netdev);
2522 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2528 * e1000_watchdog - Timer Call-back
2529 * @data: pointer to adapter cast into an unsigned long
2531 static void e1000_watchdog(unsigned long data)
2533 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2534 struct e1000_hw *hw = &adapter->hw;
2535 struct net_device *netdev = adapter->netdev;
2536 struct e1000_tx_ring *txdr = adapter->tx_ring;
2540 ret_val = e1000_check_for_link(hw);
2541 if ((ret_val == E1000_ERR_PHY) &&
2542 (hw->phy_type == e1000_phy_igp_3) &&
2543 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2544 /* See e1000_kumeran_lock_loss_workaround() */
2546 "Gigabit has been disabled, downgrading speed\n");
2549 if (hw->mac_type == e1000_82573) {
2550 e1000_enable_tx_pkt_filtering(hw);
2551 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
2552 e1000_update_mng_vlan(adapter);
2555 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2556 !(er32(TXCW) & E1000_TXCW_ANE))
2557 link = !hw->serdes_link_down;
2559 link = er32(STATUS) & E1000_STATUS_LU;
2562 if (!netif_carrier_ok(netdev)) {
2565 e1000_get_speed_and_duplex(hw,
2566 &adapter->link_speed,
2567 &adapter->link_duplex);
2570 printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, "
2571 "Flow Control: %s\n",
2573 adapter->link_speed,
2574 adapter->link_duplex == FULL_DUPLEX ?
2575 "Full Duplex" : "Half Duplex",
2576 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2577 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2578 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2579 E1000_CTRL_TFCE) ? "TX" : "None" )));
2581 /* tweak tx_queue_len according to speed/duplex
2582 * and adjust the timeout factor */
2583 netdev->tx_queue_len = adapter->tx_queue_len;
2584 adapter->tx_timeout_factor = 1;
2585 switch (adapter->link_speed) {
2588 netdev->tx_queue_len = 10;
2589 adapter->tx_timeout_factor = 8;
2593 netdev->tx_queue_len = 100;
2594 /* maybe add some timeout factor ? */
2598 if ((hw->mac_type == e1000_82571 ||
2599 hw->mac_type == e1000_82572) &&
2602 tarc0 = er32(TARC0);
2603 tarc0 &= ~(1 << 21);
2607 /* disable TSO for pcie and 10/100 speeds, to avoid
2608 * some hardware issues */
2609 if (!adapter->tso_force &&
2610 hw->bus_type == e1000_bus_type_pci_express){
2611 switch (adapter->link_speed) {
2615 "10/100 speed: disabling TSO\n");
2616 netdev->features &= ~NETIF_F_TSO;
2617 netdev->features &= ~NETIF_F_TSO6;
2620 netdev->features |= NETIF_F_TSO;
2621 netdev->features |= NETIF_F_TSO6;
2629 /* enable transmits in the hardware, need to do this
2630 * after setting TARC0 */
2632 tctl |= E1000_TCTL_EN;
2635 netif_carrier_on(netdev);
2636 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2637 adapter->smartspeed = 0;
2639 /* make sure the receive unit is started */
2640 if (hw->rx_needs_kicking) {
2641 u32 rctl = er32(RCTL);
2642 ew32(RCTL, rctl | E1000_RCTL_EN);
2646 if (netif_carrier_ok(netdev)) {
2647 adapter->link_speed = 0;
2648 adapter->link_duplex = 0;
2649 printk(KERN_INFO "e1000: %s NIC Link is Down\n",
2651 netif_carrier_off(netdev);
2652 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2654 /* 80003ES2LAN workaround--
2655 * For packet buffer work-around on link down event;
2656 * disable receives in the ISR and
2657 * reset device here in the watchdog
2659 if (hw->mac_type == e1000_80003es2lan)
2661 schedule_work(&adapter->reset_task);
2664 e1000_smartspeed(adapter);
2667 e1000_update_stats(adapter);
2669 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2670 adapter->tpt_old = adapter->stats.tpt;
2671 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2672 adapter->colc_old = adapter->stats.colc;
2674 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2675 adapter->gorcl_old = adapter->stats.gorcl;
2676 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2677 adapter->gotcl_old = adapter->stats.gotcl;
2679 e1000_update_adaptive(hw);
2681 if (!netif_carrier_ok(netdev)) {
2682 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2683 /* We've lost link, so the controller stops DMA,
2684 * but we've got queued Tx work that's never going
2685 * to get done, so reset controller to flush Tx.
2686 * (Do the reset outside of interrupt context). */
2687 adapter->tx_timeout_count++;
2688 schedule_work(&adapter->reset_task);
2689 /* return immediately since reset is imminent */
2694 /* Cause software interrupt to ensure rx ring is cleaned */
2695 ew32(ICS, E1000_ICS_RXDMT0);
2697 /* Force detection of hung controller every watchdog period */
2698 adapter->detect_tx_hung = true;
2700 /* With 82571 controllers, LAA may be overwritten due to controller
2701 * reset from the other port. Set the appropriate LAA in RAR[0] */
2702 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2703 e1000_rar_set(hw, hw->mac_addr, 0);
2705 /* Reset the timer */
2706 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
2709 enum latency_range {
2713 latency_invalid = 255
2717 * e1000_update_itr - update the dynamic ITR value based on statistics
2718 * Stores a new ITR value based on packets and byte
2719 * counts during the last interrupt. The advantage of per interrupt
2720 * computation is faster updates and more accurate ITR for the current
2721 * traffic pattern. Constants in this function were computed
2722 * based on theoretical maximum wire speed and thresholds were set based
2723 * on testing data as well as attempting to minimize response time
2724 * while increasing bulk throughput.
2725 * this functionality is controlled by the InterruptThrottleRate module
2726 * parameter (see e1000_param.c)
2727 * @adapter: pointer to adapter
2728 * @itr_setting: current adapter->itr
2729 * @packets: the number of packets during this measurement interval
2730 * @bytes: the number of bytes during this measurement interval
2732 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2733 u16 itr_setting, int packets, int bytes)
2735 unsigned int retval = itr_setting;
2736 struct e1000_hw *hw = &adapter->hw;
2738 if (unlikely(hw->mac_type < e1000_82540))
2739 goto update_itr_done;
2742 goto update_itr_done;
2744 switch (itr_setting) {
2745 case lowest_latency:
2746 /* jumbo frames get bulk treatment*/
2747 if (bytes/packets > 8000)
2748 retval = bulk_latency;
2749 else if ((packets < 5) && (bytes > 512))
2750 retval = low_latency;
2752 case low_latency: /* 50 usec aka 20000 ints/s */
2753 if (bytes > 10000) {
2754 /* jumbo frames need bulk latency setting */
2755 if (bytes/packets > 8000)
2756 retval = bulk_latency;
2757 else if ((packets < 10) || ((bytes/packets) > 1200))
2758 retval = bulk_latency;
2759 else if ((packets > 35))
2760 retval = lowest_latency;
2761 } else if (bytes/packets > 2000)
2762 retval = bulk_latency;
2763 else if (packets <= 2 && bytes < 512)
2764 retval = lowest_latency;
2766 case bulk_latency: /* 250 usec aka 4000 ints/s */
2767 if (bytes > 25000) {
2769 retval = low_latency;
2770 } else if (bytes < 6000) {
2771 retval = low_latency;
2780 static void e1000_set_itr(struct e1000_adapter *adapter)
2782 struct e1000_hw *hw = &adapter->hw;
2784 u32 new_itr = adapter->itr;
2786 if (unlikely(hw->mac_type < e1000_82540))
2789 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2790 if (unlikely(adapter->link_speed != SPEED_1000)) {
2796 adapter->tx_itr = e1000_update_itr(adapter,
2798 adapter->total_tx_packets,
2799 adapter->total_tx_bytes);
2800 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2801 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2802 adapter->tx_itr = low_latency;
2804 adapter->rx_itr = e1000_update_itr(adapter,
2806 adapter->total_rx_packets,
2807 adapter->total_rx_bytes);
2808 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2809 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2810 adapter->rx_itr = low_latency;
2812 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2814 switch (current_itr) {
2815 /* counts and packets in update_itr are dependent on these numbers */
2816 case lowest_latency:
2820 new_itr = 20000; /* aka hwitr = ~200 */
2830 if (new_itr != adapter->itr) {
2831 /* this attempts to bias the interrupt rate towards Bulk
2832 * by adding intermediate steps when interrupt rate is
2834 new_itr = new_itr > adapter->itr ?
2835 min(adapter->itr + (new_itr >> 2), new_itr) :
2837 adapter->itr = new_itr;
2838 ew32(ITR, 1000000000 / (new_itr * 256));
2844 #define E1000_TX_FLAGS_CSUM 0x00000001
2845 #define E1000_TX_FLAGS_VLAN 0x00000002
2846 #define E1000_TX_FLAGS_TSO 0x00000004
2847 #define E1000_TX_FLAGS_IPV4 0x00000008
2848 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2849 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2851 static int e1000_tso(struct e1000_adapter *adapter,
2852 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2854 struct e1000_context_desc *context_desc;
2855 struct e1000_buffer *buffer_info;
2858 u16 ipcse = 0, tucse, mss;
2859 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2862 if (skb_is_gso(skb)) {
2863 if (skb_header_cloned(skb)) {
2864 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2869 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2870 mss = skb_shinfo(skb)->gso_size;
2871 if (skb->protocol == htons(ETH_P_IP)) {
2872 struct iphdr *iph = ip_hdr(skb);
2875 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2879 cmd_length = E1000_TXD_CMD_IP;
2880 ipcse = skb_transport_offset(skb) - 1;
2881 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2882 ipv6_hdr(skb)->payload_len = 0;
2883 tcp_hdr(skb)->check =
2884 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2885 &ipv6_hdr(skb)->daddr,
2889 ipcss = skb_network_offset(skb);
2890 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2891 tucss = skb_transport_offset(skb);
2892 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2895 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2896 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2898 i = tx_ring->next_to_use;
2899 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2900 buffer_info = &tx_ring->buffer_info[i];
2902 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2903 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2904 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2905 context_desc->upper_setup.tcp_fields.tucss = tucss;
2906 context_desc->upper_setup.tcp_fields.tucso = tucso;
2907 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2908 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2909 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2910 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2912 buffer_info->time_stamp = jiffies;
2913 buffer_info->next_to_watch = i;
2915 if (++i == tx_ring->count) i = 0;
2916 tx_ring->next_to_use = i;
2923 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2924 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2926 struct e1000_context_desc *context_desc;
2927 struct e1000_buffer *buffer_info;
2930 u32 cmd_len = E1000_TXD_CMD_DEXT;
2932 if (skb->ip_summed != CHECKSUM_PARTIAL)
2935 switch (skb->protocol) {
2936 case cpu_to_be16(ETH_P_IP):
2937 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2938 cmd_len |= E1000_TXD_CMD_TCP;
2940 case cpu_to_be16(ETH_P_IPV6):
2941 /* XXX not handling all IPV6 headers */
2942 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2943 cmd_len |= E1000_TXD_CMD_TCP;
2946 if (unlikely(net_ratelimit()))
2947 DPRINTK(DRV, WARNING,
2948 "checksum_partial proto=%x!\n", skb->protocol);
2952 css = skb_transport_offset(skb);
2954 i = tx_ring->next_to_use;
2955 buffer_info = &tx_ring->buffer_info[i];
2956 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2958 context_desc->lower_setup.ip_config = 0;
2959 context_desc->upper_setup.tcp_fields.tucss = css;
2960 context_desc->upper_setup.tcp_fields.tucso =
2961 css + skb->csum_offset;
2962 context_desc->upper_setup.tcp_fields.tucse = 0;
2963 context_desc->tcp_seg_setup.data = 0;
2964 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2966 buffer_info->time_stamp = jiffies;
2967 buffer_info->next_to_watch = i;
2969 if (unlikely(++i == tx_ring->count)) i = 0;
2970 tx_ring->next_to_use = i;
2975 #define E1000_MAX_TXD_PWR 12
2976 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2978 static int e1000_tx_map(struct e1000_adapter *adapter,
2979 struct e1000_tx_ring *tx_ring,
2980 struct sk_buff *skb, unsigned int first,
2981 unsigned int max_per_txd, unsigned int nr_frags,
2984 struct e1000_hw *hw = &adapter->hw;
2985 struct e1000_buffer *buffer_info;
2986 unsigned int len = skb_headlen(skb);
2987 unsigned int offset, size, count = 0, i;
2991 i = tx_ring->next_to_use;
2993 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
2994 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
2998 map = skb_shinfo(skb)->dma_maps;
3002 buffer_info = &tx_ring->buffer_info[i];
3003 size = min(len, max_per_txd);
3004 /* Workaround for Controller erratum --
3005 * descriptor for non-tso packet in a linear SKB that follows a
3006 * tso gets written back prematurely before the data is fully
3007 * DMA'd to the controller */
3008 if (!skb->data_len && tx_ring->last_tx_tso &&
3010 tx_ring->last_tx_tso = 0;
3014 /* Workaround for premature desc write-backs
3015 * in TSO mode. Append 4-byte sentinel desc */
3016 if (unlikely(mss && !nr_frags && size == len && size > 8))
3018 /* work-around for errata 10 and it applies
3019 * to all controllers in PCI-X mode
3020 * The fix is to make sure that the first descriptor of a
3021 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3023 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3024 (size > 2015) && count == 0))
3027 /* Workaround for potential 82544 hang in PCI-X. Avoid
3028 * terminating buffers within evenly-aligned dwords. */
3029 if (unlikely(adapter->pcix_82544 &&
3030 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3034 buffer_info->length = size;
3035 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
3036 buffer_info->time_stamp = jiffies;
3037 buffer_info->next_to_watch = i;
3044 if (unlikely(i == tx_ring->count))
3049 for (f = 0; f < nr_frags; f++) {
3050 struct skb_frag_struct *frag;
3052 frag = &skb_shinfo(skb)->frags[f];
3058 if (unlikely(i == tx_ring->count))
3061 buffer_info = &tx_ring->buffer_info[i];
3062 size = min(len, max_per_txd);
3063 /* Workaround for premature desc write-backs
3064 * in TSO mode. Append 4-byte sentinel desc */
3065 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
3067 /* Workaround for potential 82544 hang in PCI-X.
3068 * Avoid terminating buffers within evenly-aligned
3070 if (unlikely(adapter->pcix_82544 &&
3071 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3075 buffer_info->length = size;
3076 buffer_info->dma = map[f] + offset;
3077 buffer_info->time_stamp = jiffies;
3078 buffer_info->next_to_watch = i;
3086 tx_ring->buffer_info[i].skb = skb;
3087 tx_ring->buffer_info[first].next_to_watch = i;
3092 static void e1000_tx_queue(struct e1000_adapter *adapter,
3093 struct e1000_tx_ring *tx_ring, int tx_flags,
3096 struct e1000_hw *hw = &adapter->hw;
3097 struct e1000_tx_desc *tx_desc = NULL;
3098 struct e1000_buffer *buffer_info;
3099 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3102 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
3103 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3105 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3107 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3108 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3111 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3112 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3113 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3116 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3117 txd_lower |= E1000_TXD_CMD_VLE;
3118 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3121 i = tx_ring->next_to_use;
3124 buffer_info = &tx_ring->buffer_info[i];
3125 tx_desc = E1000_TX_DESC(*tx_ring, i);
3126 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3127 tx_desc->lower.data =
3128 cpu_to_le32(txd_lower | buffer_info->length);
3129 tx_desc->upper.data = cpu_to_le32(txd_upper);
3130 if (unlikely(++i == tx_ring->count)) i = 0;
3133 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3135 /* Force memory writes to complete before letting h/w
3136 * know there are new descriptors to fetch. (Only
3137 * applicable for weak-ordered memory model archs,
3138 * such as IA-64). */
3141 tx_ring->next_to_use = i;
3142 writel(i, hw->hw_addr + tx_ring->tdt);
3143 /* we need this if more than one processor can write to our tail
3144 * at a time, it syncronizes IO on IA64/Altix systems */
3149 * 82547 workaround to avoid controller hang in half-duplex environment.
3150 * The workaround is to avoid queuing a large packet that would span
3151 * the internal Tx FIFO ring boundary by notifying the stack to resend
3152 * the packet at a later time. This gives the Tx FIFO an opportunity to
3153 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3154 * to the beginning of the Tx FIFO.
3157 #define E1000_FIFO_HDR 0x10
3158 #define E1000_82547_PAD_LEN 0x3E0
3160 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3161 struct sk_buff *skb)
3163 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3164 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3166 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3168 if (adapter->link_duplex != HALF_DUPLEX)
3169 goto no_fifo_stall_required;
3171 if (atomic_read(&adapter->tx_fifo_stall))
3174 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3175 atomic_set(&adapter->tx_fifo_stall, 1);
3179 no_fifo_stall_required:
3180 adapter->tx_fifo_head += skb_fifo_len;
3181 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3182 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3186 #define MINIMUM_DHCP_PACKET_SIZE 282
3187 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3188 struct sk_buff *skb)
3190 struct e1000_hw *hw = &adapter->hw;
3192 if (vlan_tx_tag_present(skb)) {
3193 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3194 ( hw->mng_cookie.status &
3195 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3198 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
3199 struct ethhdr *eth = (struct ethhdr *)skb->data;
3200 if ((htons(ETH_P_IP) == eth->h_proto)) {
3201 const struct iphdr *ip =
3202 (struct iphdr *)((u8 *)skb->data+14);
3203 if (IPPROTO_UDP == ip->protocol) {
3204 struct udphdr *udp =
3205 (struct udphdr *)((u8 *)ip +
3207 if (ntohs(udp->dest) == 67) {
3208 offset = (u8 *)udp + 8 - skb->data;
3209 length = skb->len - offset;
3211 return e1000_mng_write_dhcp_info(hw,
3221 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3223 struct e1000_adapter *adapter = netdev_priv(netdev);
3224 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3226 netif_stop_queue(netdev);
3227 /* Herbert's original patch had:
3228 * smp_mb__after_netif_stop_queue();
3229 * but since that doesn't exist yet, just open code it. */
3232 /* We need to check again in a case another CPU has just
3233 * made room available. */
3234 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3238 netif_start_queue(netdev);
3239 ++adapter->restart_queue;
3243 static int e1000_maybe_stop_tx(struct net_device *netdev,
3244 struct e1000_tx_ring *tx_ring, int size)
3246 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3248 return __e1000_maybe_stop_tx(netdev, size);
3251 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3252 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3254 struct e1000_adapter *adapter = netdev_priv(netdev);
3255 struct e1000_hw *hw = &adapter->hw;
3256 struct e1000_tx_ring *tx_ring;
3257 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3258 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3259 unsigned int tx_flags = 0;
3260 unsigned int len = skb->len - skb->data_len;
3261 unsigned int nr_frags;
3267 /* This goes back to the question of how to logically map a tx queue
3268 * to a flow. Right now, performance is impacted slightly negatively
3269 * if using multiple tx queues. If the stack breaks away from a
3270 * single qdisc implementation, we can look at this again. */
3271 tx_ring = adapter->tx_ring;
3273 if (unlikely(skb->len <= 0)) {
3274 dev_kfree_skb_any(skb);
3275 return NETDEV_TX_OK;
3278 /* 82571 and newer doesn't need the workaround that limited descriptor
3280 if (hw->mac_type >= e1000_82571)
3283 mss = skb_shinfo(skb)->gso_size;
3284 /* The controller does a simple calculation to
3285 * make sure there is enough room in the FIFO before
3286 * initiating the DMA for each buffer. The calc is:
3287 * 4 = ceil(buffer len/mss). To make sure we don't
3288 * overrun the FIFO, adjust the max buffer len if mss
3292 max_per_txd = min(mss << 2, max_per_txd);
3293 max_txd_pwr = fls(max_per_txd) - 1;
3295 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3296 * points to just header, pull a few bytes of payload from
3297 * frags into skb->data */
3298 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3299 if (skb->data_len && hdr_len == len) {
3300 switch (hw->mac_type) {
3301 unsigned int pull_size;
3303 /* Make sure we have room to chop off 4 bytes,
3304 * and that the end alignment will work out to
3305 * this hardware's requirements
3306 * NOTE: this is a TSO only workaround
3307 * if end byte alignment not correct move us
3308 * into the next dword */
3309 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
3316 pull_size = min((unsigned int)4, skb->data_len);
3317 if (!__pskb_pull_tail(skb, pull_size)) {
3319 "__pskb_pull_tail failed.\n");
3320 dev_kfree_skb_any(skb);
3321 return NETDEV_TX_OK;
3323 len = skb->len - skb->data_len;
3332 /* reserve a descriptor for the offload context */
3333 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3337 /* Controller Erratum workaround */
3338 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3341 count += TXD_USE_COUNT(len, max_txd_pwr);
3343 if (adapter->pcix_82544)
3346 /* work-around for errata 10 and it applies to all controllers
3347 * in PCI-X mode, so add one more descriptor to the count
3349 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3353 nr_frags = skb_shinfo(skb)->nr_frags;
3354 for (f = 0; f < nr_frags; f++)
3355 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3357 if (adapter->pcix_82544)
3361 if (hw->tx_pkt_filtering &&
3362 (hw->mac_type == e1000_82573))
3363 e1000_transfer_dhcp_info(adapter, skb);
3365 /* need: count + 2 desc gap to keep tail from touching
3366 * head, otherwise try next time */
3367 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3368 return NETDEV_TX_BUSY;
3370 if (unlikely(hw->mac_type == e1000_82547)) {
3371 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3372 netif_stop_queue(netdev);
3373 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3374 return NETDEV_TX_BUSY;
3378 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3379 tx_flags |= E1000_TX_FLAGS_VLAN;
3380 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3383 first = tx_ring->next_to_use;
3385 tso = e1000_tso(adapter, tx_ring, skb);
3387 dev_kfree_skb_any(skb);
3388 return NETDEV_TX_OK;
3392 tx_ring->last_tx_tso = 1;
3393 tx_flags |= E1000_TX_FLAGS_TSO;
3394 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3395 tx_flags |= E1000_TX_FLAGS_CSUM;
3397 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3398 * 82571 hardware supports TSO capabilities for IPv6 as well...
3399 * no longer assume, we must. */
3400 if (likely(skb->protocol == htons(ETH_P_IP)))
3401 tx_flags |= E1000_TX_FLAGS_IPV4;
3403 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3407 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3408 /* Make sure there is space in the ring for the next send. */
3409 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3412 dev_kfree_skb_any(skb);
3413 tx_ring->buffer_info[first].time_stamp = 0;
3414 tx_ring->next_to_use = first;
3417 return NETDEV_TX_OK;
3421 * e1000_tx_timeout - Respond to a Tx Hang
3422 * @netdev: network interface device structure
3425 static void e1000_tx_timeout(struct net_device *netdev)
3427 struct e1000_adapter *adapter = netdev_priv(netdev);
3429 /* Do the reset outside of interrupt context */
3430 adapter->tx_timeout_count++;
3431 schedule_work(&adapter->reset_task);
3434 static void e1000_reset_task(struct work_struct *work)
3436 struct e1000_adapter *adapter =
3437 container_of(work, struct e1000_adapter, reset_task);
3439 e1000_reinit_locked(adapter);
3443 * e1000_get_stats - Get System Network Statistics
3444 * @netdev: network interface device structure
3446 * Returns the address of the device statistics structure.
3447 * The statistics are actually updated from the timer callback.
3450 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3452 struct e1000_adapter *adapter = netdev_priv(netdev);
3454 /* only return the current stats */
3455 return &adapter->net_stats;
3459 * e1000_change_mtu - Change the Maximum Transfer Unit
3460 * @netdev: network interface device structure
3461 * @new_mtu: new value for maximum frame size
3463 * Returns 0 on success, negative on failure
3466 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3468 struct e1000_adapter *adapter = netdev_priv(netdev);
3469 struct e1000_hw *hw = &adapter->hw;
3470 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3471 u16 eeprom_data = 0;
3473 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3474 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3475 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3479 /* Adapter-specific max frame size limits. */
3480 switch (hw->mac_type) {
3481 case e1000_undefined ... e1000_82542_rev2_1:
3483 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3484 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3489 /* Jumbo Frames not supported if:
3490 * - this is not an 82573L device
3491 * - ASPM is enabled in any way (0x1A bits 3:2) */
3492 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
3494 if ((hw->device_id != E1000_DEV_ID_82573L) ||
3495 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3496 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3498 "Jumbo Frames not supported.\n");
3503 /* ERT will be enabled later to enable wire speed receives */
3505 /* fall through to get support */
3508 case e1000_80003es2lan:
3509 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3510 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3511 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3516 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3520 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3521 * means we reserve 2 more, this pushes us to allocate from the next
3523 * i.e. RXBUFFER_2048 --> size-4096 slab
3524 * however with the new *_jumbo_rx* routines, jumbo receives will use
3525 * fragmented skbs */
3527 if (max_frame <= E1000_RXBUFFER_256)
3528 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3529 else if (max_frame <= E1000_RXBUFFER_512)
3530 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3531 else if (max_frame <= E1000_RXBUFFER_1024)
3532 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3533 else if (max_frame <= E1000_RXBUFFER_2048)
3534 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3536 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3537 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3538 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3539 adapter->rx_buffer_len = PAGE_SIZE;
3542 /* adjust allocation if LPE protects us, and we aren't using SBP */
3543 if (!hw->tbi_compatibility_on &&
3544 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3545 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3546 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3548 netdev->mtu = new_mtu;
3549 hw->max_frame_size = max_frame;
3551 if (netif_running(netdev))
3552 e1000_reinit_locked(adapter);
3558 * e1000_update_stats - Update the board statistics counters
3559 * @adapter: board private structure
3562 void e1000_update_stats(struct e1000_adapter *adapter)
3564 struct e1000_hw *hw = &adapter->hw;
3565 struct pci_dev *pdev = adapter->pdev;
3566 unsigned long flags;
3569 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3572 * Prevent stats update while adapter is being reset, or if the pci
3573 * connection is down.
3575 if (adapter->link_speed == 0)
3577 if (pci_channel_offline(pdev))
3580 spin_lock_irqsave(&adapter->stats_lock, flags);
3582 /* these counters are modified from e1000_tbi_adjust_stats,
3583 * called from the interrupt context, so they must only
3584 * be written while holding adapter->stats_lock
3587 adapter->stats.crcerrs += er32(CRCERRS);
3588 adapter->stats.gprc += er32(GPRC);
3589 adapter->stats.gorcl += er32(GORCL);
3590 adapter->stats.gorch += er32(GORCH);
3591 adapter->stats.bprc += er32(BPRC);
3592 adapter->stats.mprc += er32(MPRC);
3593 adapter->stats.roc += er32(ROC);
3595 if (hw->mac_type != e1000_ich8lan) {
3596 adapter->stats.prc64 += er32(PRC64);
3597 adapter->stats.prc127 += er32(PRC127);
3598 adapter->stats.prc255 += er32(PRC255);
3599 adapter->stats.prc511 += er32(PRC511);
3600 adapter->stats.prc1023 += er32(PRC1023);
3601 adapter->stats.prc1522 += er32(PRC1522);
3604 adapter->stats.symerrs += er32(SYMERRS);
3605 adapter->stats.mpc += er32(MPC);
3606 adapter->stats.scc += er32(SCC);
3607 adapter->stats.ecol += er32(ECOL);
3608 adapter->stats.mcc += er32(MCC);
3609 adapter->stats.latecol += er32(LATECOL);
3610 adapter->stats.dc += er32(DC);
3611 adapter->stats.sec += er32(SEC);
3612 adapter->stats.rlec += er32(RLEC);
3613 adapter->stats.xonrxc += er32(XONRXC);
3614 adapter->stats.xontxc += er32(XONTXC);
3615 adapter->stats.xoffrxc += er32(XOFFRXC);
3616 adapter->stats.xofftxc += er32(XOFFTXC);
3617 adapter->stats.fcruc += er32(FCRUC);
3618 adapter->stats.gptc += er32(GPTC);
3619 adapter->stats.gotcl += er32(GOTCL);
3620 adapter->stats.gotch += er32(GOTCH);
3621 adapter->stats.rnbc += er32(RNBC);
3622 adapter->stats.ruc += er32(RUC);
3623 adapter->stats.rfc += er32(RFC);
3624 adapter->stats.rjc += er32(RJC);
3625 adapter->stats.torl += er32(TORL);
3626 adapter->stats.torh += er32(TORH);
3627 adapter->stats.totl += er32(TOTL);
3628 adapter->stats.toth += er32(TOTH);
3629 adapter->stats.tpr += er32(TPR);
3631 if (hw->mac_type != e1000_ich8lan) {
3632 adapter->stats.ptc64 += er32(PTC64);
3633 adapter->stats.ptc127 += er32(PTC127);
3634 adapter->stats.ptc255 += er32(PTC255);
3635 adapter->stats.ptc511 += er32(PTC511);
3636 adapter->stats.ptc1023 += er32(PTC1023);
3637 adapter->stats.ptc1522 += er32(PTC1522);
3640 adapter->stats.mptc += er32(MPTC);
3641 adapter->stats.bptc += er32(BPTC);
3643 /* used for adaptive IFS */
3645 hw->tx_packet_delta = er32(TPT);
3646 adapter->stats.tpt += hw->tx_packet_delta;
3647 hw->collision_delta = er32(COLC);
3648 adapter->stats.colc += hw->collision_delta;
3650 if (hw->mac_type >= e1000_82543) {
3651 adapter->stats.algnerrc += er32(ALGNERRC);
3652 adapter->stats.rxerrc += er32(RXERRC);
3653 adapter->stats.tncrs += er32(TNCRS);
3654 adapter->stats.cexterr += er32(CEXTERR);
3655 adapter->stats.tsctc += er32(TSCTC);
3656 adapter->stats.tsctfc += er32(TSCTFC);
3658 if (hw->mac_type > e1000_82547_rev_2) {
3659 adapter->stats.iac += er32(IAC);
3660 adapter->stats.icrxoc += er32(ICRXOC);
3662 if (hw->mac_type != e1000_ich8lan) {
3663 adapter->stats.icrxptc += er32(ICRXPTC);
3664 adapter->stats.icrxatc += er32(ICRXATC);
3665 adapter->stats.ictxptc += er32(ICTXPTC);
3666 adapter->stats.ictxatc += er32(ICTXATC);
3667 adapter->stats.ictxqec += er32(ICTXQEC);
3668 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3669 adapter->stats.icrxdmtc += er32(ICRXDMTC);
3673 /* Fill out the OS statistics structure */
3674 adapter->net_stats.multicast = adapter->stats.mprc;
3675 adapter->net_stats.collisions = adapter->stats.colc;
3679 /* RLEC on some newer hardware can be incorrect so build
3680 * our own version based on RUC and ROC */
3681 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3682 adapter->stats.crcerrs + adapter->stats.algnerrc +
3683 adapter->stats.ruc + adapter->stats.roc +
3684 adapter->stats.cexterr;
3685 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3686 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3687 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3688 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3689 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3692 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3693 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3694 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3695 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3696 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3697 if (hw->bad_tx_carr_stats_fd &&
3698 adapter->link_duplex == FULL_DUPLEX) {
3699 adapter->net_stats.tx_carrier_errors = 0;
3700 adapter->stats.tncrs = 0;
3703 /* Tx Dropped needs to be maintained elsewhere */
3706 if (hw->media_type == e1000_media_type_copper) {
3707 if ((adapter->link_speed == SPEED_1000) &&
3708 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3709 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3710 adapter->phy_stats.idle_errors += phy_tmp;
3713 if ((hw->mac_type <= e1000_82546) &&
3714 (hw->phy_type == e1000_phy_m88) &&
3715 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3716 adapter->phy_stats.receive_errors += phy_tmp;
3719 /* Management Stats */
3720 if (hw->has_smbus) {
3721 adapter->stats.mgptc += er32(MGTPTC);
3722 adapter->stats.mgprc += er32(MGTPRC);
3723 adapter->stats.mgpdc += er32(MGTPDC);
3726 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3730 * e1000_intr_msi - Interrupt Handler
3731 * @irq: interrupt number
3732 * @data: pointer to a network interface device structure
3735 static irqreturn_t e1000_intr_msi(int irq, void *data)
3737 struct net_device *netdev = data;
3738 struct e1000_adapter *adapter = netdev_priv(netdev);
3739 struct e1000_hw *hw = &adapter->hw;
3740 u32 icr = er32(ICR);
3742 /* in NAPI mode read ICR disables interrupts using IAM */
3744 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3745 hw->get_link_status = 1;
3746 /* 80003ES2LAN workaround-- For packet buffer work-around on
3747 * link down event; disable receives here in the ISR and reset
3748 * adapter in watchdog */
3749 if (netif_carrier_ok(netdev) &&
3750 (hw->mac_type == e1000_80003es2lan)) {
3751 /* disable receives */
3752 u32 rctl = er32(RCTL);
3753 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3755 /* guard against interrupt when we're going down */
3756 if (!test_bit(__E1000_DOWN, &adapter->flags))
3757 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3760 if (likely(napi_schedule_prep(&adapter->napi))) {
3761 adapter->total_tx_bytes = 0;
3762 adapter->total_tx_packets = 0;
3763 adapter->total_rx_bytes = 0;
3764 adapter->total_rx_packets = 0;
3765 __napi_schedule(&adapter->napi);
3767 e1000_irq_enable(adapter);
3773 * e1000_intr - Interrupt Handler
3774 * @irq: interrupt number
3775 * @data: pointer to a network interface device structure
3778 static irqreturn_t e1000_intr(int irq, void *data)
3780 struct net_device *netdev = data;
3781 struct e1000_adapter *adapter = netdev_priv(netdev);
3782 struct e1000_hw *hw = &adapter->hw;
3783 u32 rctl, icr = er32(ICR);
3785 if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags)))
3786 return IRQ_NONE; /* Not our interrupt */
3788 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3789 * not set, then the adapter didn't send an interrupt */
3790 if (unlikely(hw->mac_type >= e1000_82571 &&
3791 !(icr & E1000_ICR_INT_ASSERTED)))
3794 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3795 * need for the IMC write */
3797 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3798 hw->get_link_status = 1;
3799 /* 80003ES2LAN workaround--
3800 * For packet buffer work-around on link down event;
3801 * disable receives here in the ISR and
3802 * reset adapter in watchdog
3804 if (netif_carrier_ok(netdev) &&
3805 (hw->mac_type == e1000_80003es2lan)) {
3806 /* disable receives */
3808 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3810 /* guard against interrupt when we're going down */
3811 if (!test_bit(__E1000_DOWN, &adapter->flags))
3812 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3815 if (unlikely(hw->mac_type < e1000_82571)) {
3816 /* disable interrupts, without the synchronize_irq bit */
3818 E1000_WRITE_FLUSH();
3820 if (likely(napi_schedule_prep(&adapter->napi))) {
3821 adapter->total_tx_bytes = 0;
3822 adapter->total_tx_packets = 0;
3823 adapter->total_rx_bytes = 0;
3824 adapter->total_rx_packets = 0;
3825 __napi_schedule(&adapter->napi);
3827 /* this really should not happen! if it does it is basically a
3828 * bug, but not a hard error, so enable ints and continue */
3829 if (!test_bit(__E1000_DOWN, &adapter->flags))
3830 e1000_irq_enable(adapter);
3837 * e1000_clean - NAPI Rx polling callback
3838 * @adapter: board private structure
3840 static int e1000_clean(struct napi_struct *napi, int budget)
3842 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3843 struct net_device *poll_dev = adapter->netdev;
3844 int tx_cleaned = 0, work_done = 0;
3846 adapter = netdev_priv(poll_dev);
3848 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3850 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3851 &work_done, budget);
3856 /* If budget not fully consumed, exit the polling mode */
3857 if (work_done < budget) {
3858 if (likely(adapter->itr_setting & 3))
3859 e1000_set_itr(adapter);
3860 napi_complete(napi);
3861 if (!test_bit(__E1000_DOWN, &adapter->flags))
3862 e1000_irq_enable(adapter);
3869 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3870 * @adapter: board private structure
3872 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3873 struct e1000_tx_ring *tx_ring)
3875 struct e1000_hw *hw = &adapter->hw;
3876 struct net_device *netdev = adapter->netdev;
3877 struct e1000_tx_desc *tx_desc, *eop_desc;
3878 struct e1000_buffer *buffer_info;
3879 unsigned int i, eop;
3880 unsigned int count = 0;
3881 unsigned int total_tx_bytes=0, total_tx_packets=0;
3883 i = tx_ring->next_to_clean;
3884 eop = tx_ring->buffer_info[i].next_to_watch;
3885 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3887 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3888 (count < tx_ring->count)) {
3889 bool cleaned = false;
3890 for ( ; !cleaned; count++) {
3891 tx_desc = E1000_TX_DESC(*tx_ring, i);
3892 buffer_info = &tx_ring->buffer_info[i];
3893 cleaned = (i == eop);
3896 struct sk_buff *skb = buffer_info->skb;
3897 unsigned int segs, bytecount;
3898 segs = skb_shinfo(skb)->gso_segs ?: 1;
3899 /* multiply data chunks by size of headers */
3900 bytecount = ((segs - 1) * skb_headlen(skb)) +
3902 total_tx_packets += segs;
3903 total_tx_bytes += bytecount;
3905 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3906 tx_desc->upper.data = 0;
3908 if (unlikely(++i == tx_ring->count)) i = 0;
3911 eop = tx_ring->buffer_info[i].next_to_watch;
3912 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3915 tx_ring->next_to_clean = i;
3917 #define TX_WAKE_THRESHOLD 32
3918 if (unlikely(count && netif_carrier_ok(netdev) &&
3919 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3920 /* Make sure that anybody stopping the queue after this
3921 * sees the new next_to_clean.
3924 if (netif_queue_stopped(netdev)) {
3925 netif_wake_queue(netdev);
3926 ++adapter->restart_queue;
3930 if (adapter->detect_tx_hung) {
3931 /* Detect a transmit hang in hardware, this serializes the
3932 * check with the clearing of time_stamp and movement of i */
3933 adapter->detect_tx_hung = false;
3934 if (tx_ring->buffer_info[i].time_stamp &&
3935 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
3936 (adapter->tx_timeout_factor * HZ))
3937 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3939 /* detected Tx unit hang */
3940 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3944 " next_to_use <%x>\n"
3945 " next_to_clean <%x>\n"
3946 "buffer_info[next_to_clean]\n"
3947 " time_stamp <%lx>\n"
3948 " next_to_watch <%x>\n"
3950 " next_to_watch.status <%x>\n",
3951 (unsigned long)((tx_ring - adapter->tx_ring) /
3952 sizeof(struct e1000_tx_ring)),
3953 readl(hw->hw_addr + tx_ring->tdh),
3954 readl(hw->hw_addr + tx_ring->tdt),
3955 tx_ring->next_to_use,
3956 tx_ring->next_to_clean,
3957 tx_ring->buffer_info[i].time_stamp,
3960 eop_desc->upper.fields.status);
3961 netif_stop_queue(netdev);
3964 adapter->total_tx_bytes += total_tx_bytes;
3965 adapter->total_tx_packets += total_tx_packets;
3966 adapter->net_stats.tx_bytes += total_tx_bytes;
3967 adapter->net_stats.tx_packets += total_tx_packets;
3968 return (count < tx_ring->count);
3972 * e1000_rx_checksum - Receive Checksum Offload for 82543
3973 * @adapter: board private structure
3974 * @status_err: receive descriptor status and error fields
3975 * @csum: receive descriptor csum field
3976 * @sk_buff: socket buffer with received data
3979 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3980 u32 csum, struct sk_buff *skb)
3982 struct e1000_hw *hw = &adapter->hw;
3983 u16 status = (u16)status_err;
3984 u8 errors = (u8)(status_err >> 24);
3985 skb->ip_summed = CHECKSUM_NONE;
3987 /* 82543 or newer only */
3988 if (unlikely(hw->mac_type < e1000_82543)) return;
3989 /* Ignore Checksum bit is set */
3990 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3991 /* TCP/UDP checksum error bit is set */
3992 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3993 /* let the stack verify checksum errors */
3994 adapter->hw_csum_err++;
3997 /* TCP/UDP Checksum has not been calculated */
3998 if (hw->mac_type <= e1000_82547_rev_2) {
3999 if (!(status & E1000_RXD_STAT_TCPCS))
4002 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
4005 /* It must be a TCP or UDP packet with a valid checksum */
4006 if (likely(status & E1000_RXD_STAT_TCPCS)) {
4007 /* TCP checksum is good */
4008 skb->ip_summed = CHECKSUM_UNNECESSARY;
4009 } else if (hw->mac_type > e1000_82547_rev_2) {
4010 /* IP fragment with UDP payload */
4011 /* Hardware complements the payload checksum, so we undo it
4012 * and then put the value in host order for further stack use.
4014 __sum16 sum = (__force __sum16)htons(csum);
4015 skb->csum = csum_unfold(~sum);
4016 skb->ip_summed = CHECKSUM_COMPLETE;
4018 adapter->hw_csum_good++;
4022 * e1000_consume_page - helper function
4024 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
4029 skb->data_len += length;
4030 skb->truesize += length;
4034 * e1000_receive_skb - helper function to handle rx indications
4035 * @adapter: board private structure
4036 * @status: descriptor status field as written by hardware
4037 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4038 * @skb: pointer to sk_buff to be indicated to stack
4040 static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4041 __le16 vlan, struct sk_buff *skb)
4043 if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) {
4044 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4046 E1000_RXD_SPC_VLAN_MASK);
4048 netif_receive_skb(skb);
4053 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4054 * @adapter: board private structure
4055 * @rx_ring: ring to clean
4056 * @work_done: amount of napi work completed this call
4057 * @work_to_do: max amount of work allowed for this call to do
4059 * the return value indicates whether actual cleaning was done, there
4060 * is no guarantee that everything was cleaned
4062 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4063 struct e1000_rx_ring *rx_ring,
4064 int *work_done, int work_to_do)
4066 struct e1000_hw *hw = &adapter->hw;
4067 struct net_device *netdev = adapter->netdev;
4068 struct pci_dev *pdev = adapter->pdev;
4069 struct e1000_rx_desc *rx_desc, *next_rxd;
4070 struct e1000_buffer *buffer_info, *next_buffer;
4071 unsigned long irq_flags;
4074 int cleaned_count = 0;
4075 bool cleaned = false;
4076 unsigned int total_rx_bytes=0, total_rx_packets=0;
4078 i = rx_ring->next_to_clean;
4079 rx_desc = E1000_RX_DESC(*rx_ring, i);
4080 buffer_info = &rx_ring->buffer_info[i];
4082 while (rx_desc->status & E1000_RXD_STAT_DD) {
4083 struct sk_buff *skb;
4086 if (*work_done >= work_to_do)
4090 status = rx_desc->status;
4091 skb = buffer_info->skb;
4092 buffer_info->skb = NULL;
4094 if (++i == rx_ring->count) i = 0;
4095 next_rxd = E1000_RX_DESC(*rx_ring, i);
4098 next_buffer = &rx_ring->buffer_info[i];
4102 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
4103 PCI_DMA_FROMDEVICE);
4104 buffer_info->dma = 0;
4106 length = le16_to_cpu(rx_desc->length);
4108 /* errors is only valid for DD + EOP descriptors */
4109 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4110 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4111 u8 last_byte = *(skb->data + length - 1);
4112 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4114 spin_lock_irqsave(&adapter->stats_lock,
4116 e1000_tbi_adjust_stats(hw, &adapter->stats,
4118 spin_unlock_irqrestore(&adapter->stats_lock,
4122 /* recycle both page and skb */
4123 buffer_info->skb = skb;
4124 /* an error means any chain goes out the window
4126 if (rx_ring->rx_skb_top)
4127 dev_kfree_skb(rx_ring->rx_skb_top);
4128 rx_ring->rx_skb_top = NULL;
4133 #define rxtop rx_ring->rx_skb_top
4134 if (!(status & E1000_RXD_STAT_EOP)) {
4135 /* this descriptor is only the beginning (or middle) */
4137 /* this is the beginning of a chain */
4139 skb_fill_page_desc(rxtop, 0, buffer_info->page,
4142 /* this is the middle of a chain */
4143 skb_fill_page_desc(rxtop,
4144 skb_shinfo(rxtop)->nr_frags,
4145 buffer_info->page, 0, length);
4146 /* re-use the skb, only consumed the page */
4147 buffer_info->skb = skb;
4149 e1000_consume_page(buffer_info, rxtop, length);
4153 /* end of the chain */
4154 skb_fill_page_desc(rxtop,
4155 skb_shinfo(rxtop)->nr_frags,
4156 buffer_info->page, 0, length);
4157 /* re-use the current skb, we only consumed the
4159 buffer_info->skb = skb;
4162 e1000_consume_page(buffer_info, skb, length);
4164 /* no chain, got EOP, this buf is the packet
4165 * copybreak to save the put_page/alloc_page */
4166 if (length <= copybreak &&
4167 skb_tailroom(skb) >= length) {
4169 vaddr = kmap_atomic(buffer_info->page,
4170 KM_SKB_DATA_SOFTIRQ);
4171 memcpy(skb_tail_pointer(skb), vaddr, length);
4172 kunmap_atomic(vaddr,
4173 KM_SKB_DATA_SOFTIRQ);
4174 /* re-use the page, so don't erase
4175 * buffer_info->page */
4176 skb_put(skb, length);
4178 skb_fill_page_desc(skb, 0,
4179 buffer_info->page, 0,
4181 e1000_consume_page(buffer_info, skb,
4187 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4188 e1000_rx_checksum(adapter,
4190 ((u32)(rx_desc->errors) << 24),
4191 le16_to_cpu(rx_desc->csum), skb);
4193 pskb_trim(skb, skb->len - 4);
4195 /* probably a little skewed due to removing CRC */
4196 total_rx_bytes += skb->len;
4199 /* eth type trans needs skb->data to point to something */
4200 if (!pskb_may_pull(skb, ETH_HLEN)) {
4201 DPRINTK(DRV, ERR, "pskb_may_pull failed.\n");
4206 skb->protocol = eth_type_trans(skb, netdev);
4208 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4211 rx_desc->status = 0;
4213 /* return some buffers to hardware, one at a time is too slow */
4214 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4215 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4219 /* use prefetched values */
4221 buffer_info = next_buffer;
4223 rx_ring->next_to_clean = i;
4225 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4227 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4229 adapter->total_rx_packets += total_rx_packets;
4230 adapter->total_rx_bytes += total_rx_bytes;
4231 adapter->net_stats.rx_bytes += total_rx_bytes;
4232 adapter->net_stats.rx_packets += total_rx_packets;
4237 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4238 * @adapter: board private structure
4239 * @rx_ring: ring to clean
4240 * @work_done: amount of napi work completed this call
4241 * @work_to_do: max amount of work allowed for this call to do
4243 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4244 struct e1000_rx_ring *rx_ring,
4245 int *work_done, int work_to_do)
4247 struct e1000_hw *hw = &adapter->hw;
4248 struct net_device *netdev = adapter->netdev;
4249 struct pci_dev *pdev = adapter->pdev;
4250 struct e1000_rx_desc *rx_desc, *next_rxd;
4251 struct e1000_buffer *buffer_info, *next_buffer;
4252 unsigned long flags;
4255 int cleaned_count = 0;
4256 bool cleaned = false;
4257 unsigned int total_rx_bytes=0, total_rx_packets=0;
4259 i = rx_ring->next_to_clean;
4260 rx_desc = E1000_RX_DESC(*rx_ring, i);
4261 buffer_info = &rx_ring->buffer_info[i];
4263 while (rx_desc->status & E1000_RXD_STAT_DD) {
4264 struct sk_buff *skb;
4267 if (*work_done >= work_to_do)
4271 status = rx_desc->status;
4272 skb = buffer_info->skb;
4273 buffer_info->skb = NULL;
4275 prefetch(skb->data - NET_IP_ALIGN);
4277 if (++i == rx_ring->count) i = 0;
4278 next_rxd = E1000_RX_DESC(*rx_ring, i);
4281 next_buffer = &rx_ring->buffer_info[i];
4285 pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
4286 PCI_DMA_FROMDEVICE);
4287 buffer_info->dma = 0;
4289 length = le16_to_cpu(rx_desc->length);
4290 /* !EOP means multiple descriptors were used to store a single
4291 * packet, also make sure the frame isn't just CRC only */
4292 if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) {
4293 /* All receives must fit into a single buffer */
4294 E1000_DBG("%s: Receive packet consumed multiple"
4295 " buffers\n", netdev->name);
4297 buffer_info->skb = skb;
4301 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4302 u8 last_byte = *(skb->data + length - 1);
4303 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4305 spin_lock_irqsave(&adapter->stats_lock, flags);
4306 e1000_tbi_adjust_stats(hw, &adapter->stats,
4308 spin_unlock_irqrestore(&adapter->stats_lock,
4313 buffer_info->skb = skb;
4318 /* adjust length to remove Ethernet CRC, this must be
4319 * done after the TBI_ACCEPT workaround above */
4322 /* probably a little skewed due to removing CRC */
4323 total_rx_bytes += length;
4326 /* code added for copybreak, this should improve
4327 * performance for small packets with large amounts
4328 * of reassembly being done in the stack */
4329 if (length < copybreak) {
4330 struct sk_buff *new_skb =
4331 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4333 skb_reserve(new_skb, NET_IP_ALIGN);
4334 skb_copy_to_linear_data_offset(new_skb,
4340 /* save the skb in buffer_info as good */
4341 buffer_info->skb = skb;
4344 /* else just continue with the old one */
4346 /* end copybreak code */
4347 skb_put(skb, length);
4349 /* Receive Checksum Offload */
4350 e1000_rx_checksum(adapter,
4352 ((u32)(rx_desc->errors) << 24),
4353 le16_to_cpu(rx_desc->csum), skb);
4355 skb->protocol = eth_type_trans(skb, netdev);
4357 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4360 rx_desc->status = 0;
4362 /* return some buffers to hardware, one at a time is too slow */
4363 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4364 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4368 /* use prefetched values */
4370 buffer_info = next_buffer;
4372 rx_ring->next_to_clean = i;
4374 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4376 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4378 adapter->total_rx_packets += total_rx_packets;
4379 adapter->total_rx_bytes += total_rx_bytes;
4380 adapter->net_stats.rx_bytes += total_rx_bytes;
4381 adapter->net_stats.rx_packets += total_rx_packets;
4386 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4387 * @adapter: address of board private structure
4388 * @rx_ring: pointer to receive ring structure
4389 * @cleaned_count: number of buffers to allocate this pass
4393 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4394 struct e1000_rx_ring *rx_ring, int cleaned_count)
4396 struct net_device *netdev = adapter->netdev;
4397 struct pci_dev *pdev = adapter->pdev;
4398 struct e1000_rx_desc *rx_desc;
4399 struct e1000_buffer *buffer_info;
4400 struct sk_buff *skb;
4402 unsigned int bufsz = 256 -
4403 16 /*for skb_reserve */ -
4406 i = rx_ring->next_to_use;
4407 buffer_info = &rx_ring->buffer_info[i];
4409 while (cleaned_count--) {
4410 skb = buffer_info->skb;
4416 skb = netdev_alloc_skb(netdev, bufsz);
4417 if (unlikely(!skb)) {
4418 /* Better luck next round */
4419 adapter->alloc_rx_buff_failed++;
4423 /* Fix for errata 23, can't cross 64kB boundary */
4424 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4425 struct sk_buff *oldskb = skb;
4426 DPRINTK(PROBE, ERR, "skb align check failed: %u bytes "
4427 "at %p\n", bufsz, skb->data);
4428 /* Try again, without freeing the previous */
4429 skb = netdev_alloc_skb(netdev, bufsz);
4430 /* Failed allocation, critical failure */
4432 dev_kfree_skb(oldskb);
4433 adapter->alloc_rx_buff_failed++;
4437 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4440 dev_kfree_skb(oldskb);
4441 break; /* while (cleaned_count--) */
4444 /* Use new allocation */
4445 dev_kfree_skb(oldskb);
4447 /* Make buffer alignment 2 beyond a 16 byte boundary
4448 * this will result in a 16 byte aligned IP header after
4449 * the 14 byte MAC header is removed
4451 skb_reserve(skb, NET_IP_ALIGN);
4453 buffer_info->skb = skb;
4454 buffer_info->length = adapter->rx_buffer_len;
4456 /* allocate a new page if necessary */
4457 if (!buffer_info->page) {
4458 buffer_info->page = alloc_page(GFP_ATOMIC);
4459 if (unlikely(!buffer_info->page)) {
4460 adapter->alloc_rx_buff_failed++;
4465 if (!buffer_info->dma)
4466 buffer_info->dma = pci_map_page(pdev,
4467 buffer_info->page, 0,
4468 buffer_info->length,
4469 PCI_DMA_FROMDEVICE);
4471 rx_desc = E1000_RX_DESC(*rx_ring, i);
4472 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4474 if (unlikely(++i == rx_ring->count))
4476 buffer_info = &rx_ring->buffer_info[i];
4479 if (likely(rx_ring->next_to_use != i)) {
4480 rx_ring->next_to_use = i;
4481 if (unlikely(i-- == 0))
4482 i = (rx_ring->count - 1);
4484 /* Force memory writes to complete before letting h/w
4485 * know there are new descriptors to fetch. (Only
4486 * applicable for weak-ordered memory model archs,
4487 * such as IA-64). */
4489 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4494 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4495 * @adapter: address of board private structure
4498 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4499 struct e1000_rx_ring *rx_ring,
4502 struct e1000_hw *hw = &adapter->hw;
4503 struct net_device *netdev = adapter->netdev;
4504 struct pci_dev *pdev = adapter->pdev;
4505 struct e1000_rx_desc *rx_desc;
4506 struct e1000_buffer *buffer_info;
4507 struct sk_buff *skb;
4509 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4511 i = rx_ring->next_to_use;
4512 buffer_info = &rx_ring->buffer_info[i];
4514 while (cleaned_count--) {
4515 skb = buffer_info->skb;
4521 skb = netdev_alloc_skb(netdev, bufsz);
4522 if (unlikely(!skb)) {
4523 /* Better luck next round */
4524 adapter->alloc_rx_buff_failed++;
4528 /* Fix for errata 23, can't cross 64kB boundary */
4529 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4530 struct sk_buff *oldskb = skb;
4531 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4532 "at %p\n", bufsz, skb->data);
4533 /* Try again, without freeing the previous */
4534 skb = netdev_alloc_skb(netdev, bufsz);
4535 /* Failed allocation, critical failure */
4537 dev_kfree_skb(oldskb);
4538 adapter->alloc_rx_buff_failed++;
4542 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4545 dev_kfree_skb(oldskb);
4546 adapter->alloc_rx_buff_failed++;
4547 break; /* while !buffer_info->skb */
4550 /* Use new allocation */
4551 dev_kfree_skb(oldskb);
4553 /* Make buffer alignment 2 beyond a 16 byte boundary
4554 * this will result in a 16 byte aligned IP header after
4555 * the 14 byte MAC header is removed
4557 skb_reserve(skb, NET_IP_ALIGN);
4559 buffer_info->skb = skb;
4560 buffer_info->length = adapter->rx_buffer_len;
4562 buffer_info->dma = pci_map_single(pdev,
4564 buffer_info->length,
4565 PCI_DMA_FROMDEVICE);
4568 * XXX if it was allocated cleanly it will never map to a
4572 /* Fix for errata 23, can't cross 64kB boundary */
4573 if (!e1000_check_64k_bound(adapter,
4574 (void *)(unsigned long)buffer_info->dma,
4575 adapter->rx_buffer_len)) {
4576 DPRINTK(RX_ERR, ERR,
4577 "dma align check failed: %u bytes at %p\n",
4578 adapter->rx_buffer_len,
4579 (void *)(unsigned long)buffer_info->dma);
4581 buffer_info->skb = NULL;
4583 pci_unmap_single(pdev, buffer_info->dma,
4584 adapter->rx_buffer_len,
4585 PCI_DMA_FROMDEVICE);
4586 buffer_info->dma = 0;
4588 adapter->alloc_rx_buff_failed++;
4589 break; /* while !buffer_info->skb */
4591 rx_desc = E1000_RX_DESC(*rx_ring, i);
4592 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4594 if (unlikely(++i == rx_ring->count))
4596 buffer_info = &rx_ring->buffer_info[i];
4599 if (likely(rx_ring->next_to_use != i)) {
4600 rx_ring->next_to_use = i;
4601 if (unlikely(i-- == 0))
4602 i = (rx_ring->count - 1);
4604 /* Force memory writes to complete before letting h/w
4605 * know there are new descriptors to fetch. (Only
4606 * applicable for weak-ordered memory model archs,
4607 * such as IA-64). */
4609 writel(i, hw->hw_addr + rx_ring->rdt);
4614 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4618 static void e1000_smartspeed(struct e1000_adapter *adapter)
4620 struct e1000_hw *hw = &adapter->hw;
4624 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4625 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4628 if (adapter->smartspeed == 0) {
4629 /* If Master/Slave config fault is asserted twice,
4630 * we assume back-to-back */
4631 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4632 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4633 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4634 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4635 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4636 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4637 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4638 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4640 adapter->smartspeed++;
4641 if (!e1000_phy_setup_autoneg(hw) &&
4642 !e1000_read_phy_reg(hw, PHY_CTRL,
4644 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4645 MII_CR_RESTART_AUTO_NEG);
4646 e1000_write_phy_reg(hw, PHY_CTRL,
4651 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4652 /* If still no link, perhaps using 2/3 pair cable */
4653 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4654 phy_ctrl |= CR_1000T_MS_ENABLE;
4655 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4656 if (!e1000_phy_setup_autoneg(hw) &&
4657 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4658 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4659 MII_CR_RESTART_AUTO_NEG);
4660 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4663 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4664 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4665 adapter->smartspeed = 0;
4675 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4681 return e1000_mii_ioctl(netdev, ifr, cmd);
4694 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4697 struct e1000_adapter *adapter = netdev_priv(netdev);
4698 struct e1000_hw *hw = &adapter->hw;
4699 struct mii_ioctl_data *data = if_mii(ifr);
4703 unsigned long flags;
4705 if (hw->media_type != e1000_media_type_copper)
4710 data->phy_id = hw->phy_addr;
4713 if (!capable(CAP_NET_ADMIN))
4715 spin_lock_irqsave(&adapter->stats_lock, flags);
4716 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4718 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4721 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4724 if (!capable(CAP_NET_ADMIN))
4726 if (data->reg_num & ~(0x1F))
4728 mii_reg = data->val_in;
4729 spin_lock_irqsave(&adapter->stats_lock, flags);
4730 if (e1000_write_phy_reg(hw, data->reg_num,
4732 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4735 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4736 if (hw->media_type == e1000_media_type_copper) {
4737 switch (data->reg_num) {
4739 if (mii_reg & MII_CR_POWER_DOWN)
4741 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4743 hw->autoneg_advertised = 0x2F;
4746 spddplx = SPEED_1000;
4747 else if (mii_reg & 0x2000)
4748 spddplx = SPEED_100;
4751 spddplx += (mii_reg & 0x100)
4754 retval = e1000_set_spd_dplx(adapter,
4759 if (netif_running(adapter->netdev))
4760 e1000_reinit_locked(adapter);
4762 e1000_reset(adapter);
4764 case M88E1000_PHY_SPEC_CTRL:
4765 case M88E1000_EXT_PHY_SPEC_CTRL:
4766 if (e1000_phy_reset(hw))
4771 switch (data->reg_num) {
4773 if (mii_reg & MII_CR_POWER_DOWN)
4775 if (netif_running(adapter->netdev))
4776 e1000_reinit_locked(adapter);
4778 e1000_reset(adapter);
4786 return E1000_SUCCESS;
4789 void e1000_pci_set_mwi(struct e1000_hw *hw)
4791 struct e1000_adapter *adapter = hw->back;
4792 int ret_val = pci_set_mwi(adapter->pdev);
4795 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4798 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4800 struct e1000_adapter *adapter = hw->back;
4802 pci_clear_mwi(adapter->pdev);
4805 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4807 struct e1000_adapter *adapter = hw->back;
4808 return pcix_get_mmrbc(adapter->pdev);
4811 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4813 struct e1000_adapter *adapter = hw->back;
4814 pcix_set_mmrbc(adapter->pdev, mmrbc);
4817 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
4819 struct e1000_adapter *adapter = hw->back;
4822 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4824 return -E1000_ERR_CONFIG;
4826 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4828 return E1000_SUCCESS;
4831 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4836 static void e1000_vlan_rx_register(struct net_device *netdev,
4837 struct vlan_group *grp)
4839 struct e1000_adapter *adapter = netdev_priv(netdev);
4840 struct e1000_hw *hw = &adapter->hw;
4843 if (!test_bit(__E1000_DOWN, &adapter->flags))
4844 e1000_irq_disable(adapter);
4845 adapter->vlgrp = grp;
4848 /* enable VLAN tag insert/strip */
4850 ctrl |= E1000_CTRL_VME;
4853 if (adapter->hw.mac_type != e1000_ich8lan) {
4854 /* enable VLAN receive filtering */
4856 rctl &= ~E1000_RCTL_CFIEN;
4858 e1000_update_mng_vlan(adapter);
4861 /* disable VLAN tag insert/strip */
4863 ctrl &= ~E1000_CTRL_VME;
4866 if (adapter->hw.mac_type != e1000_ich8lan) {
4867 if (adapter->mng_vlan_id !=
4868 (u16)E1000_MNG_VLAN_NONE) {
4869 e1000_vlan_rx_kill_vid(netdev,
4870 adapter->mng_vlan_id);
4871 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4876 if (!test_bit(__E1000_DOWN, &adapter->flags))
4877 e1000_irq_enable(adapter);
4880 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4882 struct e1000_adapter *adapter = netdev_priv(netdev);
4883 struct e1000_hw *hw = &adapter->hw;
4886 if ((hw->mng_cookie.status &
4887 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4888 (vid == adapter->mng_vlan_id))
4890 /* add VID to filter table */
4891 index = (vid >> 5) & 0x7F;
4892 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4893 vfta |= (1 << (vid & 0x1F));
4894 e1000_write_vfta(hw, index, vfta);
4897 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4899 struct e1000_adapter *adapter = netdev_priv(netdev);
4900 struct e1000_hw *hw = &adapter->hw;
4903 if (!test_bit(__E1000_DOWN, &adapter->flags))
4904 e1000_irq_disable(adapter);
4905 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4906 if (!test_bit(__E1000_DOWN, &adapter->flags))
4907 e1000_irq_enable(adapter);
4909 if ((hw->mng_cookie.status &
4910 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4911 (vid == adapter->mng_vlan_id)) {
4912 /* release control to f/w */
4913 e1000_release_hw_control(adapter);
4917 /* remove VID from filter table */
4918 index = (vid >> 5) & 0x7F;
4919 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4920 vfta &= ~(1 << (vid & 0x1F));
4921 e1000_write_vfta(hw, index, vfta);
4924 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4926 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4928 if (adapter->vlgrp) {
4930 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4931 if (!vlan_group_get_device(adapter->vlgrp, vid))
4933 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4938 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
4940 struct e1000_hw *hw = &adapter->hw;
4944 /* Fiber NICs only allow 1000 gbps Full duplex */
4945 if ((hw->media_type == e1000_media_type_fiber) &&
4946 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4947 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4952 case SPEED_10 + DUPLEX_HALF:
4953 hw->forced_speed_duplex = e1000_10_half;
4955 case SPEED_10 + DUPLEX_FULL:
4956 hw->forced_speed_duplex = e1000_10_full;
4958 case SPEED_100 + DUPLEX_HALF:
4959 hw->forced_speed_duplex = e1000_100_half;
4961 case SPEED_100 + DUPLEX_FULL:
4962 hw->forced_speed_duplex = e1000_100_full;
4964 case SPEED_1000 + DUPLEX_FULL:
4966 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4968 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4970 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4976 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4978 struct net_device *netdev = pci_get_drvdata(pdev);
4979 struct e1000_adapter *adapter = netdev_priv(netdev);
4980 struct e1000_hw *hw = &adapter->hw;
4981 u32 ctrl, ctrl_ext, rctl, status;
4982 u32 wufc = adapter->wol;
4987 netif_device_detach(netdev);
4989 if (netif_running(netdev)) {
4990 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4991 e1000_down(adapter);
4995 retval = pci_save_state(pdev);
5000 status = er32(STATUS);
5001 if (status & E1000_STATUS_LU)
5002 wufc &= ~E1000_WUFC_LNKC;
5005 e1000_setup_rctl(adapter);
5006 e1000_set_rx_mode(netdev);
5008 /* turn on all-multi mode if wake on multicast is enabled */
5009 if (wufc & E1000_WUFC_MC) {
5011 rctl |= E1000_RCTL_MPE;
5015 if (hw->mac_type >= e1000_82540) {
5017 /* advertise wake from D3Cold */
5018 #define E1000_CTRL_ADVD3WUC 0x00100000
5019 /* phy power management enable */
5020 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5021 ctrl |= E1000_CTRL_ADVD3WUC |
5022 E1000_CTRL_EN_PHY_PWR_MGMT;
5026 if (hw->media_type == e1000_media_type_fiber ||
5027 hw->media_type == e1000_media_type_internal_serdes) {
5028 /* keep the laser running in D3 */
5029 ctrl_ext = er32(CTRL_EXT);
5030 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5031 ew32(CTRL_EXT, ctrl_ext);
5034 /* Allow time for pending master requests to run */
5035 e1000_disable_pciex_master(hw);
5037 ew32(WUC, E1000_WUC_PME_EN);
5044 e1000_release_manageability(adapter);
5046 *enable_wake = !!wufc;
5048 /* make sure adapter isn't asleep if manageability is enabled */
5049 if (adapter->en_mng_pt)
5050 *enable_wake = true;
5052 if (hw->phy_type == e1000_phy_igp_3)
5053 e1000_phy_powerdown_workaround(hw);
5055 if (netif_running(netdev))
5056 e1000_free_irq(adapter);
5058 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5059 * would have already happened in close and is redundant. */
5060 e1000_release_hw_control(adapter);
5062 pci_disable_device(pdev);
5068 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5073 retval = __e1000_shutdown(pdev, &wake);
5078 pci_prepare_to_sleep(pdev);
5080 pci_wake_from_d3(pdev, false);
5081 pci_set_power_state(pdev, PCI_D3hot);
5087 static int e1000_resume(struct pci_dev *pdev)
5089 struct net_device *netdev = pci_get_drvdata(pdev);
5090 struct e1000_adapter *adapter = netdev_priv(netdev);
5091 struct e1000_hw *hw = &adapter->hw;
5094 pci_set_power_state(pdev, PCI_D0);
5095 pci_restore_state(pdev);
5097 if (adapter->need_ioport)
5098 err = pci_enable_device(pdev);
5100 err = pci_enable_device_mem(pdev);
5102 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5105 pci_set_master(pdev);
5107 pci_enable_wake(pdev, PCI_D3hot, 0);
5108 pci_enable_wake(pdev, PCI_D3cold, 0);
5110 if (netif_running(netdev)) {
5111 err = e1000_request_irq(adapter);
5116 e1000_power_up_phy(adapter);
5117 e1000_reset(adapter);
5120 e1000_init_manageability(adapter);
5122 if (netif_running(netdev))
5125 netif_device_attach(netdev);
5127 /* If the controller is 82573 and f/w is AMT, do not set
5128 * DRV_LOAD until the interface is up. For all other cases,
5129 * let the f/w know that the h/w is now under the control
5131 if (hw->mac_type != e1000_82573 ||
5132 !e1000_check_mng_mode(hw))
5133 e1000_get_hw_control(adapter);
5139 static void e1000_shutdown(struct pci_dev *pdev)
5143 __e1000_shutdown(pdev, &wake);
5145 if (system_state == SYSTEM_POWER_OFF) {
5146 pci_wake_from_d3(pdev, wake);
5147 pci_set_power_state(pdev, PCI_D3hot);
5151 #ifdef CONFIG_NET_POLL_CONTROLLER
5153 * Polling 'interrupt' - used by things like netconsole to send skbs
5154 * without having to re-enable interrupts. It's not called while
5155 * the interrupt routine is executing.
5157 static void e1000_netpoll(struct net_device *netdev)
5159 struct e1000_adapter *adapter = netdev_priv(netdev);
5161 disable_irq(adapter->pdev->irq);
5162 e1000_intr(adapter->pdev->irq, netdev);
5163 enable_irq(adapter->pdev->irq);
5168 * e1000_io_error_detected - called when PCI error is detected
5169 * @pdev: Pointer to PCI device
5170 * @state: The current pci conneection state
5172 * This function is called after a PCI bus error affecting
5173 * this device has been detected.
5175 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5176 pci_channel_state_t state)
5178 struct net_device *netdev = pci_get_drvdata(pdev);
5179 struct e1000_adapter *adapter = netdev_priv(netdev);
5181 netif_device_detach(netdev);
5183 if (state == pci_channel_io_perm_failure)
5184 return PCI_ERS_RESULT_DISCONNECT;
5186 if (netif_running(netdev))
5187 e1000_down(adapter);
5188 pci_disable_device(pdev);
5190 /* Request a slot slot reset. */
5191 return PCI_ERS_RESULT_NEED_RESET;
5195 * e1000_io_slot_reset - called after the pci bus has been reset.
5196 * @pdev: Pointer to PCI device
5198 * Restart the card from scratch, as if from a cold-boot. Implementation
5199 * resembles the first-half of the e1000_resume routine.
5201 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5203 struct net_device *netdev = pci_get_drvdata(pdev);
5204 struct e1000_adapter *adapter = netdev_priv(netdev);
5205 struct e1000_hw *hw = &adapter->hw;
5208 if (adapter->need_ioport)
5209 err = pci_enable_device(pdev);
5211 err = pci_enable_device_mem(pdev);
5213 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5214 return PCI_ERS_RESULT_DISCONNECT;
5216 pci_set_master(pdev);
5218 pci_enable_wake(pdev, PCI_D3hot, 0);
5219 pci_enable_wake(pdev, PCI_D3cold, 0);
5221 e1000_reset(adapter);
5224 return PCI_ERS_RESULT_RECOVERED;
5228 * e1000_io_resume - called when traffic can start flowing again.
5229 * @pdev: Pointer to PCI device
5231 * This callback is called when the error recovery driver tells us that
5232 * its OK to resume normal operation. Implementation resembles the
5233 * second-half of the e1000_resume routine.
5235 static void e1000_io_resume(struct pci_dev *pdev)
5237 struct net_device *netdev = pci_get_drvdata(pdev);
5238 struct e1000_adapter *adapter = netdev_priv(netdev);
5239 struct e1000_hw *hw = &adapter->hw;
5241 e1000_init_manageability(adapter);
5243 if (netif_running(netdev)) {
5244 if (e1000_up(adapter)) {
5245 printk("e1000: can't bring device back up after reset\n");
5250 netif_device_attach(netdev);
5252 /* If the controller is 82573 and f/w is AMT, do not set
5253 * DRV_LOAD until the interface is up. For all other cases,
5254 * let the f/w know that the h/w is now under the control
5256 if (hw->mac_type != e1000_82573 ||
5257 !e1000_check_mng_mode(hw))
5258 e1000_get_hw_control(adapter);