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_is_need_ioport - determine if an adapter needs ioport resources or not
863 * @pdev: PCI device information struct
865 * Return true if an adapter needs ioport resources
867 static int e1000_is_need_ioport(struct pci_dev *pdev)
869 switch (pdev->device) {
870 case E1000_DEV_ID_82540EM:
871 case E1000_DEV_ID_82540EM_LOM:
872 case E1000_DEV_ID_82540EP:
873 case E1000_DEV_ID_82540EP_LOM:
874 case E1000_DEV_ID_82540EP_LP:
875 case E1000_DEV_ID_82541EI:
876 case E1000_DEV_ID_82541EI_MOBILE:
877 case E1000_DEV_ID_82541ER:
878 case E1000_DEV_ID_82541ER_LOM:
879 case E1000_DEV_ID_82541GI:
880 case E1000_DEV_ID_82541GI_LF:
881 case E1000_DEV_ID_82541GI_MOBILE:
882 case E1000_DEV_ID_82544EI_COPPER:
883 case E1000_DEV_ID_82544EI_FIBER:
884 case E1000_DEV_ID_82544GC_COPPER:
885 case E1000_DEV_ID_82544GC_LOM:
886 case E1000_DEV_ID_82545EM_COPPER:
887 case E1000_DEV_ID_82545EM_FIBER:
888 case E1000_DEV_ID_82546EB_COPPER:
889 case E1000_DEV_ID_82546EB_FIBER:
890 case E1000_DEV_ID_82546EB_QUAD_COPPER:
898 * e1000_probe - Device Initialization Routine
899 * @pdev: PCI device information struct
900 * @ent: entry in e1000_pci_tbl
902 * Returns 0 on success, negative on failure
904 * e1000_probe initializes an adapter identified by a pci_dev structure.
905 * The OS initialization, configuring of the adapter private structure,
906 * and a hardware reset occur.
908 static int __devinit e1000_probe(struct pci_dev *pdev,
909 const struct pci_device_id *ent)
911 struct net_device *netdev;
912 struct e1000_adapter *adapter;
915 static int cards_found = 0;
916 static int global_quad_port_a = 0; /* global ksp3 port a indication */
917 int i, err, pci_using_dac;
919 u16 eeprom_apme_mask = E1000_EEPROM_APME;
920 int bars, need_ioport;
921 DECLARE_MAC_BUF(mac);
923 /* do not allocate ioport bars when not needed */
924 need_ioport = e1000_is_need_ioport(pdev);
926 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
927 err = pci_enable_device(pdev);
929 bars = pci_select_bars(pdev, IORESOURCE_MEM);
930 err = pci_enable_device(pdev);
935 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
936 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
939 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
941 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
943 E1000_ERR("No usable DMA configuration, "
951 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
955 pci_set_master(pdev);
958 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
960 goto err_alloc_etherdev;
962 SET_NETDEV_DEV(netdev, &pdev->dev);
964 pci_set_drvdata(pdev, netdev);
965 adapter = netdev_priv(netdev);
966 adapter->netdev = netdev;
967 adapter->pdev = pdev;
968 adapter->msg_enable = (1 << debug) - 1;
969 adapter->bars = bars;
970 adapter->need_ioport = need_ioport;
976 hw->hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
977 pci_resource_len(pdev, BAR_0));
981 if (adapter->need_ioport) {
982 for (i = BAR_1; i <= BAR_5; i++) {
983 if (pci_resource_len(pdev, i) == 0)
985 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
986 hw->io_base = pci_resource_start(pdev, i);
992 netdev->open = &e1000_open;
993 netdev->stop = &e1000_close;
994 netdev->hard_start_xmit = &e1000_xmit_frame;
995 netdev->get_stats = &e1000_get_stats;
996 netdev->set_rx_mode = &e1000_set_rx_mode;
997 netdev->set_mac_address = &e1000_set_mac;
998 netdev->change_mtu = &e1000_change_mtu;
999 netdev->do_ioctl = &e1000_ioctl;
1000 e1000_set_ethtool_ops(netdev);
1001 netdev->tx_timeout = &e1000_tx_timeout;
1002 netdev->watchdog_timeo = 5 * HZ;
1003 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1004 netdev->vlan_rx_register = e1000_vlan_rx_register;
1005 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
1006 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
1007 #ifdef CONFIG_NET_POLL_CONTROLLER
1008 netdev->poll_controller = e1000_netpoll;
1010 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1012 adapter->bd_number = cards_found;
1014 /* setup the private structure */
1016 err = e1000_sw_init(adapter);
1021 /* Flash BAR mapping must happen after e1000_sw_init
1022 * because it depends on mac_type */
1023 if ((hw->mac_type == e1000_ich8lan) &&
1024 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
1026 ioremap(pci_resource_start(pdev, 1),
1027 pci_resource_len(pdev, 1));
1028 if (!hw->flash_address)
1032 if (e1000_check_phy_reset_block(hw))
1033 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1035 if (hw->mac_type >= e1000_82543) {
1036 netdev->features = NETIF_F_SG |
1038 NETIF_F_HW_VLAN_TX |
1039 NETIF_F_HW_VLAN_RX |
1040 NETIF_F_HW_VLAN_FILTER;
1041 if (hw->mac_type == e1000_ich8lan)
1042 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
1045 if ((hw->mac_type >= e1000_82544) &&
1046 (hw->mac_type != e1000_82547))
1047 netdev->features |= NETIF_F_TSO;
1049 if (hw->mac_type > e1000_82547_rev_2)
1050 netdev->features |= NETIF_F_TSO6;
1052 netdev->features |= NETIF_F_HIGHDMA;
1054 netdev->features |= NETIF_F_LLTX;
1056 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1058 /* initialize eeprom parameters */
1059 if (e1000_init_eeprom_params(hw)) {
1060 E1000_ERR("EEPROM initialization failed\n");
1064 /* before reading the EEPROM, reset the controller to
1065 * put the device in a known good starting state */
1069 /* make sure the EEPROM is good */
1070 if (e1000_validate_eeprom_checksum(hw) < 0) {
1071 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1072 e1000_dump_eeprom(adapter);
1074 * set MAC address to all zeroes to invalidate and temporary
1075 * disable this device for the user. This blocks regular
1076 * traffic while still permitting ethtool ioctls from reaching
1077 * the hardware as well as allowing the user to run the
1078 * interface after manually setting a hw addr using
1081 memset(hw->mac_addr, 0, netdev->addr_len);
1083 /* copy the MAC address out of the EEPROM */
1084 if (e1000_read_mac_addr(hw))
1085 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1087 /* don't block initalization here due to bad MAC address */
1088 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1089 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
1091 if (!is_valid_ether_addr(netdev->perm_addr))
1092 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1094 e1000_get_bus_info(hw);
1096 init_timer(&adapter->tx_fifo_stall_timer);
1097 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1098 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
1100 init_timer(&adapter->watchdog_timer);
1101 adapter->watchdog_timer.function = &e1000_watchdog;
1102 adapter->watchdog_timer.data = (unsigned long) adapter;
1104 init_timer(&adapter->phy_info_timer);
1105 adapter->phy_info_timer.function = &e1000_update_phy_info;
1106 adapter->phy_info_timer.data = (unsigned long)adapter;
1108 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1110 e1000_check_options(adapter);
1112 /* Initial Wake on LAN setting
1113 * If APM wake is enabled in the EEPROM,
1114 * enable the ACPI Magic Packet filter
1117 switch (hw->mac_type) {
1118 case e1000_82542_rev2_0:
1119 case e1000_82542_rev2_1:
1123 e1000_read_eeprom(hw,
1124 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1125 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1128 e1000_read_eeprom(hw,
1129 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1130 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1133 case e1000_82546_rev_3:
1135 case e1000_80003es2lan:
1136 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1137 e1000_read_eeprom(hw,
1138 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1143 e1000_read_eeprom(hw,
1144 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1147 if (eeprom_data & eeprom_apme_mask)
1148 adapter->eeprom_wol |= E1000_WUFC_MAG;
1150 /* now that we have the eeprom settings, apply the special cases
1151 * where the eeprom may be wrong or the board simply won't support
1152 * wake on lan on a particular port */
1153 switch (pdev->device) {
1154 case E1000_DEV_ID_82546GB_PCIE:
1155 adapter->eeprom_wol = 0;
1157 case E1000_DEV_ID_82546EB_FIBER:
1158 case E1000_DEV_ID_82546GB_FIBER:
1159 case E1000_DEV_ID_82571EB_FIBER:
1160 /* Wake events only supported on port A for dual fiber
1161 * regardless of eeprom setting */
1162 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1163 adapter->eeprom_wol = 0;
1165 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1166 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1167 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1168 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1169 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1170 /* if quad port adapter, disable WoL on all but port A */
1171 if (global_quad_port_a != 0)
1172 adapter->eeprom_wol = 0;
1174 adapter->quad_port_a = 1;
1175 /* Reset for multiple quad port adapters */
1176 if (++global_quad_port_a == 4)
1177 global_quad_port_a = 0;
1181 /* initialize the wol settings based on the eeprom settings */
1182 adapter->wol = adapter->eeprom_wol;
1184 /* print bus type/speed/width info */
1185 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1186 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1187 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1188 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1189 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1190 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1191 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1192 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1193 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1194 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1195 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1198 printk("%s\n", print_mac(mac, netdev->dev_addr));
1200 if (hw->bus_type == e1000_bus_type_pci_express) {
1201 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1202 "longer be supported by this driver in the future.\n",
1203 pdev->vendor, pdev->device);
1204 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1205 "driver instead.\n");
1208 /* reset the hardware with the new settings */
1209 e1000_reset(adapter);
1211 /* If the controller is 82573 and f/w is AMT, do not set
1212 * DRV_LOAD until the interface is up. For all other cases,
1213 * let the f/w know that the h/w is now under the control
1215 if (hw->mac_type != e1000_82573 ||
1216 !e1000_check_mng_mode(hw))
1217 e1000_get_hw_control(adapter);
1219 /* tell the stack to leave us alone until e1000_open() is called */
1220 netif_carrier_off(netdev);
1221 netif_stop_queue(netdev);
1223 strcpy(netdev->name, "eth%d");
1224 err = register_netdev(netdev);
1228 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1234 e1000_release_hw_control(adapter);
1236 if (!e1000_check_phy_reset_block(hw))
1237 e1000_phy_hw_reset(hw);
1239 if (hw->flash_address)
1240 iounmap(hw->flash_address);
1242 for (i = 0; i < adapter->num_rx_queues; i++)
1243 dev_put(&adapter->polling_netdev[i]);
1245 kfree(adapter->tx_ring);
1246 kfree(adapter->rx_ring);
1247 kfree(adapter->polling_netdev);
1249 iounmap(hw->hw_addr);
1251 free_netdev(netdev);
1253 pci_release_selected_regions(pdev, bars);
1256 pci_disable_device(pdev);
1261 * e1000_remove - Device Removal Routine
1262 * @pdev: PCI device information struct
1264 * e1000_remove is called by the PCI subsystem to alert the driver
1265 * that it should release a PCI device. The could be caused by a
1266 * Hot-Plug event, or because the driver is going to be removed from
1270 static void __devexit e1000_remove(struct pci_dev *pdev)
1272 struct net_device *netdev = pci_get_drvdata(pdev);
1273 struct e1000_adapter *adapter = netdev_priv(netdev);
1274 struct e1000_hw *hw = &adapter->hw;
1277 cancel_work_sync(&adapter->reset_task);
1279 e1000_release_manageability(adapter);
1281 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1282 * would have already happened in close and is redundant. */
1283 e1000_release_hw_control(adapter);
1285 for (i = 0; i < adapter->num_rx_queues; i++)
1286 dev_put(&adapter->polling_netdev[i]);
1288 unregister_netdev(netdev);
1290 if (!e1000_check_phy_reset_block(hw))
1291 e1000_phy_hw_reset(hw);
1293 kfree(adapter->tx_ring);
1294 kfree(adapter->rx_ring);
1295 kfree(adapter->polling_netdev);
1297 iounmap(hw->hw_addr);
1298 if (hw->flash_address)
1299 iounmap(hw->flash_address);
1300 pci_release_selected_regions(pdev, adapter->bars);
1302 free_netdev(netdev);
1304 pci_disable_device(pdev);
1308 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1309 * @adapter: board private structure to initialize
1311 * e1000_sw_init initializes the Adapter private data structure.
1312 * Fields are initialized based on PCI device information and
1313 * OS network device settings (MTU size).
1316 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1318 struct e1000_hw *hw = &adapter->hw;
1319 struct net_device *netdev = adapter->netdev;
1320 struct pci_dev *pdev = adapter->pdev;
1323 /* PCI config space info */
1325 hw->vendor_id = pdev->vendor;
1326 hw->device_id = pdev->device;
1327 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1328 hw->subsystem_id = pdev->subsystem_device;
1329 hw->revision_id = pdev->revision;
1331 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1333 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1334 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1335 hw->max_frame_size = netdev->mtu +
1336 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1337 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1339 /* identify the MAC */
1341 if (e1000_set_mac_type(hw)) {
1342 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1346 switch (hw->mac_type) {
1351 case e1000_82541_rev_2:
1352 case e1000_82547_rev_2:
1353 hw->phy_init_script = 1;
1357 e1000_set_media_type(hw);
1359 hw->wait_autoneg_complete = false;
1360 hw->tbi_compatibility_en = true;
1361 hw->adaptive_ifs = true;
1363 /* Copper options */
1365 if (hw->media_type == e1000_media_type_copper) {
1366 hw->mdix = AUTO_ALL_MODES;
1367 hw->disable_polarity_correction = false;
1368 hw->master_slave = E1000_MASTER_SLAVE;
1371 adapter->num_tx_queues = 1;
1372 adapter->num_rx_queues = 1;
1374 if (e1000_alloc_queues(adapter)) {
1375 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1379 for (i = 0; i < adapter->num_rx_queues; i++) {
1380 adapter->polling_netdev[i].priv = adapter;
1381 dev_hold(&adapter->polling_netdev[i]);
1382 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1384 spin_lock_init(&adapter->tx_queue_lock);
1386 /* Explicitly disable IRQ since the NIC can be in any state. */
1387 e1000_irq_disable(adapter);
1389 spin_lock_init(&adapter->stats_lock);
1391 set_bit(__E1000_DOWN, &adapter->flags);
1397 * e1000_alloc_queues - Allocate memory for all rings
1398 * @adapter: board private structure to initialize
1400 * We allocate one ring per queue at run-time since we don't know the
1401 * number of queues at compile-time. The polling_netdev array is
1402 * intended for Multiqueue, but should work fine with a single queue.
1405 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1407 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1408 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1409 if (!adapter->tx_ring)
1412 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1413 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1414 if (!adapter->rx_ring) {
1415 kfree(adapter->tx_ring);
1419 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1420 sizeof(struct net_device),
1422 if (!adapter->polling_netdev) {
1423 kfree(adapter->tx_ring);
1424 kfree(adapter->rx_ring);
1428 return E1000_SUCCESS;
1432 * e1000_open - Called when a network interface is made active
1433 * @netdev: network interface device structure
1435 * Returns 0 on success, negative value on failure
1437 * The open entry point is called when a network interface is made
1438 * active by the system (IFF_UP). At this point all resources needed
1439 * for transmit and receive operations are allocated, the interrupt
1440 * handler is registered with the OS, the watchdog timer is started,
1441 * and the stack is notified that the interface is ready.
1444 static int e1000_open(struct net_device *netdev)
1446 struct e1000_adapter *adapter = netdev_priv(netdev);
1447 struct e1000_hw *hw = &adapter->hw;
1450 /* disallow open during test */
1451 if (test_bit(__E1000_TESTING, &adapter->flags))
1454 /* allocate transmit descriptors */
1455 err = e1000_setup_all_tx_resources(adapter);
1459 /* allocate receive descriptors */
1460 err = e1000_setup_all_rx_resources(adapter);
1464 e1000_power_up_phy(adapter);
1466 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1467 if ((hw->mng_cookie.status &
1468 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1469 e1000_update_mng_vlan(adapter);
1472 /* If AMT is enabled, let the firmware know that the network
1473 * interface is now open */
1474 if (hw->mac_type == e1000_82573 &&
1475 e1000_check_mng_mode(hw))
1476 e1000_get_hw_control(adapter);
1478 /* before we allocate an interrupt, we must be ready to handle it.
1479 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1480 * as soon as we call pci_request_irq, so we have to setup our
1481 * clean_rx handler before we do so. */
1482 e1000_configure(adapter);
1484 err = e1000_request_irq(adapter);
1488 /* From here on the code is the same as e1000_up() */
1489 clear_bit(__E1000_DOWN, &adapter->flags);
1491 napi_enable(&adapter->napi);
1493 e1000_irq_enable(adapter);
1495 netif_start_queue(netdev);
1497 /* fire a link status change interrupt to start the watchdog */
1498 ew32(ICS, E1000_ICS_LSC);
1500 return E1000_SUCCESS;
1503 e1000_release_hw_control(adapter);
1504 e1000_power_down_phy(adapter);
1505 e1000_free_all_rx_resources(adapter);
1507 e1000_free_all_tx_resources(adapter);
1509 e1000_reset(adapter);
1515 * e1000_close - Disables a network interface
1516 * @netdev: network interface device structure
1518 * Returns 0, this is not allowed to fail
1520 * The close entry point is called when an interface is de-activated
1521 * by the OS. The hardware is still under the drivers control, but
1522 * needs to be disabled. A global MAC reset is issued to stop the
1523 * hardware, and all transmit and receive resources are freed.
1526 static int e1000_close(struct net_device *netdev)
1528 struct e1000_adapter *adapter = netdev_priv(netdev);
1529 struct e1000_hw *hw = &adapter->hw;
1531 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1532 e1000_down(adapter);
1533 e1000_power_down_phy(adapter);
1534 e1000_free_irq(adapter);
1536 e1000_free_all_tx_resources(adapter);
1537 e1000_free_all_rx_resources(adapter);
1539 /* kill manageability vlan ID if supported, but not if a vlan with
1540 * the same ID is registered on the host OS (let 8021q kill it) */
1541 if ((hw->mng_cookie.status &
1542 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1544 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1545 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1548 /* If AMT is enabled, let the firmware know that the network
1549 * interface is now closed */
1550 if (hw->mac_type == e1000_82573 &&
1551 e1000_check_mng_mode(hw))
1552 e1000_release_hw_control(adapter);
1558 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1559 * @adapter: address of board private structure
1560 * @start: address of beginning of memory
1561 * @len: length of memory
1563 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1566 struct e1000_hw *hw = &adapter->hw;
1567 unsigned long begin = (unsigned long)start;
1568 unsigned long end = begin + len;
1570 /* First rev 82545 and 82546 need to not allow any memory
1571 * write location to cross 64k boundary due to errata 23 */
1572 if (hw->mac_type == e1000_82545 ||
1573 hw->mac_type == e1000_82546) {
1574 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1581 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1582 * @adapter: board private structure
1583 * @txdr: tx descriptor ring (for a specific queue) to setup
1585 * Return 0 on success, negative on failure
1588 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1589 struct e1000_tx_ring *txdr)
1591 struct pci_dev *pdev = adapter->pdev;
1594 size = sizeof(struct e1000_buffer) * txdr->count;
1595 txdr->buffer_info = vmalloc(size);
1596 if (!txdr->buffer_info) {
1598 "Unable to allocate memory for the transmit descriptor ring\n");
1601 memset(txdr->buffer_info, 0, size);
1603 /* round up to nearest 4K */
1605 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1606 txdr->size = ALIGN(txdr->size, 4096);
1608 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1611 vfree(txdr->buffer_info);
1613 "Unable to allocate memory for the transmit descriptor ring\n");
1617 /* Fix for errata 23, can't cross 64kB boundary */
1618 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1619 void *olddesc = txdr->desc;
1620 dma_addr_t olddma = txdr->dma;
1621 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1622 "at %p\n", txdr->size, txdr->desc);
1623 /* Try again, without freeing the previous */
1624 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1625 /* Failed allocation, critical failure */
1627 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1628 goto setup_tx_desc_die;
1631 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1633 pci_free_consistent(pdev, txdr->size, txdr->desc,
1635 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1637 "Unable to allocate aligned memory "
1638 "for the transmit descriptor ring\n");
1639 vfree(txdr->buffer_info);
1642 /* Free old allocation, new allocation was successful */
1643 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1646 memset(txdr->desc, 0, txdr->size);
1648 txdr->next_to_use = 0;
1649 txdr->next_to_clean = 0;
1650 spin_lock_init(&txdr->tx_lock);
1656 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1657 * (Descriptors) for all queues
1658 * @adapter: board private structure
1660 * Return 0 on success, negative on failure
1663 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1667 for (i = 0; i < adapter->num_tx_queues; i++) {
1668 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1671 "Allocation for Tx Queue %u failed\n", i);
1672 for (i-- ; i >= 0; i--)
1673 e1000_free_tx_resources(adapter,
1674 &adapter->tx_ring[i]);
1683 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1684 * @adapter: board private structure
1686 * Configure the Tx unit of the MAC after a reset.
1689 static void e1000_configure_tx(struct e1000_adapter *adapter)
1692 struct e1000_hw *hw = &adapter->hw;
1693 u32 tdlen, tctl, tipg, tarc;
1696 /* Setup the HW Tx Head and Tail descriptor pointers */
1698 switch (adapter->num_tx_queues) {
1701 tdba = adapter->tx_ring[0].dma;
1702 tdlen = adapter->tx_ring[0].count *
1703 sizeof(struct e1000_tx_desc);
1705 ew32(TDBAH, (tdba >> 32));
1706 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1709 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1710 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1714 /* Set the default values for the Tx Inter Packet Gap timer */
1715 if (hw->mac_type <= e1000_82547_rev_2 &&
1716 (hw->media_type == e1000_media_type_fiber ||
1717 hw->media_type == e1000_media_type_internal_serdes))
1718 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1720 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1722 switch (hw->mac_type) {
1723 case e1000_82542_rev2_0:
1724 case e1000_82542_rev2_1:
1725 tipg = DEFAULT_82542_TIPG_IPGT;
1726 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1727 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1729 case e1000_80003es2lan:
1730 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1731 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1734 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1735 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1738 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1739 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1742 /* Set the Tx Interrupt Delay register */
1744 ew32(TIDV, adapter->tx_int_delay);
1745 if (hw->mac_type >= e1000_82540)
1746 ew32(TADV, adapter->tx_abs_int_delay);
1748 /* Program the Transmit Control Register */
1751 tctl &= ~E1000_TCTL_CT;
1752 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1753 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1755 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1757 /* set the speed mode bit, we'll clear it if we're not at
1758 * gigabit link later */
1761 } else if (hw->mac_type == e1000_80003es2lan) {
1770 e1000_config_collision_dist(hw);
1772 /* Setup Transmit Descriptor Settings for eop descriptor */
1773 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1775 /* only set IDE if we are delaying interrupts using the timers */
1776 if (adapter->tx_int_delay)
1777 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1779 if (hw->mac_type < e1000_82543)
1780 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1782 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1784 /* Cache if we're 82544 running in PCI-X because we'll
1785 * need this to apply a workaround later in the send path. */
1786 if (hw->mac_type == e1000_82544 &&
1787 hw->bus_type == e1000_bus_type_pcix)
1788 adapter->pcix_82544 = 1;
1795 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1796 * @adapter: board private structure
1797 * @rxdr: rx descriptor ring (for a specific queue) to setup
1799 * Returns 0 on success, negative on failure
1802 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1803 struct e1000_rx_ring *rxdr)
1805 struct e1000_hw *hw = &adapter->hw;
1806 struct pci_dev *pdev = adapter->pdev;
1809 size = sizeof(struct e1000_buffer) * rxdr->count;
1810 rxdr->buffer_info = vmalloc(size);
1811 if (!rxdr->buffer_info) {
1813 "Unable to allocate memory for the receive descriptor ring\n");
1816 memset(rxdr->buffer_info, 0, size);
1818 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1820 if (!rxdr->ps_page) {
1821 vfree(rxdr->buffer_info);
1823 "Unable to allocate memory for the receive descriptor ring\n");
1827 rxdr->ps_page_dma = kcalloc(rxdr->count,
1828 sizeof(struct e1000_ps_page_dma),
1830 if (!rxdr->ps_page_dma) {
1831 vfree(rxdr->buffer_info);
1832 kfree(rxdr->ps_page);
1834 "Unable to allocate memory for the receive descriptor ring\n");
1838 if (hw->mac_type <= e1000_82547_rev_2)
1839 desc_len = sizeof(struct e1000_rx_desc);
1841 desc_len = sizeof(union e1000_rx_desc_packet_split);
1843 /* Round up to nearest 4K */
1845 rxdr->size = rxdr->count * desc_len;
1846 rxdr->size = ALIGN(rxdr->size, 4096);
1848 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1852 "Unable to allocate memory for the receive descriptor ring\n");
1854 vfree(rxdr->buffer_info);
1855 kfree(rxdr->ps_page);
1856 kfree(rxdr->ps_page_dma);
1860 /* Fix for errata 23, can't cross 64kB boundary */
1861 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1862 void *olddesc = rxdr->desc;
1863 dma_addr_t olddma = rxdr->dma;
1864 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1865 "at %p\n", rxdr->size, rxdr->desc);
1866 /* Try again, without freeing the previous */
1867 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1868 /* Failed allocation, critical failure */
1870 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1872 "Unable to allocate memory "
1873 "for the receive descriptor ring\n");
1874 goto setup_rx_desc_die;
1877 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1879 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1881 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1883 "Unable to allocate aligned memory "
1884 "for the receive descriptor ring\n");
1885 goto setup_rx_desc_die;
1887 /* Free old allocation, new allocation was successful */
1888 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1891 memset(rxdr->desc, 0, rxdr->size);
1893 rxdr->next_to_clean = 0;
1894 rxdr->next_to_use = 0;
1900 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1901 * (Descriptors) for all queues
1902 * @adapter: board private structure
1904 * Return 0 on success, negative on failure
1907 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1911 for (i = 0; i < adapter->num_rx_queues; i++) {
1912 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1915 "Allocation for Rx Queue %u failed\n", i);
1916 for (i-- ; i >= 0; i--)
1917 e1000_free_rx_resources(adapter,
1918 &adapter->rx_ring[i]);
1927 * e1000_setup_rctl - configure the receive control registers
1928 * @adapter: Board private structure
1930 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1931 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1932 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1934 struct e1000_hw *hw = &adapter->hw;
1937 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1943 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1945 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1946 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1947 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1949 if (hw->tbi_compatibility_on == 1)
1950 rctl |= E1000_RCTL_SBP;
1952 rctl &= ~E1000_RCTL_SBP;
1954 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1955 rctl &= ~E1000_RCTL_LPE;
1957 rctl |= E1000_RCTL_LPE;
1959 /* Setup buffer sizes */
1960 rctl &= ~E1000_RCTL_SZ_4096;
1961 rctl |= E1000_RCTL_BSEX;
1962 switch (adapter->rx_buffer_len) {
1963 case E1000_RXBUFFER_256:
1964 rctl |= E1000_RCTL_SZ_256;
1965 rctl &= ~E1000_RCTL_BSEX;
1967 case E1000_RXBUFFER_512:
1968 rctl |= E1000_RCTL_SZ_512;
1969 rctl &= ~E1000_RCTL_BSEX;
1971 case E1000_RXBUFFER_1024:
1972 rctl |= E1000_RCTL_SZ_1024;
1973 rctl &= ~E1000_RCTL_BSEX;
1975 case E1000_RXBUFFER_2048:
1977 rctl |= E1000_RCTL_SZ_2048;
1978 rctl &= ~E1000_RCTL_BSEX;
1980 case E1000_RXBUFFER_4096:
1981 rctl |= E1000_RCTL_SZ_4096;
1983 case E1000_RXBUFFER_8192:
1984 rctl |= E1000_RCTL_SZ_8192;
1986 case E1000_RXBUFFER_16384:
1987 rctl |= E1000_RCTL_SZ_16384;
1991 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1992 /* 82571 and greater support packet-split where the protocol
1993 * header is placed in skb->data and the packet data is
1994 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1995 * In the case of a non-split, skb->data is linearly filled,
1996 * followed by the page buffers. Therefore, skb->data is
1997 * sized to hold the largest protocol header.
1999 /* allocations using alloc_page take too long for regular MTU
2000 * so only enable packet split for jumbo frames */
2001 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
2002 if ((hw->mac_type >= e1000_82571) && (pages <= 3) &&
2003 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
2004 adapter->rx_ps_pages = pages;
2006 adapter->rx_ps_pages = 0;
2008 if (adapter->rx_ps_pages) {
2009 /* Configure extra packet-split registers */
2010 rfctl = er32(RFCTL);
2011 rfctl |= E1000_RFCTL_EXTEN;
2012 /* disable packet split support for IPv6 extension headers,
2013 * because some malformed IPv6 headers can hang the RX */
2014 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2015 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2019 rctl |= E1000_RCTL_DTYP_PS;
2021 psrctl |= adapter->rx_ps_bsize0 >>
2022 E1000_PSRCTL_BSIZE0_SHIFT;
2024 switch (adapter->rx_ps_pages) {
2026 psrctl |= PAGE_SIZE <<
2027 E1000_PSRCTL_BSIZE3_SHIFT;
2029 psrctl |= PAGE_SIZE <<
2030 E1000_PSRCTL_BSIZE2_SHIFT;
2032 psrctl |= PAGE_SIZE >>
2033 E1000_PSRCTL_BSIZE1_SHIFT;
2037 ew32(PSRCTL, psrctl);
2044 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2045 * @adapter: board private structure
2047 * Configure the Rx unit of the MAC after a reset.
2050 static void e1000_configure_rx(struct e1000_adapter *adapter)
2053 struct e1000_hw *hw = &adapter->hw;
2054 u32 rdlen, rctl, rxcsum, ctrl_ext;
2056 if (adapter->rx_ps_pages) {
2057 /* this is a 32 byte descriptor */
2058 rdlen = adapter->rx_ring[0].count *
2059 sizeof(union e1000_rx_desc_packet_split);
2060 adapter->clean_rx = e1000_clean_rx_irq_ps;
2061 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2063 rdlen = adapter->rx_ring[0].count *
2064 sizeof(struct e1000_rx_desc);
2065 adapter->clean_rx = e1000_clean_rx_irq;
2066 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2069 /* disable receives while setting up the descriptors */
2071 ew32(RCTL, rctl & ~E1000_RCTL_EN);
2073 /* set the Receive Delay Timer Register */
2074 ew32(RDTR, adapter->rx_int_delay);
2076 if (hw->mac_type >= e1000_82540) {
2077 ew32(RADV, adapter->rx_abs_int_delay);
2078 if (adapter->itr_setting != 0)
2079 ew32(ITR, 1000000000 / (adapter->itr * 256));
2082 if (hw->mac_type >= e1000_82571) {
2083 ctrl_ext = er32(CTRL_EXT);
2084 /* Reset delay timers after every interrupt */
2085 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2086 /* Auto-Mask interrupts upon ICR access */
2087 ctrl_ext |= E1000_CTRL_EXT_IAME;
2088 ew32(IAM, 0xffffffff);
2089 ew32(CTRL_EXT, ctrl_ext);
2090 E1000_WRITE_FLUSH();
2093 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2094 * the Base and Length of the Rx Descriptor Ring */
2095 switch (adapter->num_rx_queues) {
2098 rdba = adapter->rx_ring[0].dma;
2100 ew32(RDBAH, (rdba >> 32));
2101 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2104 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2105 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
2109 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2110 if (hw->mac_type >= e1000_82543) {
2111 rxcsum = er32(RXCSUM);
2112 if (adapter->rx_csum) {
2113 rxcsum |= E1000_RXCSUM_TUOFL;
2115 /* Enable 82571 IPv4 payload checksum for UDP fragments
2116 * Must be used in conjunction with packet-split. */
2117 if ((hw->mac_type >= e1000_82571) &&
2118 (adapter->rx_ps_pages)) {
2119 rxcsum |= E1000_RXCSUM_IPPCSE;
2122 rxcsum &= ~E1000_RXCSUM_TUOFL;
2123 /* don't need to clear IPPCSE as it defaults to 0 */
2125 ew32(RXCSUM, rxcsum);
2128 /* enable early receives on 82573, only takes effect if using > 2048
2129 * byte total frame size. for example only for jumbo frames */
2130 #define E1000_ERT_2048 0x100
2131 if (hw->mac_type == e1000_82573)
2132 ew32(ERT, E1000_ERT_2048);
2134 /* Enable Receives */
2139 * e1000_free_tx_resources - Free Tx Resources per Queue
2140 * @adapter: board private structure
2141 * @tx_ring: Tx descriptor ring for a specific queue
2143 * Free all transmit software resources
2146 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2147 struct e1000_tx_ring *tx_ring)
2149 struct pci_dev *pdev = adapter->pdev;
2151 e1000_clean_tx_ring(adapter, tx_ring);
2153 vfree(tx_ring->buffer_info);
2154 tx_ring->buffer_info = NULL;
2156 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2158 tx_ring->desc = NULL;
2162 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2163 * @adapter: board private structure
2165 * Free all transmit software resources
2168 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
2172 for (i = 0; i < adapter->num_tx_queues; i++)
2173 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
2176 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2177 struct e1000_buffer *buffer_info)
2179 if (buffer_info->dma) {
2180 pci_unmap_page(adapter->pdev,
2182 buffer_info->length,
2184 buffer_info->dma = 0;
2186 if (buffer_info->skb) {
2187 dev_kfree_skb_any(buffer_info->skb);
2188 buffer_info->skb = NULL;
2190 /* buffer_info must be completely set up in the transmit path */
2194 * e1000_clean_tx_ring - Free Tx Buffers
2195 * @adapter: board private structure
2196 * @tx_ring: ring to be cleaned
2199 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2200 struct e1000_tx_ring *tx_ring)
2202 struct e1000_hw *hw = &adapter->hw;
2203 struct e1000_buffer *buffer_info;
2207 /* Free all the Tx ring sk_buffs */
2209 for (i = 0; i < tx_ring->count; i++) {
2210 buffer_info = &tx_ring->buffer_info[i];
2211 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2214 size = sizeof(struct e1000_buffer) * tx_ring->count;
2215 memset(tx_ring->buffer_info, 0, size);
2217 /* Zero out the descriptor ring */
2219 memset(tx_ring->desc, 0, tx_ring->size);
2221 tx_ring->next_to_use = 0;
2222 tx_ring->next_to_clean = 0;
2223 tx_ring->last_tx_tso = 0;
2225 writel(0, hw->hw_addr + tx_ring->tdh);
2226 writel(0, hw->hw_addr + tx_ring->tdt);
2230 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2231 * @adapter: board private structure
2234 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2238 for (i = 0; i < adapter->num_tx_queues; i++)
2239 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2243 * e1000_free_rx_resources - Free Rx Resources
2244 * @adapter: board private structure
2245 * @rx_ring: ring to clean the resources from
2247 * Free all receive software resources
2250 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2251 struct e1000_rx_ring *rx_ring)
2253 struct pci_dev *pdev = adapter->pdev;
2255 e1000_clean_rx_ring(adapter, rx_ring);
2257 vfree(rx_ring->buffer_info);
2258 rx_ring->buffer_info = NULL;
2259 kfree(rx_ring->ps_page);
2260 rx_ring->ps_page = NULL;
2261 kfree(rx_ring->ps_page_dma);
2262 rx_ring->ps_page_dma = NULL;
2264 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2266 rx_ring->desc = NULL;
2270 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2271 * @adapter: board private structure
2273 * Free all receive software resources
2276 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2280 for (i = 0; i < adapter->num_rx_queues; i++)
2281 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2285 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2286 * @adapter: board private structure
2287 * @rx_ring: ring to free buffers from
2290 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2291 struct e1000_rx_ring *rx_ring)
2293 struct e1000_hw *hw = &adapter->hw;
2294 struct e1000_buffer *buffer_info;
2295 struct e1000_ps_page *ps_page;
2296 struct e1000_ps_page_dma *ps_page_dma;
2297 struct pci_dev *pdev = adapter->pdev;
2301 /* Free all the Rx ring sk_buffs */
2302 for (i = 0; i < rx_ring->count; i++) {
2303 buffer_info = &rx_ring->buffer_info[i];
2304 if (buffer_info->skb) {
2305 pci_unmap_single(pdev,
2307 buffer_info->length,
2308 PCI_DMA_FROMDEVICE);
2310 dev_kfree_skb(buffer_info->skb);
2311 buffer_info->skb = NULL;
2313 ps_page = &rx_ring->ps_page[i];
2314 ps_page_dma = &rx_ring->ps_page_dma[i];
2315 for (j = 0; j < adapter->rx_ps_pages; j++) {
2316 if (!ps_page->ps_page[j]) break;
2317 pci_unmap_page(pdev,
2318 ps_page_dma->ps_page_dma[j],
2319 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2320 ps_page_dma->ps_page_dma[j] = 0;
2321 put_page(ps_page->ps_page[j]);
2322 ps_page->ps_page[j] = NULL;
2326 size = sizeof(struct e1000_buffer) * rx_ring->count;
2327 memset(rx_ring->buffer_info, 0, size);
2328 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2329 memset(rx_ring->ps_page, 0, size);
2330 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2331 memset(rx_ring->ps_page_dma, 0, size);
2333 /* Zero out the descriptor ring */
2335 memset(rx_ring->desc, 0, rx_ring->size);
2337 rx_ring->next_to_clean = 0;
2338 rx_ring->next_to_use = 0;
2340 writel(0, hw->hw_addr + rx_ring->rdh);
2341 writel(0, hw->hw_addr + rx_ring->rdt);
2345 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2346 * @adapter: board private structure
2349 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2353 for (i = 0; i < adapter->num_rx_queues; i++)
2354 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2357 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2358 * and memory write and invalidate disabled for certain operations
2360 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2362 struct e1000_hw *hw = &adapter->hw;
2363 struct net_device *netdev = adapter->netdev;
2366 e1000_pci_clear_mwi(hw);
2369 rctl |= E1000_RCTL_RST;
2371 E1000_WRITE_FLUSH();
2374 if (netif_running(netdev))
2375 e1000_clean_all_rx_rings(adapter);
2378 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2380 struct e1000_hw *hw = &adapter->hw;
2381 struct net_device *netdev = adapter->netdev;
2385 rctl &= ~E1000_RCTL_RST;
2387 E1000_WRITE_FLUSH();
2390 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2391 e1000_pci_set_mwi(hw);
2393 if (netif_running(netdev)) {
2394 /* No need to loop, because 82542 supports only 1 queue */
2395 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2396 e1000_configure_rx(adapter);
2397 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2402 * e1000_set_mac - Change the Ethernet Address of the NIC
2403 * @netdev: network interface device structure
2404 * @p: pointer to an address structure
2406 * Returns 0 on success, negative on failure
2409 static int e1000_set_mac(struct net_device *netdev, void *p)
2411 struct e1000_adapter *adapter = netdev_priv(netdev);
2412 struct e1000_hw *hw = &adapter->hw;
2413 struct sockaddr *addr = p;
2415 if (!is_valid_ether_addr(addr->sa_data))
2416 return -EADDRNOTAVAIL;
2418 /* 82542 2.0 needs to be in reset to write receive address registers */
2420 if (hw->mac_type == e1000_82542_rev2_0)
2421 e1000_enter_82542_rst(adapter);
2423 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2424 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2426 e1000_rar_set(hw, hw->mac_addr, 0);
2428 /* With 82571 controllers, LAA may be overwritten (with the default)
2429 * due to controller reset from the other port. */
2430 if (hw->mac_type == e1000_82571) {
2431 /* activate the work around */
2432 hw->laa_is_present = 1;
2434 /* Hold a copy of the LAA in RAR[14] This is done so that
2435 * between the time RAR[0] gets clobbered and the time it
2436 * gets fixed (in e1000_watchdog), the actual LAA is in one
2437 * of the RARs and no incoming packets directed to this port
2438 * are dropped. Eventaully the LAA will be in RAR[0] and
2440 e1000_rar_set(hw, hw->mac_addr,
2441 E1000_RAR_ENTRIES - 1);
2444 if (hw->mac_type == e1000_82542_rev2_0)
2445 e1000_leave_82542_rst(adapter);
2451 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2452 * @netdev: network interface device structure
2454 * The set_rx_mode entry point is called whenever the unicast or multicast
2455 * address lists or the network interface flags are updated. This routine is
2456 * responsible for configuring the hardware for proper unicast, multicast,
2457 * promiscuous mode, and all-multi behavior.
2460 static void e1000_set_rx_mode(struct net_device *netdev)
2462 struct e1000_adapter *adapter = netdev_priv(netdev);
2463 struct e1000_hw *hw = &adapter->hw;
2464 struct dev_addr_list *uc_ptr;
2465 struct dev_addr_list *mc_ptr;
2468 int i, rar_entries = E1000_RAR_ENTRIES;
2469 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2470 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2471 E1000_NUM_MTA_REGISTERS;
2473 if (hw->mac_type == e1000_ich8lan)
2474 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2476 /* reserve RAR[14] for LAA over-write work-around */
2477 if (hw->mac_type == e1000_82571)
2480 /* Check for Promiscuous and All Multicast modes */
2484 if (netdev->flags & IFF_PROMISC) {
2485 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2486 rctl &= ~E1000_RCTL_VFE;
2488 if (netdev->flags & IFF_ALLMULTI) {
2489 rctl |= E1000_RCTL_MPE;
2491 rctl &= ~E1000_RCTL_MPE;
2493 if (adapter->hw.mac_type != e1000_ich8lan)
2494 rctl |= E1000_RCTL_VFE;
2498 if (netdev->uc_count > rar_entries - 1) {
2499 rctl |= E1000_RCTL_UPE;
2500 } else if (!(netdev->flags & IFF_PROMISC)) {
2501 rctl &= ~E1000_RCTL_UPE;
2502 uc_ptr = netdev->uc_list;
2507 /* 82542 2.0 needs to be in reset to write receive address registers */
2509 if (hw->mac_type == e1000_82542_rev2_0)
2510 e1000_enter_82542_rst(adapter);
2512 /* load the first 14 addresses into the exact filters 1-14. Unicast
2513 * addresses take precedence to avoid disabling unicast filtering
2516 * RAR 0 is used for the station MAC adddress
2517 * if there are not 14 addresses, go ahead and clear the filters
2518 * -- with 82571 controllers only 0-13 entries are filled here
2520 mc_ptr = netdev->mc_list;
2522 for (i = 1; i < rar_entries; i++) {
2524 e1000_rar_set(hw, uc_ptr->da_addr, i);
2525 uc_ptr = uc_ptr->next;
2526 } else if (mc_ptr) {
2527 e1000_rar_set(hw, mc_ptr->da_addr, i);
2528 mc_ptr = mc_ptr->next;
2530 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2531 E1000_WRITE_FLUSH();
2532 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2533 E1000_WRITE_FLUSH();
2536 WARN_ON(uc_ptr != NULL);
2538 /* clear the old settings from the multicast hash table */
2540 for (i = 0; i < mta_reg_count; i++) {
2541 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2542 E1000_WRITE_FLUSH();
2545 /* load any remaining addresses into the hash table */
2547 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2548 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
2549 e1000_mta_set(hw, hash_value);
2552 if (hw->mac_type == e1000_82542_rev2_0)
2553 e1000_leave_82542_rst(adapter);
2556 /* Need to wait a few seconds after link up to get diagnostic information from
2559 static void e1000_update_phy_info(unsigned long data)
2561 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2562 struct e1000_hw *hw = &adapter->hw;
2563 e1000_phy_get_info(hw, &adapter->phy_info);
2567 * e1000_82547_tx_fifo_stall - Timer Call-back
2568 * @data: pointer to adapter cast into an unsigned long
2571 static void e1000_82547_tx_fifo_stall(unsigned long data)
2573 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2574 struct e1000_hw *hw = &adapter->hw;
2575 struct net_device *netdev = adapter->netdev;
2578 if (atomic_read(&adapter->tx_fifo_stall)) {
2579 if ((er32(TDT) == er32(TDH)) &&
2580 (er32(TDFT) == er32(TDFH)) &&
2581 (er32(TDFTS) == er32(TDFHS))) {
2583 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2584 ew32(TDFT, adapter->tx_head_addr);
2585 ew32(TDFH, adapter->tx_head_addr);
2586 ew32(TDFTS, adapter->tx_head_addr);
2587 ew32(TDFHS, adapter->tx_head_addr);
2589 E1000_WRITE_FLUSH();
2591 adapter->tx_fifo_head = 0;
2592 atomic_set(&adapter->tx_fifo_stall, 0);
2593 netif_wake_queue(netdev);
2595 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2601 * e1000_watchdog - Timer Call-back
2602 * @data: pointer to adapter cast into an unsigned long
2604 static void e1000_watchdog(unsigned long data)
2606 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2607 struct e1000_hw *hw = &adapter->hw;
2608 struct net_device *netdev = adapter->netdev;
2609 struct e1000_tx_ring *txdr = adapter->tx_ring;
2613 ret_val = e1000_check_for_link(hw);
2614 if ((ret_val == E1000_ERR_PHY) &&
2615 (hw->phy_type == e1000_phy_igp_3) &&
2616 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2617 /* See e1000_kumeran_lock_loss_workaround() */
2619 "Gigabit has been disabled, downgrading speed\n");
2622 if (hw->mac_type == e1000_82573) {
2623 e1000_enable_tx_pkt_filtering(hw);
2624 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
2625 e1000_update_mng_vlan(adapter);
2628 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2629 !(er32(TXCW) & E1000_TXCW_ANE))
2630 link = !hw->serdes_link_down;
2632 link = er32(STATUS) & E1000_STATUS_LU;
2635 if (!netif_carrier_ok(netdev)) {
2638 e1000_get_speed_and_duplex(hw,
2639 &adapter->link_speed,
2640 &adapter->link_duplex);
2643 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2644 "Flow Control: %s\n",
2645 adapter->link_speed,
2646 adapter->link_duplex == FULL_DUPLEX ?
2647 "Full Duplex" : "Half Duplex",
2648 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2649 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2650 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2651 E1000_CTRL_TFCE) ? "TX" : "None" )));
2653 /* tweak tx_queue_len according to speed/duplex
2654 * and adjust the timeout factor */
2655 netdev->tx_queue_len = adapter->tx_queue_len;
2656 adapter->tx_timeout_factor = 1;
2657 switch (adapter->link_speed) {
2660 netdev->tx_queue_len = 10;
2661 adapter->tx_timeout_factor = 8;
2665 netdev->tx_queue_len = 100;
2666 /* maybe add some timeout factor ? */
2670 if ((hw->mac_type == e1000_82571 ||
2671 hw->mac_type == e1000_82572) &&
2674 tarc0 = er32(TARC0);
2675 tarc0 &= ~(1 << 21);
2679 /* disable TSO for pcie and 10/100 speeds, to avoid
2680 * some hardware issues */
2681 if (!adapter->tso_force &&
2682 hw->bus_type == e1000_bus_type_pci_express){
2683 switch (adapter->link_speed) {
2687 "10/100 speed: disabling TSO\n");
2688 netdev->features &= ~NETIF_F_TSO;
2689 netdev->features &= ~NETIF_F_TSO6;
2692 netdev->features |= NETIF_F_TSO;
2693 netdev->features |= NETIF_F_TSO6;
2701 /* enable transmits in the hardware, need to do this
2702 * after setting TARC0 */
2704 tctl |= E1000_TCTL_EN;
2707 netif_carrier_on(netdev);
2708 netif_wake_queue(netdev);
2709 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2710 adapter->smartspeed = 0;
2712 /* make sure the receive unit is started */
2713 if (hw->rx_needs_kicking) {
2714 u32 rctl = er32(RCTL);
2715 ew32(RCTL, rctl | E1000_RCTL_EN);
2719 if (netif_carrier_ok(netdev)) {
2720 adapter->link_speed = 0;
2721 adapter->link_duplex = 0;
2722 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2723 netif_carrier_off(netdev);
2724 netif_stop_queue(netdev);
2725 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2727 /* 80003ES2LAN workaround--
2728 * For packet buffer work-around on link down event;
2729 * disable receives in the ISR and
2730 * reset device here in the watchdog
2732 if (hw->mac_type == e1000_80003es2lan)
2734 schedule_work(&adapter->reset_task);
2737 e1000_smartspeed(adapter);
2740 e1000_update_stats(adapter);
2742 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2743 adapter->tpt_old = adapter->stats.tpt;
2744 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2745 adapter->colc_old = adapter->stats.colc;
2747 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2748 adapter->gorcl_old = adapter->stats.gorcl;
2749 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2750 adapter->gotcl_old = adapter->stats.gotcl;
2752 e1000_update_adaptive(hw);
2754 if (!netif_carrier_ok(netdev)) {
2755 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2756 /* We've lost link, so the controller stops DMA,
2757 * but we've got queued Tx work that's never going
2758 * to get done, so reset controller to flush Tx.
2759 * (Do the reset outside of interrupt context). */
2760 adapter->tx_timeout_count++;
2761 schedule_work(&adapter->reset_task);
2765 /* Cause software interrupt to ensure rx ring is cleaned */
2766 ew32(ICS, E1000_ICS_RXDMT0);
2768 /* Force detection of hung controller every watchdog period */
2769 adapter->detect_tx_hung = true;
2771 /* With 82571 controllers, LAA may be overwritten due to controller
2772 * reset from the other port. Set the appropriate LAA in RAR[0] */
2773 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2774 e1000_rar_set(hw, hw->mac_addr, 0);
2776 /* Reset the timer */
2777 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
2780 enum latency_range {
2784 latency_invalid = 255
2788 * e1000_update_itr - update the dynamic ITR value based on statistics
2789 * Stores a new ITR value based on packets and byte
2790 * counts during the last interrupt. The advantage of per interrupt
2791 * computation is faster updates and more accurate ITR for the current
2792 * traffic pattern. Constants in this function were computed
2793 * based on theoretical maximum wire speed and thresholds were set based
2794 * on testing data as well as attempting to minimize response time
2795 * while increasing bulk throughput.
2796 * this functionality is controlled by the InterruptThrottleRate module
2797 * parameter (see e1000_param.c)
2798 * @adapter: pointer to adapter
2799 * @itr_setting: current adapter->itr
2800 * @packets: the number of packets during this measurement interval
2801 * @bytes: the number of bytes during this measurement interval
2803 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2804 u16 itr_setting, int packets, int bytes)
2806 unsigned int retval = itr_setting;
2807 struct e1000_hw *hw = &adapter->hw;
2809 if (unlikely(hw->mac_type < e1000_82540))
2810 goto update_itr_done;
2813 goto update_itr_done;
2815 switch (itr_setting) {
2816 case lowest_latency:
2817 /* jumbo frames get bulk treatment*/
2818 if (bytes/packets > 8000)
2819 retval = bulk_latency;
2820 else if ((packets < 5) && (bytes > 512))
2821 retval = low_latency;
2823 case low_latency: /* 50 usec aka 20000 ints/s */
2824 if (bytes > 10000) {
2825 /* jumbo frames need bulk latency setting */
2826 if (bytes/packets > 8000)
2827 retval = bulk_latency;
2828 else if ((packets < 10) || ((bytes/packets) > 1200))
2829 retval = bulk_latency;
2830 else if ((packets > 35))
2831 retval = lowest_latency;
2832 } else if (bytes/packets > 2000)
2833 retval = bulk_latency;
2834 else if (packets <= 2 && bytes < 512)
2835 retval = lowest_latency;
2837 case bulk_latency: /* 250 usec aka 4000 ints/s */
2838 if (bytes > 25000) {
2840 retval = low_latency;
2841 } else if (bytes < 6000) {
2842 retval = low_latency;
2851 static void e1000_set_itr(struct e1000_adapter *adapter)
2853 struct e1000_hw *hw = &adapter->hw;
2855 u32 new_itr = adapter->itr;
2857 if (unlikely(hw->mac_type < e1000_82540))
2860 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2861 if (unlikely(adapter->link_speed != SPEED_1000)) {
2867 adapter->tx_itr = e1000_update_itr(adapter,
2869 adapter->total_tx_packets,
2870 adapter->total_tx_bytes);
2871 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2872 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2873 adapter->tx_itr = low_latency;
2875 adapter->rx_itr = e1000_update_itr(adapter,
2877 adapter->total_rx_packets,
2878 adapter->total_rx_bytes);
2879 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2880 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2881 adapter->rx_itr = low_latency;
2883 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2885 switch (current_itr) {
2886 /* counts and packets in update_itr are dependent on these numbers */
2887 case lowest_latency:
2891 new_itr = 20000; /* aka hwitr = ~200 */
2901 if (new_itr != adapter->itr) {
2902 /* this attempts to bias the interrupt rate towards Bulk
2903 * by adding intermediate steps when interrupt rate is
2905 new_itr = new_itr > adapter->itr ?
2906 min(adapter->itr + (new_itr >> 2), new_itr) :
2908 adapter->itr = new_itr;
2909 ew32(ITR, 1000000000 / (new_itr * 256));
2915 #define E1000_TX_FLAGS_CSUM 0x00000001
2916 #define E1000_TX_FLAGS_VLAN 0x00000002
2917 #define E1000_TX_FLAGS_TSO 0x00000004
2918 #define E1000_TX_FLAGS_IPV4 0x00000008
2919 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2920 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2922 static int e1000_tso(struct e1000_adapter *adapter,
2923 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2925 struct e1000_context_desc *context_desc;
2926 struct e1000_buffer *buffer_info;
2929 u16 ipcse = 0, tucse, mss;
2930 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2933 if (skb_is_gso(skb)) {
2934 if (skb_header_cloned(skb)) {
2935 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2940 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2941 mss = skb_shinfo(skb)->gso_size;
2942 if (skb->protocol == htons(ETH_P_IP)) {
2943 struct iphdr *iph = ip_hdr(skb);
2946 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2950 cmd_length = E1000_TXD_CMD_IP;
2951 ipcse = skb_transport_offset(skb) - 1;
2952 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2953 ipv6_hdr(skb)->payload_len = 0;
2954 tcp_hdr(skb)->check =
2955 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2956 &ipv6_hdr(skb)->daddr,
2960 ipcss = skb_network_offset(skb);
2961 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2962 tucss = skb_transport_offset(skb);
2963 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2966 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2967 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2969 i = tx_ring->next_to_use;
2970 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2971 buffer_info = &tx_ring->buffer_info[i];
2973 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2974 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2975 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2976 context_desc->upper_setup.tcp_fields.tucss = tucss;
2977 context_desc->upper_setup.tcp_fields.tucso = tucso;
2978 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2979 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2980 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2981 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2983 buffer_info->time_stamp = jiffies;
2984 buffer_info->next_to_watch = i;
2986 if (++i == tx_ring->count) i = 0;
2987 tx_ring->next_to_use = i;
2994 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2995 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2997 struct e1000_context_desc *context_desc;
2998 struct e1000_buffer *buffer_info;
3002 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
3003 css = skb_transport_offset(skb);
3005 i = tx_ring->next_to_use;
3006 buffer_info = &tx_ring->buffer_info[i];
3007 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
3009 context_desc->lower_setup.ip_config = 0;
3010 context_desc->upper_setup.tcp_fields.tucss = css;
3011 context_desc->upper_setup.tcp_fields.tucso =
3012 css + skb->csum_offset;
3013 context_desc->upper_setup.tcp_fields.tucse = 0;
3014 context_desc->tcp_seg_setup.data = 0;
3015 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3017 buffer_info->time_stamp = jiffies;
3018 buffer_info->next_to_watch = i;
3020 if (unlikely(++i == tx_ring->count)) i = 0;
3021 tx_ring->next_to_use = i;
3029 #define E1000_MAX_TXD_PWR 12
3030 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3032 static int e1000_tx_map(struct e1000_adapter *adapter,
3033 struct e1000_tx_ring *tx_ring,
3034 struct sk_buff *skb, unsigned int first,
3035 unsigned int max_per_txd, unsigned int nr_frags,
3038 struct e1000_hw *hw = &adapter->hw;
3039 struct e1000_buffer *buffer_info;
3040 unsigned int len = skb->len;
3041 unsigned int offset = 0, size, count = 0, i;
3043 len -= skb->data_len;
3045 i = tx_ring->next_to_use;
3048 buffer_info = &tx_ring->buffer_info[i];
3049 size = min(len, max_per_txd);
3050 /* Workaround for Controller erratum --
3051 * descriptor for non-tso packet in a linear SKB that follows a
3052 * tso gets written back prematurely before the data is fully
3053 * DMA'd to the controller */
3054 if (!skb->data_len && tx_ring->last_tx_tso &&
3056 tx_ring->last_tx_tso = 0;
3060 /* Workaround for premature desc write-backs
3061 * in TSO mode. Append 4-byte sentinel desc */
3062 if (unlikely(mss && !nr_frags && size == len && size > 8))
3064 /* work-around for errata 10 and it applies
3065 * to all controllers in PCI-X mode
3066 * The fix is to make sure that the first descriptor of a
3067 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3069 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3070 (size > 2015) && count == 0))
3073 /* Workaround for potential 82544 hang in PCI-X. Avoid
3074 * terminating buffers within evenly-aligned dwords. */
3075 if (unlikely(adapter->pcix_82544 &&
3076 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3080 buffer_info->length = size;
3082 pci_map_single(adapter->pdev,
3086 buffer_info->time_stamp = jiffies;
3087 buffer_info->next_to_watch = i;
3092 if (unlikely(++i == tx_ring->count)) i = 0;
3095 for (f = 0; f < nr_frags; f++) {
3096 struct skb_frag_struct *frag;
3098 frag = &skb_shinfo(skb)->frags[f];
3100 offset = frag->page_offset;
3103 buffer_info = &tx_ring->buffer_info[i];
3104 size = min(len, max_per_txd);
3105 /* Workaround for premature desc write-backs
3106 * in TSO mode. Append 4-byte sentinel desc */
3107 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
3109 /* Workaround for potential 82544 hang in PCI-X.
3110 * Avoid terminating buffers within evenly-aligned
3112 if (unlikely(adapter->pcix_82544 &&
3113 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3117 buffer_info->length = size;
3119 pci_map_page(adapter->pdev,
3124 buffer_info->time_stamp = jiffies;
3125 buffer_info->next_to_watch = i;
3130 if (unlikely(++i == tx_ring->count)) i = 0;
3134 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3135 tx_ring->buffer_info[i].skb = skb;
3136 tx_ring->buffer_info[first].next_to_watch = i;
3141 static void e1000_tx_queue(struct e1000_adapter *adapter,
3142 struct e1000_tx_ring *tx_ring, int tx_flags,
3145 struct e1000_hw *hw = &adapter->hw;
3146 struct e1000_tx_desc *tx_desc = NULL;
3147 struct e1000_buffer *buffer_info;
3148 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3151 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
3152 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3154 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3156 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3157 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3160 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3161 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3162 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3165 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3166 txd_lower |= E1000_TXD_CMD_VLE;
3167 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3170 i = tx_ring->next_to_use;
3173 buffer_info = &tx_ring->buffer_info[i];
3174 tx_desc = E1000_TX_DESC(*tx_ring, i);
3175 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3176 tx_desc->lower.data =
3177 cpu_to_le32(txd_lower | buffer_info->length);
3178 tx_desc->upper.data = cpu_to_le32(txd_upper);
3179 if (unlikely(++i == tx_ring->count)) i = 0;
3182 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3184 /* Force memory writes to complete before letting h/w
3185 * know there are new descriptors to fetch. (Only
3186 * applicable for weak-ordered memory model archs,
3187 * such as IA-64). */
3190 tx_ring->next_to_use = i;
3191 writel(i, hw->hw_addr + tx_ring->tdt);
3192 /* we need this if more than one processor can write to our tail
3193 * at a time, it syncronizes IO on IA64/Altix systems */
3198 * 82547 workaround to avoid controller hang in half-duplex environment.
3199 * The workaround is to avoid queuing a large packet that would span
3200 * the internal Tx FIFO ring boundary by notifying the stack to resend
3201 * the packet at a later time. This gives the Tx FIFO an opportunity to
3202 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3203 * to the beginning of the Tx FIFO.
3206 #define E1000_FIFO_HDR 0x10
3207 #define E1000_82547_PAD_LEN 0x3E0
3209 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3210 struct sk_buff *skb)
3212 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3213 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3215 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3217 if (adapter->link_duplex != HALF_DUPLEX)
3218 goto no_fifo_stall_required;
3220 if (atomic_read(&adapter->tx_fifo_stall))
3223 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3224 atomic_set(&adapter->tx_fifo_stall, 1);
3228 no_fifo_stall_required:
3229 adapter->tx_fifo_head += skb_fifo_len;
3230 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3231 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3235 #define MINIMUM_DHCP_PACKET_SIZE 282
3236 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3237 struct sk_buff *skb)
3239 struct e1000_hw *hw = &adapter->hw;
3241 if (vlan_tx_tag_present(skb)) {
3242 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3243 ( hw->mng_cookie.status &
3244 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3247 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
3248 struct ethhdr *eth = (struct ethhdr *)skb->data;
3249 if ((htons(ETH_P_IP) == eth->h_proto)) {
3250 const struct iphdr *ip =
3251 (struct iphdr *)((u8 *)skb->data+14);
3252 if (IPPROTO_UDP == ip->protocol) {
3253 struct udphdr *udp =
3254 (struct udphdr *)((u8 *)ip +
3256 if (ntohs(udp->dest) == 67) {
3257 offset = (u8 *)udp + 8 - skb->data;
3258 length = skb->len - offset;
3260 return e1000_mng_write_dhcp_info(hw,
3270 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3272 struct e1000_adapter *adapter = netdev_priv(netdev);
3273 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3275 netif_stop_queue(netdev);
3276 /* Herbert's original patch had:
3277 * smp_mb__after_netif_stop_queue();
3278 * but since that doesn't exist yet, just open code it. */
3281 /* We need to check again in a case another CPU has just
3282 * made room available. */
3283 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3287 netif_start_queue(netdev);
3288 ++adapter->restart_queue;
3292 static int e1000_maybe_stop_tx(struct net_device *netdev,
3293 struct e1000_tx_ring *tx_ring, int size)
3295 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3297 return __e1000_maybe_stop_tx(netdev, size);
3300 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3301 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3303 struct e1000_adapter *adapter = netdev_priv(netdev);
3304 struct e1000_hw *hw = &adapter->hw;
3305 struct e1000_tx_ring *tx_ring;
3306 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3307 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3308 unsigned int tx_flags = 0;
3309 unsigned int len = skb->len - skb->data_len;
3310 unsigned long flags;
3311 unsigned int nr_frags;
3317 /* This goes back to the question of how to logically map a tx queue
3318 * to a flow. Right now, performance is impacted slightly negatively
3319 * if using multiple tx queues. If the stack breaks away from a
3320 * single qdisc implementation, we can look at this again. */
3321 tx_ring = adapter->tx_ring;
3323 if (unlikely(skb->len <= 0)) {
3324 dev_kfree_skb_any(skb);
3325 return NETDEV_TX_OK;
3328 /* 82571 and newer doesn't need the workaround that limited descriptor
3330 if (hw->mac_type >= e1000_82571)
3333 mss = skb_shinfo(skb)->gso_size;
3334 /* The controller does a simple calculation to
3335 * make sure there is enough room in the FIFO before
3336 * initiating the DMA for each buffer. The calc is:
3337 * 4 = ceil(buffer len/mss). To make sure we don't
3338 * overrun the FIFO, adjust the max buffer len if mss
3342 max_per_txd = min(mss << 2, max_per_txd);
3343 max_txd_pwr = fls(max_per_txd) - 1;
3345 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3346 * points to just header, pull a few bytes of payload from
3347 * frags into skb->data */
3348 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3349 if (skb->data_len && hdr_len == len) {
3350 switch (hw->mac_type) {
3351 unsigned int pull_size;
3353 /* Make sure we have room to chop off 4 bytes,
3354 * and that the end alignment will work out to
3355 * this hardware's requirements
3356 * NOTE: this is a TSO only workaround
3357 * if end byte alignment not correct move us
3358 * into the next dword */
3359 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
3366 pull_size = min((unsigned int)4, skb->data_len);
3367 if (!__pskb_pull_tail(skb, pull_size)) {
3369 "__pskb_pull_tail failed.\n");
3370 dev_kfree_skb_any(skb);
3371 return NETDEV_TX_OK;
3373 len = skb->len - skb->data_len;
3382 /* reserve a descriptor for the offload context */
3383 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3387 /* Controller Erratum workaround */
3388 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3391 count += TXD_USE_COUNT(len, max_txd_pwr);
3393 if (adapter->pcix_82544)
3396 /* work-around for errata 10 and it applies to all controllers
3397 * in PCI-X mode, so add one more descriptor to the count
3399 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3403 nr_frags = skb_shinfo(skb)->nr_frags;
3404 for (f = 0; f < nr_frags; f++)
3405 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3407 if (adapter->pcix_82544)
3411 if (hw->tx_pkt_filtering &&
3412 (hw->mac_type == e1000_82573))
3413 e1000_transfer_dhcp_info(adapter, skb);
3415 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
3416 /* Collision - tell upper layer to requeue */
3417 return NETDEV_TX_LOCKED;
3419 /* need: count + 2 desc gap to keep tail from touching
3420 * head, otherwise try next time */
3421 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
3422 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3423 return NETDEV_TX_BUSY;
3426 if (unlikely(hw->mac_type == e1000_82547)) {
3427 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3428 netif_stop_queue(netdev);
3429 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3430 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3431 return NETDEV_TX_BUSY;
3435 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3436 tx_flags |= E1000_TX_FLAGS_VLAN;
3437 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3440 first = tx_ring->next_to_use;
3442 tso = e1000_tso(adapter, tx_ring, skb);
3444 dev_kfree_skb_any(skb);
3445 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3446 return NETDEV_TX_OK;
3450 tx_ring->last_tx_tso = 1;
3451 tx_flags |= E1000_TX_FLAGS_TSO;
3452 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3453 tx_flags |= E1000_TX_FLAGS_CSUM;
3455 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3456 * 82571 hardware supports TSO capabilities for IPv6 as well...
3457 * no longer assume, we must. */
3458 if (likely(skb->protocol == htons(ETH_P_IP)))
3459 tx_flags |= E1000_TX_FLAGS_IPV4;
3461 e1000_tx_queue(adapter, tx_ring, tx_flags,
3462 e1000_tx_map(adapter, tx_ring, skb, first,
3463 max_per_txd, nr_frags, mss));
3465 netdev->trans_start = jiffies;
3467 /* Make sure there is space in the ring for the next send. */
3468 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3470 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3471 return NETDEV_TX_OK;
3475 * e1000_tx_timeout - Respond to a Tx Hang
3476 * @netdev: network interface device structure
3479 static void e1000_tx_timeout(struct net_device *netdev)
3481 struct e1000_adapter *adapter = netdev_priv(netdev);
3483 /* Do the reset outside of interrupt context */
3484 adapter->tx_timeout_count++;
3485 schedule_work(&adapter->reset_task);
3488 static void e1000_reset_task(struct work_struct *work)
3490 struct e1000_adapter *adapter =
3491 container_of(work, struct e1000_adapter, reset_task);
3493 e1000_reinit_locked(adapter);
3497 * e1000_get_stats - Get System Network Statistics
3498 * @netdev: network interface device structure
3500 * Returns the address of the device statistics structure.
3501 * The statistics are actually updated from the timer callback.
3504 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3506 struct e1000_adapter *adapter = netdev_priv(netdev);
3508 /* only return the current stats */
3509 return &adapter->net_stats;
3513 * e1000_change_mtu - Change the Maximum Transfer Unit
3514 * @netdev: network interface device structure
3515 * @new_mtu: new value for maximum frame size
3517 * Returns 0 on success, negative on failure
3520 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3522 struct e1000_adapter *adapter = netdev_priv(netdev);
3523 struct e1000_hw *hw = &adapter->hw;
3524 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3525 u16 eeprom_data = 0;
3527 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3528 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3529 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3533 /* Adapter-specific max frame size limits. */
3534 switch (hw->mac_type) {
3535 case e1000_undefined ... e1000_82542_rev2_1:
3537 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3538 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3543 /* Jumbo Frames not supported if:
3544 * - this is not an 82573L device
3545 * - ASPM is enabled in any way (0x1A bits 3:2) */
3546 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
3548 if ((hw->device_id != E1000_DEV_ID_82573L) ||
3549 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3550 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3552 "Jumbo Frames not supported.\n");
3557 /* ERT will be enabled later to enable wire speed receives */
3559 /* fall through to get support */
3562 case e1000_80003es2lan:
3563 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3564 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3565 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3570 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3574 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3575 * means we reserve 2 more, this pushes us to allocate from the next
3577 * i.e. RXBUFFER_2048 --> size-4096 slab */
3579 if (max_frame <= E1000_RXBUFFER_256)
3580 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3581 else if (max_frame <= E1000_RXBUFFER_512)
3582 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3583 else if (max_frame <= E1000_RXBUFFER_1024)
3584 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3585 else if (max_frame <= E1000_RXBUFFER_2048)
3586 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3587 else if (max_frame <= E1000_RXBUFFER_4096)
3588 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3589 else if (max_frame <= E1000_RXBUFFER_8192)
3590 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3591 else if (max_frame <= E1000_RXBUFFER_16384)
3592 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3594 /* adjust allocation if LPE protects us, and we aren't using SBP */
3595 if (!hw->tbi_compatibility_on &&
3596 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3597 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3598 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3600 netdev->mtu = new_mtu;
3601 hw->max_frame_size = max_frame;
3603 if (netif_running(netdev))
3604 e1000_reinit_locked(adapter);
3610 * e1000_update_stats - Update the board statistics counters
3611 * @adapter: board private structure
3614 void e1000_update_stats(struct e1000_adapter *adapter)
3616 struct e1000_hw *hw = &adapter->hw;
3617 struct pci_dev *pdev = adapter->pdev;
3618 unsigned long flags;
3621 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3624 * Prevent stats update while adapter is being reset, or if the pci
3625 * connection is down.
3627 if (adapter->link_speed == 0)
3629 if (pci_channel_offline(pdev))
3632 spin_lock_irqsave(&adapter->stats_lock, flags);
3634 /* these counters are modified from e1000_tbi_adjust_stats,
3635 * called from the interrupt context, so they must only
3636 * be written while holding adapter->stats_lock
3639 adapter->stats.crcerrs += er32(CRCERRS);
3640 adapter->stats.gprc += er32(GPRC);
3641 adapter->stats.gorcl += er32(GORCL);
3642 adapter->stats.gorch += er32(GORCH);
3643 adapter->stats.bprc += er32(BPRC);
3644 adapter->stats.mprc += er32(MPRC);
3645 adapter->stats.roc += er32(ROC);
3647 if (hw->mac_type != e1000_ich8lan) {
3648 adapter->stats.prc64 += er32(PRC64);
3649 adapter->stats.prc127 += er32(PRC127);
3650 adapter->stats.prc255 += er32(PRC255);
3651 adapter->stats.prc511 += er32(PRC511);
3652 adapter->stats.prc1023 += er32(PRC1023);
3653 adapter->stats.prc1522 += er32(PRC1522);
3656 adapter->stats.symerrs += er32(SYMERRS);
3657 adapter->stats.mpc += er32(MPC);
3658 adapter->stats.scc += er32(SCC);
3659 adapter->stats.ecol += er32(ECOL);
3660 adapter->stats.mcc += er32(MCC);
3661 adapter->stats.latecol += er32(LATECOL);
3662 adapter->stats.dc += er32(DC);
3663 adapter->stats.sec += er32(SEC);
3664 adapter->stats.rlec += er32(RLEC);
3665 adapter->stats.xonrxc += er32(XONRXC);
3666 adapter->stats.xontxc += er32(XONTXC);
3667 adapter->stats.xoffrxc += er32(XOFFRXC);
3668 adapter->stats.xofftxc += er32(XOFFTXC);
3669 adapter->stats.fcruc += er32(FCRUC);
3670 adapter->stats.gptc += er32(GPTC);
3671 adapter->stats.gotcl += er32(GOTCL);
3672 adapter->stats.gotch += er32(GOTCH);
3673 adapter->stats.rnbc += er32(RNBC);
3674 adapter->stats.ruc += er32(RUC);
3675 adapter->stats.rfc += er32(RFC);
3676 adapter->stats.rjc += er32(RJC);
3677 adapter->stats.torl += er32(TORL);
3678 adapter->stats.torh += er32(TORH);
3679 adapter->stats.totl += er32(TOTL);
3680 adapter->stats.toth += er32(TOTH);
3681 adapter->stats.tpr += er32(TPR);
3683 if (hw->mac_type != e1000_ich8lan) {
3684 adapter->stats.ptc64 += er32(PTC64);
3685 adapter->stats.ptc127 += er32(PTC127);
3686 adapter->stats.ptc255 += er32(PTC255);
3687 adapter->stats.ptc511 += er32(PTC511);
3688 adapter->stats.ptc1023 += er32(PTC1023);
3689 adapter->stats.ptc1522 += er32(PTC1522);
3692 adapter->stats.mptc += er32(MPTC);
3693 adapter->stats.bptc += er32(BPTC);
3695 /* used for adaptive IFS */
3697 hw->tx_packet_delta = er32(TPT);
3698 adapter->stats.tpt += hw->tx_packet_delta;
3699 hw->collision_delta = er32(COLC);
3700 adapter->stats.colc += hw->collision_delta;
3702 if (hw->mac_type >= e1000_82543) {
3703 adapter->stats.algnerrc += er32(ALGNERRC);
3704 adapter->stats.rxerrc += er32(RXERRC);
3705 adapter->stats.tncrs += er32(TNCRS);
3706 adapter->stats.cexterr += er32(CEXTERR);
3707 adapter->stats.tsctc += er32(TSCTC);
3708 adapter->stats.tsctfc += er32(TSCTFC);
3710 if (hw->mac_type > e1000_82547_rev_2) {
3711 adapter->stats.iac += er32(IAC);
3712 adapter->stats.icrxoc += er32(ICRXOC);
3714 if (hw->mac_type != e1000_ich8lan) {
3715 adapter->stats.icrxptc += er32(ICRXPTC);
3716 adapter->stats.icrxatc += er32(ICRXATC);
3717 adapter->stats.ictxptc += er32(ICTXPTC);
3718 adapter->stats.ictxatc += er32(ICTXATC);
3719 adapter->stats.ictxqec += er32(ICTXQEC);
3720 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3721 adapter->stats.icrxdmtc += er32(ICRXDMTC);
3725 /* Fill out the OS statistics structure */
3726 adapter->net_stats.multicast = adapter->stats.mprc;
3727 adapter->net_stats.collisions = adapter->stats.colc;
3731 /* RLEC on some newer hardware can be incorrect so build
3732 * our own version based on RUC and ROC */
3733 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3734 adapter->stats.crcerrs + adapter->stats.algnerrc +
3735 adapter->stats.ruc + adapter->stats.roc +
3736 adapter->stats.cexterr;
3737 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3738 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3739 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3740 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3741 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3744 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3745 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3746 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3747 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3748 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3749 if (hw->bad_tx_carr_stats_fd &&
3750 adapter->link_duplex == FULL_DUPLEX) {
3751 adapter->net_stats.tx_carrier_errors = 0;
3752 adapter->stats.tncrs = 0;
3755 /* Tx Dropped needs to be maintained elsewhere */
3758 if (hw->media_type == e1000_media_type_copper) {
3759 if ((adapter->link_speed == SPEED_1000) &&
3760 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3761 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3762 adapter->phy_stats.idle_errors += phy_tmp;
3765 if ((hw->mac_type <= e1000_82546) &&
3766 (hw->phy_type == e1000_phy_m88) &&
3767 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3768 adapter->phy_stats.receive_errors += phy_tmp;
3771 /* Management Stats */
3772 if (hw->has_smbus) {
3773 adapter->stats.mgptc += er32(MGTPTC);
3774 adapter->stats.mgprc += er32(MGTPRC);
3775 adapter->stats.mgpdc += er32(MGTPDC);
3778 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3782 * e1000_intr_msi - Interrupt Handler
3783 * @irq: interrupt number
3784 * @data: pointer to a network interface device structure
3787 static irqreturn_t e1000_intr_msi(int irq, void *data)
3789 struct net_device *netdev = data;
3790 struct e1000_adapter *adapter = netdev_priv(netdev);
3791 struct e1000_hw *hw = &adapter->hw;
3792 u32 icr = er32(ICR);
3794 /* in NAPI mode read ICR disables interrupts using IAM */
3796 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3797 hw->get_link_status = 1;
3798 /* 80003ES2LAN workaround-- For packet buffer work-around on
3799 * link down event; disable receives here in the ISR and reset
3800 * adapter in watchdog */
3801 if (netif_carrier_ok(netdev) &&
3802 (hw->mac_type == e1000_80003es2lan)) {
3803 /* disable receives */
3804 u32 rctl = er32(RCTL);
3805 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3807 /* guard against interrupt when we're going down */
3808 if (!test_bit(__E1000_DOWN, &adapter->flags))
3809 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3812 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3813 adapter->total_tx_bytes = 0;
3814 adapter->total_tx_packets = 0;
3815 adapter->total_rx_bytes = 0;
3816 adapter->total_rx_packets = 0;
3817 __netif_rx_schedule(netdev, &adapter->napi);
3819 e1000_irq_enable(adapter);
3825 * e1000_intr - Interrupt Handler
3826 * @irq: interrupt number
3827 * @data: pointer to a network interface device structure
3830 static irqreturn_t e1000_intr(int irq, void *data)
3832 struct net_device *netdev = data;
3833 struct e1000_adapter *adapter = netdev_priv(netdev);
3834 struct e1000_hw *hw = &adapter->hw;
3835 u32 rctl, icr = er32(ICR);
3838 return IRQ_NONE; /* Not our interrupt */
3840 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3841 * not set, then the adapter didn't send an interrupt */
3842 if (unlikely(hw->mac_type >= e1000_82571 &&
3843 !(icr & E1000_ICR_INT_ASSERTED)))
3846 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3847 * need for the IMC write */
3849 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3850 hw->get_link_status = 1;
3851 /* 80003ES2LAN workaround--
3852 * For packet buffer work-around on link down event;
3853 * disable receives here in the ISR and
3854 * reset adapter in watchdog
3856 if (netif_carrier_ok(netdev) &&
3857 (hw->mac_type == e1000_80003es2lan)) {
3858 /* disable receives */
3860 ew32(RCTL, rctl & ~E1000_RCTL_EN);
3862 /* guard against interrupt when we're going down */
3863 if (!test_bit(__E1000_DOWN, &adapter->flags))
3864 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3867 if (unlikely(hw->mac_type < e1000_82571)) {
3868 /* disable interrupts, without the synchronize_irq bit */
3870 E1000_WRITE_FLUSH();
3872 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3873 adapter->total_tx_bytes = 0;
3874 adapter->total_tx_packets = 0;
3875 adapter->total_rx_bytes = 0;
3876 adapter->total_rx_packets = 0;
3877 __netif_rx_schedule(netdev, &adapter->napi);
3879 /* this really should not happen! if it does it is basically a
3880 * bug, but not a hard error, so enable ints and continue */
3881 e1000_irq_enable(adapter);
3887 * e1000_clean - NAPI Rx polling callback
3888 * @adapter: board private structure
3890 static int e1000_clean(struct napi_struct *napi, int budget)
3892 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3893 struct net_device *poll_dev = adapter->netdev;
3894 int tx_cleaned = 0, work_done = 0;
3896 /* Must NOT use netdev_priv macro here. */
3897 adapter = poll_dev->priv;
3899 /* e1000_clean is called per-cpu. This lock protects
3900 * tx_ring[0] from being cleaned by multiple cpus
3901 * simultaneously. A failure obtaining the lock means
3902 * tx_ring[0] is currently being cleaned anyway. */
3903 if (spin_trylock(&adapter->tx_queue_lock)) {
3904 tx_cleaned = e1000_clean_tx_irq(adapter,
3905 &adapter->tx_ring[0]);
3906 spin_unlock(&adapter->tx_queue_lock);
3909 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3910 &work_done, budget);
3915 /* If budget not fully consumed, exit the polling mode */
3916 if (work_done < budget) {
3917 if (likely(adapter->itr_setting & 3))
3918 e1000_set_itr(adapter);
3919 netif_rx_complete(poll_dev, napi);
3920 e1000_irq_enable(adapter);
3927 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3928 * @adapter: board private structure
3930 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3931 struct e1000_tx_ring *tx_ring)
3933 struct e1000_hw *hw = &adapter->hw;
3934 struct net_device *netdev = adapter->netdev;
3935 struct e1000_tx_desc *tx_desc, *eop_desc;
3936 struct e1000_buffer *buffer_info;
3937 unsigned int i, eop;
3938 unsigned int count = 0;
3939 bool cleaned = false;
3940 unsigned int total_tx_bytes=0, total_tx_packets=0;
3942 i = tx_ring->next_to_clean;
3943 eop = tx_ring->buffer_info[i].next_to_watch;
3944 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3946 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3947 for (cleaned = false; !cleaned; ) {
3948 tx_desc = E1000_TX_DESC(*tx_ring, i);
3949 buffer_info = &tx_ring->buffer_info[i];
3950 cleaned = (i == eop);
3953 struct sk_buff *skb = buffer_info->skb;
3954 unsigned int segs, bytecount;
3955 segs = skb_shinfo(skb)->gso_segs ?: 1;
3956 /* multiply data chunks by size of headers */
3957 bytecount = ((segs - 1) * skb_headlen(skb)) +
3959 total_tx_packets += segs;
3960 total_tx_bytes += bytecount;
3962 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3963 tx_desc->upper.data = 0;
3965 if (unlikely(++i == tx_ring->count)) i = 0;
3968 eop = tx_ring->buffer_info[i].next_to_watch;
3969 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3970 #define E1000_TX_WEIGHT 64
3971 /* weight of a sort for tx, to avoid endless transmit cleanup */
3972 if (count++ == E1000_TX_WEIGHT)
3976 tx_ring->next_to_clean = i;
3978 #define TX_WAKE_THRESHOLD 32
3979 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3980 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3981 /* Make sure that anybody stopping the queue after this
3982 * sees the new next_to_clean.
3985 if (netif_queue_stopped(netdev)) {
3986 netif_wake_queue(netdev);
3987 ++adapter->restart_queue;
3991 if (adapter->detect_tx_hung) {
3992 /* Detect a transmit hang in hardware, this serializes the
3993 * check with the clearing of time_stamp and movement of i */
3994 adapter->detect_tx_hung = false;
3995 if (tx_ring->buffer_info[eop].dma &&
3996 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3997 (adapter->tx_timeout_factor * HZ))
3998 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
4000 /* detected Tx unit hang */
4001 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
4005 " next_to_use <%x>\n"
4006 " next_to_clean <%x>\n"
4007 "buffer_info[next_to_clean]\n"
4008 " time_stamp <%lx>\n"
4009 " next_to_watch <%x>\n"
4011 " next_to_watch.status <%x>\n",
4012 (unsigned long)((tx_ring - adapter->tx_ring) /
4013 sizeof(struct e1000_tx_ring)),
4014 readl(hw->hw_addr + tx_ring->tdh),
4015 readl(hw->hw_addr + tx_ring->tdt),
4016 tx_ring->next_to_use,
4017 tx_ring->next_to_clean,
4018 tx_ring->buffer_info[eop].time_stamp,
4021 eop_desc->upper.fields.status);
4022 netif_stop_queue(netdev);
4025 adapter->total_tx_bytes += total_tx_bytes;
4026 adapter->total_tx_packets += total_tx_packets;
4027 adapter->net_stats.tx_bytes += total_tx_bytes;
4028 adapter->net_stats.tx_packets += total_tx_packets;
4033 * e1000_rx_checksum - Receive Checksum Offload for 82543
4034 * @adapter: board private structure
4035 * @status_err: receive descriptor status and error fields
4036 * @csum: receive descriptor csum field
4037 * @sk_buff: socket buffer with received data
4040 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
4041 u32 csum, struct sk_buff *skb)
4043 struct e1000_hw *hw = &adapter->hw;
4044 u16 status = (u16)status_err;
4045 u8 errors = (u8)(status_err >> 24);
4046 skb->ip_summed = CHECKSUM_NONE;
4048 /* 82543 or newer only */
4049 if (unlikely(hw->mac_type < e1000_82543)) return;
4050 /* Ignore Checksum bit is set */
4051 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
4052 /* TCP/UDP checksum error bit is set */
4053 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
4054 /* let the stack verify checksum errors */
4055 adapter->hw_csum_err++;
4058 /* TCP/UDP Checksum has not been calculated */
4059 if (hw->mac_type <= e1000_82547_rev_2) {
4060 if (!(status & E1000_RXD_STAT_TCPCS))
4063 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
4066 /* It must be a TCP or UDP packet with a valid checksum */
4067 if (likely(status & E1000_RXD_STAT_TCPCS)) {
4068 /* TCP checksum is good */
4069 skb->ip_summed = CHECKSUM_UNNECESSARY;
4070 } else if (hw->mac_type > e1000_82547_rev_2) {
4071 /* IP fragment with UDP payload */
4072 /* Hardware complements the payload checksum, so we undo it
4073 * and then put the value in host order for further stack use.
4075 __sum16 sum = (__force __sum16)htons(csum);
4076 skb->csum = csum_unfold(~sum);
4077 skb->ip_summed = CHECKSUM_COMPLETE;
4079 adapter->hw_csum_good++;
4083 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4084 * @adapter: board private structure
4086 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4087 struct e1000_rx_ring *rx_ring,
4088 int *work_done, int work_to_do)
4090 struct e1000_hw *hw = &adapter->hw;
4091 struct net_device *netdev = adapter->netdev;
4092 struct pci_dev *pdev = adapter->pdev;
4093 struct e1000_rx_desc *rx_desc, *next_rxd;
4094 struct e1000_buffer *buffer_info, *next_buffer;
4095 unsigned long flags;
4099 int cleaned_count = 0;
4100 bool cleaned = false;
4101 unsigned int total_rx_bytes=0, total_rx_packets=0;
4103 i = rx_ring->next_to_clean;
4104 rx_desc = E1000_RX_DESC(*rx_ring, i);
4105 buffer_info = &rx_ring->buffer_info[i];
4107 while (rx_desc->status & E1000_RXD_STAT_DD) {
4108 struct sk_buff *skb;
4111 if (*work_done >= work_to_do)
4115 status = rx_desc->status;
4116 skb = buffer_info->skb;
4117 buffer_info->skb = NULL;
4119 prefetch(skb->data - NET_IP_ALIGN);
4121 if (++i == rx_ring->count) i = 0;
4122 next_rxd = E1000_RX_DESC(*rx_ring, i);
4125 next_buffer = &rx_ring->buffer_info[i];
4129 pci_unmap_single(pdev,
4131 buffer_info->length,
4132 PCI_DMA_FROMDEVICE);
4134 length = le16_to_cpu(rx_desc->length);
4136 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4137 /* All receives must fit into a single buffer */
4138 E1000_DBG("%s: Receive packet consumed multiple"
4139 " buffers\n", netdev->name);
4141 buffer_info->skb = skb;
4145 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4146 last_byte = *(skb->data + length - 1);
4147 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4149 spin_lock_irqsave(&adapter->stats_lock, flags);
4150 e1000_tbi_adjust_stats(hw, &adapter->stats,
4152 spin_unlock_irqrestore(&adapter->stats_lock,
4157 buffer_info->skb = skb;
4162 /* adjust length to remove Ethernet CRC, this must be
4163 * done after the TBI_ACCEPT workaround above */
4166 /* probably a little skewed due to removing CRC */
4167 total_rx_bytes += length;
4170 /* code added for copybreak, this should improve
4171 * performance for small packets with large amounts
4172 * of reassembly being done in the stack */
4173 if (length < copybreak) {
4174 struct sk_buff *new_skb =
4175 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4177 skb_reserve(new_skb, NET_IP_ALIGN);
4178 skb_copy_to_linear_data_offset(new_skb,
4184 /* save the skb in buffer_info as good */
4185 buffer_info->skb = skb;
4188 /* else just continue with the old one */
4190 /* end copybreak code */
4191 skb_put(skb, length);
4193 /* Receive Checksum Offload */
4194 e1000_rx_checksum(adapter,
4196 ((u32)(rx_desc->errors) << 24),
4197 le16_to_cpu(rx_desc->csum), skb);
4199 skb->protocol = eth_type_trans(skb, netdev);
4201 if (unlikely(adapter->vlgrp &&
4202 (status & E1000_RXD_STAT_VP))) {
4203 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4204 le16_to_cpu(rx_desc->special));
4206 netif_receive_skb(skb);
4209 netdev->last_rx = jiffies;
4212 rx_desc->status = 0;
4214 /* return some buffers to hardware, one at a time is too slow */
4215 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4216 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4220 /* use prefetched values */
4222 buffer_info = next_buffer;
4224 rx_ring->next_to_clean = i;
4226 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4228 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4230 adapter->total_rx_packets += total_rx_packets;
4231 adapter->total_rx_bytes += total_rx_bytes;
4232 adapter->net_stats.rx_bytes += total_rx_bytes;
4233 adapter->net_stats.rx_packets += total_rx_packets;
4238 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4239 * @adapter: board private structure
4242 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4243 struct e1000_rx_ring *rx_ring,
4244 int *work_done, int work_to_do)
4246 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
4247 struct net_device *netdev = adapter->netdev;
4248 struct pci_dev *pdev = adapter->pdev;
4249 struct e1000_buffer *buffer_info, *next_buffer;
4250 struct e1000_ps_page *ps_page;
4251 struct e1000_ps_page_dma *ps_page_dma;
4252 struct sk_buff *skb;
4254 u32 length, staterr;
4255 int cleaned_count = 0;
4256 bool cleaned = false;
4257 unsigned int total_rx_bytes=0, total_rx_packets=0;
4259 i = rx_ring->next_to_clean;
4260 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4261 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4262 buffer_info = &rx_ring->buffer_info[i];
4264 while (staterr & E1000_RXD_STAT_DD) {
4265 ps_page = &rx_ring->ps_page[i];
4266 ps_page_dma = &rx_ring->ps_page_dma[i];
4268 if (unlikely(*work_done >= work_to_do))
4272 skb = buffer_info->skb;
4274 /* in the packet split case this is header only */
4275 prefetch(skb->data - NET_IP_ALIGN);
4277 if (++i == rx_ring->count) i = 0;
4278 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
4281 next_buffer = &rx_ring->buffer_info[i];
4285 pci_unmap_single(pdev, buffer_info->dma,
4286 buffer_info->length,
4287 PCI_DMA_FROMDEVICE);
4289 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
4290 E1000_DBG("%s: Packet Split buffers didn't pick up"
4291 " the full packet\n", netdev->name);
4292 dev_kfree_skb_irq(skb);
4296 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
4297 dev_kfree_skb_irq(skb);
4301 length = le16_to_cpu(rx_desc->wb.middle.length0);
4303 if (unlikely(!length)) {
4304 E1000_DBG("%s: Last part of the packet spanning"
4305 " multiple descriptors\n", netdev->name);
4306 dev_kfree_skb_irq(skb);
4311 skb_put(skb, length);
4314 /* this looks ugly, but it seems compiler issues make it
4315 more efficient than reusing j */
4316 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4318 /* page alloc/put takes too long and effects small packet
4319 * throughput, so unsplit small packets and save the alloc/put*/
4320 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
4322 /* there is no documentation about how to call
4323 * kmap_atomic, so we can't hold the mapping
4325 pci_dma_sync_single_for_cpu(pdev,
4326 ps_page_dma->ps_page_dma[0],
4328 PCI_DMA_FROMDEVICE);
4329 vaddr = kmap_atomic(ps_page->ps_page[0],
4330 KM_SKB_DATA_SOFTIRQ);
4331 memcpy(skb_tail_pointer(skb), vaddr, l1);
4332 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4333 pci_dma_sync_single_for_device(pdev,
4334 ps_page_dma->ps_page_dma[0],
4335 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4336 /* remove the CRC */
4343 for (j = 0; j < adapter->rx_ps_pages; j++) {
4344 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
4347 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4348 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4349 ps_page_dma->ps_page_dma[j] = 0;
4350 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4352 ps_page->ps_page[j] = NULL;
4354 skb->data_len += length;
4355 skb->truesize += length;
4358 /* strip the ethernet crc, problem is we're using pages now so
4359 * this whole operation can get a little cpu intensive */
4360 pskb_trim(skb, skb->len - 4);
4363 total_rx_bytes += skb->len;
4366 e1000_rx_checksum(adapter, staterr,
4367 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
4368 skb->protocol = eth_type_trans(skb, netdev);
4370 if (likely(rx_desc->wb.upper.header_status &
4371 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
4372 adapter->rx_hdr_split++;
4374 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4375 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4376 le16_to_cpu(rx_desc->wb.middle.vlan));
4378 netif_receive_skb(skb);
4381 netdev->last_rx = jiffies;
4384 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
4385 buffer_info->skb = NULL;
4387 /* return some buffers to hardware, one at a time is too slow */
4388 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4389 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4393 /* use prefetched values */
4395 buffer_info = next_buffer;
4397 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4399 rx_ring->next_to_clean = i;
4401 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4403 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4405 adapter->total_rx_packets += total_rx_packets;
4406 adapter->total_rx_bytes += total_rx_bytes;
4407 adapter->net_stats.rx_bytes += total_rx_bytes;
4408 adapter->net_stats.rx_packets += total_rx_packets;
4413 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4414 * @adapter: address of board private structure
4417 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4418 struct e1000_rx_ring *rx_ring,
4421 struct e1000_hw *hw = &adapter->hw;
4422 struct net_device *netdev = adapter->netdev;
4423 struct pci_dev *pdev = adapter->pdev;
4424 struct e1000_rx_desc *rx_desc;
4425 struct e1000_buffer *buffer_info;
4426 struct sk_buff *skb;
4428 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4430 i = rx_ring->next_to_use;
4431 buffer_info = &rx_ring->buffer_info[i];
4433 while (cleaned_count--) {
4434 skb = buffer_info->skb;
4440 skb = netdev_alloc_skb(netdev, bufsz);
4441 if (unlikely(!skb)) {
4442 /* Better luck next round */
4443 adapter->alloc_rx_buff_failed++;
4447 /* Fix for errata 23, can't cross 64kB boundary */
4448 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4449 struct sk_buff *oldskb = skb;
4450 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4451 "at %p\n", bufsz, skb->data);
4452 /* Try again, without freeing the previous */
4453 skb = netdev_alloc_skb(netdev, bufsz);
4454 /* Failed allocation, critical failure */
4456 dev_kfree_skb(oldskb);
4460 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4463 dev_kfree_skb(oldskb);
4464 break; /* while !buffer_info->skb */
4467 /* Use new allocation */
4468 dev_kfree_skb(oldskb);
4470 /* Make buffer alignment 2 beyond a 16 byte boundary
4471 * this will result in a 16 byte aligned IP header after
4472 * the 14 byte MAC header is removed
4474 skb_reserve(skb, NET_IP_ALIGN);
4476 buffer_info->skb = skb;
4477 buffer_info->length = adapter->rx_buffer_len;
4479 buffer_info->dma = pci_map_single(pdev,
4481 adapter->rx_buffer_len,
4482 PCI_DMA_FROMDEVICE);
4484 /* Fix for errata 23, can't cross 64kB boundary */
4485 if (!e1000_check_64k_bound(adapter,
4486 (void *)(unsigned long)buffer_info->dma,
4487 adapter->rx_buffer_len)) {
4488 DPRINTK(RX_ERR, ERR,
4489 "dma align check failed: %u bytes at %p\n",
4490 adapter->rx_buffer_len,
4491 (void *)(unsigned long)buffer_info->dma);
4493 buffer_info->skb = NULL;
4495 pci_unmap_single(pdev, buffer_info->dma,
4496 adapter->rx_buffer_len,
4497 PCI_DMA_FROMDEVICE);
4499 break; /* while !buffer_info->skb */
4501 rx_desc = E1000_RX_DESC(*rx_ring, i);
4502 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4504 if (unlikely(++i == rx_ring->count))
4506 buffer_info = &rx_ring->buffer_info[i];
4509 if (likely(rx_ring->next_to_use != i)) {
4510 rx_ring->next_to_use = i;
4511 if (unlikely(i-- == 0))
4512 i = (rx_ring->count - 1);
4514 /* Force memory writes to complete before letting h/w
4515 * know there are new descriptors to fetch. (Only
4516 * applicable for weak-ordered memory model archs,
4517 * such as IA-64). */
4519 writel(i, hw->hw_addr + rx_ring->rdt);
4524 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4525 * @adapter: address of board private structure
4528 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4529 struct e1000_rx_ring *rx_ring,
4532 struct e1000_hw *hw = &adapter->hw;
4533 struct net_device *netdev = adapter->netdev;
4534 struct pci_dev *pdev = adapter->pdev;
4535 union e1000_rx_desc_packet_split *rx_desc;
4536 struct e1000_buffer *buffer_info;
4537 struct e1000_ps_page *ps_page;
4538 struct e1000_ps_page_dma *ps_page_dma;
4539 struct sk_buff *skb;
4542 i = rx_ring->next_to_use;
4543 buffer_info = &rx_ring->buffer_info[i];
4544 ps_page = &rx_ring->ps_page[i];
4545 ps_page_dma = &rx_ring->ps_page_dma[i];
4547 while (cleaned_count--) {
4548 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4550 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4551 if (j < adapter->rx_ps_pages) {
4552 if (likely(!ps_page->ps_page[j])) {
4553 ps_page->ps_page[j] =
4554 alloc_page(GFP_ATOMIC);
4555 if (unlikely(!ps_page->ps_page[j])) {
4556 adapter->alloc_rx_buff_failed++;
4559 ps_page_dma->ps_page_dma[j] =
4561 ps_page->ps_page[j],
4563 PCI_DMA_FROMDEVICE);
4565 /* Refresh the desc even if buffer_addrs didn't
4566 * change because each write-back erases
4569 rx_desc->read.buffer_addr[j+1] =
4570 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4572 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
4575 skb = netdev_alloc_skb(netdev,
4576 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4578 if (unlikely(!skb)) {
4579 adapter->alloc_rx_buff_failed++;
4583 /* Make buffer alignment 2 beyond a 16 byte boundary
4584 * this will result in a 16 byte aligned IP header after
4585 * the 14 byte MAC header is removed
4587 skb_reserve(skb, NET_IP_ALIGN);
4589 buffer_info->skb = skb;
4590 buffer_info->length = adapter->rx_ps_bsize0;
4591 buffer_info->dma = pci_map_single(pdev, skb->data,
4592 adapter->rx_ps_bsize0,
4593 PCI_DMA_FROMDEVICE);
4595 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4597 if (unlikely(++i == rx_ring->count)) i = 0;
4598 buffer_info = &rx_ring->buffer_info[i];
4599 ps_page = &rx_ring->ps_page[i];
4600 ps_page_dma = &rx_ring->ps_page_dma[i];
4604 if (likely(rx_ring->next_to_use != i)) {
4605 rx_ring->next_to_use = i;
4606 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4608 /* Force memory writes to complete before letting h/w
4609 * know there are new descriptors to fetch. (Only
4610 * applicable for weak-ordered memory model archs,
4611 * such as IA-64). */
4613 /* Hardware increments by 16 bytes, but packet split
4614 * descriptors are 32 bytes...so we increment tail
4617 writel(i<<1, hw->hw_addr + rx_ring->rdt);
4622 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4626 static void e1000_smartspeed(struct e1000_adapter *adapter)
4628 struct e1000_hw *hw = &adapter->hw;
4632 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4633 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4636 if (adapter->smartspeed == 0) {
4637 /* If Master/Slave config fault is asserted twice,
4638 * we assume back-to-back */
4639 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4640 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4641 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4642 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4643 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4644 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4645 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4646 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4648 adapter->smartspeed++;
4649 if (!e1000_phy_setup_autoneg(hw) &&
4650 !e1000_read_phy_reg(hw, PHY_CTRL,
4652 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4653 MII_CR_RESTART_AUTO_NEG);
4654 e1000_write_phy_reg(hw, PHY_CTRL,
4659 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4660 /* If still no link, perhaps using 2/3 pair cable */
4661 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4662 phy_ctrl |= CR_1000T_MS_ENABLE;
4663 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4664 if (!e1000_phy_setup_autoneg(hw) &&
4665 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4666 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4667 MII_CR_RESTART_AUTO_NEG);
4668 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4671 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4672 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4673 adapter->smartspeed = 0;
4683 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4689 return e1000_mii_ioctl(netdev, ifr, cmd);
4702 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4705 struct e1000_adapter *adapter = netdev_priv(netdev);
4706 struct e1000_hw *hw = &adapter->hw;
4707 struct mii_ioctl_data *data = if_mii(ifr);
4711 unsigned long flags;
4713 if (hw->media_type != e1000_media_type_copper)
4718 data->phy_id = hw->phy_addr;
4721 if (!capable(CAP_NET_ADMIN))
4723 spin_lock_irqsave(&adapter->stats_lock, flags);
4724 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4726 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4729 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4732 if (!capable(CAP_NET_ADMIN))
4734 if (data->reg_num & ~(0x1F))
4736 mii_reg = data->val_in;
4737 spin_lock_irqsave(&adapter->stats_lock, flags);
4738 if (e1000_write_phy_reg(hw, data->reg_num,
4740 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4743 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4744 if (hw->media_type == e1000_media_type_copper) {
4745 switch (data->reg_num) {
4747 if (mii_reg & MII_CR_POWER_DOWN)
4749 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4751 hw->autoneg_advertised = 0x2F;
4754 spddplx = SPEED_1000;
4755 else if (mii_reg & 0x2000)
4756 spddplx = SPEED_100;
4759 spddplx += (mii_reg & 0x100)
4762 retval = e1000_set_spd_dplx(adapter,
4767 if (netif_running(adapter->netdev))
4768 e1000_reinit_locked(adapter);
4770 e1000_reset(adapter);
4772 case M88E1000_PHY_SPEC_CTRL:
4773 case M88E1000_EXT_PHY_SPEC_CTRL:
4774 if (e1000_phy_reset(hw))
4779 switch (data->reg_num) {
4781 if (mii_reg & MII_CR_POWER_DOWN)
4783 if (netif_running(adapter->netdev))
4784 e1000_reinit_locked(adapter);
4786 e1000_reset(adapter);
4794 return E1000_SUCCESS;
4797 void e1000_pci_set_mwi(struct e1000_hw *hw)
4799 struct e1000_adapter *adapter = hw->back;
4800 int ret_val = pci_set_mwi(adapter->pdev);
4803 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4806 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4808 struct e1000_adapter *adapter = hw->back;
4810 pci_clear_mwi(adapter->pdev);
4813 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4815 struct e1000_adapter *adapter = hw->back;
4816 return pcix_get_mmrbc(adapter->pdev);
4819 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4821 struct e1000_adapter *adapter = hw->back;
4822 pcix_set_mmrbc(adapter->pdev, mmrbc);
4825 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
4827 struct e1000_adapter *adapter = hw->back;
4830 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4832 return -E1000_ERR_CONFIG;
4834 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4836 return E1000_SUCCESS;
4839 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4844 static void e1000_vlan_rx_register(struct net_device *netdev,
4845 struct vlan_group *grp)
4847 struct e1000_adapter *adapter = netdev_priv(netdev);
4848 struct e1000_hw *hw = &adapter->hw;
4851 if (!test_bit(__E1000_DOWN, &adapter->flags))
4852 e1000_irq_disable(adapter);
4853 adapter->vlgrp = grp;
4856 /* enable VLAN tag insert/strip */
4858 ctrl |= E1000_CTRL_VME;
4861 if (adapter->hw.mac_type != e1000_ich8lan) {
4862 /* enable VLAN receive filtering */
4864 rctl &= ~E1000_RCTL_CFIEN;
4866 e1000_update_mng_vlan(adapter);
4869 /* disable VLAN tag insert/strip */
4871 ctrl &= ~E1000_CTRL_VME;
4874 if (adapter->hw.mac_type != e1000_ich8lan) {
4875 if (adapter->mng_vlan_id !=
4876 (u16)E1000_MNG_VLAN_NONE) {
4877 e1000_vlan_rx_kill_vid(netdev,
4878 adapter->mng_vlan_id);
4879 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4884 if (!test_bit(__E1000_DOWN, &adapter->flags))
4885 e1000_irq_enable(adapter);
4888 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4890 struct e1000_adapter *adapter = netdev_priv(netdev);
4891 struct e1000_hw *hw = &adapter->hw;
4894 if ((hw->mng_cookie.status &
4895 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4896 (vid == adapter->mng_vlan_id))
4898 /* add VID to filter table */
4899 index = (vid >> 5) & 0x7F;
4900 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4901 vfta |= (1 << (vid & 0x1F));
4902 e1000_write_vfta(hw, index, vfta);
4905 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4907 struct e1000_adapter *adapter = netdev_priv(netdev);
4908 struct e1000_hw *hw = &adapter->hw;
4911 if (!test_bit(__E1000_DOWN, &adapter->flags))
4912 e1000_irq_disable(adapter);
4913 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4914 if (!test_bit(__E1000_DOWN, &adapter->flags))
4915 e1000_irq_enable(adapter);
4917 if ((hw->mng_cookie.status &
4918 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4919 (vid == adapter->mng_vlan_id)) {
4920 /* release control to f/w */
4921 e1000_release_hw_control(adapter);
4925 /* remove VID from filter table */
4926 index = (vid >> 5) & 0x7F;
4927 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4928 vfta &= ~(1 << (vid & 0x1F));
4929 e1000_write_vfta(hw, index, vfta);
4932 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4934 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4936 if (adapter->vlgrp) {
4938 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4939 if (!vlan_group_get_device(adapter->vlgrp, vid))
4941 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4946 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
4948 struct e1000_hw *hw = &adapter->hw;
4952 /* Fiber NICs only allow 1000 gbps Full duplex */
4953 if ((hw->media_type == e1000_media_type_fiber) &&
4954 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4955 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4960 case SPEED_10 + DUPLEX_HALF:
4961 hw->forced_speed_duplex = e1000_10_half;
4963 case SPEED_10 + DUPLEX_FULL:
4964 hw->forced_speed_duplex = e1000_10_full;
4966 case SPEED_100 + DUPLEX_HALF:
4967 hw->forced_speed_duplex = e1000_100_half;
4969 case SPEED_100 + DUPLEX_FULL:
4970 hw->forced_speed_duplex = e1000_100_full;
4972 case SPEED_1000 + DUPLEX_FULL:
4974 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4976 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4978 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4984 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4986 struct net_device *netdev = pci_get_drvdata(pdev);
4987 struct e1000_adapter *adapter = netdev_priv(netdev);
4988 struct e1000_hw *hw = &adapter->hw;
4989 u32 ctrl, ctrl_ext, rctl, status;
4990 u32 wufc = adapter->wol;
4995 netif_device_detach(netdev);
4997 if (netif_running(netdev)) {
4998 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4999 e1000_down(adapter);
5003 retval = pci_save_state(pdev);
5008 status = er32(STATUS);
5009 if (status & E1000_STATUS_LU)
5010 wufc &= ~E1000_WUFC_LNKC;
5013 e1000_setup_rctl(adapter);
5014 e1000_set_rx_mode(netdev);
5016 /* turn on all-multi mode if wake on multicast is enabled */
5017 if (wufc & E1000_WUFC_MC) {
5019 rctl |= E1000_RCTL_MPE;
5023 if (hw->mac_type >= e1000_82540) {
5025 /* advertise wake from D3Cold */
5026 #define E1000_CTRL_ADVD3WUC 0x00100000
5027 /* phy power management enable */
5028 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5029 ctrl |= E1000_CTRL_ADVD3WUC |
5030 E1000_CTRL_EN_PHY_PWR_MGMT;
5034 if (hw->media_type == e1000_media_type_fiber ||
5035 hw->media_type == e1000_media_type_internal_serdes) {
5036 /* keep the laser running in D3 */
5037 ctrl_ext = er32(CTRL_EXT);
5038 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5039 ew32(CTRL_EXT, ctrl_ext);
5042 /* Allow time for pending master requests to run */
5043 e1000_disable_pciex_master(hw);
5045 ew32(WUC, E1000_WUC_PME_EN);
5047 pci_enable_wake(pdev, PCI_D3hot, 1);
5048 pci_enable_wake(pdev, PCI_D3cold, 1);
5052 pci_enable_wake(pdev, PCI_D3hot, 0);
5053 pci_enable_wake(pdev, PCI_D3cold, 0);
5056 e1000_release_manageability(adapter);
5058 /* make sure adapter isn't asleep if manageability is enabled */
5059 if (adapter->en_mng_pt) {
5060 pci_enable_wake(pdev, PCI_D3hot, 1);
5061 pci_enable_wake(pdev, PCI_D3cold, 1);
5064 if (hw->phy_type == e1000_phy_igp_3)
5065 e1000_phy_powerdown_workaround(hw);
5067 if (netif_running(netdev))
5068 e1000_free_irq(adapter);
5070 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5071 * would have already happened in close and is redundant. */
5072 e1000_release_hw_control(adapter);
5074 pci_disable_device(pdev);
5076 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5082 static int e1000_resume(struct pci_dev *pdev)
5084 struct net_device *netdev = pci_get_drvdata(pdev);
5085 struct e1000_adapter *adapter = netdev_priv(netdev);
5086 struct e1000_hw *hw = &adapter->hw;
5089 pci_set_power_state(pdev, PCI_D0);
5090 pci_restore_state(pdev);
5092 if (adapter->need_ioport)
5093 err = pci_enable_device(pdev);
5095 err = pci_enable_device_mem(pdev);
5097 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5100 pci_set_master(pdev);
5102 pci_enable_wake(pdev, PCI_D3hot, 0);
5103 pci_enable_wake(pdev, PCI_D3cold, 0);
5105 if (netif_running(netdev)) {
5106 err = e1000_request_irq(adapter);
5111 e1000_power_up_phy(adapter);
5112 e1000_reset(adapter);
5115 e1000_init_manageability(adapter);
5117 if (netif_running(netdev))
5120 netif_device_attach(netdev);
5122 /* If the controller is 82573 and f/w is AMT, do not set
5123 * DRV_LOAD until the interface is up. For all other cases,
5124 * let the f/w know that the h/w is now under the control
5126 if (hw->mac_type != e1000_82573 ||
5127 !e1000_check_mng_mode(hw))
5128 e1000_get_hw_control(adapter);
5134 static void e1000_shutdown(struct pci_dev *pdev)
5136 e1000_suspend(pdev, PMSG_SUSPEND);
5139 #ifdef CONFIG_NET_POLL_CONTROLLER
5141 * Polling 'interrupt' - used by things like netconsole to send skbs
5142 * without having to re-enable interrupts. It's not called while
5143 * the interrupt routine is executing.
5145 static void e1000_netpoll(struct net_device *netdev)
5147 struct e1000_adapter *adapter = netdev_priv(netdev);
5149 disable_irq(adapter->pdev->irq);
5150 e1000_intr(adapter->pdev->irq, netdev);
5151 enable_irq(adapter->pdev->irq);
5156 * e1000_io_error_detected - called when PCI error is detected
5157 * @pdev: Pointer to PCI device
5158 * @state: The current pci conneection state
5160 * This function is called after a PCI bus error affecting
5161 * this device has been detected.
5163 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5164 pci_channel_state_t state)
5166 struct net_device *netdev = pci_get_drvdata(pdev);
5167 struct e1000_adapter *adapter = netdev->priv;
5169 netif_device_detach(netdev);
5171 if (netif_running(netdev))
5172 e1000_down(adapter);
5173 pci_disable_device(pdev);
5175 /* Request a slot slot reset. */
5176 return PCI_ERS_RESULT_NEED_RESET;
5180 * e1000_io_slot_reset - called after the pci bus has been reset.
5181 * @pdev: Pointer to PCI device
5183 * Restart the card from scratch, as if from a cold-boot. Implementation
5184 * resembles the first-half of the e1000_resume routine.
5186 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5188 struct net_device *netdev = pci_get_drvdata(pdev);
5189 struct e1000_adapter *adapter = netdev->priv;
5190 struct e1000_hw *hw = &adapter->hw;
5193 if (adapter->need_ioport)
5194 err = pci_enable_device(pdev);
5196 err = pci_enable_device_mem(pdev);
5198 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5199 return PCI_ERS_RESULT_DISCONNECT;
5201 pci_set_master(pdev);
5203 pci_enable_wake(pdev, PCI_D3hot, 0);
5204 pci_enable_wake(pdev, PCI_D3cold, 0);
5206 e1000_reset(adapter);
5209 return PCI_ERS_RESULT_RECOVERED;
5213 * e1000_io_resume - called when traffic can start flowing again.
5214 * @pdev: Pointer to PCI device
5216 * This callback is called when the error recovery driver tells us that
5217 * its OK to resume normal operation. Implementation resembles the
5218 * second-half of the e1000_resume routine.
5220 static void e1000_io_resume(struct pci_dev *pdev)
5222 struct net_device *netdev = pci_get_drvdata(pdev);
5223 struct e1000_adapter *adapter = netdev->priv;
5224 struct e1000_hw *hw = &adapter->hw;
5226 e1000_init_manageability(adapter);
5228 if (netif_running(netdev)) {
5229 if (e1000_up(adapter)) {
5230 printk("e1000: can't bring device back up after reset\n");
5235 netif_device_attach(netdev);
5237 /* If the controller is 82573 and f/w is AMT, do not set
5238 * DRV_LOAD until the interface is up. For all other cases,
5239 * let the f/w know that the h/w is now under the control
5241 if (hw->mac_type != e1000_82573 ||
5242 !e1000_check_mng_mode(hw))
5243 e1000_get_hw_control(adapter);