1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <net/ip6_checksum.h>
32 #include <linux/prefetch.h>
34 /* Intel Media SOC GbE MDIO physical base address */
35 static unsigned long ce4100_gbe_mdio_base_phy;
36 /* Intel Media SOC GbE MDIO virtual base address */
37 void __iomem *ce4100_gbe_mdio_base_virt;
39 char e1000_driver_name[] = "e1000";
40 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41 #define DRV_VERSION "7.3.21-k8-NAPI"
42 const char e1000_driver_version[] = DRV_VERSION;
43 static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
45 /* e1000_pci_tbl - PCI Device ID Table
47 * Last entry must be all 0s
50 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
52 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
53 INTEL_E1000_ETHERNET_DEVICE(0x1000),
54 INTEL_E1000_ETHERNET_DEVICE(0x1001),
55 INTEL_E1000_ETHERNET_DEVICE(0x1004),
56 INTEL_E1000_ETHERNET_DEVICE(0x1008),
57 INTEL_E1000_ETHERNET_DEVICE(0x1009),
58 INTEL_E1000_ETHERNET_DEVICE(0x100C),
59 INTEL_E1000_ETHERNET_DEVICE(0x100D),
60 INTEL_E1000_ETHERNET_DEVICE(0x100E),
61 INTEL_E1000_ETHERNET_DEVICE(0x100F),
62 INTEL_E1000_ETHERNET_DEVICE(0x1010),
63 INTEL_E1000_ETHERNET_DEVICE(0x1011),
64 INTEL_E1000_ETHERNET_DEVICE(0x1012),
65 INTEL_E1000_ETHERNET_DEVICE(0x1013),
66 INTEL_E1000_ETHERNET_DEVICE(0x1014),
67 INTEL_E1000_ETHERNET_DEVICE(0x1015),
68 INTEL_E1000_ETHERNET_DEVICE(0x1016),
69 INTEL_E1000_ETHERNET_DEVICE(0x1017),
70 INTEL_E1000_ETHERNET_DEVICE(0x1018),
71 INTEL_E1000_ETHERNET_DEVICE(0x1019),
72 INTEL_E1000_ETHERNET_DEVICE(0x101A),
73 INTEL_E1000_ETHERNET_DEVICE(0x101D),
74 INTEL_E1000_ETHERNET_DEVICE(0x101E),
75 INTEL_E1000_ETHERNET_DEVICE(0x1026),
76 INTEL_E1000_ETHERNET_DEVICE(0x1027),
77 INTEL_E1000_ETHERNET_DEVICE(0x1028),
78 INTEL_E1000_ETHERNET_DEVICE(0x1075),
79 INTEL_E1000_ETHERNET_DEVICE(0x1076),
80 INTEL_E1000_ETHERNET_DEVICE(0x1077),
81 INTEL_E1000_ETHERNET_DEVICE(0x1078),
82 INTEL_E1000_ETHERNET_DEVICE(0x1079),
83 INTEL_E1000_ETHERNET_DEVICE(0x107A),
84 INTEL_E1000_ETHERNET_DEVICE(0x107B),
85 INTEL_E1000_ETHERNET_DEVICE(0x107C),
86 INTEL_E1000_ETHERNET_DEVICE(0x108A),
87 INTEL_E1000_ETHERNET_DEVICE(0x1099),
88 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
89 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
90 /* required last entry */
94 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
96 int e1000_up(struct e1000_adapter *adapter);
97 void e1000_down(struct e1000_adapter *adapter);
98 void e1000_reinit_locked(struct e1000_adapter *adapter);
99 void e1000_reset(struct e1000_adapter *adapter);
100 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
101 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
102 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
103 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
104 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
105 struct e1000_tx_ring *txdr);
106 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
107 struct e1000_rx_ring *rxdr);
108 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
109 struct e1000_tx_ring *tx_ring);
110 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
111 struct e1000_rx_ring *rx_ring);
112 void e1000_update_stats(struct e1000_adapter *adapter);
114 static int e1000_init_module(void);
115 static void e1000_exit_module(void);
116 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
117 static void __devexit e1000_remove(struct pci_dev *pdev);
118 static int e1000_alloc_queues(struct e1000_adapter *adapter);
119 static int e1000_sw_init(struct e1000_adapter *adapter);
120 static int e1000_open(struct net_device *netdev);
121 static int e1000_close(struct net_device *netdev);
122 static void e1000_configure_tx(struct e1000_adapter *adapter);
123 static void e1000_configure_rx(struct e1000_adapter *adapter);
124 static void e1000_setup_rctl(struct e1000_adapter *adapter);
125 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
126 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
127 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
128 struct e1000_tx_ring *tx_ring);
129 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
130 struct e1000_rx_ring *rx_ring);
131 static void e1000_set_rx_mode(struct net_device *netdev);
132 static void e1000_update_phy_info(unsigned long data);
133 static void e1000_update_phy_info_task(struct work_struct *work);
134 static void e1000_watchdog(unsigned long data);
135 static void e1000_82547_tx_fifo_stall(unsigned long data);
136 static void e1000_82547_tx_fifo_stall_task(struct work_struct *work);
137 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
138 struct net_device *netdev);
139 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
140 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
141 static int e1000_set_mac(struct net_device *netdev, void *p);
142 static irqreturn_t e1000_intr(int irq, void *data);
143 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
145 static int e1000_clean(struct napi_struct *napi, int budget);
146 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int *work_done, int work_to_do);
149 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
150 struct e1000_rx_ring *rx_ring,
151 int *work_done, int work_to_do);
152 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
153 struct e1000_rx_ring *rx_ring,
155 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
156 struct e1000_rx_ring *rx_ring,
158 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
159 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
161 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
162 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
163 static void e1000_tx_timeout(struct net_device *dev);
164 static void e1000_reset_task(struct work_struct *work);
165 static void e1000_smartspeed(struct e1000_adapter *adapter);
166 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
167 struct sk_buff *skb);
169 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
170 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
171 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
172 static void e1000_restore_vlan(struct e1000_adapter *adapter);
175 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
176 static int e1000_resume(struct pci_dev *pdev);
178 static void e1000_shutdown(struct pci_dev *pdev);
180 #ifdef CONFIG_NET_POLL_CONTROLLER
181 /* for netdump / net console */
182 static void e1000_netpoll (struct net_device *netdev);
185 #define COPYBREAK_DEFAULT 256
186 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
187 module_param(copybreak, uint, 0644);
188 MODULE_PARM_DESC(copybreak,
189 "Maximum size of packet that is copied to a new buffer on receive");
191 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
192 pci_channel_state_t state);
193 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
194 static void e1000_io_resume(struct pci_dev *pdev);
196 static struct pci_error_handlers e1000_err_handler = {
197 .error_detected = e1000_io_error_detected,
198 .slot_reset = e1000_io_slot_reset,
199 .resume = e1000_io_resume,
202 static struct pci_driver e1000_driver = {
203 .name = e1000_driver_name,
204 .id_table = e1000_pci_tbl,
205 .probe = e1000_probe,
206 .remove = __devexit_p(e1000_remove),
208 /* Power Management Hooks */
209 .suspend = e1000_suspend,
210 .resume = e1000_resume,
212 .shutdown = e1000_shutdown,
213 .err_handler = &e1000_err_handler
216 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
217 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
218 MODULE_LICENSE("GPL");
219 MODULE_VERSION(DRV_VERSION);
221 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
222 module_param(debug, int, 0);
223 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
226 * e1000_get_hw_dev - return device
227 * used by hardware layer to print debugging information
230 struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
232 struct e1000_adapter *adapter = hw->back;
233 return adapter->netdev;
237 * e1000_init_module - Driver Registration Routine
239 * e1000_init_module is the first routine called when the driver is
240 * loaded. All it does is register with the PCI subsystem.
243 static int __init e1000_init_module(void)
246 pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
248 pr_info("%s\n", e1000_copyright);
250 ret = pci_register_driver(&e1000_driver);
251 if (copybreak != COPYBREAK_DEFAULT) {
253 pr_info("copybreak disabled\n");
255 pr_info("copybreak enabled for "
256 "packets <= %u bytes\n", copybreak);
261 module_init(e1000_init_module);
264 * e1000_exit_module - Driver Exit Cleanup Routine
266 * e1000_exit_module is called just before the driver is removed
270 static void __exit e1000_exit_module(void)
272 pci_unregister_driver(&e1000_driver);
275 module_exit(e1000_exit_module);
277 static int e1000_request_irq(struct e1000_adapter *adapter)
279 struct net_device *netdev = adapter->netdev;
280 irq_handler_t handler = e1000_intr;
281 int irq_flags = IRQF_SHARED;
284 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
287 e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
293 static void e1000_free_irq(struct e1000_adapter *adapter)
295 struct net_device *netdev = adapter->netdev;
297 free_irq(adapter->pdev->irq, netdev);
301 * e1000_irq_disable - Mask off interrupt generation on the NIC
302 * @adapter: board private structure
305 static void e1000_irq_disable(struct e1000_adapter *adapter)
307 struct e1000_hw *hw = &adapter->hw;
311 synchronize_irq(adapter->pdev->irq);
315 * e1000_irq_enable - Enable default interrupt generation settings
316 * @adapter: board private structure
319 static void e1000_irq_enable(struct e1000_adapter *adapter)
321 struct e1000_hw *hw = &adapter->hw;
323 ew32(IMS, IMS_ENABLE_MASK);
327 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
329 struct e1000_hw *hw = &adapter->hw;
330 struct net_device *netdev = adapter->netdev;
331 u16 vid = hw->mng_cookie.vlan_id;
332 u16 old_vid = adapter->mng_vlan_id;
333 if (adapter->vlgrp) {
334 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
335 if (hw->mng_cookie.status &
336 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
337 e1000_vlan_rx_add_vid(netdev, vid);
338 adapter->mng_vlan_id = vid;
340 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
342 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
344 !vlan_group_get_device(adapter->vlgrp, old_vid))
345 e1000_vlan_rx_kill_vid(netdev, old_vid);
347 adapter->mng_vlan_id = vid;
351 static void e1000_init_manageability(struct e1000_adapter *adapter)
353 struct e1000_hw *hw = &adapter->hw;
355 if (adapter->en_mng_pt) {
356 u32 manc = er32(MANC);
358 /* disable hardware interception of ARP */
359 manc &= ~(E1000_MANC_ARP_EN);
365 static void e1000_release_manageability(struct e1000_adapter *adapter)
367 struct e1000_hw *hw = &adapter->hw;
369 if (adapter->en_mng_pt) {
370 u32 manc = er32(MANC);
372 /* re-enable hardware interception of ARP */
373 manc |= E1000_MANC_ARP_EN;
380 * e1000_configure - configure the hardware for RX and TX
381 * @adapter = private board structure
383 static void e1000_configure(struct e1000_adapter *adapter)
385 struct net_device *netdev = adapter->netdev;
388 e1000_set_rx_mode(netdev);
390 e1000_restore_vlan(adapter);
391 e1000_init_manageability(adapter);
393 e1000_configure_tx(adapter);
394 e1000_setup_rctl(adapter);
395 e1000_configure_rx(adapter);
396 /* call E1000_DESC_UNUSED which always leaves
397 * at least 1 descriptor unused to make sure
398 * next_to_use != next_to_clean */
399 for (i = 0; i < adapter->num_rx_queues; i++) {
400 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
401 adapter->alloc_rx_buf(adapter, ring,
402 E1000_DESC_UNUSED(ring));
406 int e1000_up(struct e1000_adapter *adapter)
408 struct e1000_hw *hw = &adapter->hw;
410 /* hardware has been reset, we need to reload some things */
411 e1000_configure(adapter);
413 clear_bit(__E1000_DOWN, &adapter->flags);
415 napi_enable(&adapter->napi);
417 e1000_irq_enable(adapter);
419 netif_wake_queue(adapter->netdev);
421 /* fire a link change interrupt to start the watchdog */
422 ew32(ICS, E1000_ICS_LSC);
427 * e1000_power_up_phy - restore link in case the phy was powered down
428 * @adapter: address of board private structure
430 * The phy may be powered down to save power and turn off link when the
431 * driver is unloaded and wake on lan is not enabled (among others)
432 * *** this routine MUST be followed by a call to e1000_reset ***
436 void e1000_power_up_phy(struct e1000_adapter *adapter)
438 struct e1000_hw *hw = &adapter->hw;
441 /* Just clear the power down bit to wake the phy back up */
442 if (hw->media_type == e1000_media_type_copper) {
443 /* according to the manual, the phy will retain its
444 * settings across a power-down/up cycle */
445 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
446 mii_reg &= ~MII_CR_POWER_DOWN;
447 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
451 static void e1000_power_down_phy(struct e1000_adapter *adapter)
453 struct e1000_hw *hw = &adapter->hw;
455 /* Power down the PHY so no link is implied when interface is down *
456 * The PHY cannot be powered down if any of the following is true *
459 * (c) SoL/IDER session is active */
460 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
461 hw->media_type == e1000_media_type_copper) {
464 switch (hw->mac_type) {
467 case e1000_82545_rev_3:
470 case e1000_82546_rev_3:
472 case e1000_82541_rev_2:
474 case e1000_82547_rev_2:
475 if (er32(MANC) & E1000_MANC_SMBUS_EN)
481 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
482 mii_reg |= MII_CR_POWER_DOWN;
483 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
490 void e1000_down(struct e1000_adapter *adapter)
492 struct e1000_hw *hw = &adapter->hw;
493 struct net_device *netdev = adapter->netdev;
497 /* disable receives in the hardware */
499 ew32(RCTL, rctl & ~E1000_RCTL_EN);
500 /* flush and sleep below */
502 netif_tx_disable(netdev);
504 /* disable transmits in the hardware */
506 tctl &= ~E1000_TCTL_EN;
508 /* flush both disables and wait for them to finish */
512 napi_disable(&adapter->napi);
514 e1000_irq_disable(adapter);
517 * Setting DOWN must be after irq_disable to prevent
518 * a screaming interrupt. Setting DOWN also prevents
519 * timers and tasks from rescheduling.
521 set_bit(__E1000_DOWN, &adapter->flags);
523 del_timer_sync(&adapter->tx_fifo_stall_timer);
524 del_timer_sync(&adapter->watchdog_timer);
525 del_timer_sync(&adapter->phy_info_timer);
527 adapter->link_speed = 0;
528 adapter->link_duplex = 0;
529 netif_carrier_off(netdev);
531 e1000_reset(adapter);
532 e1000_clean_all_tx_rings(adapter);
533 e1000_clean_all_rx_rings(adapter);
536 static void e1000_reinit_safe(struct e1000_adapter *adapter)
538 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
544 clear_bit(__E1000_RESETTING, &adapter->flags);
547 void e1000_reinit_locked(struct e1000_adapter *adapter)
549 /* if rtnl_lock is not held the call path is bogus */
551 WARN_ON(in_interrupt());
552 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
556 clear_bit(__E1000_RESETTING, &adapter->flags);
559 void e1000_reset(struct e1000_adapter *adapter)
561 struct e1000_hw *hw = &adapter->hw;
562 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
563 bool legacy_pba_adjust = false;
566 /* Repartition Pba for greater than 9k mtu
567 * To take effect CTRL.RST is required.
570 switch (hw->mac_type) {
571 case e1000_82542_rev2_0:
572 case e1000_82542_rev2_1:
577 case e1000_82541_rev_2:
578 legacy_pba_adjust = true;
582 case e1000_82545_rev_3:
585 case e1000_82546_rev_3:
589 case e1000_82547_rev_2:
590 legacy_pba_adjust = true;
593 case e1000_undefined:
598 if (legacy_pba_adjust) {
599 if (hw->max_frame_size > E1000_RXBUFFER_8192)
600 pba -= 8; /* allocate more FIFO for Tx */
602 if (hw->mac_type == e1000_82547) {
603 adapter->tx_fifo_head = 0;
604 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
605 adapter->tx_fifo_size =
606 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
607 atomic_set(&adapter->tx_fifo_stall, 0);
609 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
610 /* adjust PBA for jumbo frames */
613 /* To maintain wire speed transmits, the Tx FIFO should be
614 * large enough to accommodate two full transmit packets,
615 * rounded up to the next 1KB and expressed in KB. Likewise,
616 * the Rx FIFO should be large enough to accommodate at least
617 * one full receive packet and is similarly rounded up and
618 * expressed in KB. */
620 /* upper 16 bits has Tx packet buffer allocation size in KB */
621 tx_space = pba >> 16;
622 /* lower 16 bits has Rx packet buffer allocation size in KB */
625 * the tx fifo also stores 16 bytes of information about the tx
626 * but don't include ethernet FCS because hardware appends it
628 min_tx_space = (hw->max_frame_size +
629 sizeof(struct e1000_tx_desc) -
631 min_tx_space = ALIGN(min_tx_space, 1024);
633 /* software strips receive CRC, so leave room for it */
634 min_rx_space = hw->max_frame_size;
635 min_rx_space = ALIGN(min_rx_space, 1024);
638 /* If current Tx allocation is less than the min Tx FIFO size,
639 * and the min Tx FIFO size is less than the current Rx FIFO
640 * allocation, take space away from current Rx allocation */
641 if (tx_space < min_tx_space &&
642 ((min_tx_space - tx_space) < pba)) {
643 pba = pba - (min_tx_space - tx_space);
645 /* PCI/PCIx hardware has PBA alignment constraints */
646 switch (hw->mac_type) {
647 case e1000_82545 ... e1000_82546_rev_3:
648 pba &= ~(E1000_PBA_8K - 1);
654 /* if short on rx space, rx wins and must trump tx
655 * adjustment or use Early Receive if available */
656 if (pba < min_rx_space)
664 * flow control settings:
665 * The high water mark must be low enough to fit one full frame
666 * (or the size used for early receive) above it in the Rx FIFO.
667 * Set it to the lower of:
668 * - 90% of the Rx FIFO size, and
669 * - the full Rx FIFO size minus the early receive size (for parts
670 * with ERT support assuming ERT set to E1000_ERT_2048), or
671 * - the full Rx FIFO size minus one full frame
673 hwm = min(((pba << 10) * 9 / 10),
674 ((pba << 10) - hw->max_frame_size));
676 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
677 hw->fc_low_water = hw->fc_high_water - 8;
678 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
680 hw->fc = hw->original_fc;
682 /* Allow time for pending master requests to run */
684 if (hw->mac_type >= e1000_82544)
687 if (e1000_init_hw(hw))
688 e_dev_err("Hardware Error\n");
689 e1000_update_mng_vlan(adapter);
691 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
692 if (hw->mac_type >= e1000_82544 &&
694 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
695 u32 ctrl = er32(CTRL);
696 /* clear phy power management bit if we are in gig only mode,
697 * which if enabled will attempt negotiation to 100Mb, which
698 * can cause a loss of link at power off or driver unload */
699 ctrl &= ~E1000_CTRL_SWDPIN3;
703 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
704 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
706 e1000_reset_adaptive(hw);
707 e1000_phy_get_info(hw, &adapter->phy_info);
709 e1000_release_manageability(adapter);
713 * Dump the eeprom for users having checksum issues
715 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
717 struct net_device *netdev = adapter->netdev;
718 struct ethtool_eeprom eeprom;
719 const struct ethtool_ops *ops = netdev->ethtool_ops;
722 u16 csum_old, csum_new = 0;
724 eeprom.len = ops->get_eeprom_len(netdev);
727 data = kmalloc(eeprom.len, GFP_KERNEL);
729 pr_err("Unable to allocate memory to dump EEPROM data\n");
733 ops->get_eeprom(netdev, &eeprom, data);
735 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
736 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
737 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
738 csum_new += data[i] + (data[i + 1] << 8);
739 csum_new = EEPROM_SUM - csum_new;
741 pr_err("/*********************/\n");
742 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
743 pr_err("Calculated : 0x%04x\n", csum_new);
745 pr_err("Offset Values\n");
746 pr_err("======== ======\n");
747 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
749 pr_err("Include this output when contacting your support provider.\n");
750 pr_err("This is not a software error! Something bad happened to\n");
751 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
752 pr_err("result in further problems, possibly loss of data,\n");
753 pr_err("corruption or system hangs!\n");
754 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
755 pr_err("which is invalid and requires you to set the proper MAC\n");
756 pr_err("address manually before continuing to enable this network\n");
757 pr_err("device. Please inspect the EEPROM dump and report the\n");
758 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
759 pr_err("/*********************/\n");
765 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
766 * @pdev: PCI device information struct
768 * Return true if an adapter needs ioport resources
770 static int e1000_is_need_ioport(struct pci_dev *pdev)
772 switch (pdev->device) {
773 case E1000_DEV_ID_82540EM:
774 case E1000_DEV_ID_82540EM_LOM:
775 case E1000_DEV_ID_82540EP:
776 case E1000_DEV_ID_82540EP_LOM:
777 case E1000_DEV_ID_82540EP_LP:
778 case E1000_DEV_ID_82541EI:
779 case E1000_DEV_ID_82541EI_MOBILE:
780 case E1000_DEV_ID_82541ER:
781 case E1000_DEV_ID_82541ER_LOM:
782 case E1000_DEV_ID_82541GI:
783 case E1000_DEV_ID_82541GI_LF:
784 case E1000_DEV_ID_82541GI_MOBILE:
785 case E1000_DEV_ID_82544EI_COPPER:
786 case E1000_DEV_ID_82544EI_FIBER:
787 case E1000_DEV_ID_82544GC_COPPER:
788 case E1000_DEV_ID_82544GC_LOM:
789 case E1000_DEV_ID_82545EM_COPPER:
790 case E1000_DEV_ID_82545EM_FIBER:
791 case E1000_DEV_ID_82546EB_COPPER:
792 case E1000_DEV_ID_82546EB_FIBER:
793 case E1000_DEV_ID_82546EB_QUAD_COPPER:
800 static int e1000_set_features(struct net_device *netdev, u32 features)
802 struct e1000_adapter *adapter = netdev_priv(netdev);
803 u32 changed = features ^ netdev->features;
805 if (!(changed & NETIF_F_RXCSUM))
808 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
810 if (netif_running(netdev))
811 e1000_reinit_locked(adapter);
813 e1000_reset(adapter);
818 static const struct net_device_ops e1000_netdev_ops = {
819 .ndo_open = e1000_open,
820 .ndo_stop = e1000_close,
821 .ndo_start_xmit = e1000_xmit_frame,
822 .ndo_get_stats = e1000_get_stats,
823 .ndo_set_rx_mode = e1000_set_rx_mode,
824 .ndo_set_mac_address = e1000_set_mac,
825 .ndo_tx_timeout = e1000_tx_timeout,
826 .ndo_change_mtu = e1000_change_mtu,
827 .ndo_do_ioctl = e1000_ioctl,
828 .ndo_validate_addr = eth_validate_addr,
830 .ndo_vlan_rx_register = e1000_vlan_rx_register,
831 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
832 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
833 #ifdef CONFIG_NET_POLL_CONTROLLER
834 .ndo_poll_controller = e1000_netpoll,
836 .ndo_set_features = e1000_set_features,
840 * e1000_init_hw_struct - initialize members of hw struct
841 * @adapter: board private struct
842 * @hw: structure used by e1000_hw.c
844 * Factors out initialization of the e1000_hw struct to its own function
845 * that can be called very early at init (just after struct allocation).
846 * Fields are initialized based on PCI device information and
847 * OS network device settings (MTU size).
848 * Returns negative error codes if MAC type setup fails.
850 static int e1000_init_hw_struct(struct e1000_adapter *adapter,
853 struct pci_dev *pdev = adapter->pdev;
855 /* PCI config space info */
856 hw->vendor_id = pdev->vendor;
857 hw->device_id = pdev->device;
858 hw->subsystem_vendor_id = pdev->subsystem_vendor;
859 hw->subsystem_id = pdev->subsystem_device;
860 hw->revision_id = pdev->revision;
862 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
864 hw->max_frame_size = adapter->netdev->mtu +
865 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
866 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
868 /* identify the MAC */
869 if (e1000_set_mac_type(hw)) {
870 e_err(probe, "Unknown MAC Type\n");
874 switch (hw->mac_type) {
879 case e1000_82541_rev_2:
880 case e1000_82547_rev_2:
881 hw->phy_init_script = 1;
885 e1000_set_media_type(hw);
886 e1000_get_bus_info(hw);
888 hw->wait_autoneg_complete = false;
889 hw->tbi_compatibility_en = true;
890 hw->adaptive_ifs = true;
894 if (hw->media_type == e1000_media_type_copper) {
895 hw->mdix = AUTO_ALL_MODES;
896 hw->disable_polarity_correction = false;
897 hw->master_slave = E1000_MASTER_SLAVE;
904 * e1000_probe - Device Initialization Routine
905 * @pdev: PCI device information struct
906 * @ent: entry in e1000_pci_tbl
908 * Returns 0 on success, negative on failure
910 * e1000_probe initializes an adapter identified by a pci_dev structure.
911 * The OS initialization, configuring of the adapter private structure,
912 * and a hardware reset occur.
914 static int __devinit e1000_probe(struct pci_dev *pdev,
915 const struct pci_device_id *ent)
917 struct net_device *netdev;
918 struct e1000_adapter *adapter;
921 static int cards_found = 0;
922 static int global_quad_port_a = 0; /* global ksp3 port a indication */
923 int i, err, pci_using_dac;
926 u16 eeprom_apme_mask = E1000_EEPROM_APME;
927 int bars, need_ioport;
929 /* do not allocate ioport bars when not needed */
930 need_ioport = e1000_is_need_ioport(pdev);
932 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
933 err = pci_enable_device(pdev);
935 bars = pci_select_bars(pdev, IORESOURCE_MEM);
936 err = pci_enable_device_mem(pdev);
941 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
945 pci_set_master(pdev);
946 err = pci_save_state(pdev);
948 goto err_alloc_etherdev;
951 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
953 goto err_alloc_etherdev;
955 SET_NETDEV_DEV(netdev, &pdev->dev);
957 pci_set_drvdata(pdev, netdev);
958 adapter = netdev_priv(netdev);
959 adapter->netdev = netdev;
960 adapter->pdev = pdev;
961 adapter->msg_enable = (1 << debug) - 1;
962 adapter->bars = bars;
963 adapter->need_ioport = need_ioport;
969 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
973 if (adapter->need_ioport) {
974 for (i = BAR_1; i <= BAR_5; i++) {
975 if (pci_resource_len(pdev, i) == 0)
977 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
978 hw->io_base = pci_resource_start(pdev, i);
984 /* make ready for any if (hw->...) below */
985 err = e1000_init_hw_struct(adapter, hw);
990 * there is a workaround being applied below that limits
991 * 64-bit DMA addresses to 64-bit hardware. There are some
992 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
995 if ((hw->bus_type == e1000_bus_type_pcix) &&
996 !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
998 * according to DMA-API-HOWTO, coherent calls will always
999 * succeed if the set call did
1001 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
1004 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
1006 pr_err("No usable DMA config, aborting\n");
1009 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
1012 netdev->netdev_ops = &e1000_netdev_ops;
1013 e1000_set_ethtool_ops(netdev);
1014 netdev->watchdog_timeo = 5 * HZ;
1015 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1017 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1019 adapter->bd_number = cards_found;
1021 /* setup the private structure */
1023 err = e1000_sw_init(adapter);
1028 if (hw->mac_type == e1000_ce4100) {
1029 ce4100_gbe_mdio_base_phy = pci_resource_start(pdev, BAR_1);
1030 ce4100_gbe_mdio_base_virt = ioremap(ce4100_gbe_mdio_base_phy,
1031 pci_resource_len(pdev, BAR_1));
1033 if (!ce4100_gbe_mdio_base_virt)
1034 goto err_mdio_ioremap;
1037 if (hw->mac_type >= e1000_82543) {
1038 netdev->hw_features = NETIF_F_SG |
1040 netdev->features = NETIF_F_HW_VLAN_TX |
1041 NETIF_F_HW_VLAN_RX |
1042 NETIF_F_HW_VLAN_FILTER;
1045 if ((hw->mac_type >= e1000_82544) &&
1046 (hw->mac_type != e1000_82547))
1047 netdev->hw_features |= NETIF_F_TSO;
1049 netdev->features |= netdev->hw_features;
1050 netdev->hw_features |= NETIF_F_RXCSUM;
1052 if (pci_using_dac) {
1053 netdev->features |= NETIF_F_HIGHDMA;
1054 netdev->vlan_features |= NETIF_F_HIGHDMA;
1057 netdev->vlan_features |= NETIF_F_TSO;
1058 netdev->vlan_features |= NETIF_F_HW_CSUM;
1059 netdev->vlan_features |= NETIF_F_SG;
1061 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1063 /* initialize eeprom parameters */
1064 if (e1000_init_eeprom_params(hw)) {
1065 e_err(probe, "EEPROM initialization failed\n");
1069 /* before reading the EEPROM, reset the controller to
1070 * put the device in a known good starting state */
1074 /* make sure the EEPROM is good */
1075 if (e1000_validate_eeprom_checksum(hw) < 0) {
1076 e_err(probe, "The EEPROM Checksum Is Not Valid\n");
1077 e1000_dump_eeprom(adapter);
1079 * set MAC address to all zeroes to invalidate and temporary
1080 * disable this device for the user. This blocks regular
1081 * traffic while still permitting ethtool ioctls from reaching
1082 * the hardware as well as allowing the user to run the
1083 * interface after manually setting a hw addr using
1086 memset(hw->mac_addr, 0, netdev->addr_len);
1088 /* copy the MAC address out of the EEPROM */
1089 if (e1000_read_mac_addr(hw))
1090 e_err(probe, "EEPROM Read Error\n");
1092 /* don't block initalization here due to bad MAC address */
1093 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1094 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
1096 if (!is_valid_ether_addr(netdev->perm_addr))
1097 e_err(probe, "Invalid MAC Address\n");
1099 init_timer(&adapter->tx_fifo_stall_timer);
1100 adapter->tx_fifo_stall_timer.function = e1000_82547_tx_fifo_stall;
1101 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
1103 init_timer(&adapter->watchdog_timer);
1104 adapter->watchdog_timer.function = e1000_watchdog;
1105 adapter->watchdog_timer.data = (unsigned long) adapter;
1107 init_timer(&adapter->phy_info_timer);
1108 adapter->phy_info_timer.function = e1000_update_phy_info;
1109 adapter->phy_info_timer.data = (unsigned long)adapter;
1111 INIT_WORK(&adapter->fifo_stall_task, e1000_82547_tx_fifo_stall_task);
1112 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1113 INIT_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
1115 e1000_check_options(adapter);
1117 /* Initial Wake on LAN setting
1118 * If APM wake is enabled in the EEPROM,
1119 * enable the ACPI Magic Packet filter
1122 switch (hw->mac_type) {
1123 case e1000_82542_rev2_0:
1124 case e1000_82542_rev2_1:
1128 e1000_read_eeprom(hw,
1129 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1130 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1133 case e1000_82546_rev_3:
1134 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1135 e1000_read_eeprom(hw,
1136 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1141 e1000_read_eeprom(hw,
1142 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1145 if (eeprom_data & eeprom_apme_mask)
1146 adapter->eeprom_wol |= E1000_WUFC_MAG;
1148 /* now that we have the eeprom settings, apply the special cases
1149 * where the eeprom may be wrong or the board simply won't support
1150 * wake on lan on a particular port */
1151 switch (pdev->device) {
1152 case E1000_DEV_ID_82546GB_PCIE:
1153 adapter->eeprom_wol = 0;
1155 case E1000_DEV_ID_82546EB_FIBER:
1156 case E1000_DEV_ID_82546GB_FIBER:
1157 /* Wake events only supported on port A for dual fiber
1158 * regardless of eeprom setting */
1159 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1160 adapter->eeprom_wol = 0;
1162 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1163 /* if quad port adapter, disable WoL on all but port A */
1164 if (global_quad_port_a != 0)
1165 adapter->eeprom_wol = 0;
1167 adapter->quad_port_a = 1;
1168 /* Reset for multiple quad port adapters */
1169 if (++global_quad_port_a == 4)
1170 global_quad_port_a = 0;
1174 /* initialize the wol settings based on the eeprom settings */
1175 adapter->wol = adapter->eeprom_wol;
1176 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1178 /* Auto detect PHY address */
1179 if (hw->mac_type == e1000_ce4100) {
1180 for (i = 0; i < 32; i++) {
1182 e1000_read_phy_reg(hw, PHY_ID2, &tmp);
1183 if (tmp == 0 || tmp == 0xFF) {
1192 /* reset the hardware with the new settings */
1193 e1000_reset(adapter);
1195 strcpy(netdev->name, "eth%d");
1196 err = register_netdev(netdev);
1200 /* print bus type/speed/width info */
1201 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
1202 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1203 ((hw->bus_speed == e1000_bus_speed_133) ? 133 :
1204 (hw->bus_speed == e1000_bus_speed_120) ? 120 :
1205 (hw->bus_speed == e1000_bus_speed_100) ? 100 :
1206 (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33),
1207 ((hw->bus_width == e1000_bus_width_64) ? 64 : 32),
1210 /* carrier off reporting is important to ethtool even BEFORE open */
1211 netif_carrier_off(netdev);
1213 e_info(probe, "Intel(R) PRO/1000 Network Connection\n");
1220 e1000_phy_hw_reset(hw);
1222 if (hw->flash_address)
1223 iounmap(hw->flash_address);
1224 kfree(adapter->tx_ring);
1225 kfree(adapter->rx_ring);
1229 iounmap(ce4100_gbe_mdio_base_virt);
1230 iounmap(hw->hw_addr);
1232 free_netdev(netdev);
1234 pci_release_selected_regions(pdev, bars);
1236 pci_disable_device(pdev);
1241 * e1000_remove - Device Removal Routine
1242 * @pdev: PCI device information struct
1244 * e1000_remove is called by the PCI subsystem to alert the driver
1245 * that it should release a PCI device. The could be caused by a
1246 * Hot-Plug event, or because the driver is going to be removed from
1250 static void __devexit e1000_remove(struct pci_dev *pdev)
1252 struct net_device *netdev = pci_get_drvdata(pdev);
1253 struct e1000_adapter *adapter = netdev_priv(netdev);
1254 struct e1000_hw *hw = &adapter->hw;
1256 set_bit(__E1000_DOWN, &adapter->flags);
1257 del_timer_sync(&adapter->tx_fifo_stall_timer);
1258 del_timer_sync(&adapter->watchdog_timer);
1259 del_timer_sync(&adapter->phy_info_timer);
1261 cancel_work_sync(&adapter->reset_task);
1263 e1000_release_manageability(adapter);
1265 unregister_netdev(netdev);
1267 e1000_phy_hw_reset(hw);
1269 kfree(adapter->tx_ring);
1270 kfree(adapter->rx_ring);
1272 iounmap(hw->hw_addr);
1273 if (hw->flash_address)
1274 iounmap(hw->flash_address);
1275 pci_release_selected_regions(pdev, adapter->bars);
1277 free_netdev(netdev);
1279 pci_disable_device(pdev);
1283 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1284 * @adapter: board private structure to initialize
1286 * e1000_sw_init initializes the Adapter private data structure.
1287 * e1000_init_hw_struct MUST be called before this function
1290 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1292 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1294 adapter->num_tx_queues = 1;
1295 adapter->num_rx_queues = 1;
1297 if (e1000_alloc_queues(adapter)) {
1298 e_err(probe, "Unable to allocate memory for queues\n");
1302 /* Explicitly disable IRQ since the NIC can be in any state. */
1303 e1000_irq_disable(adapter);
1305 spin_lock_init(&adapter->stats_lock);
1307 set_bit(__E1000_DOWN, &adapter->flags);
1313 * e1000_alloc_queues - Allocate memory for all rings
1314 * @adapter: board private structure to initialize
1316 * We allocate one ring per queue at run-time since we don't know the
1317 * number of queues at compile-time.
1320 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1322 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1323 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1324 if (!adapter->tx_ring)
1327 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1328 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1329 if (!adapter->rx_ring) {
1330 kfree(adapter->tx_ring);
1334 return E1000_SUCCESS;
1338 * e1000_open - Called when a network interface is made active
1339 * @netdev: network interface device structure
1341 * Returns 0 on success, negative value on failure
1343 * The open entry point is called when a network interface is made
1344 * active by the system (IFF_UP). At this point all resources needed
1345 * for transmit and receive operations are allocated, the interrupt
1346 * handler is registered with the OS, the watchdog timer is started,
1347 * and the stack is notified that the interface is ready.
1350 static int e1000_open(struct net_device *netdev)
1352 struct e1000_adapter *adapter = netdev_priv(netdev);
1353 struct e1000_hw *hw = &adapter->hw;
1356 /* disallow open during test */
1357 if (test_bit(__E1000_TESTING, &adapter->flags))
1360 netif_carrier_off(netdev);
1362 /* allocate transmit descriptors */
1363 err = e1000_setup_all_tx_resources(adapter);
1367 /* allocate receive descriptors */
1368 err = e1000_setup_all_rx_resources(adapter);
1372 e1000_power_up_phy(adapter);
1374 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1375 if ((hw->mng_cookie.status &
1376 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1377 e1000_update_mng_vlan(adapter);
1380 /* before we allocate an interrupt, we must be ready to handle it.
1381 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1382 * as soon as we call pci_request_irq, so we have to setup our
1383 * clean_rx handler before we do so. */
1384 e1000_configure(adapter);
1386 err = e1000_request_irq(adapter);
1390 /* From here on the code is the same as e1000_up() */
1391 clear_bit(__E1000_DOWN, &adapter->flags);
1393 napi_enable(&adapter->napi);
1395 e1000_irq_enable(adapter);
1397 netif_start_queue(netdev);
1399 /* fire a link status change interrupt to start the watchdog */
1400 ew32(ICS, E1000_ICS_LSC);
1402 return E1000_SUCCESS;
1405 e1000_power_down_phy(adapter);
1406 e1000_free_all_rx_resources(adapter);
1408 e1000_free_all_tx_resources(adapter);
1410 e1000_reset(adapter);
1416 * e1000_close - Disables a network interface
1417 * @netdev: network interface device structure
1419 * Returns 0, this is not allowed to fail
1421 * The close entry point is called when an interface is de-activated
1422 * by the OS. The hardware is still under the drivers control, but
1423 * needs to be disabled. A global MAC reset is issued to stop the
1424 * hardware, and all transmit and receive resources are freed.
1427 static int e1000_close(struct net_device *netdev)
1429 struct e1000_adapter *adapter = netdev_priv(netdev);
1430 struct e1000_hw *hw = &adapter->hw;
1432 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1433 e1000_down(adapter);
1434 e1000_power_down_phy(adapter);
1435 e1000_free_irq(adapter);
1437 e1000_free_all_tx_resources(adapter);
1438 e1000_free_all_rx_resources(adapter);
1440 /* kill manageability vlan ID if supported, but not if a vlan with
1441 * the same ID is registered on the host OS (let 8021q kill it) */
1442 if ((hw->mng_cookie.status &
1443 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1445 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1446 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1453 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1454 * @adapter: address of board private structure
1455 * @start: address of beginning of memory
1456 * @len: length of memory
1458 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1461 struct e1000_hw *hw = &adapter->hw;
1462 unsigned long begin = (unsigned long)start;
1463 unsigned long end = begin + len;
1465 /* First rev 82545 and 82546 need to not allow any memory
1466 * write location to cross 64k boundary due to errata 23 */
1467 if (hw->mac_type == e1000_82545 ||
1468 hw->mac_type == e1000_ce4100 ||
1469 hw->mac_type == e1000_82546) {
1470 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1477 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1478 * @adapter: board private structure
1479 * @txdr: tx descriptor ring (for a specific queue) to setup
1481 * Return 0 on success, negative on failure
1484 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1485 struct e1000_tx_ring *txdr)
1487 struct pci_dev *pdev = adapter->pdev;
1490 size = sizeof(struct e1000_buffer) * txdr->count;
1491 txdr->buffer_info = vzalloc(size);
1492 if (!txdr->buffer_info) {
1493 e_err(probe, "Unable to allocate memory for the Tx descriptor "
1498 /* round up to nearest 4K */
1500 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1501 txdr->size = ALIGN(txdr->size, 4096);
1503 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1507 vfree(txdr->buffer_info);
1508 e_err(probe, "Unable to allocate memory for the Tx descriptor "
1513 /* Fix for errata 23, can't cross 64kB boundary */
1514 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1515 void *olddesc = txdr->desc;
1516 dma_addr_t olddma = txdr->dma;
1517 e_err(tx_err, "txdr align check failed: %u bytes at %p\n",
1518 txdr->size, txdr->desc);
1519 /* Try again, without freeing the previous */
1520 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size,
1521 &txdr->dma, GFP_KERNEL);
1522 /* Failed allocation, critical failure */
1524 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1526 goto setup_tx_desc_die;
1529 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1531 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1533 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1535 e_err(probe, "Unable to allocate aligned memory "
1536 "for the transmit descriptor ring\n");
1537 vfree(txdr->buffer_info);
1540 /* Free old allocation, new allocation was successful */
1541 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1545 memset(txdr->desc, 0, txdr->size);
1547 txdr->next_to_use = 0;
1548 txdr->next_to_clean = 0;
1554 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1555 * (Descriptors) for all queues
1556 * @adapter: board private structure
1558 * Return 0 on success, negative on failure
1561 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1565 for (i = 0; i < adapter->num_tx_queues; i++) {
1566 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1568 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1569 for (i-- ; i >= 0; i--)
1570 e1000_free_tx_resources(adapter,
1571 &adapter->tx_ring[i]);
1580 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1581 * @adapter: board private structure
1583 * Configure the Tx unit of the MAC after a reset.
1586 static void e1000_configure_tx(struct e1000_adapter *adapter)
1589 struct e1000_hw *hw = &adapter->hw;
1590 u32 tdlen, tctl, tipg;
1593 /* Setup the HW Tx Head and Tail descriptor pointers */
1595 switch (adapter->num_tx_queues) {
1598 tdba = adapter->tx_ring[0].dma;
1599 tdlen = adapter->tx_ring[0].count *
1600 sizeof(struct e1000_tx_desc);
1602 ew32(TDBAH, (tdba >> 32));
1603 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1606 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1607 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1611 /* Set the default values for the Tx Inter Packet Gap timer */
1612 if ((hw->media_type == e1000_media_type_fiber ||
1613 hw->media_type == e1000_media_type_internal_serdes))
1614 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1616 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1618 switch (hw->mac_type) {
1619 case e1000_82542_rev2_0:
1620 case e1000_82542_rev2_1:
1621 tipg = DEFAULT_82542_TIPG_IPGT;
1622 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1623 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1626 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1627 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1630 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1631 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1634 /* Set the Tx Interrupt Delay register */
1636 ew32(TIDV, adapter->tx_int_delay);
1637 if (hw->mac_type >= e1000_82540)
1638 ew32(TADV, adapter->tx_abs_int_delay);
1640 /* Program the Transmit Control Register */
1643 tctl &= ~E1000_TCTL_CT;
1644 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1645 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1647 e1000_config_collision_dist(hw);
1649 /* Setup Transmit Descriptor Settings for eop descriptor */
1650 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1652 /* only set IDE if we are delaying interrupts using the timers */
1653 if (adapter->tx_int_delay)
1654 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1656 if (hw->mac_type < e1000_82543)
1657 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1659 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1661 /* Cache if we're 82544 running in PCI-X because we'll
1662 * need this to apply a workaround later in the send path. */
1663 if (hw->mac_type == e1000_82544 &&
1664 hw->bus_type == e1000_bus_type_pcix)
1665 adapter->pcix_82544 = 1;
1672 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1673 * @adapter: board private structure
1674 * @rxdr: rx descriptor ring (for a specific queue) to setup
1676 * Returns 0 on success, negative on failure
1679 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1680 struct e1000_rx_ring *rxdr)
1682 struct pci_dev *pdev = adapter->pdev;
1685 size = sizeof(struct e1000_buffer) * rxdr->count;
1686 rxdr->buffer_info = vzalloc(size);
1687 if (!rxdr->buffer_info) {
1688 e_err(probe, "Unable to allocate memory for the Rx descriptor "
1693 desc_len = sizeof(struct e1000_rx_desc);
1695 /* Round up to nearest 4K */
1697 rxdr->size = rxdr->count * desc_len;
1698 rxdr->size = ALIGN(rxdr->size, 4096);
1700 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1704 e_err(probe, "Unable to allocate memory for the Rx descriptor "
1707 vfree(rxdr->buffer_info);
1711 /* Fix for errata 23, can't cross 64kB boundary */
1712 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1713 void *olddesc = rxdr->desc;
1714 dma_addr_t olddma = rxdr->dma;
1715 e_err(rx_err, "rxdr align check failed: %u bytes at %p\n",
1716 rxdr->size, rxdr->desc);
1717 /* Try again, without freeing the previous */
1718 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size,
1719 &rxdr->dma, GFP_KERNEL);
1720 /* Failed allocation, critical failure */
1722 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1724 e_err(probe, "Unable to allocate memory for the Rx "
1725 "descriptor ring\n");
1726 goto setup_rx_desc_die;
1729 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1731 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1733 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1735 e_err(probe, "Unable to allocate aligned memory for "
1736 "the Rx descriptor ring\n");
1737 goto setup_rx_desc_die;
1739 /* Free old allocation, new allocation was successful */
1740 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1744 memset(rxdr->desc, 0, rxdr->size);
1746 rxdr->next_to_clean = 0;
1747 rxdr->next_to_use = 0;
1748 rxdr->rx_skb_top = NULL;
1754 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1755 * (Descriptors) for all queues
1756 * @adapter: board private structure
1758 * Return 0 on success, negative on failure
1761 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1765 for (i = 0; i < adapter->num_rx_queues; i++) {
1766 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1768 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1769 for (i-- ; i >= 0; i--)
1770 e1000_free_rx_resources(adapter,
1771 &adapter->rx_ring[i]);
1780 * e1000_setup_rctl - configure the receive control registers
1781 * @adapter: Board private structure
1783 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1785 struct e1000_hw *hw = &adapter->hw;
1790 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1792 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1793 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1794 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1796 if (hw->tbi_compatibility_on == 1)
1797 rctl |= E1000_RCTL_SBP;
1799 rctl &= ~E1000_RCTL_SBP;
1801 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1802 rctl &= ~E1000_RCTL_LPE;
1804 rctl |= E1000_RCTL_LPE;
1806 /* Setup buffer sizes */
1807 rctl &= ~E1000_RCTL_SZ_4096;
1808 rctl |= E1000_RCTL_BSEX;
1809 switch (adapter->rx_buffer_len) {
1810 case E1000_RXBUFFER_2048:
1812 rctl |= E1000_RCTL_SZ_2048;
1813 rctl &= ~E1000_RCTL_BSEX;
1815 case E1000_RXBUFFER_4096:
1816 rctl |= E1000_RCTL_SZ_4096;
1818 case E1000_RXBUFFER_8192:
1819 rctl |= E1000_RCTL_SZ_8192;
1821 case E1000_RXBUFFER_16384:
1822 rctl |= E1000_RCTL_SZ_16384;
1830 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1831 * @adapter: board private structure
1833 * Configure the Rx unit of the MAC after a reset.
1836 static void e1000_configure_rx(struct e1000_adapter *adapter)
1839 struct e1000_hw *hw = &adapter->hw;
1840 u32 rdlen, rctl, rxcsum;
1842 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1843 rdlen = adapter->rx_ring[0].count *
1844 sizeof(struct e1000_rx_desc);
1845 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1846 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1848 rdlen = adapter->rx_ring[0].count *
1849 sizeof(struct e1000_rx_desc);
1850 adapter->clean_rx = e1000_clean_rx_irq;
1851 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1854 /* disable receives while setting up the descriptors */
1856 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1858 /* set the Receive Delay Timer Register */
1859 ew32(RDTR, adapter->rx_int_delay);
1861 if (hw->mac_type >= e1000_82540) {
1862 ew32(RADV, adapter->rx_abs_int_delay);
1863 if (adapter->itr_setting != 0)
1864 ew32(ITR, 1000000000 / (adapter->itr * 256));
1867 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1868 * the Base and Length of the Rx Descriptor Ring */
1869 switch (adapter->num_rx_queues) {
1872 rdba = adapter->rx_ring[0].dma;
1874 ew32(RDBAH, (rdba >> 32));
1875 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1878 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1879 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
1883 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1884 if (hw->mac_type >= e1000_82543) {
1885 rxcsum = er32(RXCSUM);
1886 if (adapter->rx_csum)
1887 rxcsum |= E1000_RXCSUM_TUOFL;
1889 /* don't need to clear IPPCSE as it defaults to 0 */
1890 rxcsum &= ~E1000_RXCSUM_TUOFL;
1891 ew32(RXCSUM, rxcsum);
1894 /* Enable Receives */
1899 * e1000_free_tx_resources - Free Tx Resources per Queue
1900 * @adapter: board private structure
1901 * @tx_ring: Tx descriptor ring for a specific queue
1903 * Free all transmit software resources
1906 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1907 struct e1000_tx_ring *tx_ring)
1909 struct pci_dev *pdev = adapter->pdev;
1911 e1000_clean_tx_ring(adapter, tx_ring);
1913 vfree(tx_ring->buffer_info);
1914 tx_ring->buffer_info = NULL;
1916 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1919 tx_ring->desc = NULL;
1923 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1924 * @adapter: board private structure
1926 * Free all transmit software resources
1929 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1933 for (i = 0; i < adapter->num_tx_queues; i++)
1934 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1937 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1938 struct e1000_buffer *buffer_info)
1940 if (buffer_info->dma) {
1941 if (buffer_info->mapped_as_page)
1942 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1943 buffer_info->length, DMA_TO_DEVICE);
1945 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1946 buffer_info->length,
1948 buffer_info->dma = 0;
1950 if (buffer_info->skb) {
1951 dev_kfree_skb_any(buffer_info->skb);
1952 buffer_info->skb = NULL;
1954 buffer_info->time_stamp = 0;
1955 /* buffer_info must be completely set up in the transmit path */
1959 * e1000_clean_tx_ring - Free Tx Buffers
1960 * @adapter: board private structure
1961 * @tx_ring: ring to be cleaned
1964 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1965 struct e1000_tx_ring *tx_ring)
1967 struct e1000_hw *hw = &adapter->hw;
1968 struct e1000_buffer *buffer_info;
1972 /* Free all the Tx ring sk_buffs */
1974 for (i = 0; i < tx_ring->count; i++) {
1975 buffer_info = &tx_ring->buffer_info[i];
1976 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1979 size = sizeof(struct e1000_buffer) * tx_ring->count;
1980 memset(tx_ring->buffer_info, 0, size);
1982 /* Zero out the descriptor ring */
1984 memset(tx_ring->desc, 0, tx_ring->size);
1986 tx_ring->next_to_use = 0;
1987 tx_ring->next_to_clean = 0;
1988 tx_ring->last_tx_tso = 0;
1990 writel(0, hw->hw_addr + tx_ring->tdh);
1991 writel(0, hw->hw_addr + tx_ring->tdt);
1995 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1996 * @adapter: board private structure
1999 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2003 for (i = 0; i < adapter->num_tx_queues; i++)
2004 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2008 * e1000_free_rx_resources - Free Rx Resources
2009 * @adapter: board private structure
2010 * @rx_ring: ring to clean the resources from
2012 * Free all receive software resources
2015 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2016 struct e1000_rx_ring *rx_ring)
2018 struct pci_dev *pdev = adapter->pdev;
2020 e1000_clean_rx_ring(adapter, rx_ring);
2022 vfree(rx_ring->buffer_info);
2023 rx_ring->buffer_info = NULL;
2025 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2028 rx_ring->desc = NULL;
2032 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2033 * @adapter: board private structure
2035 * Free all receive software resources
2038 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2042 for (i = 0; i < adapter->num_rx_queues; i++)
2043 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2047 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2048 * @adapter: board private structure
2049 * @rx_ring: ring to free buffers from
2052 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2053 struct e1000_rx_ring *rx_ring)
2055 struct e1000_hw *hw = &adapter->hw;
2056 struct e1000_buffer *buffer_info;
2057 struct pci_dev *pdev = adapter->pdev;
2061 /* Free all the Rx ring sk_buffs */
2062 for (i = 0; i < rx_ring->count; i++) {
2063 buffer_info = &rx_ring->buffer_info[i];
2064 if (buffer_info->dma &&
2065 adapter->clean_rx == e1000_clean_rx_irq) {
2066 dma_unmap_single(&pdev->dev, buffer_info->dma,
2067 buffer_info->length,
2069 } else if (buffer_info->dma &&
2070 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2071 dma_unmap_page(&pdev->dev, buffer_info->dma,
2072 buffer_info->length,
2076 buffer_info->dma = 0;
2077 if (buffer_info->page) {
2078 put_page(buffer_info->page);
2079 buffer_info->page = NULL;
2081 if (buffer_info->skb) {
2082 dev_kfree_skb(buffer_info->skb);
2083 buffer_info->skb = NULL;
2087 /* there also may be some cached data from a chained receive */
2088 if (rx_ring->rx_skb_top) {
2089 dev_kfree_skb(rx_ring->rx_skb_top);
2090 rx_ring->rx_skb_top = NULL;
2093 size = sizeof(struct e1000_buffer) * rx_ring->count;
2094 memset(rx_ring->buffer_info, 0, size);
2096 /* Zero out the descriptor ring */
2097 memset(rx_ring->desc, 0, rx_ring->size);
2099 rx_ring->next_to_clean = 0;
2100 rx_ring->next_to_use = 0;
2102 writel(0, hw->hw_addr + rx_ring->rdh);
2103 writel(0, hw->hw_addr + rx_ring->rdt);
2107 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2108 * @adapter: board private structure
2111 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2115 for (i = 0; i < adapter->num_rx_queues; i++)
2116 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2119 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2120 * and memory write and invalidate disabled for certain operations
2122 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2124 struct e1000_hw *hw = &adapter->hw;
2125 struct net_device *netdev = adapter->netdev;
2128 e1000_pci_clear_mwi(hw);
2131 rctl |= E1000_RCTL_RST;
2133 E1000_WRITE_FLUSH();
2136 if (netif_running(netdev))
2137 e1000_clean_all_rx_rings(adapter);
2140 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2142 struct e1000_hw *hw = &adapter->hw;
2143 struct net_device *netdev = adapter->netdev;
2147 rctl &= ~E1000_RCTL_RST;
2149 E1000_WRITE_FLUSH();
2152 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2153 e1000_pci_set_mwi(hw);
2155 if (netif_running(netdev)) {
2156 /* No need to loop, because 82542 supports only 1 queue */
2157 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2158 e1000_configure_rx(adapter);
2159 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2164 * e1000_set_mac - Change the Ethernet Address of the NIC
2165 * @netdev: network interface device structure
2166 * @p: pointer to an address structure
2168 * Returns 0 on success, negative on failure
2171 static int e1000_set_mac(struct net_device *netdev, void *p)
2173 struct e1000_adapter *adapter = netdev_priv(netdev);
2174 struct e1000_hw *hw = &adapter->hw;
2175 struct sockaddr *addr = p;
2177 if (!is_valid_ether_addr(addr->sa_data))
2178 return -EADDRNOTAVAIL;
2180 /* 82542 2.0 needs to be in reset to write receive address registers */
2182 if (hw->mac_type == e1000_82542_rev2_0)
2183 e1000_enter_82542_rst(adapter);
2185 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2186 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2188 e1000_rar_set(hw, hw->mac_addr, 0);
2190 if (hw->mac_type == e1000_82542_rev2_0)
2191 e1000_leave_82542_rst(adapter);
2197 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2198 * @netdev: network interface device structure
2200 * The set_rx_mode entry point is called whenever the unicast or multicast
2201 * address lists or the network interface flags are updated. This routine is
2202 * responsible for configuring the hardware for proper unicast, multicast,
2203 * promiscuous mode, and all-multi behavior.
2206 static void e1000_set_rx_mode(struct net_device *netdev)
2208 struct e1000_adapter *adapter = netdev_priv(netdev);
2209 struct e1000_hw *hw = &adapter->hw;
2210 struct netdev_hw_addr *ha;
2211 bool use_uc = false;
2214 int i, rar_entries = E1000_RAR_ENTRIES;
2215 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
2216 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2219 e_err(probe, "memory allocation failed\n");
2223 /* Check for Promiscuous and All Multicast modes */
2227 if (netdev->flags & IFF_PROMISC) {
2228 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2229 rctl &= ~E1000_RCTL_VFE;
2231 if (netdev->flags & IFF_ALLMULTI)
2232 rctl |= E1000_RCTL_MPE;
2234 rctl &= ~E1000_RCTL_MPE;
2235 /* Enable VLAN filter if there is a VLAN */
2237 rctl |= E1000_RCTL_VFE;
2240 if (netdev_uc_count(netdev) > rar_entries - 1) {
2241 rctl |= E1000_RCTL_UPE;
2242 } else if (!(netdev->flags & IFF_PROMISC)) {
2243 rctl &= ~E1000_RCTL_UPE;
2249 /* 82542 2.0 needs to be in reset to write receive address registers */
2251 if (hw->mac_type == e1000_82542_rev2_0)
2252 e1000_enter_82542_rst(adapter);
2254 /* load the first 14 addresses into the exact filters 1-14. Unicast
2255 * addresses take precedence to avoid disabling unicast filtering
2258 * RAR 0 is used for the station MAC address
2259 * if there are not 14 addresses, go ahead and clear the filters
2263 netdev_for_each_uc_addr(ha, netdev) {
2264 if (i == rar_entries)
2266 e1000_rar_set(hw, ha->addr, i++);
2269 netdev_for_each_mc_addr(ha, netdev) {
2270 if (i == rar_entries) {
2271 /* load any remaining addresses into the hash table */
2272 u32 hash_reg, hash_bit, mta;
2273 hash_value = e1000_hash_mc_addr(hw, ha->addr);
2274 hash_reg = (hash_value >> 5) & 0x7F;
2275 hash_bit = hash_value & 0x1F;
2276 mta = (1 << hash_bit);
2277 mcarray[hash_reg] |= mta;
2279 e1000_rar_set(hw, ha->addr, i++);
2283 for (; i < rar_entries; i++) {
2284 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2285 E1000_WRITE_FLUSH();
2286 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2287 E1000_WRITE_FLUSH();
2290 /* write the hash table completely, write from bottom to avoid
2291 * both stupid write combining chipsets, and flushing each write */
2292 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2294 * If we are on an 82544 has an errata where writing odd
2295 * offsets overwrites the previous even offset, but writing
2296 * backwards over the range solves the issue by always
2297 * writing the odd offset first
2299 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2301 E1000_WRITE_FLUSH();
2303 if (hw->mac_type == e1000_82542_rev2_0)
2304 e1000_leave_82542_rst(adapter);
2309 /* Need to wait a few seconds after link up to get diagnostic information from
2312 static void e1000_update_phy_info(unsigned long data)
2314 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2315 schedule_work(&adapter->phy_info_task);
2318 static void e1000_update_phy_info_task(struct work_struct *work)
2320 struct e1000_adapter *adapter = container_of(work,
2321 struct e1000_adapter,
2323 struct e1000_hw *hw = &adapter->hw;
2326 e1000_phy_get_info(hw, &adapter->phy_info);
2331 * e1000_82547_tx_fifo_stall - Timer Call-back
2332 * @data: pointer to adapter cast into an unsigned long
2334 static void e1000_82547_tx_fifo_stall(unsigned long data)
2336 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2337 schedule_work(&adapter->fifo_stall_task);
2341 * e1000_82547_tx_fifo_stall_task - task to complete work
2342 * @work: work struct contained inside adapter struct
2344 static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
2346 struct e1000_adapter *adapter = container_of(work,
2347 struct e1000_adapter,
2349 struct e1000_hw *hw = &adapter->hw;
2350 struct net_device *netdev = adapter->netdev;
2354 if (atomic_read(&adapter->tx_fifo_stall)) {
2355 if ((er32(TDT) == er32(TDH)) &&
2356 (er32(TDFT) == er32(TDFH)) &&
2357 (er32(TDFTS) == er32(TDFHS))) {
2359 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2360 ew32(TDFT, adapter->tx_head_addr);
2361 ew32(TDFH, adapter->tx_head_addr);
2362 ew32(TDFTS, adapter->tx_head_addr);
2363 ew32(TDFHS, adapter->tx_head_addr);
2365 E1000_WRITE_FLUSH();
2367 adapter->tx_fifo_head = 0;
2368 atomic_set(&adapter->tx_fifo_stall, 0);
2369 netif_wake_queue(netdev);
2370 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
2371 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2377 bool e1000_has_link(struct e1000_adapter *adapter)
2379 struct e1000_hw *hw = &adapter->hw;
2380 bool link_active = false;
2382 /* get_link_status is set on LSC (link status) interrupt or
2383 * rx sequence error interrupt. get_link_status will stay
2384 * false until the e1000_check_for_link establishes link
2385 * for copper adapters ONLY
2387 switch (hw->media_type) {
2388 case e1000_media_type_copper:
2389 if (hw->get_link_status) {
2390 e1000_check_for_link(hw);
2391 link_active = !hw->get_link_status;
2396 case e1000_media_type_fiber:
2397 e1000_check_for_link(hw);
2398 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2400 case e1000_media_type_internal_serdes:
2401 e1000_check_for_link(hw);
2402 link_active = hw->serdes_has_link;
2412 * e1000_watchdog - Timer Call-back
2413 * @data: pointer to adapter cast into an unsigned long
2415 static void e1000_watchdog(unsigned long data)
2417 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2418 struct e1000_hw *hw = &adapter->hw;
2419 struct net_device *netdev = adapter->netdev;
2420 struct e1000_tx_ring *txdr = adapter->tx_ring;
2423 link = e1000_has_link(adapter);
2424 if ((netif_carrier_ok(netdev)) && link)
2428 if (!netif_carrier_ok(netdev)) {
2431 /* update snapshot of PHY registers on LSC */
2432 e1000_get_speed_and_duplex(hw,
2433 &adapter->link_speed,
2434 &adapter->link_duplex);
2437 pr_info("%s NIC Link is Up %d Mbps %s, "
2438 "Flow Control: %s\n",
2440 adapter->link_speed,
2441 adapter->link_duplex == FULL_DUPLEX ?
2442 "Full Duplex" : "Half Duplex",
2443 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2444 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2445 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2446 E1000_CTRL_TFCE) ? "TX" : "None")));
2448 /* adjust timeout factor according to speed/duplex */
2449 adapter->tx_timeout_factor = 1;
2450 switch (adapter->link_speed) {
2453 adapter->tx_timeout_factor = 16;
2457 /* maybe add some timeout factor ? */
2461 /* enable transmits in the hardware */
2463 tctl |= E1000_TCTL_EN;
2466 netif_carrier_on(netdev);
2467 if (!test_bit(__E1000_DOWN, &adapter->flags))
2468 mod_timer(&adapter->phy_info_timer,
2469 round_jiffies(jiffies + 2 * HZ));
2470 adapter->smartspeed = 0;
2473 if (netif_carrier_ok(netdev)) {
2474 adapter->link_speed = 0;
2475 adapter->link_duplex = 0;
2476 pr_info("%s NIC Link is Down\n",
2478 netif_carrier_off(netdev);
2480 if (!test_bit(__E1000_DOWN, &adapter->flags))
2481 mod_timer(&adapter->phy_info_timer,
2482 round_jiffies(jiffies + 2 * HZ));
2485 e1000_smartspeed(adapter);
2489 e1000_update_stats(adapter);
2491 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2492 adapter->tpt_old = adapter->stats.tpt;
2493 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2494 adapter->colc_old = adapter->stats.colc;
2496 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2497 adapter->gorcl_old = adapter->stats.gorcl;
2498 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2499 adapter->gotcl_old = adapter->stats.gotcl;
2501 e1000_update_adaptive(hw);
2503 if (!netif_carrier_ok(netdev)) {
2504 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2505 /* We've lost link, so the controller stops DMA,
2506 * but we've got queued Tx work that's never going
2507 * to get done, so reset controller to flush Tx.
2508 * (Do the reset outside of interrupt context). */
2509 adapter->tx_timeout_count++;
2510 schedule_work(&adapter->reset_task);
2511 /* return immediately since reset is imminent */
2516 /* Simple mode for Interrupt Throttle Rate (ITR) */
2517 if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) {
2519 * Symmetric Tx/Rx gets a reduced ITR=2000;
2520 * Total asymmetrical Tx or Rx gets ITR=8000;
2521 * everyone else is between 2000-8000.
2523 u32 goc = (adapter->gotcl + adapter->gorcl) / 10000;
2524 u32 dif = (adapter->gotcl > adapter->gorcl ?
2525 adapter->gotcl - adapter->gorcl :
2526 adapter->gorcl - adapter->gotcl) / 10000;
2527 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2529 ew32(ITR, 1000000000 / (itr * 256));
2532 /* Cause software interrupt to ensure rx ring is cleaned */
2533 ew32(ICS, E1000_ICS_RXDMT0);
2535 /* Force detection of hung controller every watchdog period */
2536 adapter->detect_tx_hung = true;
2538 /* Reset the timer */
2539 if (!test_bit(__E1000_DOWN, &adapter->flags))
2540 mod_timer(&adapter->watchdog_timer,
2541 round_jiffies(jiffies + 2 * HZ));
2544 enum latency_range {
2548 latency_invalid = 255
2552 * e1000_update_itr - update the dynamic ITR value based on statistics
2553 * @adapter: pointer to adapter
2554 * @itr_setting: current adapter->itr
2555 * @packets: the number of packets during this measurement interval
2556 * @bytes: the number of bytes during this measurement interval
2558 * Stores a new ITR value based on packets and byte
2559 * counts during the last interrupt. The advantage of per interrupt
2560 * computation is faster updates and more accurate ITR for the current
2561 * traffic pattern. Constants in this function were computed
2562 * based on theoretical maximum wire speed and thresholds were set based
2563 * on testing data as well as attempting to minimize response time
2564 * while increasing bulk throughput.
2565 * this functionality is controlled by the InterruptThrottleRate module
2566 * parameter (see e1000_param.c)
2568 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2569 u16 itr_setting, int packets, int bytes)
2571 unsigned int retval = itr_setting;
2572 struct e1000_hw *hw = &adapter->hw;
2574 if (unlikely(hw->mac_type < e1000_82540))
2575 goto update_itr_done;
2578 goto update_itr_done;
2580 switch (itr_setting) {
2581 case lowest_latency:
2582 /* jumbo frames get bulk treatment*/
2583 if (bytes/packets > 8000)
2584 retval = bulk_latency;
2585 else if ((packets < 5) && (bytes > 512))
2586 retval = low_latency;
2588 case low_latency: /* 50 usec aka 20000 ints/s */
2589 if (bytes > 10000) {
2590 /* jumbo frames need bulk latency setting */
2591 if (bytes/packets > 8000)
2592 retval = bulk_latency;
2593 else if ((packets < 10) || ((bytes/packets) > 1200))
2594 retval = bulk_latency;
2595 else if ((packets > 35))
2596 retval = lowest_latency;
2597 } else if (bytes/packets > 2000)
2598 retval = bulk_latency;
2599 else if (packets <= 2 && bytes < 512)
2600 retval = lowest_latency;
2602 case bulk_latency: /* 250 usec aka 4000 ints/s */
2603 if (bytes > 25000) {
2605 retval = low_latency;
2606 } else if (bytes < 6000) {
2607 retval = low_latency;
2616 static void e1000_set_itr(struct e1000_adapter *adapter)
2618 struct e1000_hw *hw = &adapter->hw;
2620 u32 new_itr = adapter->itr;
2622 if (unlikely(hw->mac_type < e1000_82540))
2625 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2626 if (unlikely(adapter->link_speed != SPEED_1000)) {
2632 adapter->tx_itr = e1000_update_itr(adapter,
2634 adapter->total_tx_packets,
2635 adapter->total_tx_bytes);
2636 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2637 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2638 adapter->tx_itr = low_latency;
2640 adapter->rx_itr = e1000_update_itr(adapter,
2642 adapter->total_rx_packets,
2643 adapter->total_rx_bytes);
2644 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2645 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2646 adapter->rx_itr = low_latency;
2648 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2650 switch (current_itr) {
2651 /* counts and packets in update_itr are dependent on these numbers */
2652 case lowest_latency:
2656 new_itr = 20000; /* aka hwitr = ~200 */
2666 if (new_itr != adapter->itr) {
2667 /* this attempts to bias the interrupt rate towards Bulk
2668 * by adding intermediate steps when interrupt rate is
2670 new_itr = new_itr > adapter->itr ?
2671 min(adapter->itr + (new_itr >> 2), new_itr) :
2673 adapter->itr = new_itr;
2674 ew32(ITR, 1000000000 / (new_itr * 256));
2678 #define E1000_TX_FLAGS_CSUM 0x00000001
2679 #define E1000_TX_FLAGS_VLAN 0x00000002
2680 #define E1000_TX_FLAGS_TSO 0x00000004
2681 #define E1000_TX_FLAGS_IPV4 0x00000008
2682 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2683 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2685 static int e1000_tso(struct e1000_adapter *adapter,
2686 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2688 struct e1000_context_desc *context_desc;
2689 struct e1000_buffer *buffer_info;
2692 u16 ipcse = 0, tucse, mss;
2693 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2696 if (skb_is_gso(skb)) {
2697 if (skb_header_cloned(skb)) {
2698 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2703 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2704 mss = skb_shinfo(skb)->gso_size;
2705 if (skb->protocol == htons(ETH_P_IP)) {
2706 struct iphdr *iph = ip_hdr(skb);
2709 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2713 cmd_length = E1000_TXD_CMD_IP;
2714 ipcse = skb_transport_offset(skb) - 1;
2715 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2716 ipv6_hdr(skb)->payload_len = 0;
2717 tcp_hdr(skb)->check =
2718 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2719 &ipv6_hdr(skb)->daddr,
2723 ipcss = skb_network_offset(skb);
2724 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2725 tucss = skb_transport_offset(skb);
2726 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2729 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2730 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2732 i = tx_ring->next_to_use;
2733 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2734 buffer_info = &tx_ring->buffer_info[i];
2736 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2737 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2738 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2739 context_desc->upper_setup.tcp_fields.tucss = tucss;
2740 context_desc->upper_setup.tcp_fields.tucso = tucso;
2741 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2742 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2743 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2744 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2746 buffer_info->time_stamp = jiffies;
2747 buffer_info->next_to_watch = i;
2749 if (++i == tx_ring->count) i = 0;
2750 tx_ring->next_to_use = i;
2757 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2758 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2760 struct e1000_context_desc *context_desc;
2761 struct e1000_buffer *buffer_info;
2764 u32 cmd_len = E1000_TXD_CMD_DEXT;
2766 if (skb->ip_summed != CHECKSUM_PARTIAL)
2769 switch (skb->protocol) {
2770 case cpu_to_be16(ETH_P_IP):
2771 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2772 cmd_len |= E1000_TXD_CMD_TCP;
2774 case cpu_to_be16(ETH_P_IPV6):
2775 /* XXX not handling all IPV6 headers */
2776 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2777 cmd_len |= E1000_TXD_CMD_TCP;
2780 if (unlikely(net_ratelimit()))
2781 e_warn(drv, "checksum_partial proto=%x!\n",
2786 css = skb_checksum_start_offset(skb);
2788 i = tx_ring->next_to_use;
2789 buffer_info = &tx_ring->buffer_info[i];
2790 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2792 context_desc->lower_setup.ip_config = 0;
2793 context_desc->upper_setup.tcp_fields.tucss = css;
2794 context_desc->upper_setup.tcp_fields.tucso =
2795 css + skb->csum_offset;
2796 context_desc->upper_setup.tcp_fields.tucse = 0;
2797 context_desc->tcp_seg_setup.data = 0;
2798 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2800 buffer_info->time_stamp = jiffies;
2801 buffer_info->next_to_watch = i;
2803 if (unlikely(++i == tx_ring->count)) i = 0;
2804 tx_ring->next_to_use = i;
2809 #define E1000_MAX_TXD_PWR 12
2810 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2812 static int e1000_tx_map(struct e1000_adapter *adapter,
2813 struct e1000_tx_ring *tx_ring,
2814 struct sk_buff *skb, unsigned int first,
2815 unsigned int max_per_txd, unsigned int nr_frags,
2818 struct e1000_hw *hw = &adapter->hw;
2819 struct pci_dev *pdev = adapter->pdev;
2820 struct e1000_buffer *buffer_info;
2821 unsigned int len = skb_headlen(skb);
2822 unsigned int offset = 0, size, count = 0, i;
2825 i = tx_ring->next_to_use;
2828 buffer_info = &tx_ring->buffer_info[i];
2829 size = min(len, max_per_txd);
2830 /* Workaround for Controller erratum --
2831 * descriptor for non-tso packet in a linear SKB that follows a
2832 * tso gets written back prematurely before the data is fully
2833 * DMA'd to the controller */
2834 if (!skb->data_len && tx_ring->last_tx_tso &&
2836 tx_ring->last_tx_tso = 0;
2840 /* Workaround for premature desc write-backs
2841 * in TSO mode. Append 4-byte sentinel desc */
2842 if (unlikely(mss && !nr_frags && size == len && size > 8))
2844 /* work-around for errata 10 and it applies
2845 * to all controllers in PCI-X mode
2846 * The fix is to make sure that the first descriptor of a
2847 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2849 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
2850 (size > 2015) && count == 0))
2853 /* Workaround for potential 82544 hang in PCI-X. Avoid
2854 * terminating buffers within evenly-aligned dwords. */
2855 if (unlikely(adapter->pcix_82544 &&
2856 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2860 buffer_info->length = size;
2861 /* set time_stamp *before* dma to help avoid a possible race */
2862 buffer_info->time_stamp = jiffies;
2863 buffer_info->mapped_as_page = false;
2864 buffer_info->dma = dma_map_single(&pdev->dev,
2866 size, DMA_TO_DEVICE);
2867 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2869 buffer_info->next_to_watch = i;
2876 if (unlikely(i == tx_ring->count))
2881 for (f = 0; f < nr_frags; f++) {
2882 struct skb_frag_struct *frag;
2884 frag = &skb_shinfo(skb)->frags[f];
2886 offset = frag->page_offset;
2890 if (unlikely(i == tx_ring->count))
2893 buffer_info = &tx_ring->buffer_info[i];
2894 size = min(len, max_per_txd);
2895 /* Workaround for premature desc write-backs
2896 * in TSO mode. Append 4-byte sentinel desc */
2897 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2899 /* Workaround for potential 82544 hang in PCI-X.
2900 * Avoid terminating buffers within evenly-aligned
2902 if (unlikely(adapter->pcix_82544 &&
2903 !((unsigned long)(page_to_phys(frag->page) + offset
2908 buffer_info->length = size;
2909 buffer_info->time_stamp = jiffies;
2910 buffer_info->mapped_as_page = true;
2911 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
2914 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2916 buffer_info->next_to_watch = i;
2924 tx_ring->buffer_info[i].skb = skb;
2925 tx_ring->buffer_info[first].next_to_watch = i;
2930 dev_err(&pdev->dev, "TX DMA map failed\n");
2931 buffer_info->dma = 0;
2937 i += tx_ring->count;
2939 buffer_info = &tx_ring->buffer_info[i];
2940 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2946 static void e1000_tx_queue(struct e1000_adapter *adapter,
2947 struct e1000_tx_ring *tx_ring, int tx_flags,
2950 struct e1000_hw *hw = &adapter->hw;
2951 struct e1000_tx_desc *tx_desc = NULL;
2952 struct e1000_buffer *buffer_info;
2953 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2956 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2957 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2959 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2961 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2962 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2965 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2966 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2967 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2970 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2971 txd_lower |= E1000_TXD_CMD_VLE;
2972 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2975 i = tx_ring->next_to_use;
2978 buffer_info = &tx_ring->buffer_info[i];
2979 tx_desc = E1000_TX_DESC(*tx_ring, i);
2980 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2981 tx_desc->lower.data =
2982 cpu_to_le32(txd_lower | buffer_info->length);
2983 tx_desc->upper.data = cpu_to_le32(txd_upper);
2984 if (unlikely(++i == tx_ring->count)) i = 0;
2987 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2989 /* Force memory writes to complete before letting h/w
2990 * know there are new descriptors to fetch. (Only
2991 * applicable for weak-ordered memory model archs,
2992 * such as IA-64). */
2995 tx_ring->next_to_use = i;
2996 writel(i, hw->hw_addr + tx_ring->tdt);
2997 /* we need this if more than one processor can write to our tail
2998 * at a time, it syncronizes IO on IA64/Altix systems */
3003 * 82547 workaround to avoid controller hang in half-duplex environment.
3004 * The workaround is to avoid queuing a large packet that would span
3005 * the internal Tx FIFO ring boundary by notifying the stack to resend
3006 * the packet at a later time. This gives the Tx FIFO an opportunity to
3007 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3008 * to the beginning of the Tx FIFO.
3011 #define E1000_FIFO_HDR 0x10
3012 #define E1000_82547_PAD_LEN 0x3E0
3014 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3015 struct sk_buff *skb)
3017 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3018 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3020 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3022 if (adapter->link_duplex != HALF_DUPLEX)
3023 goto no_fifo_stall_required;
3025 if (atomic_read(&adapter->tx_fifo_stall))
3028 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3029 atomic_set(&adapter->tx_fifo_stall, 1);
3033 no_fifo_stall_required:
3034 adapter->tx_fifo_head += skb_fifo_len;
3035 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3036 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3040 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3042 struct e1000_adapter *adapter = netdev_priv(netdev);
3043 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3045 netif_stop_queue(netdev);
3046 /* Herbert's original patch had:
3047 * smp_mb__after_netif_stop_queue();
3048 * but since that doesn't exist yet, just open code it. */
3051 /* We need to check again in a case another CPU has just
3052 * made room available. */
3053 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3057 netif_start_queue(netdev);
3058 ++adapter->restart_queue;
3062 static int e1000_maybe_stop_tx(struct net_device *netdev,
3063 struct e1000_tx_ring *tx_ring, int size)
3065 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3067 return __e1000_maybe_stop_tx(netdev, size);
3070 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3071 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3072 struct net_device *netdev)
3074 struct e1000_adapter *adapter = netdev_priv(netdev);
3075 struct e1000_hw *hw = &adapter->hw;
3076 struct e1000_tx_ring *tx_ring;
3077 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3078 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3079 unsigned int tx_flags = 0;
3080 unsigned int len = skb_headlen(skb);
3081 unsigned int nr_frags;
3087 /* This goes back to the question of how to logically map a tx queue
3088 * to a flow. Right now, performance is impacted slightly negatively
3089 * if using multiple tx queues. If the stack breaks away from a
3090 * single qdisc implementation, we can look at this again. */
3091 tx_ring = adapter->tx_ring;
3093 if (unlikely(skb->len <= 0)) {
3094 dev_kfree_skb_any(skb);
3095 return NETDEV_TX_OK;
3098 mss = skb_shinfo(skb)->gso_size;
3099 /* The controller does a simple calculation to
3100 * make sure there is enough room in the FIFO before
3101 * initiating the DMA for each buffer. The calc is:
3102 * 4 = ceil(buffer len/mss). To make sure we don't
3103 * overrun the FIFO, adjust the max buffer len if mss
3107 max_per_txd = min(mss << 2, max_per_txd);
3108 max_txd_pwr = fls(max_per_txd) - 1;
3110 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3111 if (skb->data_len && hdr_len == len) {
3112 switch (hw->mac_type) {
3113 unsigned int pull_size;
3115 /* Make sure we have room to chop off 4 bytes,
3116 * and that the end alignment will work out to
3117 * this hardware's requirements
3118 * NOTE: this is a TSO only workaround
3119 * if end byte alignment not correct move us
3120 * into the next dword */
3121 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
3124 pull_size = min((unsigned int)4, skb->data_len);
3125 if (!__pskb_pull_tail(skb, pull_size)) {
3126 e_err(drv, "__pskb_pull_tail "
3128 dev_kfree_skb_any(skb);
3129 return NETDEV_TX_OK;
3131 len = skb_headlen(skb);
3140 /* reserve a descriptor for the offload context */
3141 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3145 /* Controller Erratum workaround */
3146 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3149 count += TXD_USE_COUNT(len, max_txd_pwr);
3151 if (adapter->pcix_82544)
3154 /* work-around for errata 10 and it applies to all controllers
3155 * in PCI-X mode, so add one more descriptor to the count
3157 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3161 nr_frags = skb_shinfo(skb)->nr_frags;
3162 for (f = 0; f < nr_frags; f++)
3163 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3165 if (adapter->pcix_82544)
3168 /* need: count + 2 desc gap to keep tail from touching
3169 * head, otherwise try next time */
3170 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3171 return NETDEV_TX_BUSY;
3173 if (unlikely(hw->mac_type == e1000_82547)) {
3174 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3175 netif_stop_queue(netdev);
3176 if (!test_bit(__E1000_DOWN, &adapter->flags))
3177 mod_timer(&adapter->tx_fifo_stall_timer,
3179 return NETDEV_TX_BUSY;
3183 if (unlikely(vlan_tx_tag_present(skb))) {
3184 tx_flags |= E1000_TX_FLAGS_VLAN;
3185 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3188 first = tx_ring->next_to_use;
3190 tso = e1000_tso(adapter, tx_ring, skb);
3192 dev_kfree_skb_any(skb);
3193 return NETDEV_TX_OK;
3197 if (likely(hw->mac_type != e1000_82544))
3198 tx_ring->last_tx_tso = 1;
3199 tx_flags |= E1000_TX_FLAGS_TSO;
3200 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3201 tx_flags |= E1000_TX_FLAGS_CSUM;
3203 if (likely(skb->protocol == htons(ETH_P_IP)))
3204 tx_flags |= E1000_TX_FLAGS_IPV4;
3206 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3210 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3211 /* Make sure there is space in the ring for the next send. */
3212 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3215 dev_kfree_skb_any(skb);
3216 tx_ring->buffer_info[first].time_stamp = 0;
3217 tx_ring->next_to_use = first;
3220 return NETDEV_TX_OK;
3224 * e1000_tx_timeout - Respond to a Tx Hang
3225 * @netdev: network interface device structure
3228 static void e1000_tx_timeout(struct net_device *netdev)
3230 struct e1000_adapter *adapter = netdev_priv(netdev);
3232 /* Do the reset outside of interrupt context */
3233 adapter->tx_timeout_count++;
3234 schedule_work(&adapter->reset_task);
3237 static void e1000_reset_task(struct work_struct *work)
3239 struct e1000_adapter *adapter =
3240 container_of(work, struct e1000_adapter, reset_task);
3242 e1000_reinit_safe(adapter);
3246 * e1000_get_stats - Get System Network Statistics
3247 * @netdev: network interface device structure
3249 * Returns the address of the device statistics structure.
3250 * The statistics are actually updated from the timer callback.
3253 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3255 /* only return the current stats */
3256 return &netdev->stats;
3260 * e1000_change_mtu - Change the Maximum Transfer Unit
3261 * @netdev: network interface device structure
3262 * @new_mtu: new value for maximum frame size
3264 * Returns 0 on success, negative on failure
3267 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3269 struct e1000_adapter *adapter = netdev_priv(netdev);
3270 struct e1000_hw *hw = &adapter->hw;
3271 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3273 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3274 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3275 e_err(probe, "Invalid MTU setting\n");
3279 /* Adapter-specific max frame size limits. */
3280 switch (hw->mac_type) {
3281 case e1000_undefined ... e1000_82542_rev2_1:
3282 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3283 e_err(probe, "Jumbo Frames not supported.\n");
3288 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3292 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3294 /* e1000_down has a dependency on max_frame_size */
3295 hw->max_frame_size = max_frame;
3296 if (netif_running(netdev))
3297 e1000_down(adapter);
3299 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3300 * means we reserve 2 more, this pushes us to allocate from the next
3302 * i.e. RXBUFFER_2048 --> size-4096 slab
3303 * however with the new *_jumbo_rx* routines, jumbo receives will use
3304 * fragmented skbs */
3306 if (max_frame <= E1000_RXBUFFER_2048)
3307 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3309 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3310 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3311 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3312 adapter->rx_buffer_len = PAGE_SIZE;
3315 /* adjust allocation if LPE protects us, and we aren't using SBP */
3316 if (!hw->tbi_compatibility_on &&
3317 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3318 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3319 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3321 pr_info("%s changing MTU from %d to %d\n",
3322 netdev->name, netdev->mtu, new_mtu);
3323 netdev->mtu = new_mtu;
3325 if (netif_running(netdev))
3328 e1000_reset(adapter);
3330 clear_bit(__E1000_RESETTING, &adapter->flags);
3336 * e1000_update_stats - Update the board statistics counters
3337 * @adapter: board private structure
3340 void e1000_update_stats(struct e1000_adapter *adapter)
3342 struct net_device *netdev = adapter->netdev;
3343 struct e1000_hw *hw = &adapter->hw;
3344 struct pci_dev *pdev = adapter->pdev;
3345 unsigned long flags;
3348 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3351 * Prevent stats update while adapter is being reset, or if the pci
3352 * connection is down.
3354 if (adapter->link_speed == 0)
3356 if (pci_channel_offline(pdev))
3359 spin_lock_irqsave(&adapter->stats_lock, flags);
3361 /* these counters are modified from e1000_tbi_adjust_stats,
3362 * called from the interrupt context, so they must only
3363 * be written while holding adapter->stats_lock
3366 adapter->stats.crcerrs += er32(CRCERRS);
3367 adapter->stats.gprc += er32(GPRC);
3368 adapter->stats.gorcl += er32(GORCL);
3369 adapter->stats.gorch += er32(GORCH);
3370 adapter->stats.bprc += er32(BPRC);
3371 adapter->stats.mprc += er32(MPRC);
3372 adapter->stats.roc += er32(ROC);
3374 adapter->stats.prc64 += er32(PRC64);
3375 adapter->stats.prc127 += er32(PRC127);
3376 adapter->stats.prc255 += er32(PRC255);
3377 adapter->stats.prc511 += er32(PRC511);
3378 adapter->stats.prc1023 += er32(PRC1023);
3379 adapter->stats.prc1522 += er32(PRC1522);
3381 adapter->stats.symerrs += er32(SYMERRS);
3382 adapter->stats.mpc += er32(MPC);
3383 adapter->stats.scc += er32(SCC);
3384 adapter->stats.ecol += er32(ECOL);
3385 adapter->stats.mcc += er32(MCC);
3386 adapter->stats.latecol += er32(LATECOL);
3387 adapter->stats.dc += er32(DC);
3388 adapter->stats.sec += er32(SEC);
3389 adapter->stats.rlec += er32(RLEC);
3390 adapter->stats.xonrxc += er32(XONRXC);
3391 adapter->stats.xontxc += er32(XONTXC);
3392 adapter->stats.xoffrxc += er32(XOFFRXC);
3393 adapter->stats.xofftxc += er32(XOFFTXC);
3394 adapter->stats.fcruc += er32(FCRUC);
3395 adapter->stats.gptc += er32(GPTC);
3396 adapter->stats.gotcl += er32(GOTCL);
3397 adapter->stats.gotch += er32(GOTCH);
3398 adapter->stats.rnbc += er32(RNBC);
3399 adapter->stats.ruc += er32(RUC);
3400 adapter->stats.rfc += er32(RFC);
3401 adapter->stats.rjc += er32(RJC);
3402 adapter->stats.torl += er32(TORL);
3403 adapter->stats.torh += er32(TORH);
3404 adapter->stats.totl += er32(TOTL);
3405 adapter->stats.toth += er32(TOTH);
3406 adapter->stats.tpr += er32(TPR);
3408 adapter->stats.ptc64 += er32(PTC64);
3409 adapter->stats.ptc127 += er32(PTC127);
3410 adapter->stats.ptc255 += er32(PTC255);
3411 adapter->stats.ptc511 += er32(PTC511);
3412 adapter->stats.ptc1023 += er32(PTC1023);
3413 adapter->stats.ptc1522 += er32(PTC1522);
3415 adapter->stats.mptc += er32(MPTC);
3416 adapter->stats.bptc += er32(BPTC);
3418 /* used for adaptive IFS */
3420 hw->tx_packet_delta = er32(TPT);
3421 adapter->stats.tpt += hw->tx_packet_delta;
3422 hw->collision_delta = er32(COLC);
3423 adapter->stats.colc += hw->collision_delta;
3425 if (hw->mac_type >= e1000_82543) {
3426 adapter->stats.algnerrc += er32(ALGNERRC);
3427 adapter->stats.rxerrc += er32(RXERRC);
3428 adapter->stats.tncrs += er32(TNCRS);
3429 adapter->stats.cexterr += er32(CEXTERR);
3430 adapter->stats.tsctc += er32(TSCTC);
3431 adapter->stats.tsctfc += er32(TSCTFC);
3434 /* Fill out the OS statistics structure */
3435 netdev->stats.multicast = adapter->stats.mprc;
3436 netdev->stats.collisions = adapter->stats.colc;
3440 /* RLEC on some newer hardware can be incorrect so build
3441 * our own version based on RUC and ROC */
3442 netdev->stats.rx_errors = adapter->stats.rxerrc +
3443 adapter->stats.crcerrs + adapter->stats.algnerrc +
3444 adapter->stats.ruc + adapter->stats.roc +
3445 adapter->stats.cexterr;
3446 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3447 netdev->stats.rx_length_errors = adapter->stats.rlerrc;
3448 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3449 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3450 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3453 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3454 netdev->stats.tx_errors = adapter->stats.txerrc;
3455 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3456 netdev->stats.tx_window_errors = adapter->stats.latecol;
3457 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3458 if (hw->bad_tx_carr_stats_fd &&
3459 adapter->link_duplex == FULL_DUPLEX) {
3460 netdev->stats.tx_carrier_errors = 0;
3461 adapter->stats.tncrs = 0;
3464 /* Tx Dropped needs to be maintained elsewhere */
3467 if (hw->media_type == e1000_media_type_copper) {
3468 if ((adapter->link_speed == SPEED_1000) &&
3469 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3470 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3471 adapter->phy_stats.idle_errors += phy_tmp;
3474 if ((hw->mac_type <= e1000_82546) &&
3475 (hw->phy_type == e1000_phy_m88) &&
3476 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3477 adapter->phy_stats.receive_errors += phy_tmp;
3480 /* Management Stats */
3481 if (hw->has_smbus) {
3482 adapter->stats.mgptc += er32(MGTPTC);
3483 adapter->stats.mgprc += er32(MGTPRC);
3484 adapter->stats.mgpdc += er32(MGTPDC);
3487 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3491 * e1000_intr - Interrupt Handler
3492 * @irq: interrupt number
3493 * @data: pointer to a network interface device structure
3496 static irqreturn_t e1000_intr(int irq, void *data)
3498 struct net_device *netdev = data;
3499 struct e1000_adapter *adapter = netdev_priv(netdev);
3500 struct e1000_hw *hw = &adapter->hw;
3501 u32 icr = er32(ICR);
3503 if (unlikely((!icr)))
3504 return IRQ_NONE; /* Not our interrupt */
3507 * we might have caused the interrupt, but the above
3508 * read cleared it, and just in case the driver is
3509 * down there is nothing to do so return handled
3511 if (unlikely(test_bit(__E1000_DOWN, &adapter->flags)))
3514 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3515 hw->get_link_status = 1;
3516 /* guard against interrupt when we're going down */
3517 if (!test_bit(__E1000_DOWN, &adapter->flags))
3518 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3521 /* disable interrupts, without the synchronize_irq bit */
3523 E1000_WRITE_FLUSH();
3525 if (likely(napi_schedule_prep(&adapter->napi))) {
3526 adapter->total_tx_bytes = 0;
3527 adapter->total_tx_packets = 0;
3528 adapter->total_rx_bytes = 0;
3529 adapter->total_rx_packets = 0;
3530 __napi_schedule(&adapter->napi);
3532 /* this really should not happen! if it does it is basically a
3533 * bug, but not a hard error, so enable ints and continue */
3534 if (!test_bit(__E1000_DOWN, &adapter->flags))
3535 e1000_irq_enable(adapter);
3542 * e1000_clean - NAPI Rx polling callback
3543 * @adapter: board private structure
3545 static int e1000_clean(struct napi_struct *napi, int budget)
3547 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3548 int tx_clean_complete = 0, work_done = 0;
3550 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3552 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
3554 if (!tx_clean_complete)
3557 /* If budget not fully consumed, exit the polling mode */
3558 if (work_done < budget) {
3559 if (likely(adapter->itr_setting & 3))
3560 e1000_set_itr(adapter);
3561 napi_complete(napi);
3562 if (!test_bit(__E1000_DOWN, &adapter->flags))
3563 e1000_irq_enable(adapter);
3570 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3571 * @adapter: board private structure
3573 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3574 struct e1000_tx_ring *tx_ring)
3576 struct e1000_hw *hw = &adapter->hw;
3577 struct net_device *netdev = adapter->netdev;
3578 struct e1000_tx_desc *tx_desc, *eop_desc;
3579 struct e1000_buffer *buffer_info;
3580 unsigned int i, eop;
3581 unsigned int count = 0;
3582 unsigned int total_tx_bytes=0, total_tx_packets=0;
3584 i = tx_ring->next_to_clean;
3585 eop = tx_ring->buffer_info[i].next_to_watch;
3586 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3588 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3589 (count < tx_ring->count)) {
3590 bool cleaned = false;
3591 rmb(); /* read buffer_info after eop_desc */
3592 for ( ; !cleaned; count++) {
3593 tx_desc = E1000_TX_DESC(*tx_ring, i);
3594 buffer_info = &tx_ring->buffer_info[i];
3595 cleaned = (i == eop);
3598 struct sk_buff *skb = buffer_info->skb;
3599 unsigned int segs, bytecount;
3600 segs = skb_shinfo(skb)->gso_segs ?: 1;
3601 /* multiply data chunks by size of headers */
3602 bytecount = ((segs - 1) * skb_headlen(skb)) +
3604 total_tx_packets += segs;
3605 total_tx_bytes += bytecount;
3607 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3608 tx_desc->upper.data = 0;
3610 if (unlikely(++i == tx_ring->count)) i = 0;
3613 eop = tx_ring->buffer_info[i].next_to_watch;
3614 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3617 tx_ring->next_to_clean = i;
3619 #define TX_WAKE_THRESHOLD 32
3620 if (unlikely(count && netif_carrier_ok(netdev) &&
3621 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3622 /* Make sure that anybody stopping the queue after this
3623 * sees the new next_to_clean.
3627 if (netif_queue_stopped(netdev) &&
3628 !(test_bit(__E1000_DOWN, &adapter->flags))) {
3629 netif_wake_queue(netdev);
3630 ++adapter->restart_queue;
3634 if (adapter->detect_tx_hung) {
3635 /* Detect a transmit hang in hardware, this serializes the
3636 * check with the clearing of time_stamp and movement of i */
3637 adapter->detect_tx_hung = false;
3638 if (tx_ring->buffer_info[eop].time_stamp &&
3639 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3640 (adapter->tx_timeout_factor * HZ)) &&
3641 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3643 /* detected Tx unit hang */
3644 e_err(drv, "Detected Tx Unit Hang\n"
3648 " next_to_use <%x>\n"
3649 " next_to_clean <%x>\n"
3650 "buffer_info[next_to_clean]\n"
3651 " time_stamp <%lx>\n"
3652 " next_to_watch <%x>\n"
3654 " next_to_watch.status <%x>\n",
3655 (unsigned long)((tx_ring - adapter->tx_ring) /
3656 sizeof(struct e1000_tx_ring)),
3657 readl(hw->hw_addr + tx_ring->tdh),
3658 readl(hw->hw_addr + tx_ring->tdt),
3659 tx_ring->next_to_use,
3660 tx_ring->next_to_clean,
3661 tx_ring->buffer_info[eop].time_stamp,
3664 eop_desc->upper.fields.status);
3665 netif_stop_queue(netdev);
3668 adapter->total_tx_bytes += total_tx_bytes;
3669 adapter->total_tx_packets += total_tx_packets;
3670 netdev->stats.tx_bytes += total_tx_bytes;
3671 netdev->stats.tx_packets += total_tx_packets;
3672 return count < tx_ring->count;
3676 * e1000_rx_checksum - Receive Checksum Offload for 82543
3677 * @adapter: board private structure
3678 * @status_err: receive descriptor status and error fields
3679 * @csum: receive descriptor csum field
3680 * @sk_buff: socket buffer with received data
3683 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3684 u32 csum, struct sk_buff *skb)
3686 struct e1000_hw *hw = &adapter->hw;
3687 u16 status = (u16)status_err;
3688 u8 errors = (u8)(status_err >> 24);
3690 skb_checksum_none_assert(skb);
3692 /* 82543 or newer only */
3693 if (unlikely(hw->mac_type < e1000_82543)) return;
3694 /* Ignore Checksum bit is set */
3695 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3696 /* TCP/UDP checksum error bit is set */
3697 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3698 /* let the stack verify checksum errors */
3699 adapter->hw_csum_err++;
3702 /* TCP/UDP Checksum has not been calculated */
3703 if (!(status & E1000_RXD_STAT_TCPCS))
3706 /* It must be a TCP or UDP packet with a valid checksum */
3707 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3708 /* TCP checksum is good */
3709 skb->ip_summed = CHECKSUM_UNNECESSARY;
3711 adapter->hw_csum_good++;
3715 * e1000_consume_page - helper function
3717 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
3722 skb->data_len += length;
3723 skb->truesize += length;
3727 * e1000_receive_skb - helper function to handle rx indications
3728 * @adapter: board private structure
3729 * @status: descriptor status field as written by hardware
3730 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3731 * @skb: pointer to sk_buff to be indicated to stack
3733 static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
3734 __le16 vlan, struct sk_buff *skb)
3736 skb->protocol = eth_type_trans(skb, adapter->netdev);
3738 if ((unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))))
3739 vlan_gro_receive(&adapter->napi, adapter->vlgrp,
3740 le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK,
3743 napi_gro_receive(&adapter->napi, skb);
3747 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
3748 * @adapter: board private structure
3749 * @rx_ring: ring to clean
3750 * @work_done: amount of napi work completed this call
3751 * @work_to_do: max amount of work allowed for this call to do
3753 * the return value indicates whether actual cleaning was done, there
3754 * is no guarantee that everything was cleaned
3756 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
3757 struct e1000_rx_ring *rx_ring,
3758 int *work_done, int work_to_do)
3760 struct e1000_hw *hw = &adapter->hw;
3761 struct net_device *netdev = adapter->netdev;
3762 struct pci_dev *pdev = adapter->pdev;
3763 struct e1000_rx_desc *rx_desc, *next_rxd;
3764 struct e1000_buffer *buffer_info, *next_buffer;
3765 unsigned long irq_flags;
3768 int cleaned_count = 0;
3769 bool cleaned = false;
3770 unsigned int total_rx_bytes=0, total_rx_packets=0;
3772 i = rx_ring->next_to_clean;
3773 rx_desc = E1000_RX_DESC(*rx_ring, i);
3774 buffer_info = &rx_ring->buffer_info[i];
3776 while (rx_desc->status & E1000_RXD_STAT_DD) {
3777 struct sk_buff *skb;
3780 if (*work_done >= work_to_do)
3783 rmb(); /* read descriptor and rx_buffer_info after status DD */
3785 status = rx_desc->status;
3786 skb = buffer_info->skb;
3787 buffer_info->skb = NULL;
3789 if (++i == rx_ring->count) i = 0;
3790 next_rxd = E1000_RX_DESC(*rx_ring, i);
3793 next_buffer = &rx_ring->buffer_info[i];
3797 dma_unmap_page(&pdev->dev, buffer_info->dma,
3798 buffer_info->length, DMA_FROM_DEVICE);
3799 buffer_info->dma = 0;
3801 length = le16_to_cpu(rx_desc->length);
3803 /* errors is only valid for DD + EOP descriptors */
3804 if (unlikely((status & E1000_RXD_STAT_EOP) &&
3805 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
3806 u8 last_byte = *(skb->data + length - 1);
3807 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
3809 spin_lock_irqsave(&adapter->stats_lock,
3811 e1000_tbi_adjust_stats(hw, &adapter->stats,
3813 spin_unlock_irqrestore(&adapter->stats_lock,
3817 /* recycle both page and skb */
3818 buffer_info->skb = skb;
3819 /* an error means any chain goes out the window
3821 if (rx_ring->rx_skb_top)
3822 dev_kfree_skb(rx_ring->rx_skb_top);
3823 rx_ring->rx_skb_top = NULL;
3828 #define rxtop rx_ring->rx_skb_top
3829 if (!(status & E1000_RXD_STAT_EOP)) {
3830 /* this descriptor is only the beginning (or middle) */
3832 /* this is the beginning of a chain */
3834 skb_fill_page_desc(rxtop, 0, buffer_info->page,
3837 /* this is the middle of a chain */
3838 skb_fill_page_desc(rxtop,
3839 skb_shinfo(rxtop)->nr_frags,
3840 buffer_info->page, 0, length);
3841 /* re-use the skb, only consumed the page */
3842 buffer_info->skb = skb;
3844 e1000_consume_page(buffer_info, rxtop, length);
3848 /* end of the chain */
3849 skb_fill_page_desc(rxtop,
3850 skb_shinfo(rxtop)->nr_frags,
3851 buffer_info->page, 0, length);
3852 /* re-use the current skb, we only consumed the
3854 buffer_info->skb = skb;
3857 e1000_consume_page(buffer_info, skb, length);
3859 /* no chain, got EOP, this buf is the packet
3860 * copybreak to save the put_page/alloc_page */
3861 if (length <= copybreak &&
3862 skb_tailroom(skb) >= length) {
3864 vaddr = kmap_atomic(buffer_info->page,
3865 KM_SKB_DATA_SOFTIRQ);
3866 memcpy(skb_tail_pointer(skb), vaddr, length);
3867 kunmap_atomic(vaddr,
3868 KM_SKB_DATA_SOFTIRQ);
3869 /* re-use the page, so don't erase
3870 * buffer_info->page */
3871 skb_put(skb, length);
3873 skb_fill_page_desc(skb, 0,
3874 buffer_info->page, 0,
3876 e1000_consume_page(buffer_info, skb,
3882 /* Receive Checksum Offload XXX recompute due to CRC strip? */
3883 e1000_rx_checksum(adapter,
3885 ((u32)(rx_desc->errors) << 24),
3886 le16_to_cpu(rx_desc->csum), skb);
3888 pskb_trim(skb, skb->len - 4);
3890 /* probably a little skewed due to removing CRC */
3891 total_rx_bytes += skb->len;
3894 /* eth type trans needs skb->data to point to something */
3895 if (!pskb_may_pull(skb, ETH_HLEN)) {
3896 e_err(drv, "pskb_may_pull failed.\n");
3901 e1000_receive_skb(adapter, status, rx_desc->special, skb);
3904 rx_desc->status = 0;
3906 /* return some buffers to hardware, one at a time is too slow */
3907 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3908 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3912 /* use prefetched values */
3914 buffer_info = next_buffer;
3916 rx_ring->next_to_clean = i;
3918 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3920 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3922 adapter->total_rx_packets += total_rx_packets;
3923 adapter->total_rx_bytes += total_rx_bytes;
3924 netdev->stats.rx_bytes += total_rx_bytes;
3925 netdev->stats.rx_packets += total_rx_packets;
3930 * this should improve performance for small packets with large amounts
3931 * of reassembly being done in the stack
3933 static void e1000_check_copybreak(struct net_device *netdev,
3934 struct e1000_buffer *buffer_info,
3935 u32 length, struct sk_buff **skb)
3937 struct sk_buff *new_skb;
3939 if (length > copybreak)
3942 new_skb = netdev_alloc_skb_ip_align(netdev, length);
3946 skb_copy_to_linear_data_offset(new_skb, -NET_IP_ALIGN,
3947 (*skb)->data - NET_IP_ALIGN,
3948 length + NET_IP_ALIGN);
3949 /* save the skb in buffer_info as good */
3950 buffer_info->skb = *skb;
3955 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3956 * @adapter: board private structure
3957 * @rx_ring: ring to clean
3958 * @work_done: amount of napi work completed this call
3959 * @work_to_do: max amount of work allowed for this call to do
3961 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
3962 struct e1000_rx_ring *rx_ring,
3963 int *work_done, int work_to_do)
3965 struct e1000_hw *hw = &adapter->hw;
3966 struct net_device *netdev = adapter->netdev;
3967 struct pci_dev *pdev = adapter->pdev;
3968 struct e1000_rx_desc *rx_desc, *next_rxd;
3969 struct e1000_buffer *buffer_info, *next_buffer;
3970 unsigned long flags;
3973 int cleaned_count = 0;
3974 bool cleaned = false;
3975 unsigned int total_rx_bytes=0, total_rx_packets=0;
3977 i = rx_ring->next_to_clean;
3978 rx_desc = E1000_RX_DESC(*rx_ring, i);
3979 buffer_info = &rx_ring->buffer_info[i];
3981 while (rx_desc->status & E1000_RXD_STAT_DD) {
3982 struct sk_buff *skb;
3985 if (*work_done >= work_to_do)
3988 rmb(); /* read descriptor and rx_buffer_info after status DD */
3990 status = rx_desc->status;
3991 skb = buffer_info->skb;
3992 buffer_info->skb = NULL;
3994 prefetch(skb->data - NET_IP_ALIGN);
3996 if (++i == rx_ring->count) i = 0;
3997 next_rxd = E1000_RX_DESC(*rx_ring, i);
4000 next_buffer = &rx_ring->buffer_info[i];
4004 dma_unmap_single(&pdev->dev, buffer_info->dma,
4005 buffer_info->length, DMA_FROM_DEVICE);
4006 buffer_info->dma = 0;
4008 length = le16_to_cpu(rx_desc->length);
4009 /* !EOP means multiple descriptors were used to store a single
4010 * packet, if thats the case we need to toss it. In fact, we
4011 * to toss every packet with the EOP bit clear and the next
4012 * frame that _does_ have the EOP bit set, as it is by
4013 * definition only a frame fragment
4015 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
4016 adapter->discarding = true;
4018 if (adapter->discarding) {
4019 /* All receives must fit into a single buffer */
4020 e_dbg("Receive packet consumed multiple buffers\n");
4022 buffer_info->skb = skb;
4023 if (status & E1000_RXD_STAT_EOP)
4024 adapter->discarding = false;
4028 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4029 u8 last_byte = *(skb->data + length - 1);
4030 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4032 spin_lock_irqsave(&adapter->stats_lock, flags);
4033 e1000_tbi_adjust_stats(hw, &adapter->stats,
4035 spin_unlock_irqrestore(&adapter->stats_lock,
4040 buffer_info->skb = skb;
4045 /* adjust length to remove Ethernet CRC, this must be
4046 * done after the TBI_ACCEPT workaround above */
4049 /* probably a little skewed due to removing CRC */
4050 total_rx_bytes += length;
4053 e1000_check_copybreak(netdev, buffer_info, length, &skb);
4055 skb_put(skb, length);
4057 /* Receive Checksum Offload */
4058 e1000_rx_checksum(adapter,
4060 ((u32)(rx_desc->errors) << 24),
4061 le16_to_cpu(rx_desc->csum), skb);
4063 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4066 rx_desc->status = 0;
4068 /* return some buffers to hardware, one at a time is too slow */
4069 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4070 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4074 /* use prefetched values */
4076 buffer_info = next_buffer;
4078 rx_ring->next_to_clean = i;
4080 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4082 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4084 adapter->total_rx_packets += total_rx_packets;
4085 adapter->total_rx_bytes += total_rx_bytes;
4086 netdev->stats.rx_bytes += total_rx_bytes;
4087 netdev->stats.rx_packets += total_rx_packets;
4092 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4093 * @adapter: address of board private structure
4094 * @rx_ring: pointer to receive ring structure
4095 * @cleaned_count: number of buffers to allocate this pass
4099 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4100 struct e1000_rx_ring *rx_ring, int cleaned_count)
4102 struct net_device *netdev = adapter->netdev;
4103 struct pci_dev *pdev = adapter->pdev;
4104 struct e1000_rx_desc *rx_desc;
4105 struct e1000_buffer *buffer_info;
4106 struct sk_buff *skb;
4108 unsigned int bufsz = 256 - 16 /*for skb_reserve */ ;
4110 i = rx_ring->next_to_use;
4111 buffer_info = &rx_ring->buffer_info[i];
4113 while (cleaned_count--) {
4114 skb = buffer_info->skb;
4120 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4121 if (unlikely(!skb)) {
4122 /* Better luck next round */
4123 adapter->alloc_rx_buff_failed++;
4127 /* Fix for errata 23, can't cross 64kB boundary */
4128 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4129 struct sk_buff *oldskb = skb;
4130 e_err(rx_err, "skb align check failed: %u bytes at "
4131 "%p\n", bufsz, skb->data);
4132 /* Try again, without freeing the previous */
4133 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4134 /* Failed allocation, critical failure */
4136 dev_kfree_skb(oldskb);
4137 adapter->alloc_rx_buff_failed++;
4141 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4144 dev_kfree_skb(oldskb);
4145 break; /* while (cleaned_count--) */
4148 /* Use new allocation */
4149 dev_kfree_skb(oldskb);
4151 buffer_info->skb = skb;
4152 buffer_info->length = adapter->rx_buffer_len;
4154 /* allocate a new page if necessary */
4155 if (!buffer_info->page) {
4156 buffer_info->page = alloc_page(GFP_ATOMIC);
4157 if (unlikely(!buffer_info->page)) {
4158 adapter->alloc_rx_buff_failed++;
4163 if (!buffer_info->dma) {
4164 buffer_info->dma = dma_map_page(&pdev->dev,
4165 buffer_info->page, 0,
4166 buffer_info->length,
4168 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4169 put_page(buffer_info->page);
4171 buffer_info->page = NULL;
4172 buffer_info->skb = NULL;
4173 buffer_info->dma = 0;
4174 adapter->alloc_rx_buff_failed++;
4175 break; /* while !buffer_info->skb */
4179 rx_desc = E1000_RX_DESC(*rx_ring, i);
4180 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4182 if (unlikely(++i == rx_ring->count))
4184 buffer_info = &rx_ring->buffer_info[i];
4187 if (likely(rx_ring->next_to_use != i)) {
4188 rx_ring->next_to_use = i;
4189 if (unlikely(i-- == 0))
4190 i = (rx_ring->count - 1);
4192 /* Force memory writes to complete before letting h/w
4193 * know there are new descriptors to fetch. (Only
4194 * applicable for weak-ordered memory model archs,
4195 * such as IA-64). */
4197 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4202 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4203 * @adapter: address of board private structure
4206 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4207 struct e1000_rx_ring *rx_ring,
4210 struct e1000_hw *hw = &adapter->hw;
4211 struct net_device *netdev = adapter->netdev;
4212 struct pci_dev *pdev = adapter->pdev;
4213 struct e1000_rx_desc *rx_desc;
4214 struct e1000_buffer *buffer_info;
4215 struct sk_buff *skb;
4217 unsigned int bufsz = adapter->rx_buffer_len;
4219 i = rx_ring->next_to_use;
4220 buffer_info = &rx_ring->buffer_info[i];
4222 while (cleaned_count--) {
4223 skb = buffer_info->skb;
4229 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4230 if (unlikely(!skb)) {
4231 /* Better luck next round */
4232 adapter->alloc_rx_buff_failed++;
4236 /* Fix for errata 23, can't cross 64kB boundary */
4237 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4238 struct sk_buff *oldskb = skb;
4239 e_err(rx_err, "skb align check failed: %u bytes at "
4240 "%p\n", bufsz, skb->data);
4241 /* Try again, without freeing the previous */
4242 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
4243 /* Failed allocation, critical failure */
4245 dev_kfree_skb(oldskb);
4246 adapter->alloc_rx_buff_failed++;
4250 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4253 dev_kfree_skb(oldskb);
4254 adapter->alloc_rx_buff_failed++;
4255 break; /* while !buffer_info->skb */
4258 /* Use new allocation */
4259 dev_kfree_skb(oldskb);
4261 buffer_info->skb = skb;
4262 buffer_info->length = adapter->rx_buffer_len;
4264 buffer_info->dma = dma_map_single(&pdev->dev,
4266 buffer_info->length,
4268 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4270 buffer_info->skb = NULL;
4271 buffer_info->dma = 0;
4272 adapter->alloc_rx_buff_failed++;
4273 break; /* while !buffer_info->skb */
4277 * XXX if it was allocated cleanly it will never map to a
4281 /* Fix for errata 23, can't cross 64kB boundary */
4282 if (!e1000_check_64k_bound(adapter,
4283 (void *)(unsigned long)buffer_info->dma,
4284 adapter->rx_buffer_len)) {
4285 e_err(rx_err, "dma align check failed: %u bytes at "
4286 "%p\n", adapter->rx_buffer_len,
4287 (void *)(unsigned long)buffer_info->dma);
4289 buffer_info->skb = NULL;
4291 dma_unmap_single(&pdev->dev, buffer_info->dma,
4292 adapter->rx_buffer_len,
4294 buffer_info->dma = 0;
4296 adapter->alloc_rx_buff_failed++;
4297 break; /* while !buffer_info->skb */
4299 rx_desc = E1000_RX_DESC(*rx_ring, i);
4300 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4302 if (unlikely(++i == rx_ring->count))
4304 buffer_info = &rx_ring->buffer_info[i];
4307 if (likely(rx_ring->next_to_use != i)) {
4308 rx_ring->next_to_use = i;
4309 if (unlikely(i-- == 0))
4310 i = (rx_ring->count - 1);
4312 /* Force memory writes to complete before letting h/w
4313 * know there are new descriptors to fetch. (Only
4314 * applicable for weak-ordered memory model archs,
4315 * such as IA-64). */
4317 writel(i, hw->hw_addr + rx_ring->rdt);
4322 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4326 static void e1000_smartspeed(struct e1000_adapter *adapter)
4328 struct e1000_hw *hw = &adapter->hw;
4332 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4333 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4336 if (adapter->smartspeed == 0) {
4337 /* If Master/Slave config fault is asserted twice,
4338 * we assume back-to-back */
4339 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4340 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4341 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4342 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4343 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4344 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4345 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4346 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4348 adapter->smartspeed++;
4349 if (!e1000_phy_setup_autoneg(hw) &&
4350 !e1000_read_phy_reg(hw, PHY_CTRL,
4352 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4353 MII_CR_RESTART_AUTO_NEG);
4354 e1000_write_phy_reg(hw, PHY_CTRL,
4359 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4360 /* If still no link, perhaps using 2/3 pair cable */
4361 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4362 phy_ctrl |= CR_1000T_MS_ENABLE;
4363 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4364 if (!e1000_phy_setup_autoneg(hw) &&
4365 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4366 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4367 MII_CR_RESTART_AUTO_NEG);
4368 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4371 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4372 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4373 adapter->smartspeed = 0;
4383 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4389 return e1000_mii_ioctl(netdev, ifr, cmd);
4402 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4405 struct e1000_adapter *adapter = netdev_priv(netdev);
4406 struct e1000_hw *hw = &adapter->hw;
4407 struct mii_ioctl_data *data = if_mii(ifr);
4410 unsigned long flags;
4412 if (hw->media_type != e1000_media_type_copper)
4417 data->phy_id = hw->phy_addr;
4420 spin_lock_irqsave(&adapter->stats_lock, flags);
4421 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4423 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4426 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4429 if (data->reg_num & ~(0x1F))
4431 mii_reg = data->val_in;
4432 spin_lock_irqsave(&adapter->stats_lock, flags);
4433 if (e1000_write_phy_reg(hw, data->reg_num,
4435 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4438 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4439 if (hw->media_type == e1000_media_type_copper) {
4440 switch (data->reg_num) {
4442 if (mii_reg & MII_CR_POWER_DOWN)
4444 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4446 hw->autoneg_advertised = 0x2F;
4451 else if (mii_reg & 0x2000)
4455 retval = e1000_set_spd_dplx(
4463 if (netif_running(adapter->netdev))
4464 e1000_reinit_locked(adapter);
4466 e1000_reset(adapter);
4468 case M88E1000_PHY_SPEC_CTRL:
4469 case M88E1000_EXT_PHY_SPEC_CTRL:
4470 if (e1000_phy_reset(hw))
4475 switch (data->reg_num) {
4477 if (mii_reg & MII_CR_POWER_DOWN)
4479 if (netif_running(adapter->netdev))
4480 e1000_reinit_locked(adapter);
4482 e1000_reset(adapter);
4490 return E1000_SUCCESS;
4493 void e1000_pci_set_mwi(struct e1000_hw *hw)
4495 struct e1000_adapter *adapter = hw->back;
4496 int ret_val = pci_set_mwi(adapter->pdev);
4499 e_err(probe, "Error in setting MWI\n");
4502 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4504 struct e1000_adapter *adapter = hw->back;
4506 pci_clear_mwi(adapter->pdev);
4509 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4511 struct e1000_adapter *adapter = hw->back;
4512 return pcix_get_mmrbc(adapter->pdev);
4515 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4517 struct e1000_adapter *adapter = hw->back;
4518 pcix_set_mmrbc(adapter->pdev, mmrbc);
4521 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4526 static void e1000_vlan_rx_register(struct net_device *netdev,
4527 struct vlan_group *grp)
4529 struct e1000_adapter *adapter = netdev_priv(netdev);
4530 struct e1000_hw *hw = &adapter->hw;
4533 if (!test_bit(__E1000_DOWN, &adapter->flags))
4534 e1000_irq_disable(adapter);
4535 adapter->vlgrp = grp;
4538 /* enable VLAN tag insert/strip */
4540 ctrl |= E1000_CTRL_VME;
4543 /* enable VLAN receive filtering */
4545 rctl &= ~E1000_RCTL_CFIEN;
4546 if (!(netdev->flags & IFF_PROMISC))
4547 rctl |= E1000_RCTL_VFE;
4549 e1000_update_mng_vlan(adapter);
4551 /* disable VLAN tag insert/strip */
4553 ctrl &= ~E1000_CTRL_VME;
4556 /* disable VLAN receive filtering */
4558 rctl &= ~E1000_RCTL_VFE;
4561 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
4562 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4563 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4567 if (!test_bit(__E1000_DOWN, &adapter->flags))
4568 e1000_irq_enable(adapter);
4571 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4573 struct e1000_adapter *adapter = netdev_priv(netdev);
4574 struct e1000_hw *hw = &adapter->hw;
4577 if ((hw->mng_cookie.status &
4578 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4579 (vid == adapter->mng_vlan_id))
4581 /* add VID to filter table */
4582 index = (vid >> 5) & 0x7F;
4583 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4584 vfta |= (1 << (vid & 0x1F));
4585 e1000_write_vfta(hw, index, vfta);
4588 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4590 struct e1000_adapter *adapter = netdev_priv(netdev);
4591 struct e1000_hw *hw = &adapter->hw;
4594 if (!test_bit(__E1000_DOWN, &adapter->flags))
4595 e1000_irq_disable(adapter);
4596 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4597 if (!test_bit(__E1000_DOWN, &adapter->flags))
4598 e1000_irq_enable(adapter);
4600 /* remove VID from filter table */
4601 index = (vid >> 5) & 0x7F;
4602 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4603 vfta &= ~(1 << (vid & 0x1F));
4604 e1000_write_vfta(hw, index, vfta);
4607 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4609 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4611 if (adapter->vlgrp) {
4613 for (vid = 0; vid < VLAN_N_VID; vid++) {
4614 if (!vlan_group_get_device(adapter->vlgrp, vid))
4616 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4621 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
4623 struct e1000_hw *hw = &adapter->hw;
4627 /* Make sure dplx is at most 1 bit and lsb of speed is not set
4628 * for the switch() below to work */
4629 if ((spd & 1) || (dplx & ~1))
4632 /* Fiber NICs only allow 1000 gbps Full duplex */
4633 if ((hw->media_type == e1000_media_type_fiber) &&
4634 spd != SPEED_1000 &&
4635 dplx != DUPLEX_FULL)
4638 switch (spd + dplx) {
4639 case SPEED_10 + DUPLEX_HALF:
4640 hw->forced_speed_duplex = e1000_10_half;
4642 case SPEED_10 + DUPLEX_FULL:
4643 hw->forced_speed_duplex = e1000_10_full;
4645 case SPEED_100 + DUPLEX_HALF:
4646 hw->forced_speed_duplex = e1000_100_half;
4648 case SPEED_100 + DUPLEX_FULL:
4649 hw->forced_speed_duplex = e1000_100_full;
4651 case SPEED_1000 + DUPLEX_FULL:
4653 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4655 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4662 e_err(probe, "Unsupported Speed/Duplex configuration\n");
4666 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4668 struct net_device *netdev = pci_get_drvdata(pdev);
4669 struct e1000_adapter *adapter = netdev_priv(netdev);
4670 struct e1000_hw *hw = &adapter->hw;
4671 u32 ctrl, ctrl_ext, rctl, status;
4672 u32 wufc = adapter->wol;
4677 netif_device_detach(netdev);
4679 if (netif_running(netdev)) {
4680 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4681 e1000_down(adapter);
4685 retval = pci_save_state(pdev);
4690 status = er32(STATUS);
4691 if (status & E1000_STATUS_LU)
4692 wufc &= ~E1000_WUFC_LNKC;
4695 e1000_setup_rctl(adapter);
4696 e1000_set_rx_mode(netdev);
4698 /* turn on all-multi mode if wake on multicast is enabled */
4699 if (wufc & E1000_WUFC_MC) {
4701 rctl |= E1000_RCTL_MPE;
4705 if (hw->mac_type >= e1000_82540) {
4707 /* advertise wake from D3Cold */
4708 #define E1000_CTRL_ADVD3WUC 0x00100000
4709 /* phy power management enable */
4710 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4711 ctrl |= E1000_CTRL_ADVD3WUC |
4712 E1000_CTRL_EN_PHY_PWR_MGMT;
4716 if (hw->media_type == e1000_media_type_fiber ||
4717 hw->media_type == e1000_media_type_internal_serdes) {
4718 /* keep the laser running in D3 */
4719 ctrl_ext = er32(CTRL_EXT);
4720 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4721 ew32(CTRL_EXT, ctrl_ext);
4724 ew32(WUC, E1000_WUC_PME_EN);
4731 e1000_release_manageability(adapter);
4733 *enable_wake = !!wufc;
4735 /* make sure adapter isn't asleep if manageability is enabled */
4736 if (adapter->en_mng_pt)
4737 *enable_wake = true;
4739 if (netif_running(netdev))
4740 e1000_free_irq(adapter);
4742 pci_disable_device(pdev);
4748 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4753 retval = __e1000_shutdown(pdev, &wake);
4758 pci_prepare_to_sleep(pdev);
4760 pci_wake_from_d3(pdev, false);
4761 pci_set_power_state(pdev, PCI_D3hot);
4767 static int e1000_resume(struct pci_dev *pdev)
4769 struct net_device *netdev = pci_get_drvdata(pdev);
4770 struct e1000_adapter *adapter = netdev_priv(netdev);
4771 struct e1000_hw *hw = &adapter->hw;
4774 pci_set_power_state(pdev, PCI_D0);
4775 pci_restore_state(pdev);
4776 pci_save_state(pdev);
4778 if (adapter->need_ioport)
4779 err = pci_enable_device(pdev);
4781 err = pci_enable_device_mem(pdev);
4783 pr_err("Cannot enable PCI device from suspend\n");
4786 pci_set_master(pdev);
4788 pci_enable_wake(pdev, PCI_D3hot, 0);
4789 pci_enable_wake(pdev, PCI_D3cold, 0);
4791 if (netif_running(netdev)) {
4792 err = e1000_request_irq(adapter);
4797 e1000_power_up_phy(adapter);
4798 e1000_reset(adapter);
4801 e1000_init_manageability(adapter);
4803 if (netif_running(netdev))
4806 netif_device_attach(netdev);
4812 static void e1000_shutdown(struct pci_dev *pdev)
4816 __e1000_shutdown(pdev, &wake);
4818 if (system_state == SYSTEM_POWER_OFF) {
4819 pci_wake_from_d3(pdev, wake);
4820 pci_set_power_state(pdev, PCI_D3hot);
4824 #ifdef CONFIG_NET_POLL_CONTROLLER
4826 * Polling 'interrupt' - used by things like netconsole to send skbs
4827 * without having to re-enable interrupts. It's not called while
4828 * the interrupt routine is executing.
4830 static void e1000_netpoll(struct net_device *netdev)
4832 struct e1000_adapter *adapter = netdev_priv(netdev);
4834 disable_irq(adapter->pdev->irq);
4835 e1000_intr(adapter->pdev->irq, netdev);
4836 enable_irq(adapter->pdev->irq);
4841 * e1000_io_error_detected - called when PCI error is detected
4842 * @pdev: Pointer to PCI device
4843 * @state: The current pci connection state
4845 * This function is called after a PCI bus error affecting
4846 * this device has been detected.
4848 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4849 pci_channel_state_t state)
4851 struct net_device *netdev = pci_get_drvdata(pdev);
4852 struct e1000_adapter *adapter = netdev_priv(netdev);
4854 netif_device_detach(netdev);
4856 if (state == pci_channel_io_perm_failure)
4857 return PCI_ERS_RESULT_DISCONNECT;
4859 if (netif_running(netdev))
4860 e1000_down(adapter);
4861 pci_disable_device(pdev);
4863 /* Request a slot slot reset. */
4864 return PCI_ERS_RESULT_NEED_RESET;
4868 * e1000_io_slot_reset - called after the pci bus has been reset.
4869 * @pdev: Pointer to PCI device
4871 * Restart the card from scratch, as if from a cold-boot. Implementation
4872 * resembles the first-half of the e1000_resume routine.
4874 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4876 struct net_device *netdev = pci_get_drvdata(pdev);
4877 struct e1000_adapter *adapter = netdev_priv(netdev);
4878 struct e1000_hw *hw = &adapter->hw;
4881 if (adapter->need_ioport)
4882 err = pci_enable_device(pdev);
4884 err = pci_enable_device_mem(pdev);
4886 pr_err("Cannot re-enable PCI device after reset.\n");
4887 return PCI_ERS_RESULT_DISCONNECT;
4889 pci_set_master(pdev);
4891 pci_enable_wake(pdev, PCI_D3hot, 0);
4892 pci_enable_wake(pdev, PCI_D3cold, 0);
4894 e1000_reset(adapter);
4897 return PCI_ERS_RESULT_RECOVERED;
4901 * e1000_io_resume - called when traffic can start flowing again.
4902 * @pdev: Pointer to PCI device
4904 * This callback is called when the error recovery driver tells us that
4905 * its OK to resume normal operation. Implementation resembles the
4906 * second-half of the e1000_resume routine.
4908 static void e1000_io_resume(struct pci_dev *pdev)
4910 struct net_device *netdev = pci_get_drvdata(pdev);
4911 struct e1000_adapter *adapter = netdev_priv(netdev);
4913 e1000_init_manageability(adapter);
4915 if (netif_running(netdev)) {
4916 if (e1000_up(adapter)) {
4917 pr_info("can't bring device back up after reset\n");
4922 netif_device_attach(netdev);