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.20-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_rx_irq_ps(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_rx_buffers_ps(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);
165 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 /* fire a link change interrupt to start the watchdog */
508 ew32(ICS, E1000_ICS_LSC);
513 * e1000_power_up_phy - restore link in case the phy was powered down
514 * @adapter: address of board private structure
516 * The phy may be powered down to save power and turn off link when the
517 * driver is unloaded and wake on lan is not enabled (among others)
518 * *** this routine MUST be followed by a call to e1000_reset ***
522 void e1000_power_up_phy(struct e1000_adapter *adapter)
524 struct e1000_hw *hw = &adapter->hw;
527 /* Just clear the power down bit to wake the phy back up */
528 if (hw->media_type == e1000_media_type_copper) {
529 /* according to the manual, the phy will retain its
530 * settings across a power-down/up cycle */
531 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
532 mii_reg &= ~MII_CR_POWER_DOWN;
533 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
537 static void e1000_power_down_phy(struct e1000_adapter *adapter)
539 struct e1000_hw *hw = &adapter->hw;
541 /* Power down the PHY so no link is implied when interface is down *
542 * The PHY cannot be powered down if any of the following is true *
545 * (c) SoL/IDER session is active */
546 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
547 hw->media_type == e1000_media_type_copper) {
550 switch (hw->mac_type) {
553 case e1000_82545_rev_3:
555 case e1000_82546_rev_3:
557 case e1000_82541_rev_2:
559 case e1000_82547_rev_2:
560 if (er32(MANC) & E1000_MANC_SMBUS_EN)
566 case e1000_80003es2lan:
568 if (e1000_check_mng_mode(hw) ||
569 e1000_check_phy_reset_block(hw))
575 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
576 mii_reg |= MII_CR_POWER_DOWN;
577 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
584 void e1000_down(struct e1000_adapter *adapter)
586 struct net_device *netdev = adapter->netdev;
588 /* signal that we're down so the interrupt handler does not
589 * reschedule our watchdog timer */
590 set_bit(__E1000_DOWN, &adapter->flags);
592 napi_disable(&adapter->napi);
594 e1000_irq_disable(adapter);
596 del_timer_sync(&adapter->tx_fifo_stall_timer);
597 del_timer_sync(&adapter->watchdog_timer);
598 del_timer_sync(&adapter->phy_info_timer);
600 netdev->tx_queue_len = adapter->tx_queue_len;
601 adapter->link_speed = 0;
602 adapter->link_duplex = 0;
603 netif_carrier_off(netdev);
604 netif_stop_queue(netdev);
606 e1000_reset(adapter);
607 e1000_clean_all_tx_rings(adapter);
608 e1000_clean_all_rx_rings(adapter);
611 void e1000_reinit_locked(struct e1000_adapter *adapter)
613 WARN_ON(in_interrupt());
614 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
618 clear_bit(__E1000_RESETTING, &adapter->flags);
621 void e1000_reset(struct e1000_adapter *adapter)
623 struct e1000_hw *hw = &adapter->hw;
624 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
625 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
626 bool legacy_pba_adjust = false;
628 /* Repartition Pba for greater than 9k mtu
629 * To take effect CTRL.RST is required.
632 switch (hw->mac_type) {
633 case e1000_82542_rev2_0:
634 case e1000_82542_rev2_1:
639 case e1000_82541_rev_2:
640 legacy_pba_adjust = true;
644 case e1000_82545_rev_3:
646 case e1000_82546_rev_3:
650 case e1000_82547_rev_2:
651 legacy_pba_adjust = true;
656 case e1000_80003es2lan:
664 case e1000_undefined:
669 if (legacy_pba_adjust) {
670 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
671 pba -= 8; /* allocate more FIFO for Tx */
673 if (hw->mac_type == e1000_82547) {
674 adapter->tx_fifo_head = 0;
675 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
676 adapter->tx_fifo_size =
677 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
678 atomic_set(&adapter->tx_fifo_stall, 0);
680 } else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
681 /* adjust PBA for jumbo frames */
684 /* To maintain wire speed transmits, the Tx FIFO should be
685 * large enough to accomodate two full transmit packets,
686 * rounded up to the next 1KB and expressed in KB. Likewise,
687 * the Rx FIFO should be large enough to accomodate at least
688 * one full receive packet and is similarly rounded up and
689 * expressed in KB. */
691 /* upper 16 bits has Tx packet buffer allocation size in KB */
692 tx_space = pba >> 16;
693 /* lower 16 bits has Rx packet buffer allocation size in KB */
695 /* don't include ethernet FCS because hardware appends/strips */
696 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
698 min_tx_space = min_rx_space;
700 min_tx_space = ALIGN(min_tx_space, 1024);
702 min_rx_space = ALIGN(min_rx_space, 1024);
705 /* If current Tx allocation is less than the min Tx FIFO size,
706 * and the min Tx FIFO size is less than the current Rx FIFO
707 * allocation, take space away from current Rx allocation */
708 if (tx_space < min_tx_space &&
709 ((min_tx_space - tx_space) < pba)) {
710 pba = pba - (min_tx_space - tx_space);
712 /* PCI/PCIx hardware has PBA alignment constraints */
713 switch (hw->mac_type) {
714 case e1000_82545 ... e1000_82546_rev_3:
715 pba &= ~(E1000_PBA_8K - 1);
721 /* if short on rx space, rx wins and must trump tx
722 * adjustment or use Early Receive if available */
723 if (pba < min_rx_space) {
724 switch (hw->mac_type) {
726 /* ERT enabled in e1000_configure_rx */
738 /* flow control settings */
739 /* Set the FC high water mark to 90% of the FIFO size.
740 * Required to clear last 3 LSB */
741 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
742 /* We can't use 90% on small FIFOs because the remainder
743 * would be less than 1 full frame. In this case, we size
744 * it to allow at least a full frame above the high water
746 if (pba < E1000_PBA_16K)
747 fc_high_water_mark = (pba * 1024) - 1600;
749 hw->fc_high_water = fc_high_water_mark;
750 hw->fc_low_water = fc_high_water_mark - 8;
751 if (hw->mac_type == e1000_80003es2lan)
752 hw->fc_pause_time = 0xFFFF;
754 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
756 hw->fc = hw->original_fc;
758 /* Allow time for pending master requests to run */
760 if (hw->mac_type >= e1000_82544)
763 if (e1000_init_hw(hw))
764 DPRINTK(PROBE, ERR, "Hardware Error\n");
765 e1000_update_mng_vlan(adapter);
767 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
768 if (hw->mac_type >= e1000_82544 &&
769 hw->mac_type <= e1000_82547_rev_2 &&
771 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
772 u32 ctrl = er32(CTRL);
773 /* clear phy power management bit if we are in gig only mode,
774 * which if enabled will attempt negotiation to 100Mb, which
775 * can cause a loss of link at power off or driver unload */
776 ctrl &= ~E1000_CTRL_SWDPIN3;
780 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
781 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
783 e1000_reset_adaptive(hw);
784 e1000_phy_get_info(hw, &adapter->phy_info);
786 if (!adapter->smart_power_down &&
787 (hw->mac_type == e1000_82571 ||
788 hw->mac_type == e1000_82572)) {
790 /* speed up time to link by disabling smart power down, ignore
791 * the return value of this function because there is nothing
792 * different we would do if it failed */
793 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
795 phy_data &= ~IGP02E1000_PM_SPD;
796 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
800 e1000_release_manageability(adapter);
804 * Dump the eeprom for users having checksum issues
806 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
808 struct net_device *netdev = adapter->netdev;
809 struct ethtool_eeprom eeprom;
810 const struct ethtool_ops *ops = netdev->ethtool_ops;
813 u16 csum_old, csum_new = 0;
815 eeprom.len = ops->get_eeprom_len(netdev);
818 data = kmalloc(eeprom.len, GFP_KERNEL);
820 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
825 ops->get_eeprom(netdev, &eeprom, data);
827 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
828 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
829 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
830 csum_new += data[i] + (data[i + 1] << 8);
831 csum_new = EEPROM_SUM - csum_new;
833 printk(KERN_ERR "/*********************/\n");
834 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
835 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
837 printk(KERN_ERR "Offset Values\n");
838 printk(KERN_ERR "======== ======\n");
839 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
841 printk(KERN_ERR "Include this output when contacting your support "
843 printk(KERN_ERR "This is not a software error! Something bad "
844 "happened to your hardware or\n");
845 printk(KERN_ERR "EEPROM image. Ignoring this "
846 "problem could result in further problems,\n");
847 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
848 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
849 "which is invalid\n");
850 printk(KERN_ERR "and requires you to set the proper MAC "
851 "address manually before continuing\n");
852 printk(KERN_ERR "to enable this network device.\n");
853 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
854 "to your hardware vendor\n");
855 printk(KERN_ERR "or Intel Customer Support.\n");
856 printk(KERN_ERR "/*********************/\n");
862 * e1000_probe - Device Initialization Routine
863 * @pdev: PCI device information struct
864 * @ent: entry in e1000_pci_tbl
866 * Returns 0 on success, negative on failure
868 * e1000_probe initializes an adapter identified by a pci_dev structure.
869 * The OS initialization, configuring of the adapter private structure,
870 * and a hardware reset occur.
873 static int __devinit e1000_probe(struct pci_dev *pdev,
874 const struct pci_device_id *ent)
876 struct net_device *netdev;
877 struct e1000_adapter *adapter;
880 static int cards_found = 0;
881 static int global_quad_port_a = 0; /* global ksp3 port a indication */
882 int i, err, pci_using_dac;
884 u16 eeprom_apme_mask = E1000_EEPROM_APME;
885 DECLARE_MAC_BUF(mac);
887 err = pci_enable_device(pdev);
891 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
892 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
895 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
897 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
899 E1000_ERR("No usable DMA configuration, "
907 err = pci_request_regions(pdev, e1000_driver_name);
911 pci_set_master(pdev);
914 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
916 goto err_alloc_etherdev;
918 SET_NETDEV_DEV(netdev, &pdev->dev);
920 pci_set_drvdata(pdev, netdev);
921 adapter = netdev_priv(netdev);
922 adapter->netdev = netdev;
923 adapter->pdev = pdev;
924 adapter->msg_enable = (1 << debug) - 1;
930 hw->hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
931 pci_resource_len(pdev, BAR_0));
935 for (i = BAR_1; i <= BAR_5; i++) {
936 if (pci_resource_len(pdev, i) == 0)
938 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
939 hw->io_base = pci_resource_start(pdev, i);
944 netdev->open = &e1000_open;
945 netdev->stop = &e1000_close;
946 netdev->hard_start_xmit = &e1000_xmit_frame;
947 netdev->get_stats = &e1000_get_stats;
948 netdev->set_rx_mode = &e1000_set_rx_mode;
949 netdev->set_mac_address = &e1000_set_mac;
950 netdev->change_mtu = &e1000_change_mtu;
951 netdev->do_ioctl = &e1000_ioctl;
952 e1000_set_ethtool_ops(netdev);
953 netdev->tx_timeout = &e1000_tx_timeout;
954 netdev->watchdog_timeo = 5 * HZ;
955 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
956 netdev->vlan_rx_register = e1000_vlan_rx_register;
957 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
958 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
959 #ifdef CONFIG_NET_POLL_CONTROLLER
960 netdev->poll_controller = e1000_netpoll;
962 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
964 adapter->bd_number = cards_found;
966 /* setup the private structure */
968 err = e1000_sw_init(adapter);
973 /* Flash BAR mapping must happen after e1000_sw_init
974 * because it depends on mac_type */
975 if ((hw->mac_type == e1000_ich8lan) &&
976 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
978 ioremap(pci_resource_start(pdev, 1),
979 pci_resource_len(pdev, 1));
980 if (!hw->flash_address)
984 if (e1000_check_phy_reset_block(hw))
985 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
987 if (hw->mac_type >= e1000_82543) {
988 netdev->features = NETIF_F_SG |
992 NETIF_F_HW_VLAN_FILTER;
993 if (hw->mac_type == e1000_ich8lan)
994 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
997 if ((hw->mac_type >= e1000_82544) &&
998 (hw->mac_type != e1000_82547))
999 netdev->features |= NETIF_F_TSO;
1001 if (hw->mac_type > e1000_82547_rev_2)
1002 netdev->features |= NETIF_F_TSO6;
1004 netdev->features |= NETIF_F_HIGHDMA;
1006 netdev->features |= NETIF_F_LLTX;
1008 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1010 /* initialize eeprom parameters */
1011 if (e1000_init_eeprom_params(hw)) {
1012 E1000_ERR("EEPROM initialization failed\n");
1016 /* before reading the EEPROM, reset the controller to
1017 * put the device in a known good starting state */
1021 /* make sure the EEPROM is good */
1022 if (e1000_validate_eeprom_checksum(hw) < 0) {
1023 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1024 e1000_dump_eeprom(adapter);
1026 * set MAC address to all zeroes to invalidate and temporary
1027 * disable this device for the user. This blocks regular
1028 * traffic while still permitting ethtool ioctls from reaching
1029 * the hardware as well as allowing the user to run the
1030 * interface after manually setting a hw addr using
1033 memset(hw->mac_addr, 0, netdev->addr_len);
1035 /* copy the MAC address out of the EEPROM */
1036 if (e1000_read_mac_addr(hw))
1037 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1039 /* don't block initalization here due to bad MAC address */
1040 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1041 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
1043 if (!is_valid_ether_addr(netdev->perm_addr))
1044 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1046 e1000_get_bus_info(hw);
1048 init_timer(&adapter->tx_fifo_stall_timer);
1049 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1050 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
1052 init_timer(&adapter->watchdog_timer);
1053 adapter->watchdog_timer.function = &e1000_watchdog;
1054 adapter->watchdog_timer.data = (unsigned long) adapter;
1056 init_timer(&adapter->phy_info_timer);
1057 adapter->phy_info_timer.function = &e1000_update_phy_info;
1058 adapter->phy_info_timer.data = (unsigned long)adapter;
1060 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1062 e1000_check_options(adapter);
1064 /* Initial Wake on LAN setting
1065 * If APM wake is enabled in the EEPROM,
1066 * enable the ACPI Magic Packet filter
1069 switch (hw->mac_type) {
1070 case e1000_82542_rev2_0:
1071 case e1000_82542_rev2_1:
1075 e1000_read_eeprom(hw,
1076 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1077 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1080 e1000_read_eeprom(hw,
1081 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1082 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1085 case e1000_82546_rev_3:
1087 case e1000_80003es2lan:
1088 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1089 e1000_read_eeprom(hw,
1090 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1095 e1000_read_eeprom(hw,
1096 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1099 if (eeprom_data & eeprom_apme_mask)
1100 adapter->eeprom_wol |= E1000_WUFC_MAG;
1102 /* now that we have the eeprom settings, apply the special cases
1103 * where the eeprom may be wrong or the board simply won't support
1104 * wake on lan on a particular port */
1105 switch (pdev->device) {
1106 case E1000_DEV_ID_82546GB_PCIE:
1107 adapter->eeprom_wol = 0;
1109 case E1000_DEV_ID_82546EB_FIBER:
1110 case E1000_DEV_ID_82546GB_FIBER:
1111 case E1000_DEV_ID_82571EB_FIBER:
1112 /* Wake events only supported on port A for dual fiber
1113 * regardless of eeprom setting */
1114 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1115 adapter->eeprom_wol = 0;
1117 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1118 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1119 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1120 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1121 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1122 /* if quad port adapter, disable WoL on all but port A */
1123 if (global_quad_port_a != 0)
1124 adapter->eeprom_wol = 0;
1126 adapter->quad_port_a = 1;
1127 /* Reset for multiple quad port adapters */
1128 if (++global_quad_port_a == 4)
1129 global_quad_port_a = 0;
1133 /* initialize the wol settings based on the eeprom settings */
1134 adapter->wol = adapter->eeprom_wol;
1136 /* print bus type/speed/width info */
1137 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1138 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1139 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1140 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1141 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1142 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1143 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1144 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1145 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1146 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1147 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1150 printk("%s\n", print_mac(mac, netdev->dev_addr));
1152 if (hw->bus_type == e1000_bus_type_pci_express) {
1153 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1154 "longer be supported by this driver in the future.\n",
1155 pdev->vendor, pdev->device);
1156 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1157 "driver instead.\n");
1160 /* reset the hardware with the new settings */
1161 e1000_reset(adapter);
1163 /* If the controller is 82573 and f/w is AMT, do not set
1164 * DRV_LOAD until the interface is up. For all other cases,
1165 * let the f/w know that the h/w is now under the control
1167 if (hw->mac_type != e1000_82573 ||
1168 !e1000_check_mng_mode(hw))
1169 e1000_get_hw_control(adapter);
1171 /* tell the stack to leave us alone until e1000_open() is called */
1172 netif_carrier_off(netdev);
1173 netif_stop_queue(netdev);
1175 strcpy(netdev->name, "eth%d");
1176 err = register_netdev(netdev);
1180 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1186 e1000_release_hw_control(adapter);
1188 if (!e1000_check_phy_reset_block(hw))
1189 e1000_phy_hw_reset(hw);
1191 if (hw->flash_address)
1192 iounmap(hw->flash_address);
1194 for (i = 0; i < adapter->num_rx_queues; i++)
1195 dev_put(&adapter->polling_netdev[i]);
1197 kfree(adapter->tx_ring);
1198 kfree(adapter->rx_ring);
1199 kfree(adapter->polling_netdev);
1201 iounmap(hw->hw_addr);
1203 free_netdev(netdev);
1205 pci_release_regions(pdev);
1208 pci_disable_device(pdev);
1213 * e1000_remove - Device Removal Routine
1214 * @pdev: PCI device information struct
1216 * e1000_remove is called by the PCI subsystem to alert the driver
1217 * that it should release a PCI device. The could be caused by a
1218 * Hot-Plug event, or because the driver is going to be removed from
1222 static void __devexit e1000_remove(struct pci_dev *pdev)
1224 struct net_device *netdev = pci_get_drvdata(pdev);
1225 struct e1000_adapter *adapter = netdev_priv(netdev);
1226 struct e1000_hw *hw = &adapter->hw;
1229 cancel_work_sync(&adapter->reset_task);
1231 e1000_release_manageability(adapter);
1233 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1234 * would have already happened in close and is redundant. */
1235 e1000_release_hw_control(adapter);
1237 for (i = 0; i < adapter->num_rx_queues; i++)
1238 dev_put(&adapter->polling_netdev[i]);
1240 unregister_netdev(netdev);
1242 if (!e1000_check_phy_reset_block(hw))
1243 e1000_phy_hw_reset(hw);
1245 kfree(adapter->tx_ring);
1246 kfree(adapter->rx_ring);
1247 kfree(adapter->polling_netdev);
1249 iounmap(hw->hw_addr);
1250 if (hw->flash_address)
1251 iounmap(hw->flash_address);
1252 pci_release_regions(pdev);
1254 free_netdev(netdev);
1256 pci_disable_device(pdev);
1260 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1261 * @adapter: board private structure to initialize
1263 * e1000_sw_init initializes the Adapter private data structure.
1264 * Fields are initialized based on PCI device information and
1265 * OS network device settings (MTU size).
1268 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1270 struct e1000_hw *hw = &adapter->hw;
1271 struct net_device *netdev = adapter->netdev;
1272 struct pci_dev *pdev = adapter->pdev;
1275 /* PCI config space info */
1277 hw->vendor_id = pdev->vendor;
1278 hw->device_id = pdev->device;
1279 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1280 hw->subsystem_id = pdev->subsystem_device;
1281 hw->revision_id = pdev->revision;
1283 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1285 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1286 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1287 hw->max_frame_size = netdev->mtu +
1288 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1289 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1291 /* identify the MAC */
1293 if (e1000_set_mac_type(hw)) {
1294 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1298 switch (hw->mac_type) {
1303 case e1000_82541_rev_2:
1304 case e1000_82547_rev_2:
1305 hw->phy_init_script = 1;
1309 e1000_set_media_type(hw);
1311 hw->wait_autoneg_complete = false;
1312 hw->tbi_compatibility_en = true;
1313 hw->adaptive_ifs = true;
1315 /* Copper options */
1317 if (hw->media_type == e1000_media_type_copper) {
1318 hw->mdix = AUTO_ALL_MODES;
1319 hw->disable_polarity_correction = false;
1320 hw->master_slave = E1000_MASTER_SLAVE;
1323 adapter->num_tx_queues = 1;
1324 adapter->num_rx_queues = 1;
1326 if (e1000_alloc_queues(adapter)) {
1327 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1331 for (i = 0; i < adapter->num_rx_queues; i++) {
1332 adapter->polling_netdev[i].priv = adapter;
1333 dev_hold(&adapter->polling_netdev[i]);
1334 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1336 spin_lock_init(&adapter->tx_queue_lock);
1338 /* Explicitly disable IRQ since the NIC can be in any state. */
1339 e1000_irq_disable(adapter);
1341 spin_lock_init(&adapter->stats_lock);
1343 set_bit(__E1000_DOWN, &adapter->flags);
1349 * e1000_alloc_queues - Allocate memory for all rings
1350 * @adapter: board private structure to initialize
1352 * We allocate one ring per queue at run-time since we don't know the
1353 * number of queues at compile-time. The polling_netdev array is
1354 * intended for Multiqueue, but should work fine with a single queue.
1357 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1359 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1360 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1361 if (!adapter->tx_ring)
1364 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1365 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1366 if (!adapter->rx_ring) {
1367 kfree(adapter->tx_ring);
1371 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1372 sizeof(struct net_device),
1374 if (!adapter->polling_netdev) {
1375 kfree(adapter->tx_ring);
1376 kfree(adapter->rx_ring);
1380 return E1000_SUCCESS;
1384 * e1000_open - Called when a network interface is made active
1385 * @netdev: network interface device structure
1387 * Returns 0 on success, negative value on failure
1389 * The open entry point is called when a network interface is made
1390 * active by the system (IFF_UP). At this point all resources needed
1391 * for transmit and receive operations are allocated, the interrupt
1392 * handler is registered with the OS, the watchdog timer is started,
1393 * and the stack is notified that the interface is ready.
1396 static int e1000_open(struct net_device *netdev)
1398 struct e1000_adapter *adapter = netdev_priv(netdev);
1399 struct e1000_hw *hw = &adapter->hw;
1402 /* disallow open during test */
1403 if (test_bit(__E1000_TESTING, &adapter->flags))
1406 /* allocate transmit descriptors */
1407 err = e1000_setup_all_tx_resources(adapter);
1411 /* allocate receive descriptors */
1412 err = e1000_setup_all_rx_resources(adapter);
1416 e1000_power_up_phy(adapter);
1418 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1419 if ((hw->mng_cookie.status &
1420 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1421 e1000_update_mng_vlan(adapter);
1424 /* If AMT is enabled, let the firmware know that the network
1425 * interface is now open */
1426 if (hw->mac_type == e1000_82573 &&
1427 e1000_check_mng_mode(hw))
1428 e1000_get_hw_control(adapter);
1430 /* before we allocate an interrupt, we must be ready to handle it.
1431 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1432 * as soon as we call pci_request_irq, so we have to setup our
1433 * clean_rx handler before we do so. */
1434 e1000_configure(adapter);
1436 err = e1000_request_irq(adapter);
1440 /* From here on the code is the same as e1000_up() */
1441 clear_bit(__E1000_DOWN, &adapter->flags);
1443 napi_enable(&adapter->napi);
1445 e1000_irq_enable(adapter);
1447 netif_start_queue(netdev);
1449 /* fire a link status change interrupt to start the watchdog */
1450 ew32(ICS, E1000_ICS_LSC);
1452 return E1000_SUCCESS;
1455 e1000_release_hw_control(adapter);
1456 e1000_power_down_phy(adapter);
1457 e1000_free_all_rx_resources(adapter);
1459 e1000_free_all_tx_resources(adapter);
1461 e1000_reset(adapter);
1467 * e1000_close - Disables a network interface
1468 * @netdev: network interface device structure
1470 * Returns 0, this is not allowed to fail
1472 * The close entry point is called when an interface is de-activated
1473 * by the OS. The hardware is still under the drivers control, but
1474 * needs to be disabled. A global MAC reset is issued to stop the
1475 * hardware, and all transmit and receive resources are freed.
1478 static int e1000_close(struct net_device *netdev)
1480 struct e1000_adapter *adapter = netdev_priv(netdev);
1481 struct e1000_hw *hw = &adapter->hw;
1483 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1484 e1000_down(adapter);
1485 e1000_power_down_phy(adapter);
1486 e1000_free_irq(adapter);
1488 e1000_free_all_tx_resources(adapter);
1489 e1000_free_all_rx_resources(adapter);
1491 /* kill manageability vlan ID if supported, but not if a vlan with
1492 * the same ID is registered on the host OS (let 8021q kill it) */
1493 if ((hw->mng_cookie.status &
1494 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1496 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1497 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1500 /* If AMT is enabled, let the firmware know that the network
1501 * interface is now closed */
1502 if (hw->mac_type == e1000_82573 &&
1503 e1000_check_mng_mode(hw))
1504 e1000_release_hw_control(adapter);
1510 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1511 * @adapter: address of board private structure
1512 * @start: address of beginning of memory
1513 * @len: length of memory
1515 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1518 struct e1000_hw *hw = &adapter->hw;
1519 unsigned long begin = (unsigned long)start;
1520 unsigned long end = begin + len;
1522 /* First rev 82545 and 82546 need to not allow any memory
1523 * write location to cross 64k boundary due to errata 23 */
1524 if (hw->mac_type == e1000_82545 ||
1525 hw->mac_type == e1000_82546) {
1526 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1533 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1534 * @adapter: board private structure
1535 * @txdr: tx descriptor ring (for a specific queue) to setup
1537 * Return 0 on success, negative on failure
1540 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1541 struct e1000_tx_ring *txdr)
1543 struct pci_dev *pdev = adapter->pdev;
1546 size = sizeof(struct e1000_buffer) * txdr->count;
1547 txdr->buffer_info = vmalloc(size);
1548 if (!txdr->buffer_info) {
1550 "Unable to allocate memory for the transmit descriptor ring\n");
1553 memset(txdr->buffer_info, 0, size);
1555 /* round up to nearest 4K */
1557 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1558 txdr->size = ALIGN(txdr->size, 4096);
1560 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1563 vfree(txdr->buffer_info);
1565 "Unable to allocate memory for the transmit descriptor ring\n");
1569 /* Fix for errata 23, can't cross 64kB boundary */
1570 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1571 void *olddesc = txdr->desc;
1572 dma_addr_t olddma = txdr->dma;
1573 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1574 "at %p\n", txdr->size, txdr->desc);
1575 /* Try again, without freeing the previous */
1576 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1577 /* Failed allocation, critical failure */
1579 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1580 goto setup_tx_desc_die;
1583 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1585 pci_free_consistent(pdev, txdr->size, txdr->desc,
1587 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1589 "Unable to allocate aligned memory "
1590 "for the transmit descriptor ring\n");
1591 vfree(txdr->buffer_info);
1594 /* Free old allocation, new allocation was successful */
1595 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1598 memset(txdr->desc, 0, txdr->size);
1600 txdr->next_to_use = 0;
1601 txdr->next_to_clean = 0;
1602 spin_lock_init(&txdr->tx_lock);
1608 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1609 * (Descriptors) for all queues
1610 * @adapter: board private structure
1612 * Return 0 on success, negative on failure
1615 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1619 for (i = 0; i < adapter->num_tx_queues; i++) {
1620 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1623 "Allocation for Tx Queue %u failed\n", i);
1624 for (i-- ; i >= 0; i--)
1625 e1000_free_tx_resources(adapter,
1626 &adapter->tx_ring[i]);
1635 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1636 * @adapter: board private structure
1638 * Configure the Tx unit of the MAC after a reset.
1641 static void e1000_configure_tx(struct e1000_adapter *adapter)
1644 struct e1000_hw *hw = &adapter->hw;
1645 u32 tdlen, tctl, tipg, tarc;
1648 /* Setup the HW Tx Head and Tail descriptor pointers */
1650 switch (adapter->num_tx_queues) {
1653 tdba = adapter->tx_ring[0].dma;
1654 tdlen = adapter->tx_ring[0].count *
1655 sizeof(struct e1000_tx_desc);
1657 ew32(TDBAH, (tdba >> 32));
1658 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1661 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1662 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1666 /* Set the default values for the Tx Inter Packet Gap timer */
1667 if (hw->mac_type <= e1000_82547_rev_2 &&
1668 (hw->media_type == e1000_media_type_fiber ||
1669 hw->media_type == e1000_media_type_internal_serdes))
1670 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1672 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1674 switch (hw->mac_type) {
1675 case e1000_82542_rev2_0:
1676 case e1000_82542_rev2_1:
1677 tipg = DEFAULT_82542_TIPG_IPGT;
1678 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1679 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1681 case e1000_80003es2lan:
1682 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1683 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1686 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1687 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1690 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1691 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1694 /* Set the Tx Interrupt Delay register */
1696 ew32(TIDV, adapter->tx_int_delay);
1697 if (hw->mac_type >= e1000_82540)
1698 ew32(TADV, adapter->tx_abs_int_delay);
1700 /* Program the Transmit Control Register */
1703 tctl &= ~E1000_TCTL_CT;
1704 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1705 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1707 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1709 /* set the speed mode bit, we'll clear it if we're not at
1710 * gigabit link later */
1713 } else if (hw->mac_type == e1000_80003es2lan) {
1722 e1000_config_collision_dist(hw);
1724 /* Setup Transmit Descriptor Settings for eop descriptor */
1725 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1727 /* only set IDE if we are delaying interrupts using the timers */
1728 if (adapter->tx_int_delay)
1729 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1731 if (hw->mac_type < e1000_82543)
1732 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1734 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1736 /* Cache if we're 82544 running in PCI-X because we'll
1737 * need this to apply a workaround later in the send path. */
1738 if (hw->mac_type == e1000_82544 &&
1739 hw->bus_type == e1000_bus_type_pcix)
1740 adapter->pcix_82544 = 1;
1747 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1748 * @adapter: board private structure
1749 * @rxdr: rx descriptor ring (for a specific queue) to setup
1751 * Returns 0 on success, negative on failure
1754 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1755 struct e1000_rx_ring *rxdr)
1757 struct e1000_hw *hw = &adapter->hw;
1758 struct pci_dev *pdev = adapter->pdev;
1761 size = sizeof(struct e1000_buffer) * rxdr->count;
1762 rxdr->buffer_info = vmalloc(size);
1763 if (!rxdr->buffer_info) {
1765 "Unable to allocate memory for the receive descriptor ring\n");
1768 memset(rxdr->buffer_info, 0, size);
1770 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1772 if (!rxdr->ps_page) {
1773 vfree(rxdr->buffer_info);
1775 "Unable to allocate memory for the receive descriptor ring\n");
1779 rxdr->ps_page_dma = kcalloc(rxdr->count,
1780 sizeof(struct e1000_ps_page_dma),
1782 if (!rxdr->ps_page_dma) {
1783 vfree(rxdr->buffer_info);
1784 kfree(rxdr->ps_page);
1786 "Unable to allocate memory for the receive descriptor ring\n");
1790 if (hw->mac_type <= e1000_82547_rev_2)
1791 desc_len = sizeof(struct e1000_rx_desc);
1793 desc_len = sizeof(union e1000_rx_desc_packet_split);
1795 /* Round up to nearest 4K */
1797 rxdr->size = rxdr->count * desc_len;
1798 rxdr->size = ALIGN(rxdr->size, 4096);
1800 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1804 "Unable to allocate memory for the receive descriptor ring\n");
1806 vfree(rxdr->buffer_info);
1807 kfree(rxdr->ps_page);
1808 kfree(rxdr->ps_page_dma);
1812 /* Fix for errata 23, can't cross 64kB boundary */
1813 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1814 void *olddesc = rxdr->desc;
1815 dma_addr_t olddma = rxdr->dma;
1816 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1817 "at %p\n", rxdr->size, rxdr->desc);
1818 /* Try again, without freeing the previous */
1819 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1820 /* Failed allocation, critical failure */
1822 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1824 "Unable to allocate memory "
1825 "for the receive descriptor ring\n");
1826 goto setup_rx_desc_die;
1829 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1831 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1833 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1835 "Unable to allocate aligned memory "
1836 "for the receive descriptor ring\n");
1837 goto setup_rx_desc_die;
1839 /* Free old allocation, new allocation was successful */
1840 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1843 memset(rxdr->desc, 0, rxdr->size);
1845 rxdr->next_to_clean = 0;
1846 rxdr->next_to_use = 0;
1852 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1853 * (Descriptors) for all queues
1854 * @adapter: board private structure
1856 * Return 0 on success, negative on failure
1859 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1863 for (i = 0; i < adapter->num_rx_queues; i++) {
1864 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1867 "Allocation for Rx Queue %u failed\n", i);
1868 for (i-- ; i >= 0; i--)
1869 e1000_free_rx_resources(adapter,
1870 &adapter->rx_ring[i]);
1879 * e1000_setup_rctl - configure the receive control registers
1880 * @adapter: Board private structure
1882 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1883 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1884 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1886 struct e1000_hw *hw = &adapter->hw;
1889 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1895 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1897 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1898 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1899 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1901 if (hw->tbi_compatibility_on == 1)
1902 rctl |= E1000_RCTL_SBP;
1904 rctl &= ~E1000_RCTL_SBP;
1906 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1907 rctl &= ~E1000_RCTL_LPE;
1909 rctl |= E1000_RCTL_LPE;
1911 /* Setup buffer sizes */
1912 rctl &= ~E1000_RCTL_SZ_4096;
1913 rctl |= E1000_RCTL_BSEX;
1914 switch (adapter->rx_buffer_len) {
1915 case E1000_RXBUFFER_256:
1916 rctl |= E1000_RCTL_SZ_256;
1917 rctl &= ~E1000_RCTL_BSEX;
1919 case E1000_RXBUFFER_512:
1920 rctl |= E1000_RCTL_SZ_512;
1921 rctl &= ~E1000_RCTL_BSEX;
1923 case E1000_RXBUFFER_1024:
1924 rctl |= E1000_RCTL_SZ_1024;
1925 rctl &= ~E1000_RCTL_BSEX;
1927 case E1000_RXBUFFER_2048:
1929 rctl |= E1000_RCTL_SZ_2048;
1930 rctl &= ~E1000_RCTL_BSEX;
1932 case E1000_RXBUFFER_4096:
1933 rctl |= E1000_RCTL_SZ_4096;
1935 case E1000_RXBUFFER_8192:
1936 rctl |= E1000_RCTL_SZ_8192;
1938 case E1000_RXBUFFER_16384:
1939 rctl |= E1000_RCTL_SZ_16384;
1943 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1944 /* 82571 and greater support packet-split where the protocol
1945 * header is placed in skb->data and the packet data is
1946 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1947 * In the case of a non-split, skb->data is linearly filled,
1948 * followed by the page buffers. Therefore, skb->data is
1949 * sized to hold the largest protocol header.
1951 /* allocations using alloc_page take too long for regular MTU
1952 * so only enable packet split for jumbo frames */
1953 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1954 if ((hw->mac_type >= e1000_82571) && (pages <= 3) &&
1955 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
1956 adapter->rx_ps_pages = pages;
1958 adapter->rx_ps_pages = 0;
1960 if (adapter->rx_ps_pages) {
1961 /* Configure extra packet-split registers */
1962 rfctl = er32(RFCTL);
1963 rfctl |= E1000_RFCTL_EXTEN;
1964 /* disable packet split support for IPv6 extension headers,
1965 * because some malformed IPv6 headers can hang the RX */
1966 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1967 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1971 rctl |= E1000_RCTL_DTYP_PS;
1973 psrctl |= adapter->rx_ps_bsize0 >>
1974 E1000_PSRCTL_BSIZE0_SHIFT;
1976 switch (adapter->rx_ps_pages) {
1978 psrctl |= PAGE_SIZE <<
1979 E1000_PSRCTL_BSIZE3_SHIFT;
1981 psrctl |= PAGE_SIZE <<
1982 E1000_PSRCTL_BSIZE2_SHIFT;
1984 psrctl |= PAGE_SIZE >>
1985 E1000_PSRCTL_BSIZE1_SHIFT;
1989 ew32(PSRCTL, psrctl);
1996 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1997 * @adapter: board private structure
1999 * Configure the Rx unit of the MAC after a reset.
2002 static void e1000_configure_rx(struct e1000_adapter *adapter)
2005 struct e1000_hw *hw = &adapter->hw;
2006 u32 rdlen, rctl, rxcsum, ctrl_ext;
2008 if (adapter->rx_ps_pages) {
2009 /* this is a 32 byte descriptor */
2010 rdlen = adapter->rx_ring[0].count *
2011 sizeof(union e1000_rx_desc_packet_split);
2012 adapter->clean_rx = e1000_clean_rx_irq_ps;
2013 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2015 rdlen = adapter->rx_ring[0].count *
2016 sizeof(struct e1000_rx_desc);
2017 adapter->clean_rx = e1000_clean_rx_irq;
2018 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2021 /* disable receives while setting up the descriptors */
2023 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2025 /* set the Receive Delay Timer Register */
2026 ew32(RDTR, adapter->rx_int_delay);
2028 if (hw->mac_type >= e1000_82540) {
2029 ew32(RADV, adapter->rx_abs_int_delay);
2030 if (adapter->itr_setting != 0)
2031 ew32(ITR, 1000000000 / (adapter->itr * 256));
2034 if (hw->mac_type >= e1000_82571) {
2035 ctrl_ext = er32(CTRL_EXT);
2036 /* Reset delay timers after every interrupt */
2037 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2038 /* Auto-Mask interrupts upon ICR access */
2039 ctrl_ext |= E1000_CTRL_EXT_IAME;
2040 ew32(IAM, 0xffffffff);
2041 ew32(CTRL_EXT, ctrl_ext);
2042 E1000_WRITE_FLUSH();
2045 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2046 * the Base and Length of the Rx Descriptor Ring */
2047 switch (adapter->num_rx_queues) {
2050 rdba = adapter->rx_ring[0].dma;
2052 ew32(RDBAH, (rdba >> 32));
2053 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2056 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2057 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
2061 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2062 if (hw->mac_type >= e1000_82543) {
2063 rxcsum = er32(RXCSUM);
2064 if (adapter->rx_csum) {
2065 rxcsum |= E1000_RXCSUM_TUOFL;
2067 /* Enable 82571 IPv4 payload checksum for UDP fragments
2068 * Must be used in conjunction with packet-split. */
2069 if ((hw->mac_type >= e1000_82571) &&
2070 (adapter->rx_ps_pages)) {
2071 rxcsum |= E1000_RXCSUM_IPPCSE;
2074 rxcsum &= ~E1000_RXCSUM_TUOFL;
2075 /* don't need to clear IPPCSE as it defaults to 0 */
2077 ew32(RXCSUM, rxcsum);
2080 /* enable early receives on 82573, only takes effect if using > 2048
2081 * byte total frame size. for example only for jumbo frames */
2082 #define E1000_ERT_2048 0x100
2083 if (hw->mac_type == e1000_82573)
2084 ew32(ERT, E1000_ERT_2048);
2086 /* Enable Receives */
2091 * e1000_free_tx_resources - Free Tx Resources per Queue
2092 * @adapter: board private structure
2093 * @tx_ring: Tx descriptor ring for a specific queue
2095 * Free all transmit software resources
2098 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2099 struct e1000_tx_ring *tx_ring)
2101 struct pci_dev *pdev = adapter->pdev;
2103 e1000_clean_tx_ring(adapter, tx_ring);
2105 vfree(tx_ring->buffer_info);
2106 tx_ring->buffer_info = NULL;
2108 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2110 tx_ring->desc = NULL;
2114 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2115 * @adapter: board private structure
2117 * Free all transmit software resources
2120 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
2124 for (i = 0; i < adapter->num_tx_queues; i++)
2125 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
2128 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2129 struct e1000_buffer *buffer_info)
2131 if (buffer_info->dma) {
2132 pci_unmap_page(adapter->pdev,
2134 buffer_info->length,
2136 buffer_info->dma = 0;
2138 if (buffer_info->skb) {
2139 dev_kfree_skb_any(buffer_info->skb);
2140 buffer_info->skb = NULL;
2142 /* buffer_info must be completely set up in the transmit path */
2146 * e1000_clean_tx_ring - Free Tx Buffers
2147 * @adapter: board private structure
2148 * @tx_ring: ring to be cleaned
2151 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2152 struct e1000_tx_ring *tx_ring)
2154 struct e1000_hw *hw = &adapter->hw;
2155 struct e1000_buffer *buffer_info;
2159 /* Free all the Tx ring sk_buffs */
2161 for (i = 0; i < tx_ring->count; i++) {
2162 buffer_info = &tx_ring->buffer_info[i];
2163 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2166 size = sizeof(struct e1000_buffer) * tx_ring->count;
2167 memset(tx_ring->buffer_info, 0, size);
2169 /* Zero out the descriptor ring */
2171 memset(tx_ring->desc, 0, tx_ring->size);
2173 tx_ring->next_to_use = 0;
2174 tx_ring->next_to_clean = 0;
2175 tx_ring->last_tx_tso = 0;
2177 writel(0, hw->hw_addr + tx_ring->tdh);
2178 writel(0, hw->hw_addr + tx_ring->tdt);
2182 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2183 * @adapter: board private structure
2186 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2190 for (i = 0; i < adapter->num_tx_queues; i++)
2191 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2195 * e1000_free_rx_resources - Free Rx Resources
2196 * @adapter: board private structure
2197 * @rx_ring: ring to clean the resources from
2199 * Free all receive software resources
2202 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2203 struct e1000_rx_ring *rx_ring)
2205 struct pci_dev *pdev = adapter->pdev;
2207 e1000_clean_rx_ring(adapter, rx_ring);
2209 vfree(rx_ring->buffer_info);
2210 rx_ring->buffer_info = NULL;
2211 kfree(rx_ring->ps_page);
2212 rx_ring->ps_page = NULL;
2213 kfree(rx_ring->ps_page_dma);
2214 rx_ring->ps_page_dma = NULL;
2216 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2218 rx_ring->desc = NULL;
2222 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2223 * @adapter: board private structure
2225 * Free all receive software resources
2228 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2232 for (i = 0; i < adapter->num_rx_queues; i++)
2233 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2237 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2238 * @adapter: board private structure
2239 * @rx_ring: ring to free buffers from
2242 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2243 struct e1000_rx_ring *rx_ring)
2245 struct e1000_hw *hw = &adapter->hw;
2246 struct e1000_buffer *buffer_info;
2247 struct e1000_ps_page *ps_page;
2248 struct e1000_ps_page_dma *ps_page_dma;
2249 struct pci_dev *pdev = adapter->pdev;
2253 /* Free all the Rx ring sk_buffs */
2254 for (i = 0; i < rx_ring->count; i++) {
2255 buffer_info = &rx_ring->buffer_info[i];
2256 if (buffer_info->skb) {
2257 pci_unmap_single(pdev,
2259 buffer_info->length,
2260 PCI_DMA_FROMDEVICE);
2262 dev_kfree_skb(buffer_info->skb);
2263 buffer_info->skb = NULL;
2265 ps_page = &rx_ring->ps_page[i];
2266 ps_page_dma = &rx_ring->ps_page_dma[i];
2267 for (j = 0; j < adapter->rx_ps_pages; j++) {
2268 if (!ps_page->ps_page[j]) break;
2269 pci_unmap_page(pdev,
2270 ps_page_dma->ps_page_dma[j],
2271 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2272 ps_page_dma->ps_page_dma[j] = 0;
2273 put_page(ps_page->ps_page[j]);
2274 ps_page->ps_page[j] = NULL;
2278 size = sizeof(struct e1000_buffer) * rx_ring->count;
2279 memset(rx_ring->buffer_info, 0, size);
2280 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2281 memset(rx_ring->ps_page, 0, size);
2282 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2283 memset(rx_ring->ps_page_dma, 0, size);
2285 /* Zero out the descriptor ring */
2287 memset(rx_ring->desc, 0, rx_ring->size);
2289 rx_ring->next_to_clean = 0;
2290 rx_ring->next_to_use = 0;
2292 writel(0, hw->hw_addr + rx_ring->rdh);
2293 writel(0, hw->hw_addr + rx_ring->rdt);
2297 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2298 * @adapter: board private structure
2301 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2305 for (i = 0; i < adapter->num_rx_queues; i++)
2306 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2309 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2310 * and memory write and invalidate disabled for certain operations
2312 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2314 struct e1000_hw *hw = &adapter->hw;
2315 struct net_device *netdev = adapter->netdev;
2318 e1000_pci_clear_mwi(hw);
2321 rctl |= E1000_RCTL_RST;
2323 E1000_WRITE_FLUSH();
2326 if (netif_running(netdev))
2327 e1000_clean_all_rx_rings(adapter);
2330 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2332 struct e1000_hw *hw = &adapter->hw;
2333 struct net_device *netdev = adapter->netdev;
2337 rctl &= ~E1000_RCTL_RST;
2339 E1000_WRITE_FLUSH();
2342 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2343 e1000_pci_set_mwi(hw);
2345 if (netif_running(netdev)) {
2346 /* No need to loop, because 82542 supports only 1 queue */
2347 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2348 e1000_configure_rx(adapter);
2349 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2354 * e1000_set_mac - Change the Ethernet Address of the NIC
2355 * @netdev: network interface device structure
2356 * @p: pointer to an address structure
2358 * Returns 0 on success, negative on failure
2361 static int e1000_set_mac(struct net_device *netdev, void *p)
2363 struct e1000_adapter *adapter = netdev_priv(netdev);
2364 struct e1000_hw *hw = &adapter->hw;
2365 struct sockaddr *addr = p;
2367 if (!is_valid_ether_addr(addr->sa_data))
2368 return -EADDRNOTAVAIL;
2370 /* 82542 2.0 needs to be in reset to write receive address registers */
2372 if (hw->mac_type == e1000_82542_rev2_0)
2373 e1000_enter_82542_rst(adapter);
2375 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2376 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2378 e1000_rar_set(hw, hw->mac_addr, 0);
2380 /* With 82571 controllers, LAA may be overwritten (with the default)
2381 * due to controller reset from the other port. */
2382 if (hw->mac_type == e1000_82571) {
2383 /* activate the work around */
2384 hw->laa_is_present = 1;
2386 /* Hold a copy of the LAA in RAR[14] This is done so that
2387 * between the time RAR[0] gets clobbered and the time it
2388 * gets fixed (in e1000_watchdog), the actual LAA is in one
2389 * of the RARs and no incoming packets directed to this port
2390 * are dropped. Eventaully the LAA will be in RAR[0] and
2392 e1000_rar_set(hw, hw->mac_addr,
2393 E1000_RAR_ENTRIES - 1);
2396 if (hw->mac_type == e1000_82542_rev2_0)
2397 e1000_leave_82542_rst(adapter);
2403 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2404 * @netdev: network interface device structure
2406 * The set_rx_mode entry point is called whenever the unicast or multicast
2407 * address lists or the network interface flags are updated. This routine is
2408 * responsible for configuring the hardware for proper unicast, multicast,
2409 * promiscuous mode, and all-multi behavior.
2412 static void e1000_set_rx_mode(struct net_device *netdev)
2414 struct e1000_adapter *adapter = netdev_priv(netdev);
2415 struct e1000_hw *hw = &adapter->hw;
2416 struct dev_addr_list *uc_ptr;
2417 struct dev_addr_list *mc_ptr;
2420 int i, rar_entries = E1000_RAR_ENTRIES;
2421 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2422 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2423 E1000_NUM_MTA_REGISTERS;
2425 if (hw->mac_type == e1000_ich8lan)
2426 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2428 /* reserve RAR[14] for LAA over-write work-around */
2429 if (hw->mac_type == e1000_82571)
2432 /* Check for Promiscuous and All Multicast modes */
2436 if (netdev->flags & IFF_PROMISC) {
2437 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2438 rctl &= ~E1000_RCTL_VFE;
2440 if (netdev->flags & IFF_ALLMULTI) {
2441 rctl |= E1000_RCTL_MPE;
2443 rctl &= ~E1000_RCTL_MPE;
2445 if (adapter->hw.mac_type != e1000_ich8lan)
2446 rctl |= E1000_RCTL_VFE;
2450 if (netdev->uc_count > rar_entries - 1) {
2451 rctl |= E1000_RCTL_UPE;
2452 } else if (!(netdev->flags & IFF_PROMISC)) {
2453 rctl &= ~E1000_RCTL_UPE;
2454 uc_ptr = netdev->uc_list;
2459 /* 82542 2.0 needs to be in reset to write receive address registers */
2461 if (hw->mac_type == e1000_82542_rev2_0)
2462 e1000_enter_82542_rst(adapter);
2464 /* load the first 14 addresses into the exact filters 1-14. Unicast
2465 * addresses take precedence to avoid disabling unicast filtering
2468 * RAR 0 is used for the station MAC adddress
2469 * if there are not 14 addresses, go ahead and clear the filters
2470 * -- with 82571 controllers only 0-13 entries are filled here
2472 mc_ptr = netdev->mc_list;
2474 for (i = 1; i < rar_entries; i++) {
2476 e1000_rar_set(hw, uc_ptr->da_addr, i);
2477 uc_ptr = uc_ptr->next;
2478 } else if (mc_ptr) {
2479 e1000_rar_set(hw, mc_ptr->da_addr, i);
2480 mc_ptr = mc_ptr->next;
2482 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2483 E1000_WRITE_FLUSH();
2484 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2485 E1000_WRITE_FLUSH();
2488 WARN_ON(uc_ptr != NULL);
2490 /* clear the old settings from the multicast hash table */
2492 for (i = 0; i < mta_reg_count; i++) {
2493 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2494 E1000_WRITE_FLUSH();
2497 /* load any remaining addresses into the hash table */
2499 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2500 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
2501 e1000_mta_set(hw, hash_value);
2504 if (hw->mac_type == e1000_82542_rev2_0)
2505 e1000_leave_82542_rst(adapter);
2508 /* Need to wait a few seconds after link up to get diagnostic information from
2511 static void e1000_update_phy_info(unsigned long data)
2513 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2514 struct e1000_hw *hw = &adapter->hw;
2515 e1000_phy_get_info(hw, &adapter->phy_info);
2519 * e1000_82547_tx_fifo_stall - Timer Call-back
2520 * @data: pointer to adapter cast into an unsigned long
2523 static void e1000_82547_tx_fifo_stall(unsigned long data)
2525 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2526 struct e1000_hw *hw = &adapter->hw;
2527 struct net_device *netdev = adapter->netdev;
2530 if (atomic_read(&adapter->tx_fifo_stall)) {
2531 if ((er32(TDT) == er32(TDH)) &&
2532 (er32(TDFT) == er32(TDFH)) &&
2533 (er32(TDFTS) == er32(TDFHS))) {
2535 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2536 ew32(TDFT, adapter->tx_head_addr);
2537 ew32(TDFH, adapter->tx_head_addr);
2538 ew32(TDFTS, adapter->tx_head_addr);
2539 ew32(TDFHS, adapter->tx_head_addr);
2541 E1000_WRITE_FLUSH();
2543 adapter->tx_fifo_head = 0;
2544 atomic_set(&adapter->tx_fifo_stall, 0);
2545 netif_wake_queue(netdev);
2547 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2553 * e1000_watchdog - Timer Call-back
2554 * @data: pointer to adapter cast into an unsigned long
2556 static void e1000_watchdog(unsigned long data)
2558 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2559 struct e1000_hw *hw = &adapter->hw;
2560 struct net_device *netdev = adapter->netdev;
2561 struct e1000_tx_ring *txdr = adapter->tx_ring;
2565 ret_val = e1000_check_for_link(hw);
2566 if ((ret_val == E1000_ERR_PHY) &&
2567 (hw->phy_type == e1000_phy_igp_3) &&
2568 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2569 /* See e1000_kumeran_lock_loss_workaround() */
2571 "Gigabit has been disabled, downgrading speed\n");
2574 if (hw->mac_type == e1000_82573) {
2575 e1000_enable_tx_pkt_filtering(hw);
2576 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
2577 e1000_update_mng_vlan(adapter);
2580 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2581 !(er32(TXCW) & E1000_TXCW_ANE))
2582 link = !hw->serdes_link_down;
2584 link = er32(STATUS) & E1000_STATUS_LU;
2587 if (!netif_carrier_ok(netdev)) {
2590 e1000_get_speed_and_duplex(hw,
2591 &adapter->link_speed,
2592 &adapter->link_duplex);
2595 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2596 "Flow Control: %s\n",
2597 adapter->link_speed,
2598 adapter->link_duplex == FULL_DUPLEX ?
2599 "Full Duplex" : "Half Duplex",
2600 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2601 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2602 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2603 E1000_CTRL_TFCE) ? "TX" : "None" )));
2605 /* tweak tx_queue_len according to speed/duplex
2606 * and adjust the timeout factor */
2607 netdev->tx_queue_len = adapter->tx_queue_len;
2608 adapter->tx_timeout_factor = 1;
2609 switch (adapter->link_speed) {
2612 netdev->tx_queue_len = 10;
2613 adapter->tx_timeout_factor = 8;
2617 netdev->tx_queue_len = 100;
2618 /* maybe add some timeout factor ? */
2622 if ((hw->mac_type == e1000_82571 ||
2623 hw->mac_type == e1000_82572) &&
2626 tarc0 = er32(TARC0);
2627 tarc0 &= ~(1 << 21);
2631 /* disable TSO for pcie and 10/100 speeds, to avoid
2632 * some hardware issues */
2633 if (!adapter->tso_force &&
2634 hw->bus_type == e1000_bus_type_pci_express){
2635 switch (adapter->link_speed) {
2639 "10/100 speed: disabling TSO\n");
2640 netdev->features &= ~NETIF_F_TSO;
2641 netdev->features &= ~NETIF_F_TSO6;
2644 netdev->features |= NETIF_F_TSO;
2645 netdev->features |= NETIF_F_TSO6;
2653 /* enable transmits in the hardware, need to do this
2654 * after setting TARC0 */
2656 tctl |= E1000_TCTL_EN;
2659 netif_carrier_on(netdev);
2660 netif_wake_queue(netdev);
2661 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2662 adapter->smartspeed = 0;
2664 /* make sure the receive unit is started */
2665 if (hw->rx_needs_kicking) {
2666 u32 rctl = er32(RCTL);
2667 ew32(RCTL, rctl | E1000_RCTL_EN);
2671 if (netif_carrier_ok(netdev)) {
2672 adapter->link_speed = 0;
2673 adapter->link_duplex = 0;
2674 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2675 netif_carrier_off(netdev);
2676 netif_stop_queue(netdev);
2677 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2679 /* 80003ES2LAN workaround--
2680 * For packet buffer work-around on link down event;
2681 * disable receives in the ISR and
2682 * reset device here in the watchdog
2684 if (hw->mac_type == e1000_80003es2lan)
2686 schedule_work(&adapter->reset_task);
2689 e1000_smartspeed(adapter);
2692 e1000_update_stats(adapter);
2694 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2695 adapter->tpt_old = adapter->stats.tpt;
2696 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2697 adapter->colc_old = adapter->stats.colc;
2699 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2700 adapter->gorcl_old = adapter->stats.gorcl;
2701 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2702 adapter->gotcl_old = adapter->stats.gotcl;
2704 e1000_update_adaptive(hw);
2706 if (!netif_carrier_ok(netdev)) {
2707 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2708 /* We've lost link, so the controller stops DMA,
2709 * but we've got queued Tx work that's never going
2710 * to get done, so reset controller to flush Tx.
2711 * (Do the reset outside of interrupt context). */
2712 adapter->tx_timeout_count++;
2713 schedule_work(&adapter->reset_task);
2717 /* Cause software interrupt to ensure rx ring is cleaned */
2718 ew32(ICS, E1000_ICS_RXDMT0);
2720 /* Force detection of hung controller every watchdog period */
2721 adapter->detect_tx_hung = true;
2723 /* With 82571 controllers, LAA may be overwritten due to controller
2724 * reset from the other port. Set the appropriate LAA in RAR[0] */
2725 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2726 e1000_rar_set(hw, hw->mac_addr, 0);
2728 /* Reset the timer */
2729 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
2732 enum latency_range {
2736 latency_invalid = 255
2740 * e1000_update_itr - update the dynamic ITR value based on statistics
2741 * Stores a new ITR value based on packets and byte
2742 * counts during the last interrupt. The advantage of per interrupt
2743 * computation is faster updates and more accurate ITR for the current
2744 * traffic pattern. Constants in this function were computed
2745 * based on theoretical maximum wire speed and thresholds were set based
2746 * on testing data as well as attempting to minimize response time
2747 * while increasing bulk throughput.
2748 * this functionality is controlled by the InterruptThrottleRate module
2749 * parameter (see e1000_param.c)
2750 * @adapter: pointer to adapter
2751 * @itr_setting: current adapter->itr
2752 * @packets: the number of packets during this measurement interval
2753 * @bytes: the number of bytes during this measurement interval
2755 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2756 u16 itr_setting, int packets, int bytes)
2758 unsigned int retval = itr_setting;
2759 struct e1000_hw *hw = &adapter->hw;
2761 if (unlikely(hw->mac_type < e1000_82540))
2762 goto update_itr_done;
2765 goto update_itr_done;
2767 switch (itr_setting) {
2768 case lowest_latency:
2769 /* jumbo frames get bulk treatment*/
2770 if (bytes/packets > 8000)
2771 retval = bulk_latency;
2772 else if ((packets < 5) && (bytes > 512))
2773 retval = low_latency;
2775 case low_latency: /* 50 usec aka 20000 ints/s */
2776 if (bytes > 10000) {
2777 /* jumbo frames need bulk latency setting */
2778 if (bytes/packets > 8000)
2779 retval = bulk_latency;
2780 else if ((packets < 10) || ((bytes/packets) > 1200))
2781 retval = bulk_latency;
2782 else if ((packets > 35))
2783 retval = lowest_latency;
2784 } else if (bytes/packets > 2000)
2785 retval = bulk_latency;
2786 else if (packets <= 2 && bytes < 512)
2787 retval = lowest_latency;
2789 case bulk_latency: /* 250 usec aka 4000 ints/s */
2790 if (bytes > 25000) {
2792 retval = low_latency;
2793 } else if (bytes < 6000) {
2794 retval = low_latency;
2803 static void e1000_set_itr(struct e1000_adapter *adapter)
2805 struct e1000_hw *hw = &adapter->hw;
2807 u32 new_itr = adapter->itr;
2809 if (unlikely(hw->mac_type < e1000_82540))
2812 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2813 if (unlikely(adapter->link_speed != SPEED_1000)) {
2819 adapter->tx_itr = e1000_update_itr(adapter,
2821 adapter->total_tx_packets,
2822 adapter->total_tx_bytes);
2823 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2824 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2825 adapter->tx_itr = low_latency;
2827 adapter->rx_itr = e1000_update_itr(adapter,
2829 adapter->total_rx_packets,
2830 adapter->total_rx_bytes);
2831 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2832 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2833 adapter->rx_itr = low_latency;
2835 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2837 switch (current_itr) {
2838 /* counts and packets in update_itr are dependent on these numbers */
2839 case lowest_latency:
2843 new_itr = 20000; /* aka hwitr = ~200 */
2853 if (new_itr != adapter->itr) {
2854 /* this attempts to bias the interrupt rate towards Bulk
2855 * by adding intermediate steps when interrupt rate is
2857 new_itr = new_itr > adapter->itr ?
2858 min(adapter->itr + (new_itr >> 2), new_itr) :
2860 adapter->itr = new_itr;
2861 ew32(ITR, 1000000000 / (new_itr * 256));
2867 #define E1000_TX_FLAGS_CSUM 0x00000001
2868 #define E1000_TX_FLAGS_VLAN 0x00000002
2869 #define E1000_TX_FLAGS_TSO 0x00000004
2870 #define E1000_TX_FLAGS_IPV4 0x00000008
2871 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2872 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2874 static int e1000_tso(struct e1000_adapter *adapter,
2875 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2877 struct e1000_context_desc *context_desc;
2878 struct e1000_buffer *buffer_info;
2881 u16 ipcse = 0, tucse, mss;
2882 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2885 if (skb_is_gso(skb)) {
2886 if (skb_header_cloned(skb)) {
2887 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2892 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2893 mss = skb_shinfo(skb)->gso_size;
2894 if (skb->protocol == htons(ETH_P_IP)) {
2895 struct iphdr *iph = ip_hdr(skb);
2898 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2902 cmd_length = E1000_TXD_CMD_IP;
2903 ipcse = skb_transport_offset(skb) - 1;
2904 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2905 ipv6_hdr(skb)->payload_len = 0;
2906 tcp_hdr(skb)->check =
2907 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2908 &ipv6_hdr(skb)->daddr,
2912 ipcss = skb_network_offset(skb);
2913 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2914 tucss = skb_transport_offset(skb);
2915 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2918 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2919 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2921 i = tx_ring->next_to_use;
2922 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2923 buffer_info = &tx_ring->buffer_info[i];
2925 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2926 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2927 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2928 context_desc->upper_setup.tcp_fields.tucss = tucss;
2929 context_desc->upper_setup.tcp_fields.tucso = tucso;
2930 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2931 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2932 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2933 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2935 buffer_info->time_stamp = jiffies;
2936 buffer_info->next_to_watch = i;
2938 if (++i == tx_ring->count) i = 0;
2939 tx_ring->next_to_use = i;
2946 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2947 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2949 struct e1000_context_desc *context_desc;
2950 struct e1000_buffer *buffer_info;
2954 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
2955 css = skb_transport_offset(skb);
2957 i = tx_ring->next_to_use;
2958 buffer_info = &tx_ring->buffer_info[i];
2959 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2961 context_desc->lower_setup.ip_config = 0;
2962 context_desc->upper_setup.tcp_fields.tucss = css;
2963 context_desc->upper_setup.tcp_fields.tucso =
2964 css + skb->csum_offset;
2965 context_desc->upper_setup.tcp_fields.tucse = 0;
2966 context_desc->tcp_seg_setup.data = 0;
2967 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2969 buffer_info->time_stamp = jiffies;
2970 buffer_info->next_to_watch = i;
2972 if (unlikely(++i == tx_ring->count)) i = 0;
2973 tx_ring->next_to_use = i;
2981 #define E1000_MAX_TXD_PWR 12
2982 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2984 static int e1000_tx_map(struct e1000_adapter *adapter,
2985 struct e1000_tx_ring *tx_ring,
2986 struct sk_buff *skb, unsigned int first,
2987 unsigned int max_per_txd, unsigned int nr_frags,
2990 struct e1000_hw *hw = &adapter->hw;
2991 struct e1000_buffer *buffer_info;
2992 unsigned int len = skb->len;
2993 unsigned int offset = 0, size, count = 0, i;
2995 len -= skb->data_len;
2997 i = tx_ring->next_to_use;
3000 buffer_info = &tx_ring->buffer_info[i];
3001 size = min(len, max_per_txd);
3002 /* Workaround for Controller erratum --
3003 * descriptor for non-tso packet in a linear SKB that follows a
3004 * tso gets written back prematurely before the data is fully
3005 * DMA'd to the controller */
3006 if (!skb->data_len && tx_ring->last_tx_tso &&
3008 tx_ring->last_tx_tso = 0;
3012 /* Workaround for premature desc write-backs
3013 * in TSO mode. Append 4-byte sentinel desc */
3014 if (unlikely(mss && !nr_frags && size == len && size > 8))
3016 /* work-around for errata 10 and it applies
3017 * to all controllers in PCI-X mode
3018 * The fix is to make sure that the first descriptor of a
3019 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3021 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3022 (size > 2015) && count == 0))
3025 /* Workaround for potential 82544 hang in PCI-X. Avoid
3026 * terminating buffers within evenly-aligned dwords. */
3027 if (unlikely(adapter->pcix_82544 &&
3028 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3032 buffer_info->length = size;
3034 pci_map_single(adapter->pdev,
3038 buffer_info->time_stamp = jiffies;
3039 buffer_info->next_to_watch = i;
3044 if (unlikely(++i == tx_ring->count)) i = 0;
3047 for (f = 0; f < nr_frags; f++) {
3048 struct skb_frag_struct *frag;
3050 frag = &skb_shinfo(skb)->frags[f];
3052 offset = frag->page_offset;
3055 buffer_info = &tx_ring->buffer_info[i];
3056 size = min(len, max_per_txd);
3057 /* Workaround for premature desc write-backs
3058 * in TSO mode. Append 4-byte sentinel desc */
3059 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
3061 /* Workaround for potential 82544 hang in PCI-X.
3062 * Avoid terminating buffers within evenly-aligned
3064 if (unlikely(adapter->pcix_82544 &&
3065 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3069 buffer_info->length = size;
3071 pci_map_page(adapter->pdev,
3076 buffer_info->time_stamp = jiffies;
3077 buffer_info->next_to_watch = i;
3082 if (unlikely(++i == tx_ring->count)) i = 0;
3086 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3087 tx_ring->buffer_info[i].skb = skb;
3088 tx_ring->buffer_info[first].next_to_watch = i;
3093 static void e1000_tx_queue(struct e1000_adapter *adapter,
3094 struct e1000_tx_ring *tx_ring, int tx_flags,
3097 struct e1000_hw *hw = &adapter->hw;
3098 struct e1000_tx_desc *tx_desc = NULL;
3099 struct e1000_buffer *buffer_info;
3100 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3103 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
3104 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3106 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3108 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3109 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3112 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3113 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3114 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3117 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3118 txd_lower |= E1000_TXD_CMD_VLE;
3119 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3122 i = tx_ring->next_to_use;
3125 buffer_info = &tx_ring->buffer_info[i];
3126 tx_desc = E1000_TX_DESC(*tx_ring, i);
3127 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3128 tx_desc->lower.data =
3129 cpu_to_le32(txd_lower | buffer_info->length);
3130 tx_desc->upper.data = cpu_to_le32(txd_upper);
3131 if (unlikely(++i == tx_ring->count)) i = 0;
3134 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3136 /* Force memory writes to complete before letting h/w
3137 * know there are new descriptors to fetch. (Only
3138 * applicable for weak-ordered memory model archs,
3139 * such as IA-64). */
3142 tx_ring->next_to_use = i;
3143 writel(i, hw->hw_addr + tx_ring->tdt);
3144 /* we need this if more than one processor can write to our tail
3145 * at a time, it syncronizes IO on IA64/Altix systems */
3150 * 82547 workaround to avoid controller hang in half-duplex environment.
3151 * The workaround is to avoid queuing a large packet that would span
3152 * the internal Tx FIFO ring boundary by notifying the stack to resend
3153 * the packet at a later time. This gives the Tx FIFO an opportunity to
3154 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3155 * to the beginning of the Tx FIFO.
3158 #define E1000_FIFO_HDR 0x10
3159 #define E1000_82547_PAD_LEN 0x3E0
3161 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3162 struct sk_buff *skb)
3164 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3165 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3167 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3169 if (adapter->link_duplex != HALF_DUPLEX)
3170 goto no_fifo_stall_required;
3172 if (atomic_read(&adapter->tx_fifo_stall))
3175 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3176 atomic_set(&adapter->tx_fifo_stall, 1);
3180 no_fifo_stall_required:
3181 adapter->tx_fifo_head += skb_fifo_len;
3182 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3183 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3187 #define MINIMUM_DHCP_PACKET_SIZE 282
3188 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3189 struct sk_buff *skb)
3191 struct e1000_hw *hw = &adapter->hw;
3193 if (vlan_tx_tag_present(skb)) {
3194 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3195 ( hw->mng_cookie.status &
3196 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3199 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
3200 struct ethhdr *eth = (struct ethhdr *)skb->data;
3201 if ((htons(ETH_P_IP) == eth->h_proto)) {
3202 const struct iphdr *ip =
3203 (struct iphdr *)((u8 *)skb->data+14);
3204 if (IPPROTO_UDP == ip->protocol) {
3205 struct udphdr *udp =
3206 (struct udphdr *)((u8 *)ip +
3208 if (ntohs(udp->dest) == 67) {
3209 offset = (u8 *)udp + 8 - skb->data;
3210 length = skb->len - offset;
3212 return e1000_mng_write_dhcp_info(hw,
3222 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3224 struct e1000_adapter *adapter = netdev_priv(netdev);
3225 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3227 netif_stop_queue(netdev);
3228 /* Herbert's original patch had:
3229 * smp_mb__after_netif_stop_queue();
3230 * but since that doesn't exist yet, just open code it. */
3233 /* We need to check again in a case another CPU has just
3234 * made room available. */
3235 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3239 netif_start_queue(netdev);
3240 ++adapter->restart_queue;
3244 static int e1000_maybe_stop_tx(struct net_device *netdev,
3245 struct e1000_tx_ring *tx_ring, int size)
3247 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3249 return __e1000_maybe_stop_tx(netdev, size);
3252 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3253 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3255 struct e1000_adapter *adapter = netdev_priv(netdev);
3256 struct e1000_hw *hw = &adapter->hw;
3257 struct e1000_tx_ring *tx_ring;
3258 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3259 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3260 unsigned int tx_flags = 0;
3261 unsigned int len = skb->len - skb->data_len;
3262 unsigned long flags;
3263 unsigned int nr_frags;
3269 /* This goes back to the question of how to logically map a tx queue
3270 * to a flow. Right now, performance is impacted slightly negatively
3271 * if using multiple tx queues. If the stack breaks away from a
3272 * single qdisc implementation, we can look at this again. */
3273 tx_ring = adapter->tx_ring;
3275 if (unlikely(skb->len <= 0)) {
3276 dev_kfree_skb_any(skb);
3277 return NETDEV_TX_OK;
3280 /* 82571 and newer doesn't need the workaround that limited descriptor
3282 if (hw->mac_type >= e1000_82571)
3285 mss = skb_shinfo(skb)->gso_size;
3286 /* The controller does a simple calculation to
3287 * make sure there is enough room in the FIFO before
3288 * initiating the DMA for each buffer. The calc is:
3289 * 4 = ceil(buffer len/mss). To make sure we don't
3290 * overrun the FIFO, adjust the max buffer len if mss
3294 max_per_txd = min(mss << 2, max_per_txd);
3295 max_txd_pwr = fls(max_per_txd) - 1;
3297 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3298 * points to just header, pull a few bytes of payload from
3299 * frags into skb->data */
3300 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3301 if (skb->data_len && hdr_len == len) {
3302 switch (hw->mac_type) {
3303 unsigned int pull_size;
3305 /* Make sure we have room to chop off 4 bytes,
3306 * and that the end alignment will work out to
3307 * this hardware's requirements
3308 * NOTE: this is a TSO only workaround
3309 * if end byte alignment not correct move us
3310 * into the next dword */
3311 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
3318 pull_size = min((unsigned int)4, skb->data_len);
3319 if (!__pskb_pull_tail(skb, pull_size)) {
3321 "__pskb_pull_tail failed.\n");
3322 dev_kfree_skb_any(skb);
3323 return NETDEV_TX_OK;
3325 len = skb->len - skb->data_len;
3334 /* reserve a descriptor for the offload context */
3335 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3339 /* Controller Erratum workaround */
3340 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3343 count += TXD_USE_COUNT(len, max_txd_pwr);
3345 if (adapter->pcix_82544)
3348 /* work-around for errata 10 and it applies to all controllers
3349 * in PCI-X mode, so add one more descriptor to the count
3351 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3355 nr_frags = skb_shinfo(skb)->nr_frags;
3356 for (f = 0; f < nr_frags; f++)
3357 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3359 if (adapter->pcix_82544)
3363 if (hw->tx_pkt_filtering &&
3364 (hw->mac_type == e1000_82573))
3365 e1000_transfer_dhcp_info(adapter, skb);
3367 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
3368 /* Collision - tell upper layer to requeue */
3369 return NETDEV_TX_LOCKED;
3371 /* need: count + 2 desc gap to keep tail from touching
3372 * head, otherwise try next time */
3373 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
3374 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3375 return NETDEV_TX_BUSY;
3378 if (unlikely(hw->mac_type == e1000_82547)) {
3379 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3380 netif_stop_queue(netdev);
3381 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3382 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3383 return NETDEV_TX_BUSY;
3387 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3388 tx_flags |= E1000_TX_FLAGS_VLAN;
3389 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3392 first = tx_ring->next_to_use;
3394 tso = e1000_tso(adapter, tx_ring, skb);
3396 dev_kfree_skb_any(skb);
3397 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3398 return NETDEV_TX_OK;
3402 tx_ring->last_tx_tso = 1;
3403 tx_flags |= E1000_TX_FLAGS_TSO;
3404 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3405 tx_flags |= E1000_TX_FLAGS_CSUM;
3407 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3408 * 82571 hardware supports TSO capabilities for IPv6 as well...
3409 * no longer assume, we must. */
3410 if (likely(skb->protocol == htons(ETH_P_IP)))
3411 tx_flags |= E1000_TX_FLAGS_IPV4;
3413 e1000_tx_queue(adapter, tx_ring, tx_flags,
3414 e1000_tx_map(adapter, tx_ring, skb, first,
3415 max_per_txd, nr_frags, mss));
3417 netdev->trans_start = jiffies;
3419 /* Make sure there is space in the ring for the next send. */
3420 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3422 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3423 return NETDEV_TX_OK;
3427 * e1000_tx_timeout - Respond to a Tx Hang
3428 * @netdev: network interface device structure
3431 static void e1000_tx_timeout(struct net_device *netdev)
3433 struct e1000_adapter *adapter = netdev_priv(netdev);
3435 /* Do the reset outside of interrupt context */
3436 adapter->tx_timeout_count++;
3437 schedule_work(&adapter->reset_task);
3440 static void e1000_reset_task(struct work_struct *work)
3442 struct e1000_adapter *adapter =
3443 container_of(work, struct e1000_adapter, reset_task);
3445 e1000_reinit_locked(adapter);
3449 * e1000_get_stats - Get System Network Statistics
3450 * @netdev: network interface device structure
3452 * Returns the address of the device statistics structure.
3453 * The statistics are actually updated from the timer callback.
3456 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3458 struct e1000_adapter *adapter = netdev_priv(netdev);
3460 /* only return the current stats */
3461 return &adapter->net_stats;
3465 * e1000_change_mtu - Change the Maximum Transfer Unit
3466 * @netdev: network interface device structure
3467 * @new_mtu: new value for maximum frame size
3469 * Returns 0 on success, negative on failure
3472 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3474 struct e1000_adapter *adapter = netdev_priv(netdev);
3475 struct e1000_hw *hw = &adapter->hw;
3476 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3477 u16 eeprom_data = 0;
3479 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3480 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3481 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3485 /* Adapter-specific max frame size limits. */
3486 switch (hw->mac_type) {
3487 case e1000_undefined ... e1000_82542_rev2_1:
3489 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3490 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3495 /* Jumbo Frames not supported if:
3496 * - this is not an 82573L device
3497 * - ASPM is enabled in any way (0x1A bits 3:2) */
3498 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
3500 if ((hw->device_id != E1000_DEV_ID_82573L) ||
3501 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3502 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3504 "Jumbo Frames not supported.\n");
3509 /* ERT will be enabled later to enable wire speed receives */
3511 /* fall through to get support */
3514 case e1000_80003es2lan:
3515 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3516 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3517 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3522 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3526 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3527 * means we reserve 2 more, this pushes us to allocate from the next
3529 * i.e. RXBUFFER_2048 --> size-4096 slab */
3531 if (max_frame <= E1000_RXBUFFER_256)
3532 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3533 else if (max_frame <= E1000_RXBUFFER_512)
3534 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3535 else if (max_frame <= E1000_RXBUFFER_1024)
3536 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3537 else if (max_frame <= E1000_RXBUFFER_2048)
3538 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3539 else if (max_frame <= E1000_RXBUFFER_4096)
3540 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3541 else if (max_frame <= E1000_RXBUFFER_8192)
3542 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3543 else if (max_frame <= E1000_RXBUFFER_16384)
3544 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3546 /* adjust allocation if LPE protects us, and we aren't using SBP */
3547 if (!hw->tbi_compatibility_on &&
3548 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3549 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3550 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3552 netdev->mtu = new_mtu;
3553 hw->max_frame_size = max_frame;
3555 if (netif_running(netdev))
3556 e1000_reinit_locked(adapter);
3562 * e1000_update_stats - Update the board statistics counters
3563 * @adapter: board private structure
3566 void e1000_update_stats(struct e1000_adapter *adapter)
3568 struct e1000_hw *hw = &adapter->hw;
3569 struct pci_dev *pdev = adapter->pdev;
3570 unsigned long flags;
3573 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3576 * Prevent stats update while adapter is being reset, or if the pci
3577 * connection is down.
3579 if (adapter->link_speed == 0)
3581 if (pci_channel_offline(pdev))
3584 spin_lock_irqsave(&adapter->stats_lock, flags);
3586 /* these counters are modified from e1000_tbi_adjust_stats,
3587 * called from the interrupt context, so they must only
3588 * be written while holding adapter->stats_lock
3591 adapter->stats.crcerrs += er32(CRCERRS);
3592 adapter->stats.gprc += er32(GPRC);
3593 adapter->stats.gorcl += er32(GORCL);
3594 adapter->stats.gorch += er32(GORCH);
3595 adapter->stats.bprc += er32(BPRC);
3596 adapter->stats.mprc += er32(MPRC);
3597 adapter->stats.roc += er32(ROC);
3599 if (hw->mac_type != e1000_ich8lan) {
3600 adapter->stats.prc64 += er32(PRC64);
3601 adapter->stats.prc127 += er32(PRC127);
3602 adapter->stats.prc255 += er32(PRC255);
3603 adapter->stats.prc511 += er32(PRC511);
3604 adapter->stats.prc1023 += er32(PRC1023);
3605 adapter->stats.prc1522 += er32(PRC1522);
3608 adapter->stats.symerrs += er32(SYMERRS);
3609 adapter->stats.mpc += er32(MPC);
3610 adapter->stats.scc += er32(SCC);
3611 adapter->stats.ecol += er32(ECOL);
3612 adapter->stats.mcc += er32(MCC);
3613 adapter->stats.latecol += er32(LATECOL);
3614 adapter->stats.dc += er32(DC);
3615 adapter->stats.sec += er32(SEC);
3616 adapter->stats.rlec += er32(RLEC);
3617 adapter->stats.xonrxc += er32(XONRXC);
3618 adapter->stats.xontxc += er32(XONTXC);
3619 adapter->stats.xoffrxc += er32(XOFFRXC);
3620 adapter->stats.xofftxc += er32(XOFFTXC);
3621 adapter->stats.fcruc += er32(FCRUC);
3622 adapter->stats.gptc += er32(GPTC);
3623 adapter->stats.gotcl += er32(GOTCL);
3624 adapter->stats.gotch += er32(GOTCH);
3625 adapter->stats.rnbc += er32(RNBC);
3626 adapter->stats.ruc += er32(RUC);
3627 adapter->stats.rfc += er32(RFC);
3628 adapter->stats.rjc += er32(RJC);
3629 adapter->stats.torl += er32(TORL);
3630 adapter->stats.torh += er32(TORH);
3631 adapter->stats.totl += er32(TOTL);
3632 adapter->stats.toth += er32(TOTH);
3633 adapter->stats.tpr += er32(TPR);
3635 if (hw->mac_type != e1000_ich8lan) {
3636 adapter->stats.ptc64 += er32(PTC64);
3637 adapter->stats.ptc127 += er32(PTC127);
3638 adapter->stats.ptc255 += er32(PTC255);
3639 adapter->stats.ptc511 += er32(PTC511);
3640 adapter->stats.ptc1023 += er32(PTC1023);
3641 adapter->stats.ptc1522 += er32(PTC1522);
3644 adapter->stats.mptc += er32(MPTC);
3645 adapter->stats.bptc += er32(BPTC);
3647 /* used for adaptive IFS */
3649 hw->tx_packet_delta = er32(TPT);
3650 adapter->stats.tpt += hw->tx_packet_delta;
3651 hw->collision_delta = er32(COLC);
3652 adapter->stats.colc += hw->collision_delta;
3654 if (hw->mac_type >= e1000_82543) {
3655 adapter->stats.algnerrc += er32(ALGNERRC);
3656 adapter->stats.rxerrc += er32(RXERRC);
3657 adapter->stats.tncrs += er32(TNCRS);
3658 adapter->stats.cexterr += er32(CEXTERR);
3659 adapter->stats.tsctc += er32(TSCTC);
3660 adapter->stats.tsctfc += er32(TSCTFC);
3662 if (hw->mac_type > e1000_82547_rev_2) {
3663 adapter->stats.iac += er32(IAC);
3664 adapter->stats.icrxoc += er32(ICRXOC);
3666 if (hw->mac_type != e1000_ich8lan) {
3667 adapter->stats.icrxptc += er32(ICRXPTC);
3668 adapter->stats.icrxatc += er32(ICRXATC);
3669 adapter->stats.ictxptc += er32(ICTXPTC);
3670 adapter->stats.ictxatc += er32(ICTXATC);
3671 adapter->stats.ictxqec += er32(ICTXQEC);
3672 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3673 adapter->stats.icrxdmtc += er32(ICRXDMTC);
3677 /* Fill out the OS statistics structure */
3678 adapter->net_stats.multicast = adapter->stats.mprc;
3679 adapter->net_stats.collisions = adapter->stats.colc;
3683 /* RLEC on some newer hardware can be incorrect so build
3684 * our own version based on RUC and ROC */
3685 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3686 adapter->stats.crcerrs + adapter->stats.algnerrc +
3687 adapter->stats.ruc + adapter->stats.roc +
3688 adapter->stats.cexterr;
3689 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3690 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3691 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3692 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3693 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3696 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3697 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3698 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3699 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3700 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3701 if (hw->bad_tx_carr_stats_fd &&
3702 adapter->link_duplex == FULL_DUPLEX) {
3703 adapter->net_stats.tx_carrier_errors = 0;
3704 adapter->stats.tncrs = 0;
3707 /* Tx Dropped needs to be maintained elsewhere */
3710 if (hw->media_type == e1000_media_type_copper) {
3711 if ((adapter->link_speed == SPEED_1000) &&
3712 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3713 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3714 adapter->phy_stats.idle_errors += phy_tmp;
3717 if ((hw->mac_type <= e1000_82546) &&
3718 (hw->phy_type == e1000_phy_m88) &&
3719 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3720 adapter->phy_stats.receive_errors += phy_tmp;
3723 /* Management Stats */
3724 if (hw->has_smbus) {
3725 adapter->stats.mgptc += er32(MGTPTC);
3726 adapter->stats.mgprc += er32(MGTPRC);
3727 adapter->stats.mgpdc += er32(MGTPDC);
3730 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3734 * e1000_intr_msi - Interrupt Handler
3735 * @irq: interrupt number
3736 * @data: pointer to a network interface device structure
3739 static irqreturn_t e1000_intr_msi(int irq, void *data)
3741 struct net_device *netdev = data;
3742 struct e1000_adapter *adapter = netdev_priv(netdev);
3743 struct e1000_hw *hw = &adapter->hw;
3744 u32 icr = er32(ICR);
3746 /* in NAPI mode read ICR disables interrupts using IAM */
3748 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3749 hw->get_link_status = 1;
3750 /* 80003ES2LAN workaround-- For packet buffer work-around on
3751 * link down event; disable receives here in the ISR and reset
3752 * adapter in watchdog */
3753 if (netif_carrier_ok(netdev) &&
3754 (hw->mac_type == e1000_80003es2lan)) {
3755 /* disable receives */
3756 u32 rctl = er32(RCTL);
3757 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3759 /* guard against interrupt when we're going down */
3760 if (!test_bit(__E1000_DOWN, &adapter->flags))
3761 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3764 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3765 adapter->total_tx_bytes = 0;
3766 adapter->total_tx_packets = 0;
3767 adapter->total_rx_bytes = 0;
3768 adapter->total_rx_packets = 0;
3769 __netif_rx_schedule(netdev, &adapter->napi);
3771 e1000_irq_enable(adapter);
3777 * e1000_intr - Interrupt Handler
3778 * @irq: interrupt number
3779 * @data: pointer to a network interface device structure
3782 static irqreturn_t e1000_intr(int irq, void *data)
3784 struct net_device *netdev = data;
3785 struct e1000_adapter *adapter = netdev_priv(netdev);
3786 struct e1000_hw *hw = &adapter->hw;
3787 u32 rctl, icr = er32(ICR);
3790 return IRQ_NONE; /* Not our interrupt */
3792 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3793 * not set, then the adapter didn't send an interrupt */
3794 if (unlikely(hw->mac_type >= e1000_82571 &&
3795 !(icr & E1000_ICR_INT_ASSERTED)))
3798 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3799 * need for the IMC write */
3801 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3802 hw->get_link_status = 1;
3803 /* 80003ES2LAN workaround--
3804 * For packet buffer work-around on link down event;
3805 * disable receives here in the ISR and
3806 * reset adapter in watchdog
3808 if (netif_carrier_ok(netdev) &&
3809 (hw->mac_type == e1000_80003es2lan)) {
3810 /* disable receives */
3812 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3814 /* guard against interrupt when we're going down */
3815 if (!test_bit(__E1000_DOWN, &adapter->flags))
3816 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3819 if (unlikely(hw->mac_type < e1000_82571)) {
3820 /* disable interrupts, without the synchronize_irq bit */
3822 E1000_WRITE_FLUSH();
3824 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3825 adapter->total_tx_bytes = 0;
3826 adapter->total_tx_packets = 0;
3827 adapter->total_rx_bytes = 0;
3828 adapter->total_rx_packets = 0;
3829 __netif_rx_schedule(netdev, &adapter->napi);
3831 /* this really should not happen! if it does it is basically a
3832 * bug, but not a hard error, so enable ints and continue */
3833 e1000_irq_enable(adapter);
3839 * e1000_clean - NAPI Rx polling callback
3840 * @adapter: board private structure
3842 static int e1000_clean(struct napi_struct *napi, int budget)
3844 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3845 struct net_device *poll_dev = adapter->netdev;
3846 int tx_cleaned = 0, work_done = 0;
3848 /* Must NOT use netdev_priv macro here. */
3849 adapter = poll_dev->priv;
3851 /* e1000_clean is called per-cpu. This lock protects
3852 * tx_ring[0] from being cleaned by multiple cpus
3853 * simultaneously. A failure obtaining the lock means
3854 * tx_ring[0] is currently being cleaned anyway. */
3855 if (spin_trylock(&adapter->tx_queue_lock)) {
3856 tx_cleaned = e1000_clean_tx_irq(adapter,
3857 &adapter->tx_ring[0]);
3858 spin_unlock(&adapter->tx_queue_lock);
3861 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3862 &work_done, budget);
3867 /* If budget not fully consumed, exit the polling mode */
3868 if (work_done < budget) {
3869 if (likely(adapter->itr_setting & 3))
3870 e1000_set_itr(adapter);
3871 netif_rx_complete(poll_dev, napi);
3872 e1000_irq_enable(adapter);
3879 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3880 * @adapter: board private structure
3882 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3883 struct e1000_tx_ring *tx_ring)
3885 struct e1000_hw *hw = &adapter->hw;
3886 struct net_device *netdev = adapter->netdev;
3887 struct e1000_tx_desc *tx_desc, *eop_desc;
3888 struct e1000_buffer *buffer_info;
3889 unsigned int i, eop;
3890 unsigned int count = 0;
3891 bool cleaned = false;
3892 unsigned int total_tx_bytes=0, total_tx_packets=0;
3894 i = tx_ring->next_to_clean;
3895 eop = tx_ring->buffer_info[i].next_to_watch;
3896 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3898 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3899 for (cleaned = false; !cleaned; ) {
3900 tx_desc = E1000_TX_DESC(*tx_ring, i);
3901 buffer_info = &tx_ring->buffer_info[i];
3902 cleaned = (i == eop);
3905 struct sk_buff *skb = buffer_info->skb;
3906 unsigned int segs, bytecount;
3907 segs = skb_shinfo(skb)->gso_segs ?: 1;
3908 /* multiply data chunks by size of headers */
3909 bytecount = ((segs - 1) * skb_headlen(skb)) +
3911 total_tx_packets += segs;
3912 total_tx_bytes += bytecount;
3914 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3915 tx_desc->upper.data = 0;
3917 if (unlikely(++i == tx_ring->count)) i = 0;
3920 eop = tx_ring->buffer_info[i].next_to_watch;
3921 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3922 #define E1000_TX_WEIGHT 64
3923 /* weight of a sort for tx, to avoid endless transmit cleanup */
3924 if (count++ == E1000_TX_WEIGHT)
3928 tx_ring->next_to_clean = i;
3930 #define TX_WAKE_THRESHOLD 32
3931 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3932 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3933 /* Make sure that anybody stopping the queue after this
3934 * sees the new next_to_clean.
3937 if (netif_queue_stopped(netdev)) {
3938 netif_wake_queue(netdev);
3939 ++adapter->restart_queue;
3943 if (adapter->detect_tx_hung) {
3944 /* Detect a transmit hang in hardware, this serializes the
3945 * check with the clearing of time_stamp and movement of i */
3946 adapter->detect_tx_hung = false;
3947 if (tx_ring->buffer_info[eop].dma &&
3948 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3949 (adapter->tx_timeout_factor * HZ))
3950 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3952 /* detected Tx unit hang */
3953 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3957 " next_to_use <%x>\n"
3958 " next_to_clean <%x>\n"
3959 "buffer_info[next_to_clean]\n"
3960 " time_stamp <%lx>\n"
3961 " next_to_watch <%x>\n"
3963 " next_to_watch.status <%x>\n",
3964 (unsigned long)((tx_ring - adapter->tx_ring) /
3965 sizeof(struct e1000_tx_ring)),
3966 readl(hw->hw_addr + tx_ring->tdh),
3967 readl(hw->hw_addr + tx_ring->tdt),
3968 tx_ring->next_to_use,
3969 tx_ring->next_to_clean,
3970 tx_ring->buffer_info[eop].time_stamp,
3973 eop_desc->upper.fields.status);
3974 netif_stop_queue(netdev);
3977 adapter->total_tx_bytes += total_tx_bytes;
3978 adapter->total_tx_packets += total_tx_packets;
3979 adapter->net_stats.tx_bytes += total_tx_bytes;
3980 adapter->net_stats.tx_packets += total_tx_packets;
3985 * e1000_rx_checksum - Receive Checksum Offload for 82543
3986 * @adapter: board private structure
3987 * @status_err: receive descriptor status and error fields
3988 * @csum: receive descriptor csum field
3989 * @sk_buff: socket buffer with received data
3992 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3993 u32 csum, struct sk_buff *skb)
3995 struct e1000_hw *hw = &adapter->hw;
3996 u16 status = (u16)status_err;
3997 u8 errors = (u8)(status_err >> 24);
3998 skb->ip_summed = CHECKSUM_NONE;
4000 /* 82543 or newer only */
4001 if (unlikely(hw->mac_type < e1000_82543)) return;
4002 /* Ignore Checksum bit is set */
4003 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
4004 /* TCP/UDP checksum error bit is set */
4005 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
4006 /* let the stack verify checksum errors */
4007 adapter->hw_csum_err++;
4010 /* TCP/UDP Checksum has not been calculated */
4011 if (hw->mac_type <= e1000_82547_rev_2) {
4012 if (!(status & E1000_RXD_STAT_TCPCS))
4015 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
4018 /* It must be a TCP or UDP packet with a valid checksum */
4019 if (likely(status & E1000_RXD_STAT_TCPCS)) {
4020 /* TCP checksum is good */
4021 skb->ip_summed = CHECKSUM_UNNECESSARY;
4022 } else if (hw->mac_type > e1000_82547_rev_2) {
4023 /* IP fragment with UDP payload */
4024 /* Hardware complements the payload checksum, so we undo it
4025 * and then put the value in host order for further stack use.
4027 __sum16 sum = (__force __sum16)htons(csum);
4028 skb->csum = csum_unfold(~sum);
4029 skb->ip_summed = CHECKSUM_COMPLETE;
4031 adapter->hw_csum_good++;
4035 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4036 * @adapter: board private structure
4038 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4039 struct e1000_rx_ring *rx_ring,
4040 int *work_done, int work_to_do)
4042 struct e1000_hw *hw = &adapter->hw;
4043 struct net_device *netdev = adapter->netdev;
4044 struct pci_dev *pdev = adapter->pdev;
4045 struct e1000_rx_desc *rx_desc, *next_rxd;
4046 struct e1000_buffer *buffer_info, *next_buffer;
4047 unsigned long flags;
4051 int cleaned_count = 0;
4052 bool cleaned = false;
4053 unsigned int total_rx_bytes=0, total_rx_packets=0;
4055 i = rx_ring->next_to_clean;
4056 rx_desc = E1000_RX_DESC(*rx_ring, i);
4057 buffer_info = &rx_ring->buffer_info[i];
4059 while (rx_desc->status & E1000_RXD_STAT_DD) {
4060 struct sk_buff *skb;
4063 if (*work_done >= work_to_do)
4067 status = rx_desc->status;
4068 skb = buffer_info->skb;
4069 buffer_info->skb = NULL;
4071 prefetch(skb->data - NET_IP_ALIGN);
4073 if (++i == rx_ring->count) i = 0;
4074 next_rxd = E1000_RX_DESC(*rx_ring, i);
4077 next_buffer = &rx_ring->buffer_info[i];
4081 pci_unmap_single(pdev,
4083 buffer_info->length,
4084 PCI_DMA_FROMDEVICE);
4086 length = le16_to_cpu(rx_desc->length);
4088 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4089 /* All receives must fit into a single buffer */
4090 E1000_DBG("%s: Receive packet consumed multiple"
4091 " buffers\n", netdev->name);
4093 buffer_info->skb = skb;
4097 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4098 last_byte = *(skb->data + length - 1);
4099 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4101 spin_lock_irqsave(&adapter->stats_lock, flags);
4102 e1000_tbi_adjust_stats(hw, &adapter->stats,
4104 spin_unlock_irqrestore(&adapter->stats_lock,
4109 buffer_info->skb = skb;
4114 /* adjust length to remove Ethernet CRC, this must be
4115 * done after the TBI_ACCEPT workaround above */
4118 /* probably a little skewed due to removing CRC */
4119 total_rx_bytes += length;
4122 /* code added for copybreak, this should improve
4123 * performance for small packets with large amounts
4124 * of reassembly being done in the stack */
4125 if (length < copybreak) {
4126 struct sk_buff *new_skb =
4127 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4129 skb_reserve(new_skb, NET_IP_ALIGN);
4130 skb_copy_to_linear_data_offset(new_skb,
4136 /* save the skb in buffer_info as good */
4137 buffer_info->skb = skb;
4140 /* else just continue with the old one */
4142 /* end copybreak code */
4143 skb_put(skb, length);
4145 /* Receive Checksum Offload */
4146 e1000_rx_checksum(adapter,
4148 ((u32)(rx_desc->errors) << 24),
4149 le16_to_cpu(rx_desc->csum), skb);
4151 skb->protocol = eth_type_trans(skb, netdev);
4153 if (unlikely(adapter->vlgrp &&
4154 (status & E1000_RXD_STAT_VP))) {
4155 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4156 le16_to_cpu(rx_desc->special));
4158 netif_receive_skb(skb);
4161 netdev->last_rx = jiffies;
4164 rx_desc->status = 0;
4166 /* return some buffers to hardware, one at a time is too slow */
4167 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4168 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4172 /* use prefetched values */
4174 buffer_info = next_buffer;
4176 rx_ring->next_to_clean = i;
4178 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4180 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4182 adapter->total_rx_packets += total_rx_packets;
4183 adapter->total_rx_bytes += total_rx_bytes;
4184 adapter->net_stats.rx_bytes += total_rx_bytes;
4185 adapter->net_stats.rx_packets += total_rx_packets;
4190 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4191 * @adapter: board private structure
4194 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4195 struct e1000_rx_ring *rx_ring,
4196 int *work_done, int work_to_do)
4198 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
4199 struct net_device *netdev = adapter->netdev;
4200 struct pci_dev *pdev = adapter->pdev;
4201 struct e1000_buffer *buffer_info, *next_buffer;
4202 struct e1000_ps_page *ps_page;
4203 struct e1000_ps_page_dma *ps_page_dma;
4204 struct sk_buff *skb;
4206 u32 length, staterr;
4207 int cleaned_count = 0;
4208 bool cleaned = false;
4209 unsigned int total_rx_bytes=0, total_rx_packets=0;
4211 i = rx_ring->next_to_clean;
4212 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4213 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4214 buffer_info = &rx_ring->buffer_info[i];
4216 while (staterr & E1000_RXD_STAT_DD) {
4217 ps_page = &rx_ring->ps_page[i];
4218 ps_page_dma = &rx_ring->ps_page_dma[i];
4220 if (unlikely(*work_done >= work_to_do))
4224 skb = buffer_info->skb;
4226 /* in the packet split case this is header only */
4227 prefetch(skb->data - NET_IP_ALIGN);
4229 if (++i == rx_ring->count) i = 0;
4230 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
4233 next_buffer = &rx_ring->buffer_info[i];
4237 pci_unmap_single(pdev, buffer_info->dma,
4238 buffer_info->length,
4239 PCI_DMA_FROMDEVICE);
4241 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
4242 E1000_DBG("%s: Packet Split buffers didn't pick up"
4243 " the full packet\n", netdev->name);
4244 dev_kfree_skb_irq(skb);
4248 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
4249 dev_kfree_skb_irq(skb);
4253 length = le16_to_cpu(rx_desc->wb.middle.length0);
4255 if (unlikely(!length)) {
4256 E1000_DBG("%s: Last part of the packet spanning"
4257 " multiple descriptors\n", netdev->name);
4258 dev_kfree_skb_irq(skb);
4263 skb_put(skb, length);
4266 /* this looks ugly, but it seems compiler issues make it
4267 more efficient than reusing j */
4268 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4270 /* page alloc/put takes too long and effects small packet
4271 * throughput, so unsplit small packets and save the alloc/put*/
4272 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
4274 /* there is no documentation about how to call
4275 * kmap_atomic, so we can't hold the mapping
4277 pci_dma_sync_single_for_cpu(pdev,
4278 ps_page_dma->ps_page_dma[0],
4280 PCI_DMA_FROMDEVICE);
4281 vaddr = kmap_atomic(ps_page->ps_page[0],
4282 KM_SKB_DATA_SOFTIRQ);
4283 memcpy(skb_tail_pointer(skb), vaddr, l1);
4284 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4285 pci_dma_sync_single_for_device(pdev,
4286 ps_page_dma->ps_page_dma[0],
4287 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4288 /* remove the CRC */
4295 for (j = 0; j < adapter->rx_ps_pages; j++) {
4296 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
4299 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4300 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4301 ps_page_dma->ps_page_dma[j] = 0;
4302 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4304 ps_page->ps_page[j] = NULL;
4306 skb->data_len += length;
4307 skb->truesize += length;
4310 /* strip the ethernet crc, problem is we're using pages now so
4311 * this whole operation can get a little cpu intensive */
4312 pskb_trim(skb, skb->len - 4);
4315 total_rx_bytes += skb->len;
4318 e1000_rx_checksum(adapter, staterr,
4319 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
4320 skb->protocol = eth_type_trans(skb, netdev);
4322 if (likely(rx_desc->wb.upper.header_status &
4323 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
4324 adapter->rx_hdr_split++;
4326 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4327 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4328 le16_to_cpu(rx_desc->wb.middle.vlan));
4330 netif_receive_skb(skb);
4333 netdev->last_rx = jiffies;
4336 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
4337 buffer_info->skb = NULL;
4339 /* return some buffers to hardware, one at a time is too slow */
4340 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4341 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4345 /* use prefetched values */
4347 buffer_info = next_buffer;
4349 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4351 rx_ring->next_to_clean = i;
4353 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4355 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4357 adapter->total_rx_packets += total_rx_packets;
4358 adapter->total_rx_bytes += total_rx_bytes;
4359 adapter->net_stats.rx_bytes += total_rx_bytes;
4360 adapter->net_stats.rx_packets += total_rx_packets;
4365 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4366 * @adapter: address of board private structure
4369 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4370 struct e1000_rx_ring *rx_ring,
4373 struct e1000_hw *hw = &adapter->hw;
4374 struct net_device *netdev = adapter->netdev;
4375 struct pci_dev *pdev = adapter->pdev;
4376 struct e1000_rx_desc *rx_desc;
4377 struct e1000_buffer *buffer_info;
4378 struct sk_buff *skb;
4380 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4382 i = rx_ring->next_to_use;
4383 buffer_info = &rx_ring->buffer_info[i];
4385 while (cleaned_count--) {
4386 skb = buffer_info->skb;
4392 skb = netdev_alloc_skb(netdev, bufsz);
4393 if (unlikely(!skb)) {
4394 /* Better luck next round */
4395 adapter->alloc_rx_buff_failed++;
4399 /* Fix for errata 23, can't cross 64kB boundary */
4400 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4401 struct sk_buff *oldskb = skb;
4402 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4403 "at %p\n", bufsz, skb->data);
4404 /* Try again, without freeing the previous */
4405 skb = netdev_alloc_skb(netdev, bufsz);
4406 /* Failed allocation, critical failure */
4408 dev_kfree_skb(oldskb);
4412 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4415 dev_kfree_skb(oldskb);
4416 break; /* while !buffer_info->skb */
4419 /* Use new allocation */
4420 dev_kfree_skb(oldskb);
4422 /* Make buffer alignment 2 beyond a 16 byte boundary
4423 * this will result in a 16 byte aligned IP header after
4424 * the 14 byte MAC header is removed
4426 skb_reserve(skb, NET_IP_ALIGN);
4428 buffer_info->skb = skb;
4429 buffer_info->length = adapter->rx_buffer_len;
4431 buffer_info->dma = pci_map_single(pdev,
4433 adapter->rx_buffer_len,
4434 PCI_DMA_FROMDEVICE);
4436 /* Fix for errata 23, can't cross 64kB boundary */
4437 if (!e1000_check_64k_bound(adapter,
4438 (void *)(unsigned long)buffer_info->dma,
4439 adapter->rx_buffer_len)) {
4440 DPRINTK(RX_ERR, ERR,
4441 "dma align check failed: %u bytes at %p\n",
4442 adapter->rx_buffer_len,
4443 (void *)(unsigned long)buffer_info->dma);
4445 buffer_info->skb = NULL;
4447 pci_unmap_single(pdev, buffer_info->dma,
4448 adapter->rx_buffer_len,
4449 PCI_DMA_FROMDEVICE);
4451 break; /* while !buffer_info->skb */
4453 rx_desc = E1000_RX_DESC(*rx_ring, i);
4454 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4456 if (unlikely(++i == rx_ring->count))
4458 buffer_info = &rx_ring->buffer_info[i];
4461 if (likely(rx_ring->next_to_use != i)) {
4462 rx_ring->next_to_use = i;
4463 if (unlikely(i-- == 0))
4464 i = (rx_ring->count - 1);
4466 /* Force memory writes to complete before letting h/w
4467 * know there are new descriptors to fetch. (Only
4468 * applicable for weak-ordered memory model archs,
4469 * such as IA-64). */
4471 writel(i, hw->hw_addr + rx_ring->rdt);
4476 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4477 * @adapter: address of board private structure
4480 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4481 struct e1000_rx_ring *rx_ring,
4484 struct e1000_hw *hw = &adapter->hw;
4485 struct net_device *netdev = adapter->netdev;
4486 struct pci_dev *pdev = adapter->pdev;
4487 union e1000_rx_desc_packet_split *rx_desc;
4488 struct e1000_buffer *buffer_info;
4489 struct e1000_ps_page *ps_page;
4490 struct e1000_ps_page_dma *ps_page_dma;
4491 struct sk_buff *skb;
4494 i = rx_ring->next_to_use;
4495 buffer_info = &rx_ring->buffer_info[i];
4496 ps_page = &rx_ring->ps_page[i];
4497 ps_page_dma = &rx_ring->ps_page_dma[i];
4499 while (cleaned_count--) {
4500 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4502 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4503 if (j < adapter->rx_ps_pages) {
4504 if (likely(!ps_page->ps_page[j])) {
4505 ps_page->ps_page[j] =
4506 alloc_page(GFP_ATOMIC);
4507 if (unlikely(!ps_page->ps_page[j])) {
4508 adapter->alloc_rx_buff_failed++;
4511 ps_page_dma->ps_page_dma[j] =
4513 ps_page->ps_page[j],
4515 PCI_DMA_FROMDEVICE);
4517 /* Refresh the desc even if buffer_addrs didn't
4518 * change because each write-back erases
4521 rx_desc->read.buffer_addr[j+1] =
4522 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4524 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
4527 skb = netdev_alloc_skb(netdev,
4528 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4530 if (unlikely(!skb)) {
4531 adapter->alloc_rx_buff_failed++;
4535 /* Make buffer alignment 2 beyond a 16 byte boundary
4536 * this will result in a 16 byte aligned IP header after
4537 * the 14 byte MAC header is removed
4539 skb_reserve(skb, NET_IP_ALIGN);
4541 buffer_info->skb = skb;
4542 buffer_info->length = adapter->rx_ps_bsize0;
4543 buffer_info->dma = pci_map_single(pdev, skb->data,
4544 adapter->rx_ps_bsize0,
4545 PCI_DMA_FROMDEVICE);
4547 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4549 if (unlikely(++i == rx_ring->count)) i = 0;
4550 buffer_info = &rx_ring->buffer_info[i];
4551 ps_page = &rx_ring->ps_page[i];
4552 ps_page_dma = &rx_ring->ps_page_dma[i];
4556 if (likely(rx_ring->next_to_use != i)) {
4557 rx_ring->next_to_use = i;
4558 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4560 /* Force memory writes to complete before letting h/w
4561 * know there are new descriptors to fetch. (Only
4562 * applicable for weak-ordered memory model archs,
4563 * such as IA-64). */
4565 /* Hardware increments by 16 bytes, but packet split
4566 * descriptors are 32 bytes...so we increment tail
4569 writel(i<<1, hw->hw_addr + rx_ring->rdt);
4574 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4578 static void e1000_smartspeed(struct e1000_adapter *adapter)
4580 struct e1000_hw *hw = &adapter->hw;
4584 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4585 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4588 if (adapter->smartspeed == 0) {
4589 /* If Master/Slave config fault is asserted twice,
4590 * we assume back-to-back */
4591 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4592 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4593 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4594 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4595 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4596 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4597 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4598 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4600 adapter->smartspeed++;
4601 if (!e1000_phy_setup_autoneg(hw) &&
4602 !e1000_read_phy_reg(hw, PHY_CTRL,
4604 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4605 MII_CR_RESTART_AUTO_NEG);
4606 e1000_write_phy_reg(hw, PHY_CTRL,
4611 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4612 /* If still no link, perhaps using 2/3 pair cable */
4613 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4614 phy_ctrl |= CR_1000T_MS_ENABLE;
4615 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4616 if (!e1000_phy_setup_autoneg(hw) &&
4617 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4618 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4619 MII_CR_RESTART_AUTO_NEG);
4620 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4623 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4624 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4625 adapter->smartspeed = 0;
4635 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4641 return e1000_mii_ioctl(netdev, ifr, cmd);
4654 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4657 struct e1000_adapter *adapter = netdev_priv(netdev);
4658 struct e1000_hw *hw = &adapter->hw;
4659 struct mii_ioctl_data *data = if_mii(ifr);
4663 unsigned long flags;
4665 if (hw->media_type != e1000_media_type_copper)
4670 data->phy_id = hw->phy_addr;
4673 if (!capable(CAP_NET_ADMIN))
4675 spin_lock_irqsave(&adapter->stats_lock, flags);
4676 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4678 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4681 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4684 if (!capable(CAP_NET_ADMIN))
4686 if (data->reg_num & ~(0x1F))
4688 mii_reg = data->val_in;
4689 spin_lock_irqsave(&adapter->stats_lock, flags);
4690 if (e1000_write_phy_reg(hw, data->reg_num,
4692 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4695 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4696 if (hw->media_type == e1000_media_type_copper) {
4697 switch (data->reg_num) {
4699 if (mii_reg & MII_CR_POWER_DOWN)
4701 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4703 hw->autoneg_advertised = 0x2F;
4706 spddplx = SPEED_1000;
4707 else if (mii_reg & 0x2000)
4708 spddplx = SPEED_100;
4711 spddplx += (mii_reg & 0x100)
4714 retval = e1000_set_spd_dplx(adapter,
4719 if (netif_running(adapter->netdev))
4720 e1000_reinit_locked(adapter);
4722 e1000_reset(adapter);
4724 case M88E1000_PHY_SPEC_CTRL:
4725 case M88E1000_EXT_PHY_SPEC_CTRL:
4726 if (e1000_phy_reset(hw))
4731 switch (data->reg_num) {
4733 if (mii_reg & MII_CR_POWER_DOWN)
4735 if (netif_running(adapter->netdev))
4736 e1000_reinit_locked(adapter);
4738 e1000_reset(adapter);
4746 return E1000_SUCCESS;
4749 void e1000_pci_set_mwi(struct e1000_hw *hw)
4751 struct e1000_adapter *adapter = hw->back;
4752 int ret_val = pci_set_mwi(adapter->pdev);
4755 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4758 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4760 struct e1000_adapter *adapter = hw->back;
4762 pci_clear_mwi(adapter->pdev);
4765 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4767 struct e1000_adapter *adapter = hw->back;
4768 return pcix_get_mmrbc(adapter->pdev);
4771 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4773 struct e1000_adapter *adapter = hw->back;
4774 pcix_set_mmrbc(adapter->pdev, mmrbc);
4777 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
4779 struct e1000_adapter *adapter = hw->back;
4782 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4784 return -E1000_ERR_CONFIG;
4786 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4788 return E1000_SUCCESS;
4791 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4796 static void e1000_vlan_rx_register(struct net_device *netdev,
4797 struct vlan_group *grp)
4799 struct e1000_adapter *adapter = netdev_priv(netdev);
4800 struct e1000_hw *hw = &adapter->hw;
4803 if (!test_bit(__E1000_DOWN, &adapter->flags))
4804 e1000_irq_disable(adapter);
4805 adapter->vlgrp = grp;
4808 /* enable VLAN tag insert/strip */
4810 ctrl |= E1000_CTRL_VME;
4813 if (adapter->hw.mac_type != e1000_ich8lan) {
4814 /* enable VLAN receive filtering */
4816 rctl &= ~E1000_RCTL_CFIEN;
4818 e1000_update_mng_vlan(adapter);
4821 /* disable VLAN tag insert/strip */
4823 ctrl &= ~E1000_CTRL_VME;
4826 if (adapter->hw.mac_type != e1000_ich8lan) {
4827 if (adapter->mng_vlan_id !=
4828 (u16)E1000_MNG_VLAN_NONE) {
4829 e1000_vlan_rx_kill_vid(netdev,
4830 adapter->mng_vlan_id);
4831 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4836 if (!test_bit(__E1000_DOWN, &adapter->flags))
4837 e1000_irq_enable(adapter);
4840 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4842 struct e1000_adapter *adapter = netdev_priv(netdev);
4843 struct e1000_hw *hw = &adapter->hw;
4846 if ((hw->mng_cookie.status &
4847 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4848 (vid == adapter->mng_vlan_id))
4850 /* add VID to filter table */
4851 index = (vid >> 5) & 0x7F;
4852 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4853 vfta |= (1 << (vid & 0x1F));
4854 e1000_write_vfta(hw, index, vfta);
4857 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4859 struct e1000_adapter *adapter = netdev_priv(netdev);
4860 struct e1000_hw *hw = &adapter->hw;
4863 if (!test_bit(__E1000_DOWN, &adapter->flags))
4864 e1000_irq_disable(adapter);
4865 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4866 if (!test_bit(__E1000_DOWN, &adapter->flags))
4867 e1000_irq_enable(adapter);
4869 if ((hw->mng_cookie.status &
4870 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4871 (vid == adapter->mng_vlan_id)) {
4872 /* release control to f/w */
4873 e1000_release_hw_control(adapter);
4877 /* remove VID from filter table */
4878 index = (vid >> 5) & 0x7F;
4879 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4880 vfta &= ~(1 << (vid & 0x1F));
4881 e1000_write_vfta(hw, index, vfta);
4884 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4886 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4888 if (adapter->vlgrp) {
4890 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4891 if (!vlan_group_get_device(adapter->vlgrp, vid))
4893 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4898 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
4900 struct e1000_hw *hw = &adapter->hw;
4904 /* Fiber NICs only allow 1000 gbps Full duplex */
4905 if ((hw->media_type == e1000_media_type_fiber) &&
4906 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4907 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4912 case SPEED_10 + DUPLEX_HALF:
4913 hw->forced_speed_duplex = e1000_10_half;
4915 case SPEED_10 + DUPLEX_FULL:
4916 hw->forced_speed_duplex = e1000_10_full;
4918 case SPEED_100 + DUPLEX_HALF:
4919 hw->forced_speed_duplex = e1000_100_half;
4921 case SPEED_100 + DUPLEX_FULL:
4922 hw->forced_speed_duplex = e1000_100_full;
4924 case SPEED_1000 + DUPLEX_FULL:
4926 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4928 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4930 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4936 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4938 struct net_device *netdev = pci_get_drvdata(pdev);
4939 struct e1000_adapter *adapter = netdev_priv(netdev);
4940 struct e1000_hw *hw = &adapter->hw;
4941 u32 ctrl, ctrl_ext, rctl, status;
4942 u32 wufc = adapter->wol;
4947 netif_device_detach(netdev);
4949 if (netif_running(netdev)) {
4950 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4951 e1000_down(adapter);
4955 retval = pci_save_state(pdev);
4960 status = er32(STATUS);
4961 if (status & E1000_STATUS_LU)
4962 wufc &= ~E1000_WUFC_LNKC;
4965 e1000_setup_rctl(adapter);
4966 e1000_set_rx_mode(netdev);
4968 /* turn on all-multi mode if wake on multicast is enabled */
4969 if (wufc & E1000_WUFC_MC) {
4971 rctl |= E1000_RCTL_MPE;
4975 if (hw->mac_type >= e1000_82540) {
4977 /* advertise wake from D3Cold */
4978 #define E1000_CTRL_ADVD3WUC 0x00100000
4979 /* phy power management enable */
4980 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4981 ctrl |= E1000_CTRL_ADVD3WUC |
4982 E1000_CTRL_EN_PHY_PWR_MGMT;
4986 if (hw->media_type == e1000_media_type_fiber ||
4987 hw->media_type == e1000_media_type_internal_serdes) {
4988 /* keep the laser running in D3 */
4989 ctrl_ext = er32(CTRL_EXT);
4990 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4991 ew32(CTRL_EXT, ctrl_ext);
4994 /* Allow time for pending master requests to run */
4995 e1000_disable_pciex_master(hw);
4997 ew32(WUC, E1000_WUC_PME_EN);
4999 pci_enable_wake(pdev, PCI_D3hot, 1);
5000 pci_enable_wake(pdev, PCI_D3cold, 1);
5004 pci_enable_wake(pdev, PCI_D3hot, 0);
5005 pci_enable_wake(pdev, PCI_D3cold, 0);
5008 e1000_release_manageability(adapter);
5010 /* make sure adapter isn't asleep if manageability is enabled */
5011 if (adapter->en_mng_pt) {
5012 pci_enable_wake(pdev, PCI_D3hot, 1);
5013 pci_enable_wake(pdev, PCI_D3cold, 1);
5016 if (hw->phy_type == e1000_phy_igp_3)
5017 e1000_phy_powerdown_workaround(hw);
5019 if (netif_running(netdev))
5020 e1000_free_irq(adapter);
5022 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5023 * would have already happened in close and is redundant. */
5024 e1000_release_hw_control(adapter);
5026 pci_disable_device(pdev);
5028 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5034 static int e1000_resume(struct pci_dev *pdev)
5036 struct net_device *netdev = pci_get_drvdata(pdev);
5037 struct e1000_adapter *adapter = netdev_priv(netdev);
5038 struct e1000_hw *hw = &adapter->hw;
5041 pci_set_power_state(pdev, PCI_D0);
5042 pci_restore_state(pdev);
5043 err = pci_enable_device(pdev);
5045 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5048 pci_set_master(pdev);
5050 pci_enable_wake(pdev, PCI_D3hot, 0);
5051 pci_enable_wake(pdev, PCI_D3cold, 0);
5053 if (netif_running(netdev)) {
5054 err = e1000_request_irq(adapter);
5059 e1000_power_up_phy(adapter);
5060 e1000_reset(adapter);
5063 e1000_init_manageability(adapter);
5065 if (netif_running(netdev))
5068 netif_device_attach(netdev);
5070 /* If the controller is 82573 and f/w is AMT, do not set
5071 * DRV_LOAD until the interface is up. For all other cases,
5072 * let the f/w know that the h/w is now under the control
5074 if (hw->mac_type != e1000_82573 ||
5075 !e1000_check_mng_mode(hw))
5076 e1000_get_hw_control(adapter);
5082 static void e1000_shutdown(struct pci_dev *pdev)
5084 e1000_suspend(pdev, PMSG_SUSPEND);
5087 #ifdef CONFIG_NET_POLL_CONTROLLER
5089 * Polling 'interrupt' - used by things like netconsole to send skbs
5090 * without having to re-enable interrupts. It's not called while
5091 * the interrupt routine is executing.
5093 static void e1000_netpoll(struct net_device *netdev)
5095 struct e1000_adapter *adapter = netdev_priv(netdev);
5097 disable_irq(adapter->pdev->irq);
5098 e1000_intr(adapter->pdev->irq, netdev);
5099 enable_irq(adapter->pdev->irq);
5104 * e1000_io_error_detected - called when PCI error is detected
5105 * @pdev: Pointer to PCI device
5106 * @state: The current pci conneection state
5108 * This function is called after a PCI bus error affecting
5109 * this device has been detected.
5111 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5112 pci_channel_state_t state)
5114 struct net_device *netdev = pci_get_drvdata(pdev);
5115 struct e1000_adapter *adapter = netdev->priv;
5117 netif_device_detach(netdev);
5119 if (netif_running(netdev))
5120 e1000_down(adapter);
5121 pci_disable_device(pdev);
5123 /* Request a slot slot reset. */
5124 return PCI_ERS_RESULT_NEED_RESET;
5128 * e1000_io_slot_reset - called after the pci bus has been reset.
5129 * @pdev: Pointer to PCI device
5131 * Restart the card from scratch, as if from a cold-boot. Implementation
5132 * resembles the first-half of the e1000_resume routine.
5134 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5136 struct net_device *netdev = pci_get_drvdata(pdev);
5137 struct e1000_adapter *adapter = netdev->priv;
5138 struct e1000_hw *hw = &adapter->hw;
5140 if (pci_enable_device(pdev)) {
5141 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5142 return PCI_ERS_RESULT_DISCONNECT;
5144 pci_set_master(pdev);
5146 pci_enable_wake(pdev, PCI_D3hot, 0);
5147 pci_enable_wake(pdev, PCI_D3cold, 0);
5149 e1000_reset(adapter);
5152 return PCI_ERS_RESULT_RECOVERED;
5156 * e1000_io_resume - called when traffic can start flowing again.
5157 * @pdev: Pointer to PCI device
5159 * This callback is called when the error recovery driver tells us that
5160 * its OK to resume normal operation. Implementation resembles the
5161 * second-half of the e1000_resume routine.
5163 static void e1000_io_resume(struct pci_dev *pdev)
5165 struct net_device *netdev = pci_get_drvdata(pdev);
5166 struct e1000_adapter *adapter = netdev->priv;
5167 struct e1000_hw *hw = &adapter->hw;
5169 e1000_init_manageability(adapter);
5171 if (netif_running(netdev)) {
5172 if (e1000_up(adapter)) {
5173 printk("e1000: can't bring device back up after reset\n");
5178 netif_device_attach(netdev);
5180 /* If the controller is 82573 and f/w is AMT, do not set
5181 * DRV_LOAD until the interface is up. For all other cases,
5182 * let the f/w know that the h/w is now under the control
5184 if (hw->mac_type != e1000_82573 ||
5185 !e1000_check_mng_mode(hw))
5186 e1000_get_hw_control(adapter);