1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <net/ip6_checksum.h>
32 char e1000_driver_name[] = "e1000";
33 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
34 #define DRV_VERSION "7.3.21-k5-NAPI"
35 const char e1000_driver_version[] = DRV_VERSION;
36 static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
38 /* e1000_pci_tbl - PCI Device ID Table
40 * Last entry must be all 0s
43 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
45 static struct pci_device_id e1000_pci_tbl[] = {
46 INTEL_E1000_ETHERNET_DEVICE(0x1000),
47 INTEL_E1000_ETHERNET_DEVICE(0x1001),
48 INTEL_E1000_ETHERNET_DEVICE(0x1004),
49 INTEL_E1000_ETHERNET_DEVICE(0x1008),
50 INTEL_E1000_ETHERNET_DEVICE(0x1009),
51 INTEL_E1000_ETHERNET_DEVICE(0x100C),
52 INTEL_E1000_ETHERNET_DEVICE(0x100D),
53 INTEL_E1000_ETHERNET_DEVICE(0x100E),
54 INTEL_E1000_ETHERNET_DEVICE(0x100F),
55 INTEL_E1000_ETHERNET_DEVICE(0x1010),
56 INTEL_E1000_ETHERNET_DEVICE(0x1011),
57 INTEL_E1000_ETHERNET_DEVICE(0x1012),
58 INTEL_E1000_ETHERNET_DEVICE(0x1013),
59 INTEL_E1000_ETHERNET_DEVICE(0x1014),
60 INTEL_E1000_ETHERNET_DEVICE(0x1015),
61 INTEL_E1000_ETHERNET_DEVICE(0x1016),
62 INTEL_E1000_ETHERNET_DEVICE(0x1017),
63 INTEL_E1000_ETHERNET_DEVICE(0x1018),
64 INTEL_E1000_ETHERNET_DEVICE(0x1019),
65 INTEL_E1000_ETHERNET_DEVICE(0x101A),
66 INTEL_E1000_ETHERNET_DEVICE(0x101D),
67 INTEL_E1000_ETHERNET_DEVICE(0x101E),
68 INTEL_E1000_ETHERNET_DEVICE(0x1026),
69 INTEL_E1000_ETHERNET_DEVICE(0x1027),
70 INTEL_E1000_ETHERNET_DEVICE(0x1028),
71 INTEL_E1000_ETHERNET_DEVICE(0x1075),
72 INTEL_E1000_ETHERNET_DEVICE(0x1076),
73 INTEL_E1000_ETHERNET_DEVICE(0x1077),
74 INTEL_E1000_ETHERNET_DEVICE(0x1078),
75 INTEL_E1000_ETHERNET_DEVICE(0x1079),
76 INTEL_E1000_ETHERNET_DEVICE(0x107A),
77 INTEL_E1000_ETHERNET_DEVICE(0x107B),
78 INTEL_E1000_ETHERNET_DEVICE(0x107C),
79 INTEL_E1000_ETHERNET_DEVICE(0x108A),
80 INTEL_E1000_ETHERNET_DEVICE(0x1099),
81 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
82 /* required last entry */
86 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
88 int e1000_up(struct e1000_adapter *adapter);
89 void e1000_down(struct e1000_adapter *adapter);
90 void e1000_reinit_locked(struct e1000_adapter *adapter);
91 void e1000_reset(struct e1000_adapter *adapter);
92 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
93 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
94 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
95 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
96 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
97 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
98 struct e1000_tx_ring *txdr);
99 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
100 struct e1000_rx_ring *rxdr);
101 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
102 struct e1000_tx_ring *tx_ring);
103 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
104 struct e1000_rx_ring *rx_ring);
105 void e1000_update_stats(struct e1000_adapter *adapter);
107 static int e1000_init_module(void);
108 static void e1000_exit_module(void);
109 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
110 static void __devexit e1000_remove(struct pci_dev *pdev);
111 static int e1000_alloc_queues(struct e1000_adapter *adapter);
112 static int e1000_sw_init(struct e1000_adapter *adapter);
113 static int e1000_open(struct net_device *netdev);
114 static int e1000_close(struct net_device *netdev);
115 static void e1000_configure_tx(struct e1000_adapter *adapter);
116 static void e1000_configure_rx(struct e1000_adapter *adapter);
117 static void e1000_setup_rctl(struct e1000_adapter *adapter);
118 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
119 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
120 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
121 struct e1000_tx_ring *tx_ring);
122 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
123 struct e1000_rx_ring *rx_ring);
124 static void e1000_set_rx_mode(struct net_device *netdev);
125 static void e1000_update_phy_info(unsigned long data);
126 static void e1000_watchdog(unsigned long data);
127 static void e1000_82547_tx_fifo_stall(unsigned long data);
128 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
129 struct net_device *netdev);
130 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
131 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
132 static int e1000_set_mac(struct net_device *netdev, void *p);
133 static irqreturn_t e1000_intr(int irq, void *data);
134 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
135 struct e1000_tx_ring *tx_ring);
136 static int e1000_clean(struct napi_struct *napi, int budget);
137 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
138 struct e1000_rx_ring *rx_ring,
139 int *work_done, int work_to_do);
140 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
143 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
146 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
149 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
150 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
152 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
153 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
154 static void e1000_tx_timeout(struct net_device *dev);
155 static void e1000_reset_task(struct work_struct *work);
156 static void e1000_smartspeed(struct e1000_adapter *adapter);
157 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
158 struct sk_buff *skb);
160 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
161 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
162 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
163 static void e1000_restore_vlan(struct e1000_adapter *adapter);
166 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
167 static int e1000_resume(struct pci_dev *pdev);
169 static void e1000_shutdown(struct pci_dev *pdev);
171 #ifdef CONFIG_NET_POLL_CONTROLLER
172 /* for netdump / net console */
173 static void e1000_netpoll (struct net_device *netdev);
176 #define COPYBREAK_DEFAULT 256
177 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
178 module_param(copybreak, uint, 0644);
179 MODULE_PARM_DESC(copybreak,
180 "Maximum size of packet that is copied to a new buffer on receive");
182 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
183 pci_channel_state_t state);
184 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
185 static void e1000_io_resume(struct pci_dev *pdev);
187 static struct pci_error_handlers e1000_err_handler = {
188 .error_detected = e1000_io_error_detected,
189 .slot_reset = e1000_io_slot_reset,
190 .resume = e1000_io_resume,
193 static struct pci_driver e1000_driver = {
194 .name = e1000_driver_name,
195 .id_table = e1000_pci_tbl,
196 .probe = e1000_probe,
197 .remove = __devexit_p(e1000_remove),
199 /* Power Managment Hooks */
200 .suspend = e1000_suspend,
201 .resume = e1000_resume,
203 .shutdown = e1000_shutdown,
204 .err_handler = &e1000_err_handler
207 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
208 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
209 MODULE_LICENSE("GPL");
210 MODULE_VERSION(DRV_VERSION);
212 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
213 module_param(debug, int, 0);
214 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
217 * e1000_init_module - Driver Registration Routine
219 * e1000_init_module is the first routine called when the driver is
220 * loaded. All it does is register with the PCI subsystem.
223 static int __init e1000_init_module(void)
226 printk(KERN_INFO "%s - version %s\n",
227 e1000_driver_string, e1000_driver_version);
229 printk(KERN_INFO "%s\n", e1000_copyright);
231 ret = pci_register_driver(&e1000_driver);
232 if (copybreak != COPYBREAK_DEFAULT) {
234 printk(KERN_INFO "e1000: copybreak disabled\n");
236 printk(KERN_INFO "e1000: copybreak enabled for "
237 "packets <= %u bytes\n", copybreak);
242 module_init(e1000_init_module);
245 * e1000_exit_module - Driver Exit Cleanup Routine
247 * e1000_exit_module is called just before the driver is removed
251 static void __exit e1000_exit_module(void)
253 pci_unregister_driver(&e1000_driver);
256 module_exit(e1000_exit_module);
258 static int e1000_request_irq(struct e1000_adapter *adapter)
260 struct net_device *netdev = adapter->netdev;
261 irq_handler_t handler = e1000_intr;
262 int irq_flags = IRQF_SHARED;
265 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
269 "Unable to allocate interrupt Error: %d\n", err);
275 static void e1000_free_irq(struct e1000_adapter *adapter)
277 struct net_device *netdev = adapter->netdev;
279 free_irq(adapter->pdev->irq, netdev);
283 * e1000_irq_disable - Mask off interrupt generation on the NIC
284 * @adapter: board private structure
287 static void e1000_irq_disable(struct e1000_adapter *adapter)
289 struct e1000_hw *hw = &adapter->hw;
293 synchronize_irq(adapter->pdev->irq);
297 * e1000_irq_enable - Enable default interrupt generation settings
298 * @adapter: board private structure
301 static void e1000_irq_enable(struct e1000_adapter *adapter)
303 struct e1000_hw *hw = &adapter->hw;
305 ew32(IMS, IMS_ENABLE_MASK);
309 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
311 struct e1000_hw *hw = &adapter->hw;
312 struct net_device *netdev = adapter->netdev;
313 u16 vid = hw->mng_cookie.vlan_id;
314 u16 old_vid = adapter->mng_vlan_id;
315 if (adapter->vlgrp) {
316 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
317 if (hw->mng_cookie.status &
318 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
319 e1000_vlan_rx_add_vid(netdev, vid);
320 adapter->mng_vlan_id = vid;
322 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
324 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
326 !vlan_group_get_device(adapter->vlgrp, old_vid))
327 e1000_vlan_rx_kill_vid(netdev, old_vid);
329 adapter->mng_vlan_id = vid;
333 static void e1000_init_manageability(struct e1000_adapter *adapter)
335 struct e1000_hw *hw = &adapter->hw;
337 if (adapter->en_mng_pt) {
338 u32 manc = er32(MANC);
340 /* disable hardware interception of ARP */
341 manc &= ~(E1000_MANC_ARP_EN);
347 static void e1000_release_manageability(struct e1000_adapter *adapter)
349 struct e1000_hw *hw = &adapter->hw;
351 if (adapter->en_mng_pt) {
352 u32 manc = er32(MANC);
354 /* re-enable hardware interception of ARP */
355 manc |= E1000_MANC_ARP_EN;
362 * e1000_configure - configure the hardware for RX and TX
363 * @adapter = private board structure
365 static void e1000_configure(struct e1000_adapter *adapter)
367 struct net_device *netdev = adapter->netdev;
370 e1000_set_rx_mode(netdev);
372 e1000_restore_vlan(adapter);
373 e1000_init_manageability(adapter);
375 e1000_configure_tx(adapter);
376 e1000_setup_rctl(adapter);
377 e1000_configure_rx(adapter);
378 /* call E1000_DESC_UNUSED which always leaves
379 * at least 1 descriptor unused to make sure
380 * next_to_use != next_to_clean */
381 for (i = 0; i < adapter->num_rx_queues; i++) {
382 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
383 adapter->alloc_rx_buf(adapter, ring,
384 E1000_DESC_UNUSED(ring));
387 adapter->tx_queue_len = netdev->tx_queue_len;
390 int e1000_up(struct e1000_adapter *adapter)
392 struct e1000_hw *hw = &adapter->hw;
394 /* hardware has been reset, we need to reload some things */
395 e1000_configure(adapter);
397 clear_bit(__E1000_DOWN, &adapter->flags);
399 napi_enable(&adapter->napi);
401 e1000_irq_enable(adapter);
403 netif_wake_queue(adapter->netdev);
405 /* fire a link change interrupt to start the watchdog */
406 ew32(ICS, E1000_ICS_LSC);
411 * e1000_power_up_phy - restore link in case the phy was powered down
412 * @adapter: address of board private structure
414 * The phy may be powered down to save power and turn off link when the
415 * driver is unloaded and wake on lan is not enabled (among others)
416 * *** this routine MUST be followed by a call to e1000_reset ***
420 void e1000_power_up_phy(struct e1000_adapter *adapter)
422 struct e1000_hw *hw = &adapter->hw;
425 /* Just clear the power down bit to wake the phy back up */
426 if (hw->media_type == e1000_media_type_copper) {
427 /* according to the manual, the phy will retain its
428 * settings across a power-down/up cycle */
429 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
430 mii_reg &= ~MII_CR_POWER_DOWN;
431 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
435 static void e1000_power_down_phy(struct e1000_adapter *adapter)
437 struct e1000_hw *hw = &adapter->hw;
439 /* Power down the PHY so no link is implied when interface is down *
440 * The PHY cannot be powered down if any of the following is true *
443 * (c) SoL/IDER session is active */
444 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
445 hw->media_type == e1000_media_type_copper) {
448 switch (hw->mac_type) {
451 case e1000_82545_rev_3:
453 case e1000_82546_rev_3:
455 case e1000_82541_rev_2:
457 case e1000_82547_rev_2:
458 if (er32(MANC) & E1000_MANC_SMBUS_EN)
464 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
465 mii_reg |= MII_CR_POWER_DOWN;
466 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
473 void e1000_down(struct e1000_adapter *adapter)
475 struct e1000_hw *hw = &adapter->hw;
476 struct net_device *netdev = adapter->netdev;
479 /* signal that we're down so the interrupt handler does not
480 * reschedule our watchdog timer */
481 set_bit(__E1000_DOWN, &adapter->flags);
483 /* disable receives in the hardware */
485 ew32(RCTL, rctl & ~E1000_RCTL_EN);
486 /* flush and sleep below */
488 netif_tx_disable(netdev);
490 /* disable transmits in the hardware */
492 tctl &= ~E1000_TCTL_EN;
494 /* flush both disables and wait for them to finish */
498 napi_disable(&adapter->napi);
500 e1000_irq_disable(adapter);
502 del_timer_sync(&adapter->tx_fifo_stall_timer);
503 del_timer_sync(&adapter->watchdog_timer);
504 del_timer_sync(&adapter->phy_info_timer);
506 netdev->tx_queue_len = adapter->tx_queue_len;
507 adapter->link_speed = 0;
508 adapter->link_duplex = 0;
509 netif_carrier_off(netdev);
511 e1000_reset(adapter);
512 e1000_clean_all_tx_rings(adapter);
513 e1000_clean_all_rx_rings(adapter);
516 void e1000_reinit_locked(struct e1000_adapter *adapter)
518 WARN_ON(in_interrupt());
519 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
523 clear_bit(__E1000_RESETTING, &adapter->flags);
526 void e1000_reset(struct e1000_adapter *adapter)
528 struct e1000_hw *hw = &adapter->hw;
529 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
530 bool legacy_pba_adjust = false;
533 /* Repartition Pba for greater than 9k mtu
534 * To take effect CTRL.RST is required.
537 switch (hw->mac_type) {
538 case e1000_82542_rev2_0:
539 case e1000_82542_rev2_1:
544 case e1000_82541_rev_2:
545 legacy_pba_adjust = true;
549 case e1000_82545_rev_3:
551 case e1000_82546_rev_3:
555 case e1000_82547_rev_2:
556 legacy_pba_adjust = true;
559 case e1000_undefined:
564 if (legacy_pba_adjust) {
565 if (hw->max_frame_size > E1000_RXBUFFER_8192)
566 pba -= 8; /* allocate more FIFO for Tx */
568 if (hw->mac_type == e1000_82547) {
569 adapter->tx_fifo_head = 0;
570 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
571 adapter->tx_fifo_size =
572 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
573 atomic_set(&adapter->tx_fifo_stall, 0);
575 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
576 /* adjust PBA for jumbo frames */
579 /* To maintain wire speed transmits, the Tx FIFO should be
580 * large enough to accommodate two full transmit packets,
581 * rounded up to the next 1KB and expressed in KB. Likewise,
582 * the Rx FIFO should be large enough to accommodate at least
583 * one full receive packet and is similarly rounded up and
584 * expressed in KB. */
586 /* upper 16 bits has Tx packet buffer allocation size in KB */
587 tx_space = pba >> 16;
588 /* lower 16 bits has Rx packet buffer allocation size in KB */
591 * the tx fifo also stores 16 bytes of information about the tx
592 * but don't include ethernet FCS because hardware appends it
594 min_tx_space = (hw->max_frame_size +
595 sizeof(struct e1000_tx_desc) -
597 min_tx_space = ALIGN(min_tx_space, 1024);
599 /* software strips receive CRC, so leave room for it */
600 min_rx_space = hw->max_frame_size;
601 min_rx_space = ALIGN(min_rx_space, 1024);
604 /* If current Tx allocation is less than the min Tx FIFO size,
605 * and the min Tx FIFO size is less than the current Rx FIFO
606 * allocation, take space away from current Rx allocation */
607 if (tx_space < min_tx_space &&
608 ((min_tx_space - tx_space) < pba)) {
609 pba = pba - (min_tx_space - tx_space);
611 /* PCI/PCIx hardware has PBA alignment constraints */
612 switch (hw->mac_type) {
613 case e1000_82545 ... e1000_82546_rev_3:
614 pba &= ~(E1000_PBA_8K - 1);
620 /* if short on rx space, rx wins and must trump tx
621 * adjustment or use Early Receive if available */
622 if (pba < min_rx_space)
630 * flow control settings:
631 * The high water mark must be low enough to fit one full frame
632 * (or the size used for early receive) above it in the Rx FIFO.
633 * Set it to the lower of:
634 * - 90% of the Rx FIFO size, and
635 * - the full Rx FIFO size minus the early receive size (for parts
636 * with ERT support assuming ERT set to E1000_ERT_2048), or
637 * - the full Rx FIFO size minus one full frame
639 hwm = min(((pba << 10) * 9 / 10),
640 ((pba << 10) - hw->max_frame_size));
642 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
643 hw->fc_low_water = hw->fc_high_water - 8;
644 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
646 hw->fc = hw->original_fc;
648 /* Allow time for pending master requests to run */
650 if (hw->mac_type >= e1000_82544)
653 if (e1000_init_hw(hw))
654 DPRINTK(PROBE, ERR, "Hardware Error\n");
655 e1000_update_mng_vlan(adapter);
657 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
658 if (hw->mac_type >= e1000_82544 &&
660 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
661 u32 ctrl = er32(CTRL);
662 /* clear phy power management bit if we are in gig only mode,
663 * which if enabled will attempt negotiation to 100Mb, which
664 * can cause a loss of link at power off or driver unload */
665 ctrl &= ~E1000_CTRL_SWDPIN3;
669 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
670 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
672 e1000_reset_adaptive(hw);
673 e1000_phy_get_info(hw, &adapter->phy_info);
675 e1000_release_manageability(adapter);
679 * Dump the eeprom for users having checksum issues
681 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
683 struct net_device *netdev = adapter->netdev;
684 struct ethtool_eeprom eeprom;
685 const struct ethtool_ops *ops = netdev->ethtool_ops;
688 u16 csum_old, csum_new = 0;
690 eeprom.len = ops->get_eeprom_len(netdev);
693 data = kmalloc(eeprom.len, GFP_KERNEL);
695 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
700 ops->get_eeprom(netdev, &eeprom, data);
702 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
703 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
704 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
705 csum_new += data[i] + (data[i + 1] << 8);
706 csum_new = EEPROM_SUM - csum_new;
708 printk(KERN_ERR "/*********************/\n");
709 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
710 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
712 printk(KERN_ERR "Offset Values\n");
713 printk(KERN_ERR "======== ======\n");
714 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
716 printk(KERN_ERR "Include this output when contacting your support "
718 printk(KERN_ERR "This is not a software error! Something bad "
719 "happened to your hardware or\n");
720 printk(KERN_ERR "EEPROM image. Ignoring this "
721 "problem could result in further problems,\n");
722 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
723 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
724 "which is invalid\n");
725 printk(KERN_ERR "and requires you to set the proper MAC "
726 "address manually before continuing\n");
727 printk(KERN_ERR "to enable this network device.\n");
728 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
729 "to your hardware vendor\n");
730 printk(KERN_ERR "or Intel Customer Support.\n");
731 printk(KERN_ERR "/*********************/\n");
737 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
738 * @pdev: PCI device information struct
740 * Return true if an adapter needs ioport resources
742 static int e1000_is_need_ioport(struct pci_dev *pdev)
744 switch (pdev->device) {
745 case E1000_DEV_ID_82540EM:
746 case E1000_DEV_ID_82540EM_LOM:
747 case E1000_DEV_ID_82540EP:
748 case E1000_DEV_ID_82540EP_LOM:
749 case E1000_DEV_ID_82540EP_LP:
750 case E1000_DEV_ID_82541EI:
751 case E1000_DEV_ID_82541EI_MOBILE:
752 case E1000_DEV_ID_82541ER:
753 case E1000_DEV_ID_82541ER_LOM:
754 case E1000_DEV_ID_82541GI:
755 case E1000_DEV_ID_82541GI_LF:
756 case E1000_DEV_ID_82541GI_MOBILE:
757 case E1000_DEV_ID_82544EI_COPPER:
758 case E1000_DEV_ID_82544EI_FIBER:
759 case E1000_DEV_ID_82544GC_COPPER:
760 case E1000_DEV_ID_82544GC_LOM:
761 case E1000_DEV_ID_82545EM_COPPER:
762 case E1000_DEV_ID_82545EM_FIBER:
763 case E1000_DEV_ID_82546EB_COPPER:
764 case E1000_DEV_ID_82546EB_FIBER:
765 case E1000_DEV_ID_82546EB_QUAD_COPPER:
772 static const struct net_device_ops e1000_netdev_ops = {
773 .ndo_open = e1000_open,
774 .ndo_stop = e1000_close,
775 .ndo_start_xmit = e1000_xmit_frame,
776 .ndo_get_stats = e1000_get_stats,
777 .ndo_set_rx_mode = e1000_set_rx_mode,
778 .ndo_set_mac_address = e1000_set_mac,
779 .ndo_tx_timeout = e1000_tx_timeout,
780 .ndo_change_mtu = e1000_change_mtu,
781 .ndo_do_ioctl = e1000_ioctl,
782 .ndo_validate_addr = eth_validate_addr,
784 .ndo_vlan_rx_register = e1000_vlan_rx_register,
785 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
786 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
787 #ifdef CONFIG_NET_POLL_CONTROLLER
788 .ndo_poll_controller = e1000_netpoll,
793 * e1000_init_hw_struct - initialize members of hw struct
794 * @adapter: board private struct
795 * @hw: structure used by e1000_hw.c
797 * Factors out initialization of the e1000_hw struct to its own function
798 * that can be called very early at init (just after struct allocation).
799 * Fields are initialized based on PCI device information and
800 * OS network device settings (MTU size).
801 * Returns negative error codes if MAC type setup fails.
803 static int e1000_init_hw_struct(struct e1000_adapter *adapter,
806 struct pci_dev *pdev = adapter->pdev;
808 /* PCI config space info */
809 hw->vendor_id = pdev->vendor;
810 hw->device_id = pdev->device;
811 hw->subsystem_vendor_id = pdev->subsystem_vendor;
812 hw->subsystem_id = pdev->subsystem_device;
813 hw->revision_id = pdev->revision;
815 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
817 hw->max_frame_size = adapter->netdev->mtu +
818 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
819 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
821 /* identify the MAC */
822 if (e1000_set_mac_type(hw)) {
823 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
827 switch (hw->mac_type) {
832 case e1000_82541_rev_2:
833 case e1000_82547_rev_2:
834 hw->phy_init_script = 1;
838 e1000_set_media_type(hw);
839 e1000_get_bus_info(hw);
841 hw->wait_autoneg_complete = false;
842 hw->tbi_compatibility_en = true;
843 hw->adaptive_ifs = true;
847 if (hw->media_type == e1000_media_type_copper) {
848 hw->mdix = AUTO_ALL_MODES;
849 hw->disable_polarity_correction = false;
850 hw->master_slave = E1000_MASTER_SLAVE;
857 * e1000_probe - Device Initialization Routine
858 * @pdev: PCI device information struct
859 * @ent: entry in e1000_pci_tbl
861 * Returns 0 on success, negative on failure
863 * e1000_probe initializes an adapter identified by a pci_dev structure.
864 * The OS initialization, configuring of the adapter private structure,
865 * and a hardware reset occur.
867 static int __devinit e1000_probe(struct pci_dev *pdev,
868 const struct pci_device_id *ent)
870 struct net_device *netdev;
871 struct e1000_adapter *adapter;
874 static int cards_found = 0;
875 static int global_quad_port_a = 0; /* global ksp3 port a indication */
876 int i, err, pci_using_dac;
878 u16 eeprom_apme_mask = E1000_EEPROM_APME;
879 int bars, need_ioport;
881 /* do not allocate ioport bars when not needed */
882 need_ioport = e1000_is_need_ioport(pdev);
884 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
885 err = pci_enable_device(pdev);
887 bars = pci_select_bars(pdev, IORESOURCE_MEM);
888 err = pci_enable_device_mem(pdev);
893 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
897 pci_set_master(pdev);
900 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
902 goto err_alloc_etherdev;
904 SET_NETDEV_DEV(netdev, &pdev->dev);
906 pci_set_drvdata(pdev, netdev);
907 adapter = netdev_priv(netdev);
908 adapter->netdev = netdev;
909 adapter->pdev = pdev;
910 adapter->msg_enable = (1 << debug) - 1;
911 adapter->bars = bars;
912 adapter->need_ioport = need_ioport;
918 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
922 if (adapter->need_ioport) {
923 for (i = BAR_1; i <= BAR_5; i++) {
924 if (pci_resource_len(pdev, i) == 0)
926 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
927 hw->io_base = pci_resource_start(pdev, i);
933 /* make ready for any if (hw->...) below */
934 err = e1000_init_hw_struct(adapter, hw);
939 * there is a workaround being applied below that limits
940 * 64-bit DMA addresses to 64-bit hardware. There are some
941 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
944 if ((hw->bus_type == e1000_bus_type_pcix) &&
945 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
947 * according to DMA-API-HOWTO, coherent calls will always
948 * succeed if the set call did
950 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
952 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
953 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
955 E1000_ERR("No usable DMA configuration, aborting\n");
959 netdev->netdev_ops = &e1000_netdev_ops;
960 e1000_set_ethtool_ops(netdev);
961 netdev->watchdog_timeo = 5 * HZ;
962 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
964 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
966 adapter->bd_number = cards_found;
968 /* setup the private structure */
970 err = e1000_sw_init(adapter);
976 if (hw->mac_type >= e1000_82543) {
977 netdev->features = NETIF_F_SG |
981 NETIF_F_HW_VLAN_FILTER;
984 if ((hw->mac_type >= e1000_82544) &&
985 (hw->mac_type != e1000_82547))
986 netdev->features |= NETIF_F_TSO;
989 netdev->features |= NETIF_F_HIGHDMA;
991 netdev->vlan_features |= NETIF_F_TSO;
992 netdev->vlan_features |= NETIF_F_HW_CSUM;
993 netdev->vlan_features |= NETIF_F_SG;
995 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
997 /* initialize eeprom parameters */
998 if (e1000_init_eeprom_params(hw)) {
999 E1000_ERR("EEPROM initialization failed\n");
1003 /* before reading the EEPROM, reset the controller to
1004 * put the device in a known good starting state */
1008 /* make sure the EEPROM is good */
1009 if (e1000_validate_eeprom_checksum(hw) < 0) {
1010 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1011 e1000_dump_eeprom(adapter);
1013 * set MAC address to all zeroes to invalidate and temporary
1014 * disable this device for the user. This blocks regular
1015 * traffic while still permitting ethtool ioctls from reaching
1016 * the hardware as well as allowing the user to run the
1017 * interface after manually setting a hw addr using
1020 memset(hw->mac_addr, 0, netdev->addr_len);
1022 /* copy the MAC address out of the EEPROM */
1023 if (e1000_read_mac_addr(hw))
1024 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1026 /* don't block initalization here due to bad MAC address */
1027 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1028 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
1030 if (!is_valid_ether_addr(netdev->perm_addr))
1031 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1033 init_timer(&adapter->tx_fifo_stall_timer);
1034 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1035 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
1037 init_timer(&adapter->watchdog_timer);
1038 adapter->watchdog_timer.function = &e1000_watchdog;
1039 adapter->watchdog_timer.data = (unsigned long) adapter;
1041 init_timer(&adapter->phy_info_timer);
1042 adapter->phy_info_timer.function = &e1000_update_phy_info;
1043 adapter->phy_info_timer.data = (unsigned long)adapter;
1045 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1047 e1000_check_options(adapter);
1049 /* Initial Wake on LAN setting
1050 * If APM wake is enabled in the EEPROM,
1051 * enable the ACPI Magic Packet filter
1054 switch (hw->mac_type) {
1055 case e1000_82542_rev2_0:
1056 case e1000_82542_rev2_1:
1060 e1000_read_eeprom(hw,
1061 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1062 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1065 case e1000_82546_rev_3:
1066 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1067 e1000_read_eeprom(hw,
1068 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1073 e1000_read_eeprom(hw,
1074 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1077 if (eeprom_data & eeprom_apme_mask)
1078 adapter->eeprom_wol |= E1000_WUFC_MAG;
1080 /* now that we have the eeprom settings, apply the special cases
1081 * where the eeprom may be wrong or the board simply won't support
1082 * wake on lan on a particular port */
1083 switch (pdev->device) {
1084 case E1000_DEV_ID_82546GB_PCIE:
1085 adapter->eeprom_wol = 0;
1087 case E1000_DEV_ID_82546EB_FIBER:
1088 case E1000_DEV_ID_82546GB_FIBER:
1089 /* Wake events only supported on port A for dual fiber
1090 * regardless of eeprom setting */
1091 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1092 adapter->eeprom_wol = 0;
1094 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1095 /* if quad port adapter, disable WoL on all but port A */
1096 if (global_quad_port_a != 0)
1097 adapter->eeprom_wol = 0;
1099 adapter->quad_port_a = 1;
1100 /* Reset for multiple quad port adapters */
1101 if (++global_quad_port_a == 4)
1102 global_quad_port_a = 0;
1106 /* initialize the wol settings based on the eeprom settings */
1107 adapter->wol = adapter->eeprom_wol;
1108 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1110 /* print bus type/speed/width info */
1111 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1112 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1113 ((hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1114 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1115 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1116 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1117 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : "32-bit"));
1119 printk("%pM\n", netdev->dev_addr);
1121 /* reset the hardware with the new settings */
1122 e1000_reset(adapter);
1124 strcpy(netdev->name, "eth%d");
1125 err = register_netdev(netdev);
1129 /* carrier off reporting is important to ethtool even BEFORE open */
1130 netif_carrier_off(netdev);
1132 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1139 e1000_phy_hw_reset(hw);
1141 if (hw->flash_address)
1142 iounmap(hw->flash_address);
1143 kfree(adapter->tx_ring);
1144 kfree(adapter->rx_ring);
1147 iounmap(hw->hw_addr);
1149 free_netdev(netdev);
1151 pci_release_selected_regions(pdev, bars);
1153 pci_disable_device(pdev);
1158 * e1000_remove - Device Removal Routine
1159 * @pdev: PCI device information struct
1161 * e1000_remove is called by the PCI subsystem to alert the driver
1162 * that it should release a PCI device. The could be caused by a
1163 * Hot-Plug event, or because the driver is going to be removed from
1167 static void __devexit e1000_remove(struct pci_dev *pdev)
1169 struct net_device *netdev = pci_get_drvdata(pdev);
1170 struct e1000_adapter *adapter = netdev_priv(netdev);
1171 struct e1000_hw *hw = &adapter->hw;
1173 set_bit(__E1000_DOWN, &adapter->flags);
1174 del_timer_sync(&adapter->tx_fifo_stall_timer);
1175 del_timer_sync(&adapter->watchdog_timer);
1176 del_timer_sync(&adapter->phy_info_timer);
1178 cancel_work_sync(&adapter->reset_task);
1180 e1000_release_manageability(adapter);
1182 unregister_netdev(netdev);
1184 e1000_phy_hw_reset(hw);
1186 kfree(adapter->tx_ring);
1187 kfree(adapter->rx_ring);
1189 iounmap(hw->hw_addr);
1190 if (hw->flash_address)
1191 iounmap(hw->flash_address);
1192 pci_release_selected_regions(pdev, adapter->bars);
1194 free_netdev(netdev);
1196 pci_disable_device(pdev);
1200 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1201 * @adapter: board private structure to initialize
1203 * e1000_sw_init initializes the Adapter private data structure.
1204 * e1000_init_hw_struct MUST be called before this function
1207 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1209 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1211 adapter->num_tx_queues = 1;
1212 adapter->num_rx_queues = 1;
1214 if (e1000_alloc_queues(adapter)) {
1215 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1219 /* Explicitly disable IRQ since the NIC can be in any state. */
1220 e1000_irq_disable(adapter);
1222 spin_lock_init(&adapter->stats_lock);
1224 set_bit(__E1000_DOWN, &adapter->flags);
1230 * e1000_alloc_queues - Allocate memory for all rings
1231 * @adapter: board private structure to initialize
1233 * We allocate one ring per queue at run-time since we don't know the
1234 * number of queues at compile-time.
1237 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1239 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1240 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1241 if (!adapter->tx_ring)
1244 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1245 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1246 if (!adapter->rx_ring) {
1247 kfree(adapter->tx_ring);
1251 return E1000_SUCCESS;
1255 * e1000_open - Called when a network interface is made active
1256 * @netdev: network interface device structure
1258 * Returns 0 on success, negative value on failure
1260 * The open entry point is called when a network interface is made
1261 * active by the system (IFF_UP). At this point all resources needed
1262 * for transmit and receive operations are allocated, the interrupt
1263 * handler is registered with the OS, the watchdog timer is started,
1264 * and the stack is notified that the interface is ready.
1267 static int e1000_open(struct net_device *netdev)
1269 struct e1000_adapter *adapter = netdev_priv(netdev);
1270 struct e1000_hw *hw = &adapter->hw;
1273 /* disallow open during test */
1274 if (test_bit(__E1000_TESTING, &adapter->flags))
1277 netif_carrier_off(netdev);
1279 /* allocate transmit descriptors */
1280 err = e1000_setup_all_tx_resources(adapter);
1284 /* allocate receive descriptors */
1285 err = e1000_setup_all_rx_resources(adapter);
1289 e1000_power_up_phy(adapter);
1291 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1292 if ((hw->mng_cookie.status &
1293 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1294 e1000_update_mng_vlan(adapter);
1297 /* before we allocate an interrupt, we must be ready to handle it.
1298 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1299 * as soon as we call pci_request_irq, so we have to setup our
1300 * clean_rx handler before we do so. */
1301 e1000_configure(adapter);
1303 err = e1000_request_irq(adapter);
1307 /* From here on the code is the same as e1000_up() */
1308 clear_bit(__E1000_DOWN, &adapter->flags);
1310 napi_enable(&adapter->napi);
1312 e1000_irq_enable(adapter);
1314 netif_start_queue(netdev);
1316 /* fire a link status change interrupt to start the watchdog */
1317 ew32(ICS, E1000_ICS_LSC);
1319 return E1000_SUCCESS;
1322 e1000_power_down_phy(adapter);
1323 e1000_free_all_rx_resources(adapter);
1325 e1000_free_all_tx_resources(adapter);
1327 e1000_reset(adapter);
1333 * e1000_close - Disables a network interface
1334 * @netdev: network interface device structure
1336 * Returns 0, this is not allowed to fail
1338 * The close entry point is called when an interface is de-activated
1339 * by the OS. The hardware is still under the drivers control, but
1340 * needs to be disabled. A global MAC reset is issued to stop the
1341 * hardware, and all transmit and receive resources are freed.
1344 static int e1000_close(struct net_device *netdev)
1346 struct e1000_adapter *adapter = netdev_priv(netdev);
1347 struct e1000_hw *hw = &adapter->hw;
1349 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1350 e1000_down(adapter);
1351 e1000_power_down_phy(adapter);
1352 e1000_free_irq(adapter);
1354 e1000_free_all_tx_resources(adapter);
1355 e1000_free_all_rx_resources(adapter);
1357 /* kill manageability vlan ID if supported, but not if a vlan with
1358 * the same ID is registered on the host OS (let 8021q kill it) */
1359 if ((hw->mng_cookie.status &
1360 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1362 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1363 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1370 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1371 * @adapter: address of board private structure
1372 * @start: address of beginning of memory
1373 * @len: length of memory
1375 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1378 struct e1000_hw *hw = &adapter->hw;
1379 unsigned long begin = (unsigned long)start;
1380 unsigned long end = begin + len;
1382 /* First rev 82545 and 82546 need to not allow any memory
1383 * write location to cross 64k boundary due to errata 23 */
1384 if (hw->mac_type == e1000_82545 ||
1385 hw->mac_type == e1000_82546) {
1386 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1393 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1394 * @adapter: board private structure
1395 * @txdr: tx descriptor ring (for a specific queue) to setup
1397 * Return 0 on success, negative on failure
1400 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1401 struct e1000_tx_ring *txdr)
1403 struct pci_dev *pdev = adapter->pdev;
1406 size = sizeof(struct e1000_buffer) * txdr->count;
1407 txdr->buffer_info = vmalloc(size);
1408 if (!txdr->buffer_info) {
1410 "Unable to allocate memory for the transmit descriptor ring\n");
1413 memset(txdr->buffer_info, 0, size);
1415 /* round up to nearest 4K */
1417 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1418 txdr->size = ALIGN(txdr->size, 4096);
1420 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1423 vfree(txdr->buffer_info);
1425 "Unable to allocate memory for the transmit descriptor ring\n");
1429 /* Fix for errata 23, can't cross 64kB boundary */
1430 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1431 void *olddesc = txdr->desc;
1432 dma_addr_t olddma = txdr->dma;
1433 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1434 "at %p\n", txdr->size, txdr->desc);
1435 /* Try again, without freeing the previous */
1436 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1437 /* Failed allocation, critical failure */
1439 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1440 goto setup_tx_desc_die;
1443 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1445 pci_free_consistent(pdev, txdr->size, txdr->desc,
1447 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1449 "Unable to allocate aligned memory "
1450 "for the transmit descriptor ring\n");
1451 vfree(txdr->buffer_info);
1454 /* Free old allocation, new allocation was successful */
1455 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1458 memset(txdr->desc, 0, txdr->size);
1460 txdr->next_to_use = 0;
1461 txdr->next_to_clean = 0;
1467 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1468 * (Descriptors) for all queues
1469 * @adapter: board private structure
1471 * Return 0 on success, negative on failure
1474 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1478 for (i = 0; i < adapter->num_tx_queues; i++) {
1479 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1482 "Allocation for Tx Queue %u failed\n", i);
1483 for (i-- ; i >= 0; i--)
1484 e1000_free_tx_resources(adapter,
1485 &adapter->tx_ring[i]);
1494 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1495 * @adapter: board private structure
1497 * Configure the Tx unit of the MAC after a reset.
1500 static void e1000_configure_tx(struct e1000_adapter *adapter)
1503 struct e1000_hw *hw = &adapter->hw;
1504 u32 tdlen, tctl, tipg;
1507 /* Setup the HW Tx Head and Tail descriptor pointers */
1509 switch (adapter->num_tx_queues) {
1512 tdba = adapter->tx_ring[0].dma;
1513 tdlen = adapter->tx_ring[0].count *
1514 sizeof(struct e1000_tx_desc);
1516 ew32(TDBAH, (tdba >> 32));
1517 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1520 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1521 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1525 /* Set the default values for the Tx Inter Packet Gap timer */
1526 if ((hw->media_type == e1000_media_type_fiber ||
1527 hw->media_type == e1000_media_type_internal_serdes))
1528 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1530 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1532 switch (hw->mac_type) {
1533 case e1000_82542_rev2_0:
1534 case e1000_82542_rev2_1:
1535 tipg = DEFAULT_82542_TIPG_IPGT;
1536 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1537 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1540 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1541 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1544 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1545 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1548 /* Set the Tx Interrupt Delay register */
1550 ew32(TIDV, adapter->tx_int_delay);
1551 if (hw->mac_type >= e1000_82540)
1552 ew32(TADV, adapter->tx_abs_int_delay);
1554 /* Program the Transmit Control Register */
1557 tctl &= ~E1000_TCTL_CT;
1558 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1559 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1561 e1000_config_collision_dist(hw);
1563 /* Setup Transmit Descriptor Settings for eop descriptor */
1564 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1566 /* only set IDE if we are delaying interrupts using the timers */
1567 if (adapter->tx_int_delay)
1568 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1570 if (hw->mac_type < e1000_82543)
1571 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1573 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1575 /* Cache if we're 82544 running in PCI-X because we'll
1576 * need this to apply a workaround later in the send path. */
1577 if (hw->mac_type == e1000_82544 &&
1578 hw->bus_type == e1000_bus_type_pcix)
1579 adapter->pcix_82544 = 1;
1586 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1587 * @adapter: board private structure
1588 * @rxdr: rx descriptor ring (for a specific queue) to setup
1590 * Returns 0 on success, negative on failure
1593 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1594 struct e1000_rx_ring *rxdr)
1596 struct pci_dev *pdev = adapter->pdev;
1599 size = sizeof(struct e1000_buffer) * rxdr->count;
1600 rxdr->buffer_info = vmalloc(size);
1601 if (!rxdr->buffer_info) {
1603 "Unable to allocate memory for the receive descriptor ring\n");
1606 memset(rxdr->buffer_info, 0, size);
1608 desc_len = sizeof(struct e1000_rx_desc);
1610 /* Round up to nearest 4K */
1612 rxdr->size = rxdr->count * desc_len;
1613 rxdr->size = ALIGN(rxdr->size, 4096);
1615 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1619 "Unable to allocate memory for the receive descriptor ring\n");
1621 vfree(rxdr->buffer_info);
1625 /* Fix for errata 23, can't cross 64kB boundary */
1626 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1627 void *olddesc = rxdr->desc;
1628 dma_addr_t olddma = rxdr->dma;
1629 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1630 "at %p\n", rxdr->size, rxdr->desc);
1631 /* Try again, without freeing the previous */
1632 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1633 /* Failed allocation, critical failure */
1635 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1637 "Unable to allocate memory "
1638 "for the receive descriptor ring\n");
1639 goto setup_rx_desc_die;
1642 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1644 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1646 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1648 "Unable to allocate aligned memory "
1649 "for the receive descriptor ring\n");
1650 goto setup_rx_desc_die;
1652 /* Free old allocation, new allocation was successful */
1653 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1656 memset(rxdr->desc, 0, rxdr->size);
1658 rxdr->next_to_clean = 0;
1659 rxdr->next_to_use = 0;
1660 rxdr->rx_skb_top = NULL;
1666 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1667 * (Descriptors) for all queues
1668 * @adapter: board private structure
1670 * Return 0 on success, negative on failure
1673 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1677 for (i = 0; i < adapter->num_rx_queues; i++) {
1678 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1681 "Allocation for Rx Queue %u failed\n", i);
1682 for (i-- ; i >= 0; i--)
1683 e1000_free_rx_resources(adapter,
1684 &adapter->rx_ring[i]);
1693 * e1000_setup_rctl - configure the receive control registers
1694 * @adapter: Board private structure
1696 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1698 struct e1000_hw *hw = &adapter->hw;
1703 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1705 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1706 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1707 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1709 if (hw->tbi_compatibility_on == 1)
1710 rctl |= E1000_RCTL_SBP;
1712 rctl &= ~E1000_RCTL_SBP;
1714 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1715 rctl &= ~E1000_RCTL_LPE;
1717 rctl |= E1000_RCTL_LPE;
1719 /* Setup buffer sizes */
1720 rctl &= ~E1000_RCTL_SZ_4096;
1721 rctl |= E1000_RCTL_BSEX;
1722 switch (adapter->rx_buffer_len) {
1723 case E1000_RXBUFFER_2048:
1725 rctl |= E1000_RCTL_SZ_2048;
1726 rctl &= ~E1000_RCTL_BSEX;
1728 case E1000_RXBUFFER_4096:
1729 rctl |= E1000_RCTL_SZ_4096;
1731 case E1000_RXBUFFER_8192:
1732 rctl |= E1000_RCTL_SZ_8192;
1734 case E1000_RXBUFFER_16384:
1735 rctl |= E1000_RCTL_SZ_16384;
1743 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1744 * @adapter: board private structure
1746 * Configure the Rx unit of the MAC after a reset.
1749 static void e1000_configure_rx(struct e1000_adapter *adapter)
1752 struct e1000_hw *hw = &adapter->hw;
1753 u32 rdlen, rctl, rxcsum;
1755 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1756 rdlen = adapter->rx_ring[0].count *
1757 sizeof(struct e1000_rx_desc);
1758 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1759 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1761 rdlen = adapter->rx_ring[0].count *
1762 sizeof(struct e1000_rx_desc);
1763 adapter->clean_rx = e1000_clean_rx_irq;
1764 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1767 /* disable receives while setting up the descriptors */
1769 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1771 /* set the Receive Delay Timer Register */
1772 ew32(RDTR, adapter->rx_int_delay);
1774 if (hw->mac_type >= e1000_82540) {
1775 ew32(RADV, adapter->rx_abs_int_delay);
1776 if (adapter->itr_setting != 0)
1777 ew32(ITR, 1000000000 / (adapter->itr * 256));
1780 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1781 * the Base and Length of the Rx Descriptor Ring */
1782 switch (adapter->num_rx_queues) {
1785 rdba = adapter->rx_ring[0].dma;
1787 ew32(RDBAH, (rdba >> 32));
1788 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1791 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1792 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
1796 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1797 if (hw->mac_type >= e1000_82543) {
1798 rxcsum = er32(RXCSUM);
1799 if (adapter->rx_csum)
1800 rxcsum |= E1000_RXCSUM_TUOFL;
1802 /* don't need to clear IPPCSE as it defaults to 0 */
1803 rxcsum &= ~E1000_RXCSUM_TUOFL;
1804 ew32(RXCSUM, rxcsum);
1807 /* Enable Receives */
1812 * e1000_free_tx_resources - Free Tx Resources per Queue
1813 * @adapter: board private structure
1814 * @tx_ring: Tx descriptor ring for a specific queue
1816 * Free all transmit software resources
1819 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1820 struct e1000_tx_ring *tx_ring)
1822 struct pci_dev *pdev = adapter->pdev;
1824 e1000_clean_tx_ring(adapter, tx_ring);
1826 vfree(tx_ring->buffer_info);
1827 tx_ring->buffer_info = NULL;
1829 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1831 tx_ring->desc = NULL;
1835 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1836 * @adapter: board private structure
1838 * Free all transmit software resources
1841 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1845 for (i = 0; i < adapter->num_tx_queues; i++)
1846 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1849 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1850 struct e1000_buffer *buffer_info)
1852 buffer_info->dma = 0;
1853 if (buffer_info->skb) {
1854 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
1856 dev_kfree_skb_any(buffer_info->skb);
1857 buffer_info->skb = NULL;
1859 buffer_info->time_stamp = 0;
1860 /* buffer_info must be completely set up in the transmit path */
1864 * e1000_clean_tx_ring - Free Tx Buffers
1865 * @adapter: board private structure
1866 * @tx_ring: ring to be cleaned
1869 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1870 struct e1000_tx_ring *tx_ring)
1872 struct e1000_hw *hw = &adapter->hw;
1873 struct e1000_buffer *buffer_info;
1877 /* Free all the Tx ring sk_buffs */
1879 for (i = 0; i < tx_ring->count; i++) {
1880 buffer_info = &tx_ring->buffer_info[i];
1881 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1884 size = sizeof(struct e1000_buffer) * tx_ring->count;
1885 memset(tx_ring->buffer_info, 0, size);
1887 /* Zero out the descriptor ring */
1889 memset(tx_ring->desc, 0, tx_ring->size);
1891 tx_ring->next_to_use = 0;
1892 tx_ring->next_to_clean = 0;
1893 tx_ring->last_tx_tso = 0;
1895 writel(0, hw->hw_addr + tx_ring->tdh);
1896 writel(0, hw->hw_addr + tx_ring->tdt);
1900 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1901 * @adapter: board private structure
1904 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1908 for (i = 0; i < adapter->num_tx_queues; i++)
1909 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1913 * e1000_free_rx_resources - Free Rx Resources
1914 * @adapter: board private structure
1915 * @rx_ring: ring to clean the resources from
1917 * Free all receive software resources
1920 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
1921 struct e1000_rx_ring *rx_ring)
1923 struct pci_dev *pdev = adapter->pdev;
1925 e1000_clean_rx_ring(adapter, rx_ring);
1927 vfree(rx_ring->buffer_info);
1928 rx_ring->buffer_info = NULL;
1930 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1932 rx_ring->desc = NULL;
1936 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1937 * @adapter: board private structure
1939 * Free all receive software resources
1942 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1946 for (i = 0; i < adapter->num_rx_queues; i++)
1947 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1951 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1952 * @adapter: board private structure
1953 * @rx_ring: ring to free buffers from
1956 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
1957 struct e1000_rx_ring *rx_ring)
1959 struct e1000_hw *hw = &adapter->hw;
1960 struct e1000_buffer *buffer_info;
1961 struct pci_dev *pdev = adapter->pdev;
1965 /* Free all the Rx ring sk_buffs */
1966 for (i = 0; i < rx_ring->count; i++) {
1967 buffer_info = &rx_ring->buffer_info[i];
1968 if (buffer_info->dma &&
1969 adapter->clean_rx == e1000_clean_rx_irq) {
1970 pci_unmap_single(pdev, buffer_info->dma,
1971 buffer_info->length,
1972 PCI_DMA_FROMDEVICE);
1973 } else if (buffer_info->dma &&
1974 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
1975 pci_unmap_page(pdev, buffer_info->dma,
1976 buffer_info->length,
1977 PCI_DMA_FROMDEVICE);
1980 buffer_info->dma = 0;
1981 if (buffer_info->page) {
1982 put_page(buffer_info->page);
1983 buffer_info->page = NULL;
1985 if (buffer_info->skb) {
1986 dev_kfree_skb(buffer_info->skb);
1987 buffer_info->skb = NULL;
1991 /* there also may be some cached data from a chained receive */
1992 if (rx_ring->rx_skb_top) {
1993 dev_kfree_skb(rx_ring->rx_skb_top);
1994 rx_ring->rx_skb_top = NULL;
1997 size = sizeof(struct e1000_buffer) * rx_ring->count;
1998 memset(rx_ring->buffer_info, 0, size);
2000 /* Zero out the descriptor ring */
2001 memset(rx_ring->desc, 0, rx_ring->size);
2003 rx_ring->next_to_clean = 0;
2004 rx_ring->next_to_use = 0;
2006 writel(0, hw->hw_addr + rx_ring->rdh);
2007 writel(0, hw->hw_addr + rx_ring->rdt);
2011 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2012 * @adapter: board private structure
2015 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2019 for (i = 0; i < adapter->num_rx_queues; i++)
2020 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2023 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2024 * and memory write and invalidate disabled for certain operations
2026 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2028 struct e1000_hw *hw = &adapter->hw;
2029 struct net_device *netdev = adapter->netdev;
2032 e1000_pci_clear_mwi(hw);
2035 rctl |= E1000_RCTL_RST;
2037 E1000_WRITE_FLUSH();
2040 if (netif_running(netdev))
2041 e1000_clean_all_rx_rings(adapter);
2044 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2046 struct e1000_hw *hw = &adapter->hw;
2047 struct net_device *netdev = adapter->netdev;
2051 rctl &= ~E1000_RCTL_RST;
2053 E1000_WRITE_FLUSH();
2056 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2057 e1000_pci_set_mwi(hw);
2059 if (netif_running(netdev)) {
2060 /* No need to loop, because 82542 supports only 1 queue */
2061 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2062 e1000_configure_rx(adapter);
2063 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2068 * e1000_set_mac - Change the Ethernet Address of the NIC
2069 * @netdev: network interface device structure
2070 * @p: pointer to an address structure
2072 * Returns 0 on success, negative on failure
2075 static int e1000_set_mac(struct net_device *netdev, void *p)
2077 struct e1000_adapter *adapter = netdev_priv(netdev);
2078 struct e1000_hw *hw = &adapter->hw;
2079 struct sockaddr *addr = p;
2081 if (!is_valid_ether_addr(addr->sa_data))
2082 return -EADDRNOTAVAIL;
2084 /* 82542 2.0 needs to be in reset to write receive address registers */
2086 if (hw->mac_type == e1000_82542_rev2_0)
2087 e1000_enter_82542_rst(adapter);
2089 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2090 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2092 e1000_rar_set(hw, hw->mac_addr, 0);
2094 if (hw->mac_type == e1000_82542_rev2_0)
2095 e1000_leave_82542_rst(adapter);
2101 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2102 * @netdev: network interface device structure
2104 * The set_rx_mode entry point is called whenever the unicast or multicast
2105 * address lists or the network interface flags are updated. This routine is
2106 * responsible for configuring the hardware for proper unicast, multicast,
2107 * promiscuous mode, and all-multi behavior.
2110 static void e1000_set_rx_mode(struct net_device *netdev)
2112 struct e1000_adapter *adapter = netdev_priv(netdev);
2113 struct e1000_hw *hw = &adapter->hw;
2114 struct netdev_hw_addr *ha;
2115 bool use_uc = false;
2116 struct dev_addr_list *mc_ptr;
2119 int i, rar_entries = E1000_RAR_ENTRIES;
2120 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
2121 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2124 DPRINTK(PROBE, ERR, "memory allocation failed\n");
2128 /* Check for Promiscuous and All Multicast modes */
2132 if (netdev->flags & IFF_PROMISC) {
2133 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2134 rctl &= ~E1000_RCTL_VFE;
2136 if (netdev->flags & IFF_ALLMULTI)
2137 rctl |= E1000_RCTL_MPE;
2139 rctl &= ~E1000_RCTL_MPE;
2140 /* Enable VLAN filter if there is a VLAN */
2142 rctl |= E1000_RCTL_VFE;
2145 if (netdev->uc.count > rar_entries - 1) {
2146 rctl |= E1000_RCTL_UPE;
2147 } else if (!(netdev->flags & IFF_PROMISC)) {
2148 rctl &= ~E1000_RCTL_UPE;
2154 /* 82542 2.0 needs to be in reset to write receive address registers */
2156 if (hw->mac_type == e1000_82542_rev2_0)
2157 e1000_enter_82542_rst(adapter);
2159 /* load the first 14 addresses into the exact filters 1-14. Unicast
2160 * addresses take precedence to avoid disabling unicast filtering
2163 * RAR 0 is used for the station MAC adddress
2164 * if there are not 14 addresses, go ahead and clear the filters
2168 list_for_each_entry(ha, &netdev->uc.list, list) {
2169 if (i == rar_entries)
2171 e1000_rar_set(hw, ha->addr, i++);
2174 WARN_ON(i == rar_entries);
2176 mc_ptr = netdev->mc_list;
2178 for (; i < rar_entries; i++) {
2180 e1000_rar_set(hw, mc_ptr->da_addr, i);
2181 mc_ptr = mc_ptr->next;
2183 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2184 E1000_WRITE_FLUSH();
2185 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2186 E1000_WRITE_FLUSH();
2190 /* load any remaining addresses into the hash table */
2192 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2193 u32 hash_reg, hash_bit, mta;
2194 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
2195 hash_reg = (hash_value >> 5) & 0x7F;
2196 hash_bit = hash_value & 0x1F;
2197 mta = (1 << hash_bit);
2198 mcarray[hash_reg] |= mta;
2201 /* write the hash table completely, write from bottom to avoid
2202 * both stupid write combining chipsets, and flushing each write */
2203 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2205 * If we are on an 82544 has an errata where writing odd
2206 * offsets overwrites the previous even offset, but writing
2207 * backwards over the range solves the issue by always
2208 * writing the odd offset first
2210 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2212 E1000_WRITE_FLUSH();
2214 if (hw->mac_type == e1000_82542_rev2_0)
2215 e1000_leave_82542_rst(adapter);
2220 /* Need to wait a few seconds after link up to get diagnostic information from
2223 static void e1000_update_phy_info(unsigned long data)
2225 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2226 struct e1000_hw *hw = &adapter->hw;
2227 e1000_phy_get_info(hw, &adapter->phy_info);
2231 * e1000_82547_tx_fifo_stall - Timer Call-back
2232 * @data: pointer to adapter cast into an unsigned long
2235 static void e1000_82547_tx_fifo_stall(unsigned long data)
2237 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2238 struct e1000_hw *hw = &adapter->hw;
2239 struct net_device *netdev = adapter->netdev;
2242 if (atomic_read(&adapter->tx_fifo_stall)) {
2243 if ((er32(TDT) == er32(TDH)) &&
2244 (er32(TDFT) == er32(TDFH)) &&
2245 (er32(TDFTS) == er32(TDFHS))) {
2247 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2248 ew32(TDFT, adapter->tx_head_addr);
2249 ew32(TDFH, adapter->tx_head_addr);
2250 ew32(TDFTS, adapter->tx_head_addr);
2251 ew32(TDFHS, adapter->tx_head_addr);
2253 E1000_WRITE_FLUSH();
2255 adapter->tx_fifo_head = 0;
2256 atomic_set(&adapter->tx_fifo_stall, 0);
2257 netif_wake_queue(netdev);
2258 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
2259 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2264 static bool e1000_has_link(struct e1000_adapter *adapter)
2266 struct e1000_hw *hw = &adapter->hw;
2267 bool link_active = false;
2269 /* get_link_status is set on LSC (link status) interrupt or
2270 * rx sequence error interrupt. get_link_status will stay
2271 * false until the e1000_check_for_link establishes link
2272 * for copper adapters ONLY
2274 switch (hw->media_type) {
2275 case e1000_media_type_copper:
2276 if (hw->get_link_status) {
2277 e1000_check_for_link(hw);
2278 link_active = !hw->get_link_status;
2283 case e1000_media_type_fiber:
2284 e1000_check_for_link(hw);
2285 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2287 case e1000_media_type_internal_serdes:
2288 e1000_check_for_link(hw);
2289 link_active = hw->serdes_has_link;
2299 * e1000_watchdog - Timer Call-back
2300 * @data: pointer to adapter cast into an unsigned long
2302 static void e1000_watchdog(unsigned long data)
2304 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
2305 struct e1000_hw *hw = &adapter->hw;
2306 struct net_device *netdev = adapter->netdev;
2307 struct e1000_tx_ring *txdr = adapter->tx_ring;
2310 link = e1000_has_link(adapter);
2311 if ((netif_carrier_ok(netdev)) && link)
2315 if (!netif_carrier_ok(netdev)) {
2318 /* update snapshot of PHY registers on LSC */
2319 e1000_get_speed_and_duplex(hw,
2320 &adapter->link_speed,
2321 &adapter->link_duplex);
2324 printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, "
2325 "Flow Control: %s\n",
2327 adapter->link_speed,
2328 adapter->link_duplex == FULL_DUPLEX ?
2329 "Full Duplex" : "Half Duplex",
2330 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2331 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2332 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2333 E1000_CTRL_TFCE) ? "TX" : "None" )));
2335 /* tweak tx_queue_len according to speed/duplex
2336 * and adjust the timeout factor */
2337 netdev->tx_queue_len = adapter->tx_queue_len;
2338 adapter->tx_timeout_factor = 1;
2339 switch (adapter->link_speed) {
2342 netdev->tx_queue_len = 10;
2343 adapter->tx_timeout_factor = 16;
2347 netdev->tx_queue_len = 100;
2348 /* maybe add some timeout factor ? */
2352 /* enable transmits in the hardware */
2354 tctl |= E1000_TCTL_EN;
2357 netif_carrier_on(netdev);
2358 if (!test_bit(__E1000_DOWN, &adapter->flags))
2359 mod_timer(&adapter->phy_info_timer,
2360 round_jiffies(jiffies + 2 * HZ));
2361 adapter->smartspeed = 0;
2364 if (netif_carrier_ok(netdev)) {
2365 adapter->link_speed = 0;
2366 adapter->link_duplex = 0;
2367 printk(KERN_INFO "e1000: %s NIC Link is Down\n",
2369 netif_carrier_off(netdev);
2371 if (!test_bit(__E1000_DOWN, &adapter->flags))
2372 mod_timer(&adapter->phy_info_timer,
2373 round_jiffies(jiffies + 2 * HZ));
2376 e1000_smartspeed(adapter);
2380 e1000_update_stats(adapter);
2382 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2383 adapter->tpt_old = adapter->stats.tpt;
2384 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2385 adapter->colc_old = adapter->stats.colc;
2387 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2388 adapter->gorcl_old = adapter->stats.gorcl;
2389 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2390 adapter->gotcl_old = adapter->stats.gotcl;
2392 e1000_update_adaptive(hw);
2394 if (!netif_carrier_ok(netdev)) {
2395 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2396 /* We've lost link, so the controller stops DMA,
2397 * but we've got queued Tx work that's never going
2398 * to get done, so reset controller to flush Tx.
2399 * (Do the reset outside of interrupt context). */
2400 adapter->tx_timeout_count++;
2401 schedule_work(&adapter->reset_task);
2402 /* return immediately since reset is imminent */
2407 /* Cause software interrupt to ensure rx ring is cleaned */
2408 ew32(ICS, E1000_ICS_RXDMT0);
2410 /* Force detection of hung controller every watchdog period */
2411 adapter->detect_tx_hung = true;
2413 /* Reset the timer */
2414 if (!test_bit(__E1000_DOWN, &adapter->flags))
2415 mod_timer(&adapter->watchdog_timer,
2416 round_jiffies(jiffies + 2 * HZ));
2419 enum latency_range {
2423 latency_invalid = 255
2427 * e1000_update_itr - update the dynamic ITR value based on statistics
2428 * @adapter: pointer to adapter
2429 * @itr_setting: current adapter->itr
2430 * @packets: the number of packets during this measurement interval
2431 * @bytes: the number of bytes during this measurement interval
2433 * Stores a new ITR value based on packets and byte
2434 * counts during the last interrupt. The advantage of per interrupt
2435 * computation is faster updates and more accurate ITR for the current
2436 * traffic pattern. Constants in this function were computed
2437 * based on theoretical maximum wire speed and thresholds were set based
2438 * on testing data as well as attempting to minimize response time
2439 * while increasing bulk throughput.
2440 * this functionality is controlled by the InterruptThrottleRate module
2441 * parameter (see e1000_param.c)
2443 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2444 u16 itr_setting, int packets, int bytes)
2446 unsigned int retval = itr_setting;
2447 struct e1000_hw *hw = &adapter->hw;
2449 if (unlikely(hw->mac_type < e1000_82540))
2450 goto update_itr_done;
2453 goto update_itr_done;
2455 switch (itr_setting) {
2456 case lowest_latency:
2457 /* jumbo frames get bulk treatment*/
2458 if (bytes/packets > 8000)
2459 retval = bulk_latency;
2460 else if ((packets < 5) && (bytes > 512))
2461 retval = low_latency;
2463 case low_latency: /* 50 usec aka 20000 ints/s */
2464 if (bytes > 10000) {
2465 /* jumbo frames need bulk latency setting */
2466 if (bytes/packets > 8000)
2467 retval = bulk_latency;
2468 else if ((packets < 10) || ((bytes/packets) > 1200))
2469 retval = bulk_latency;
2470 else if ((packets > 35))
2471 retval = lowest_latency;
2472 } else if (bytes/packets > 2000)
2473 retval = bulk_latency;
2474 else if (packets <= 2 && bytes < 512)
2475 retval = lowest_latency;
2477 case bulk_latency: /* 250 usec aka 4000 ints/s */
2478 if (bytes > 25000) {
2480 retval = low_latency;
2481 } else if (bytes < 6000) {
2482 retval = low_latency;
2491 static void e1000_set_itr(struct e1000_adapter *adapter)
2493 struct e1000_hw *hw = &adapter->hw;
2495 u32 new_itr = adapter->itr;
2497 if (unlikely(hw->mac_type < e1000_82540))
2500 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2501 if (unlikely(adapter->link_speed != SPEED_1000)) {
2507 adapter->tx_itr = e1000_update_itr(adapter,
2509 adapter->total_tx_packets,
2510 adapter->total_tx_bytes);
2511 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2512 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2513 adapter->tx_itr = low_latency;
2515 adapter->rx_itr = e1000_update_itr(adapter,
2517 adapter->total_rx_packets,
2518 adapter->total_rx_bytes);
2519 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2520 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2521 adapter->rx_itr = low_latency;
2523 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2525 switch (current_itr) {
2526 /* counts and packets in update_itr are dependent on these numbers */
2527 case lowest_latency:
2531 new_itr = 20000; /* aka hwitr = ~200 */
2541 if (new_itr != adapter->itr) {
2542 /* this attempts to bias the interrupt rate towards Bulk
2543 * by adding intermediate steps when interrupt rate is
2545 new_itr = new_itr > adapter->itr ?
2546 min(adapter->itr + (new_itr >> 2), new_itr) :
2548 adapter->itr = new_itr;
2549 ew32(ITR, 1000000000 / (new_itr * 256));
2555 #define E1000_TX_FLAGS_CSUM 0x00000001
2556 #define E1000_TX_FLAGS_VLAN 0x00000002
2557 #define E1000_TX_FLAGS_TSO 0x00000004
2558 #define E1000_TX_FLAGS_IPV4 0x00000008
2559 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2560 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2562 static int e1000_tso(struct e1000_adapter *adapter,
2563 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2565 struct e1000_context_desc *context_desc;
2566 struct e1000_buffer *buffer_info;
2569 u16 ipcse = 0, tucse, mss;
2570 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2573 if (skb_is_gso(skb)) {
2574 if (skb_header_cloned(skb)) {
2575 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2580 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2581 mss = skb_shinfo(skb)->gso_size;
2582 if (skb->protocol == htons(ETH_P_IP)) {
2583 struct iphdr *iph = ip_hdr(skb);
2586 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2590 cmd_length = E1000_TXD_CMD_IP;
2591 ipcse = skb_transport_offset(skb) - 1;
2592 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2593 ipv6_hdr(skb)->payload_len = 0;
2594 tcp_hdr(skb)->check =
2595 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2596 &ipv6_hdr(skb)->daddr,
2600 ipcss = skb_network_offset(skb);
2601 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2602 tucss = skb_transport_offset(skb);
2603 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2606 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2607 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2609 i = tx_ring->next_to_use;
2610 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2611 buffer_info = &tx_ring->buffer_info[i];
2613 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2614 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2615 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2616 context_desc->upper_setup.tcp_fields.tucss = tucss;
2617 context_desc->upper_setup.tcp_fields.tucso = tucso;
2618 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2619 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2620 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2621 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2623 buffer_info->time_stamp = jiffies;
2624 buffer_info->next_to_watch = i;
2626 if (++i == tx_ring->count) i = 0;
2627 tx_ring->next_to_use = i;
2634 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2635 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2637 struct e1000_context_desc *context_desc;
2638 struct e1000_buffer *buffer_info;
2641 u32 cmd_len = E1000_TXD_CMD_DEXT;
2643 if (skb->ip_summed != CHECKSUM_PARTIAL)
2646 switch (skb->protocol) {
2647 case cpu_to_be16(ETH_P_IP):
2648 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2649 cmd_len |= E1000_TXD_CMD_TCP;
2651 case cpu_to_be16(ETH_P_IPV6):
2652 /* XXX not handling all IPV6 headers */
2653 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2654 cmd_len |= E1000_TXD_CMD_TCP;
2657 if (unlikely(net_ratelimit()))
2658 DPRINTK(DRV, WARNING,
2659 "checksum_partial proto=%x!\n", skb->protocol);
2663 css = skb_transport_offset(skb);
2665 i = tx_ring->next_to_use;
2666 buffer_info = &tx_ring->buffer_info[i];
2667 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2669 context_desc->lower_setup.ip_config = 0;
2670 context_desc->upper_setup.tcp_fields.tucss = css;
2671 context_desc->upper_setup.tcp_fields.tucso =
2672 css + skb->csum_offset;
2673 context_desc->upper_setup.tcp_fields.tucse = 0;
2674 context_desc->tcp_seg_setup.data = 0;
2675 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2677 buffer_info->time_stamp = jiffies;
2678 buffer_info->next_to_watch = i;
2680 if (unlikely(++i == tx_ring->count)) i = 0;
2681 tx_ring->next_to_use = i;
2686 #define E1000_MAX_TXD_PWR 12
2687 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2689 static int e1000_tx_map(struct e1000_adapter *adapter,
2690 struct e1000_tx_ring *tx_ring,
2691 struct sk_buff *skb, unsigned int first,
2692 unsigned int max_per_txd, unsigned int nr_frags,
2695 struct e1000_hw *hw = &adapter->hw;
2696 struct e1000_buffer *buffer_info;
2697 unsigned int len = skb_headlen(skb);
2698 unsigned int offset, size, count = 0, i;
2702 i = tx_ring->next_to_use;
2704 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
2705 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
2709 map = skb_shinfo(skb)->dma_maps;
2713 buffer_info = &tx_ring->buffer_info[i];
2714 size = min(len, max_per_txd);
2715 /* Workaround for Controller erratum --
2716 * descriptor for non-tso packet in a linear SKB that follows a
2717 * tso gets written back prematurely before the data is fully
2718 * DMA'd to the controller */
2719 if (!skb->data_len && tx_ring->last_tx_tso &&
2721 tx_ring->last_tx_tso = 0;
2725 /* Workaround for premature desc write-backs
2726 * in TSO mode. Append 4-byte sentinel desc */
2727 if (unlikely(mss && !nr_frags && size == len && size > 8))
2729 /* work-around for errata 10 and it applies
2730 * to all controllers in PCI-X mode
2731 * The fix is to make sure that the first descriptor of a
2732 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2734 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
2735 (size > 2015) && count == 0))
2738 /* Workaround for potential 82544 hang in PCI-X. Avoid
2739 * terminating buffers within evenly-aligned dwords. */
2740 if (unlikely(adapter->pcix_82544 &&
2741 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2745 buffer_info->length = size;
2746 /* set time_stamp *before* dma to help avoid a possible race */
2747 buffer_info->time_stamp = jiffies;
2748 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
2749 buffer_info->next_to_watch = i;
2756 if (unlikely(i == tx_ring->count))
2761 for (f = 0; f < nr_frags; f++) {
2762 struct skb_frag_struct *frag;
2764 frag = &skb_shinfo(skb)->frags[f];
2770 if (unlikely(i == tx_ring->count))
2773 buffer_info = &tx_ring->buffer_info[i];
2774 size = min(len, max_per_txd);
2775 /* Workaround for premature desc write-backs
2776 * in TSO mode. Append 4-byte sentinel desc */
2777 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2779 /* Workaround for potential 82544 hang in PCI-X.
2780 * Avoid terminating buffers within evenly-aligned
2782 if (unlikely(adapter->pcix_82544 &&
2783 !((unsigned long)(page_to_phys(frag->page) + offset
2788 buffer_info->length = size;
2789 buffer_info->time_stamp = jiffies;
2790 buffer_info->dma = map[f] + offset;
2791 buffer_info->next_to_watch = i;
2799 tx_ring->buffer_info[i].skb = skb;
2800 tx_ring->buffer_info[first].next_to_watch = i;
2805 static void e1000_tx_queue(struct e1000_adapter *adapter,
2806 struct e1000_tx_ring *tx_ring, int tx_flags,
2809 struct e1000_hw *hw = &adapter->hw;
2810 struct e1000_tx_desc *tx_desc = NULL;
2811 struct e1000_buffer *buffer_info;
2812 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2815 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2816 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2818 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2820 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2821 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2824 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2825 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2826 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2829 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2830 txd_lower |= E1000_TXD_CMD_VLE;
2831 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2834 i = tx_ring->next_to_use;
2837 buffer_info = &tx_ring->buffer_info[i];
2838 tx_desc = E1000_TX_DESC(*tx_ring, i);
2839 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2840 tx_desc->lower.data =
2841 cpu_to_le32(txd_lower | buffer_info->length);
2842 tx_desc->upper.data = cpu_to_le32(txd_upper);
2843 if (unlikely(++i == tx_ring->count)) i = 0;
2846 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2848 /* Force memory writes to complete before letting h/w
2849 * know there are new descriptors to fetch. (Only
2850 * applicable for weak-ordered memory model archs,
2851 * such as IA-64). */
2854 tx_ring->next_to_use = i;
2855 writel(i, hw->hw_addr + tx_ring->tdt);
2856 /* we need this if more than one processor can write to our tail
2857 * at a time, it syncronizes IO on IA64/Altix systems */
2862 * 82547 workaround to avoid controller hang in half-duplex environment.
2863 * The workaround is to avoid queuing a large packet that would span
2864 * the internal Tx FIFO ring boundary by notifying the stack to resend
2865 * the packet at a later time. This gives the Tx FIFO an opportunity to
2866 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2867 * to the beginning of the Tx FIFO.
2870 #define E1000_FIFO_HDR 0x10
2871 #define E1000_82547_PAD_LEN 0x3E0
2873 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
2874 struct sk_buff *skb)
2876 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2877 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
2879 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
2881 if (adapter->link_duplex != HALF_DUPLEX)
2882 goto no_fifo_stall_required;
2884 if (atomic_read(&adapter->tx_fifo_stall))
2887 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2888 atomic_set(&adapter->tx_fifo_stall, 1);
2892 no_fifo_stall_required:
2893 adapter->tx_fifo_head += skb_fifo_len;
2894 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2895 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2899 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2901 struct e1000_adapter *adapter = netdev_priv(netdev);
2902 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2904 netif_stop_queue(netdev);
2905 /* Herbert's original patch had:
2906 * smp_mb__after_netif_stop_queue();
2907 * but since that doesn't exist yet, just open code it. */
2910 /* We need to check again in a case another CPU has just
2911 * made room available. */
2912 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2916 netif_start_queue(netdev);
2917 ++adapter->restart_queue;
2921 static int e1000_maybe_stop_tx(struct net_device *netdev,
2922 struct e1000_tx_ring *tx_ring, int size)
2924 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2926 return __e1000_maybe_stop_tx(netdev, size);
2929 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2930 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
2931 struct net_device *netdev)
2933 struct e1000_adapter *adapter = netdev_priv(netdev);
2934 struct e1000_hw *hw = &adapter->hw;
2935 struct e1000_tx_ring *tx_ring;
2936 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2937 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2938 unsigned int tx_flags = 0;
2939 unsigned int len = skb->len - skb->data_len;
2940 unsigned int nr_frags;
2946 /* This goes back to the question of how to logically map a tx queue
2947 * to a flow. Right now, performance is impacted slightly negatively
2948 * if using multiple tx queues. If the stack breaks away from a
2949 * single qdisc implementation, we can look at this again. */
2950 tx_ring = adapter->tx_ring;
2952 if (unlikely(skb->len <= 0)) {
2953 dev_kfree_skb_any(skb);
2954 return NETDEV_TX_OK;
2957 mss = skb_shinfo(skb)->gso_size;
2958 /* The controller does a simple calculation to
2959 * make sure there is enough room in the FIFO before
2960 * initiating the DMA for each buffer. The calc is:
2961 * 4 = ceil(buffer len/mss). To make sure we don't
2962 * overrun the FIFO, adjust the max buffer len if mss
2966 max_per_txd = min(mss << 2, max_per_txd);
2967 max_txd_pwr = fls(max_per_txd) - 1;
2969 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2970 if (skb->data_len && hdr_len == len) {
2971 switch (hw->mac_type) {
2972 unsigned int pull_size;
2974 /* Make sure we have room to chop off 4 bytes,
2975 * and that the end alignment will work out to
2976 * this hardware's requirements
2977 * NOTE: this is a TSO only workaround
2978 * if end byte alignment not correct move us
2979 * into the next dword */
2980 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
2983 pull_size = min((unsigned int)4, skb->data_len);
2984 if (!__pskb_pull_tail(skb, pull_size)) {
2986 "__pskb_pull_tail failed.\n");
2987 dev_kfree_skb_any(skb);
2988 return NETDEV_TX_OK;
2990 len = skb->len - skb->data_len;
2999 /* reserve a descriptor for the offload context */
3000 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3004 /* Controller Erratum workaround */
3005 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3008 count += TXD_USE_COUNT(len, max_txd_pwr);
3010 if (adapter->pcix_82544)
3013 /* work-around for errata 10 and it applies to all controllers
3014 * in PCI-X mode, so add one more descriptor to the count
3016 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3020 nr_frags = skb_shinfo(skb)->nr_frags;
3021 for (f = 0; f < nr_frags; f++)
3022 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3024 if (adapter->pcix_82544)
3027 /* need: count + 2 desc gap to keep tail from touching
3028 * head, otherwise try next time */
3029 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3030 return NETDEV_TX_BUSY;
3032 if (unlikely(hw->mac_type == e1000_82547)) {
3033 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3034 netif_stop_queue(netdev);
3035 if (!test_bit(__E1000_DOWN, &adapter->flags))
3036 mod_timer(&adapter->tx_fifo_stall_timer,
3038 return NETDEV_TX_BUSY;
3042 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3043 tx_flags |= E1000_TX_FLAGS_VLAN;
3044 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3047 first = tx_ring->next_to_use;
3049 tso = e1000_tso(adapter, tx_ring, skb);
3051 dev_kfree_skb_any(skb);
3052 return NETDEV_TX_OK;
3056 if (likely(hw->mac_type != e1000_82544))
3057 tx_ring->last_tx_tso = 1;
3058 tx_flags |= E1000_TX_FLAGS_TSO;
3059 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3060 tx_flags |= E1000_TX_FLAGS_CSUM;
3062 if (likely(skb->protocol == htons(ETH_P_IP)))
3063 tx_flags |= E1000_TX_FLAGS_IPV4;
3065 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3069 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3070 /* Make sure there is space in the ring for the next send. */
3071 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3074 dev_kfree_skb_any(skb);
3075 tx_ring->buffer_info[first].time_stamp = 0;
3076 tx_ring->next_to_use = first;
3079 return NETDEV_TX_OK;
3083 * e1000_tx_timeout - Respond to a Tx Hang
3084 * @netdev: network interface device structure
3087 static void e1000_tx_timeout(struct net_device *netdev)
3089 struct e1000_adapter *adapter = netdev_priv(netdev);
3091 /* Do the reset outside of interrupt context */
3092 adapter->tx_timeout_count++;
3093 schedule_work(&adapter->reset_task);
3096 static void e1000_reset_task(struct work_struct *work)
3098 struct e1000_adapter *adapter =
3099 container_of(work, struct e1000_adapter, reset_task);
3101 e1000_reinit_locked(adapter);
3105 * e1000_get_stats - Get System Network Statistics
3106 * @netdev: network interface device structure
3108 * Returns the address of the device statistics structure.
3109 * The statistics are actually updated from the timer callback.
3112 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3114 struct e1000_adapter *adapter = netdev_priv(netdev);
3116 /* only return the current stats */
3117 return &adapter->net_stats;
3121 * e1000_change_mtu - Change the Maximum Transfer Unit
3122 * @netdev: network interface device structure
3123 * @new_mtu: new value for maximum frame size
3125 * Returns 0 on success, negative on failure
3128 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3130 struct e1000_adapter *adapter = netdev_priv(netdev);
3131 struct e1000_hw *hw = &adapter->hw;
3132 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3134 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3135 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3136 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3140 /* Adapter-specific max frame size limits. */
3141 switch (hw->mac_type) {
3142 case e1000_undefined ... e1000_82542_rev2_1:
3143 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3144 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3149 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3153 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3155 /* e1000_down has a dependency on max_frame_size */
3156 hw->max_frame_size = max_frame;
3157 if (netif_running(netdev))
3158 e1000_down(adapter);
3160 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3161 * means we reserve 2 more, this pushes us to allocate from the next
3163 * i.e. RXBUFFER_2048 --> size-4096 slab
3164 * however with the new *_jumbo_rx* routines, jumbo receives will use
3165 * fragmented skbs */
3167 if (max_frame <= E1000_RXBUFFER_2048)
3168 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3170 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3171 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3172 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3173 adapter->rx_buffer_len = PAGE_SIZE;
3176 /* adjust allocation if LPE protects us, and we aren't using SBP */
3177 if (!hw->tbi_compatibility_on &&
3178 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3179 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3180 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3182 printk(KERN_INFO "e1000: %s changing MTU from %d to %d\n",
3183 netdev->name, netdev->mtu, new_mtu);
3184 netdev->mtu = new_mtu;
3186 if (netif_running(netdev))
3189 e1000_reset(adapter);
3191 clear_bit(__E1000_RESETTING, &adapter->flags);
3197 * e1000_update_stats - Update the board statistics counters
3198 * @adapter: board private structure
3201 void e1000_update_stats(struct e1000_adapter *adapter)
3203 struct e1000_hw *hw = &adapter->hw;
3204 struct pci_dev *pdev = adapter->pdev;
3205 unsigned long flags;
3208 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3211 * Prevent stats update while adapter is being reset, or if the pci
3212 * connection is down.
3214 if (adapter->link_speed == 0)
3216 if (pci_channel_offline(pdev))
3219 spin_lock_irqsave(&adapter->stats_lock, flags);
3221 /* these counters are modified from e1000_tbi_adjust_stats,
3222 * called from the interrupt context, so they must only
3223 * be written while holding adapter->stats_lock
3226 adapter->stats.crcerrs += er32(CRCERRS);
3227 adapter->stats.gprc += er32(GPRC);
3228 adapter->stats.gorcl += er32(GORCL);
3229 adapter->stats.gorch += er32(GORCH);
3230 adapter->stats.bprc += er32(BPRC);
3231 adapter->stats.mprc += er32(MPRC);
3232 adapter->stats.roc += er32(ROC);
3234 adapter->stats.prc64 += er32(PRC64);
3235 adapter->stats.prc127 += er32(PRC127);
3236 adapter->stats.prc255 += er32(PRC255);
3237 adapter->stats.prc511 += er32(PRC511);
3238 adapter->stats.prc1023 += er32(PRC1023);
3239 adapter->stats.prc1522 += er32(PRC1522);
3241 adapter->stats.symerrs += er32(SYMERRS);
3242 adapter->stats.mpc += er32(MPC);
3243 adapter->stats.scc += er32(SCC);
3244 adapter->stats.ecol += er32(ECOL);
3245 adapter->stats.mcc += er32(MCC);
3246 adapter->stats.latecol += er32(LATECOL);
3247 adapter->stats.dc += er32(DC);
3248 adapter->stats.sec += er32(SEC);
3249 adapter->stats.rlec += er32(RLEC);
3250 adapter->stats.xonrxc += er32(XONRXC);
3251 adapter->stats.xontxc += er32(XONTXC);
3252 adapter->stats.xoffrxc += er32(XOFFRXC);
3253 adapter->stats.xofftxc += er32(XOFFTXC);
3254 adapter->stats.fcruc += er32(FCRUC);
3255 adapter->stats.gptc += er32(GPTC);
3256 adapter->stats.gotcl += er32(GOTCL);
3257 adapter->stats.gotch += er32(GOTCH);
3258 adapter->stats.rnbc += er32(RNBC);
3259 adapter->stats.ruc += er32(RUC);
3260 adapter->stats.rfc += er32(RFC);
3261 adapter->stats.rjc += er32(RJC);
3262 adapter->stats.torl += er32(TORL);
3263 adapter->stats.torh += er32(TORH);
3264 adapter->stats.totl += er32(TOTL);
3265 adapter->stats.toth += er32(TOTH);
3266 adapter->stats.tpr += er32(TPR);
3268 adapter->stats.ptc64 += er32(PTC64);
3269 adapter->stats.ptc127 += er32(PTC127);
3270 adapter->stats.ptc255 += er32(PTC255);
3271 adapter->stats.ptc511 += er32(PTC511);
3272 adapter->stats.ptc1023 += er32(PTC1023);
3273 adapter->stats.ptc1522 += er32(PTC1522);
3275 adapter->stats.mptc += er32(MPTC);
3276 adapter->stats.bptc += er32(BPTC);
3278 /* used for adaptive IFS */
3280 hw->tx_packet_delta = er32(TPT);
3281 adapter->stats.tpt += hw->tx_packet_delta;
3282 hw->collision_delta = er32(COLC);
3283 adapter->stats.colc += hw->collision_delta;
3285 if (hw->mac_type >= e1000_82543) {
3286 adapter->stats.algnerrc += er32(ALGNERRC);
3287 adapter->stats.rxerrc += er32(RXERRC);
3288 adapter->stats.tncrs += er32(TNCRS);
3289 adapter->stats.cexterr += er32(CEXTERR);
3290 adapter->stats.tsctc += er32(TSCTC);
3291 adapter->stats.tsctfc += er32(TSCTFC);
3294 /* Fill out the OS statistics structure */
3295 adapter->net_stats.multicast = adapter->stats.mprc;
3296 adapter->net_stats.collisions = adapter->stats.colc;
3300 /* RLEC on some newer hardware can be incorrect so build
3301 * our own version based on RUC and ROC */
3302 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3303 adapter->stats.crcerrs + adapter->stats.algnerrc +
3304 adapter->stats.ruc + adapter->stats.roc +
3305 adapter->stats.cexterr;
3306 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3307 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3308 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3309 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3310 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3313 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3314 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3315 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3316 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3317 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3318 if (hw->bad_tx_carr_stats_fd &&
3319 adapter->link_duplex == FULL_DUPLEX) {
3320 adapter->net_stats.tx_carrier_errors = 0;
3321 adapter->stats.tncrs = 0;
3324 /* Tx Dropped needs to be maintained elsewhere */
3327 if (hw->media_type == e1000_media_type_copper) {
3328 if ((adapter->link_speed == SPEED_1000) &&
3329 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3330 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3331 adapter->phy_stats.idle_errors += phy_tmp;
3334 if ((hw->mac_type <= e1000_82546) &&
3335 (hw->phy_type == e1000_phy_m88) &&
3336 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3337 adapter->phy_stats.receive_errors += phy_tmp;
3340 /* Management Stats */
3341 if (hw->has_smbus) {
3342 adapter->stats.mgptc += er32(MGTPTC);
3343 adapter->stats.mgprc += er32(MGTPRC);
3344 adapter->stats.mgpdc += er32(MGTPDC);
3347 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3351 * e1000_intr - Interrupt Handler
3352 * @irq: interrupt number
3353 * @data: pointer to a network interface device structure
3356 static irqreturn_t e1000_intr(int irq, void *data)
3358 struct net_device *netdev = data;
3359 struct e1000_adapter *adapter = netdev_priv(netdev);
3360 struct e1000_hw *hw = &adapter->hw;
3361 u32 icr = er32(ICR);
3363 if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags)))
3364 return IRQ_NONE; /* Not our interrupt */
3366 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3367 hw->get_link_status = 1;
3368 /* guard against interrupt when we're going down */
3369 if (!test_bit(__E1000_DOWN, &adapter->flags))
3370 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3373 /* disable interrupts, without the synchronize_irq bit */
3375 E1000_WRITE_FLUSH();
3377 if (likely(napi_schedule_prep(&adapter->napi))) {
3378 adapter->total_tx_bytes = 0;
3379 adapter->total_tx_packets = 0;
3380 adapter->total_rx_bytes = 0;
3381 adapter->total_rx_packets = 0;
3382 __napi_schedule(&adapter->napi);
3384 /* this really should not happen! if it does it is basically a
3385 * bug, but not a hard error, so enable ints and continue */
3386 if (!test_bit(__E1000_DOWN, &adapter->flags))
3387 e1000_irq_enable(adapter);
3394 * e1000_clean - NAPI Rx polling callback
3395 * @adapter: board private structure
3397 static int e1000_clean(struct napi_struct *napi, int budget)
3399 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3400 int tx_clean_complete = 0, work_done = 0;
3402 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3404 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
3406 if (!tx_clean_complete)
3409 /* If budget not fully consumed, exit the polling mode */
3410 if (work_done < budget) {
3411 if (likely(adapter->itr_setting & 3))
3412 e1000_set_itr(adapter);
3413 napi_complete(napi);
3414 if (!test_bit(__E1000_DOWN, &adapter->flags))
3415 e1000_irq_enable(adapter);
3422 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3423 * @adapter: board private structure
3425 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3426 struct e1000_tx_ring *tx_ring)
3428 struct e1000_hw *hw = &adapter->hw;
3429 struct net_device *netdev = adapter->netdev;
3430 struct e1000_tx_desc *tx_desc, *eop_desc;
3431 struct e1000_buffer *buffer_info;
3432 unsigned int i, eop;
3433 unsigned int count = 0;
3434 unsigned int total_tx_bytes=0, total_tx_packets=0;
3436 i = tx_ring->next_to_clean;
3437 eop = tx_ring->buffer_info[i].next_to_watch;
3438 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3440 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3441 (count < tx_ring->count)) {
3442 bool cleaned = false;
3443 for ( ; !cleaned; count++) {
3444 tx_desc = E1000_TX_DESC(*tx_ring, i);
3445 buffer_info = &tx_ring->buffer_info[i];
3446 cleaned = (i == eop);
3449 struct sk_buff *skb = buffer_info->skb;
3450 unsigned int segs, bytecount;
3451 segs = skb_shinfo(skb)->gso_segs ?: 1;
3452 /* multiply data chunks by size of headers */
3453 bytecount = ((segs - 1) * skb_headlen(skb)) +
3455 total_tx_packets += segs;
3456 total_tx_bytes += bytecount;
3458 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3459 tx_desc->upper.data = 0;
3461 if (unlikely(++i == tx_ring->count)) i = 0;
3464 eop = tx_ring->buffer_info[i].next_to_watch;
3465 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3468 tx_ring->next_to_clean = i;
3470 #define TX_WAKE_THRESHOLD 32
3471 if (unlikely(count && netif_carrier_ok(netdev) &&
3472 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3473 /* Make sure that anybody stopping the queue after this
3474 * sees the new next_to_clean.
3478 if (netif_queue_stopped(netdev) &&
3479 !(test_bit(__E1000_DOWN, &adapter->flags))) {
3480 netif_wake_queue(netdev);
3481 ++adapter->restart_queue;
3485 if (adapter->detect_tx_hung) {
3486 /* Detect a transmit hang in hardware, this serializes the
3487 * check with the clearing of time_stamp and movement of i */
3488 adapter->detect_tx_hung = false;
3489 if (tx_ring->buffer_info[eop].time_stamp &&
3490 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3491 (adapter->tx_timeout_factor * HZ))
3492 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3494 /* detected Tx unit hang */
3495 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3499 " next_to_use <%x>\n"
3500 " next_to_clean <%x>\n"
3501 "buffer_info[next_to_clean]\n"
3502 " time_stamp <%lx>\n"
3503 " next_to_watch <%x>\n"
3505 " next_to_watch.status <%x>\n",
3506 (unsigned long)((tx_ring - adapter->tx_ring) /
3507 sizeof(struct e1000_tx_ring)),
3508 readl(hw->hw_addr + tx_ring->tdh),
3509 readl(hw->hw_addr + tx_ring->tdt),
3510 tx_ring->next_to_use,
3511 tx_ring->next_to_clean,
3512 tx_ring->buffer_info[eop].time_stamp,
3515 eop_desc->upper.fields.status);
3516 netif_stop_queue(netdev);
3519 adapter->total_tx_bytes += total_tx_bytes;
3520 adapter->total_tx_packets += total_tx_packets;
3521 adapter->net_stats.tx_bytes += total_tx_bytes;
3522 adapter->net_stats.tx_packets += total_tx_packets;
3523 return (count < tx_ring->count);
3527 * e1000_rx_checksum - Receive Checksum Offload for 82543
3528 * @adapter: board private structure
3529 * @status_err: receive descriptor status and error fields
3530 * @csum: receive descriptor csum field
3531 * @sk_buff: socket buffer with received data
3534 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3535 u32 csum, struct sk_buff *skb)
3537 struct e1000_hw *hw = &adapter->hw;
3538 u16 status = (u16)status_err;
3539 u8 errors = (u8)(status_err >> 24);
3540 skb->ip_summed = CHECKSUM_NONE;
3542 /* 82543 or newer only */
3543 if (unlikely(hw->mac_type < e1000_82543)) return;
3544 /* Ignore Checksum bit is set */
3545 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3546 /* TCP/UDP checksum error bit is set */
3547 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3548 /* let the stack verify checksum errors */
3549 adapter->hw_csum_err++;
3552 /* TCP/UDP Checksum has not been calculated */
3553 if (!(status & E1000_RXD_STAT_TCPCS))
3556 /* It must be a TCP or UDP packet with a valid checksum */
3557 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3558 /* TCP checksum is good */
3559 skb->ip_summed = CHECKSUM_UNNECESSARY;
3561 adapter->hw_csum_good++;
3565 * e1000_consume_page - helper function
3567 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
3572 skb->data_len += length;
3573 skb->truesize += length;
3577 * e1000_receive_skb - helper function to handle rx indications
3578 * @adapter: board private structure
3579 * @status: descriptor status field as written by hardware
3580 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3581 * @skb: pointer to sk_buff to be indicated to stack
3583 static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
3584 __le16 vlan, struct sk_buff *skb)
3586 if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) {
3587 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3589 E1000_RXD_SPC_VLAN_MASK);
3591 netif_receive_skb(skb);
3596 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
3597 * @adapter: board private structure
3598 * @rx_ring: ring to clean
3599 * @work_done: amount of napi work completed this call
3600 * @work_to_do: max amount of work allowed for this call to do
3602 * the return value indicates whether actual cleaning was done, there
3603 * is no guarantee that everything was cleaned
3605 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
3606 struct e1000_rx_ring *rx_ring,
3607 int *work_done, int work_to_do)
3609 struct e1000_hw *hw = &adapter->hw;
3610 struct net_device *netdev = adapter->netdev;
3611 struct pci_dev *pdev = adapter->pdev;
3612 struct e1000_rx_desc *rx_desc, *next_rxd;
3613 struct e1000_buffer *buffer_info, *next_buffer;
3614 unsigned long irq_flags;
3617 int cleaned_count = 0;
3618 bool cleaned = false;
3619 unsigned int total_rx_bytes=0, total_rx_packets=0;
3621 i = rx_ring->next_to_clean;
3622 rx_desc = E1000_RX_DESC(*rx_ring, i);
3623 buffer_info = &rx_ring->buffer_info[i];
3625 while (rx_desc->status & E1000_RXD_STAT_DD) {
3626 struct sk_buff *skb;
3629 if (*work_done >= work_to_do)
3633 status = rx_desc->status;
3634 skb = buffer_info->skb;
3635 buffer_info->skb = NULL;
3637 if (++i == rx_ring->count) i = 0;
3638 next_rxd = E1000_RX_DESC(*rx_ring, i);
3641 next_buffer = &rx_ring->buffer_info[i];
3645 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
3646 PCI_DMA_FROMDEVICE);
3647 buffer_info->dma = 0;
3649 length = le16_to_cpu(rx_desc->length);
3651 /* errors is only valid for DD + EOP descriptors */
3652 if (unlikely((status & E1000_RXD_STAT_EOP) &&
3653 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
3654 u8 last_byte = *(skb->data + length - 1);
3655 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
3657 spin_lock_irqsave(&adapter->stats_lock,
3659 e1000_tbi_adjust_stats(hw, &adapter->stats,
3661 spin_unlock_irqrestore(&adapter->stats_lock,
3665 /* recycle both page and skb */
3666 buffer_info->skb = skb;
3667 /* an error means any chain goes out the window
3669 if (rx_ring->rx_skb_top)
3670 dev_kfree_skb(rx_ring->rx_skb_top);
3671 rx_ring->rx_skb_top = NULL;
3676 #define rxtop rx_ring->rx_skb_top
3677 if (!(status & E1000_RXD_STAT_EOP)) {
3678 /* this descriptor is only the beginning (or middle) */
3680 /* this is the beginning of a chain */
3682 skb_fill_page_desc(rxtop, 0, buffer_info->page,
3685 /* this is the middle of a chain */
3686 skb_fill_page_desc(rxtop,
3687 skb_shinfo(rxtop)->nr_frags,
3688 buffer_info->page, 0, length);
3689 /* re-use the skb, only consumed the page */
3690 buffer_info->skb = skb;
3692 e1000_consume_page(buffer_info, rxtop, length);
3696 /* end of the chain */
3697 skb_fill_page_desc(rxtop,
3698 skb_shinfo(rxtop)->nr_frags,
3699 buffer_info->page, 0, length);
3700 /* re-use the current skb, we only consumed the
3702 buffer_info->skb = skb;
3705 e1000_consume_page(buffer_info, skb, length);
3707 /* no chain, got EOP, this buf is the packet
3708 * copybreak to save the put_page/alloc_page */
3709 if (length <= copybreak &&
3710 skb_tailroom(skb) >= length) {
3712 vaddr = kmap_atomic(buffer_info->page,
3713 KM_SKB_DATA_SOFTIRQ);
3714 memcpy(skb_tail_pointer(skb), vaddr, length);
3715 kunmap_atomic(vaddr,
3716 KM_SKB_DATA_SOFTIRQ);
3717 /* re-use the page, so don't erase
3718 * buffer_info->page */
3719 skb_put(skb, length);
3721 skb_fill_page_desc(skb, 0,
3722 buffer_info->page, 0,
3724 e1000_consume_page(buffer_info, skb,
3730 /* Receive Checksum Offload XXX recompute due to CRC strip? */
3731 e1000_rx_checksum(adapter,
3733 ((u32)(rx_desc->errors) << 24),
3734 le16_to_cpu(rx_desc->csum), skb);
3736 pskb_trim(skb, skb->len - 4);
3738 /* probably a little skewed due to removing CRC */
3739 total_rx_bytes += skb->len;
3742 /* eth type trans needs skb->data to point to something */
3743 if (!pskb_may_pull(skb, ETH_HLEN)) {
3744 DPRINTK(DRV, ERR, "pskb_may_pull failed.\n");
3749 skb->protocol = eth_type_trans(skb, netdev);
3751 e1000_receive_skb(adapter, status, rx_desc->special, skb);
3754 rx_desc->status = 0;
3756 /* return some buffers to hardware, one at a time is too slow */
3757 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3758 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3762 /* use prefetched values */
3764 buffer_info = next_buffer;
3766 rx_ring->next_to_clean = i;
3768 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3770 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3772 adapter->total_rx_packets += total_rx_packets;
3773 adapter->total_rx_bytes += total_rx_bytes;
3774 adapter->net_stats.rx_bytes += total_rx_bytes;
3775 adapter->net_stats.rx_packets += total_rx_packets;
3780 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3781 * @adapter: board private structure
3782 * @rx_ring: ring to clean
3783 * @work_done: amount of napi work completed this call
3784 * @work_to_do: max amount of work allowed for this call to do
3786 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
3787 struct e1000_rx_ring *rx_ring,
3788 int *work_done, int work_to_do)
3790 struct e1000_hw *hw = &adapter->hw;
3791 struct net_device *netdev = adapter->netdev;
3792 struct pci_dev *pdev = adapter->pdev;
3793 struct e1000_rx_desc *rx_desc, *next_rxd;
3794 struct e1000_buffer *buffer_info, *next_buffer;
3795 unsigned long flags;
3798 int cleaned_count = 0;
3799 bool cleaned = false;
3800 unsigned int total_rx_bytes=0, total_rx_packets=0;
3802 i = rx_ring->next_to_clean;
3803 rx_desc = E1000_RX_DESC(*rx_ring, i);
3804 buffer_info = &rx_ring->buffer_info[i];
3806 while (rx_desc->status & E1000_RXD_STAT_DD) {
3807 struct sk_buff *skb;
3810 if (*work_done >= work_to_do)
3814 status = rx_desc->status;
3815 skb = buffer_info->skb;
3816 buffer_info->skb = NULL;
3818 prefetch(skb->data - NET_IP_ALIGN);
3820 if (++i == rx_ring->count) i = 0;
3821 next_rxd = E1000_RX_DESC(*rx_ring, i);
3824 next_buffer = &rx_ring->buffer_info[i];
3828 pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
3829 PCI_DMA_FROMDEVICE);
3830 buffer_info->dma = 0;
3832 length = le16_to_cpu(rx_desc->length);
3833 /* !EOP means multiple descriptors were used to store a single
3834 * packet, if thats the case we need to toss it. In fact, we
3835 * to toss every packet with the EOP bit clear and the next
3836 * frame that _does_ have the EOP bit set, as it is by
3837 * definition only a frame fragment
3839 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
3840 adapter->discarding = true;
3842 if (adapter->discarding) {
3843 /* All receives must fit into a single buffer */
3844 E1000_DBG("%s: Receive packet consumed multiple"
3845 " buffers\n", netdev->name);
3847 buffer_info->skb = skb;
3848 if (status & E1000_RXD_STAT_EOP)
3849 adapter->discarding = false;
3853 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3854 u8 last_byte = *(skb->data + length - 1);
3855 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
3857 spin_lock_irqsave(&adapter->stats_lock, flags);
3858 e1000_tbi_adjust_stats(hw, &adapter->stats,
3860 spin_unlock_irqrestore(&adapter->stats_lock,
3865 buffer_info->skb = skb;
3870 /* adjust length to remove Ethernet CRC, this must be
3871 * done after the TBI_ACCEPT workaround above */
3874 /* probably a little skewed due to removing CRC */
3875 total_rx_bytes += length;
3878 /* code added for copybreak, this should improve
3879 * performance for small packets with large amounts
3880 * of reassembly being done in the stack */
3881 if (length < copybreak) {
3882 struct sk_buff *new_skb =
3883 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
3885 skb_reserve(new_skb, NET_IP_ALIGN);
3886 skb_copy_to_linear_data_offset(new_skb,
3892 /* save the skb in buffer_info as good */
3893 buffer_info->skb = skb;
3896 /* else just continue with the old one */
3898 /* end copybreak code */
3899 skb_put(skb, length);
3901 /* Receive Checksum Offload */
3902 e1000_rx_checksum(adapter,
3904 ((u32)(rx_desc->errors) << 24),
3905 le16_to_cpu(rx_desc->csum), skb);
3907 skb->protocol = eth_type_trans(skb, netdev);
3909 e1000_receive_skb(adapter, status, rx_desc->special, skb);
3912 rx_desc->status = 0;
3914 /* return some buffers to hardware, one at a time is too slow */
3915 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3916 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3920 /* use prefetched values */
3922 buffer_info = next_buffer;
3924 rx_ring->next_to_clean = i;
3926 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3928 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3930 adapter->total_rx_packets += total_rx_packets;
3931 adapter->total_rx_bytes += total_rx_bytes;
3932 adapter->net_stats.rx_bytes += total_rx_bytes;
3933 adapter->net_stats.rx_packets += total_rx_packets;
3938 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
3939 * @adapter: address of board private structure
3940 * @rx_ring: pointer to receive ring structure
3941 * @cleaned_count: number of buffers to allocate this pass
3945 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
3946 struct e1000_rx_ring *rx_ring, int cleaned_count)
3948 struct net_device *netdev = adapter->netdev;
3949 struct pci_dev *pdev = adapter->pdev;
3950 struct e1000_rx_desc *rx_desc;
3951 struct e1000_buffer *buffer_info;
3952 struct sk_buff *skb;
3954 unsigned int bufsz = 256 -
3955 16 /*for skb_reserve */ -
3958 i = rx_ring->next_to_use;
3959 buffer_info = &rx_ring->buffer_info[i];
3961 while (cleaned_count--) {
3962 skb = buffer_info->skb;
3968 skb = netdev_alloc_skb(netdev, bufsz);
3969 if (unlikely(!skb)) {
3970 /* Better luck next round */
3971 adapter->alloc_rx_buff_failed++;
3975 /* Fix for errata 23, can't cross 64kB boundary */
3976 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3977 struct sk_buff *oldskb = skb;
3978 DPRINTK(PROBE, ERR, "skb align check failed: %u bytes "
3979 "at %p\n", bufsz, skb->data);
3980 /* Try again, without freeing the previous */
3981 skb = netdev_alloc_skb(netdev, bufsz);
3982 /* Failed allocation, critical failure */
3984 dev_kfree_skb(oldskb);
3985 adapter->alloc_rx_buff_failed++;
3989 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3992 dev_kfree_skb(oldskb);
3993 break; /* while (cleaned_count--) */
3996 /* Use new allocation */
3997 dev_kfree_skb(oldskb);
3999 /* Make buffer alignment 2 beyond a 16 byte boundary
4000 * this will result in a 16 byte aligned IP header after
4001 * the 14 byte MAC header is removed
4003 skb_reserve(skb, NET_IP_ALIGN);
4005 buffer_info->skb = skb;
4006 buffer_info->length = adapter->rx_buffer_len;
4008 /* allocate a new page if necessary */
4009 if (!buffer_info->page) {
4010 buffer_info->page = alloc_page(GFP_ATOMIC);
4011 if (unlikely(!buffer_info->page)) {
4012 adapter->alloc_rx_buff_failed++;
4017 if (!buffer_info->dma)
4018 buffer_info->dma = pci_map_page(pdev,
4019 buffer_info->page, 0,
4020 buffer_info->length,
4021 PCI_DMA_FROMDEVICE);
4023 rx_desc = E1000_RX_DESC(*rx_ring, i);
4024 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4026 if (unlikely(++i == rx_ring->count))
4028 buffer_info = &rx_ring->buffer_info[i];
4031 if (likely(rx_ring->next_to_use != i)) {
4032 rx_ring->next_to_use = i;
4033 if (unlikely(i-- == 0))
4034 i = (rx_ring->count - 1);
4036 /* Force memory writes to complete before letting h/w
4037 * know there are new descriptors to fetch. (Only
4038 * applicable for weak-ordered memory model archs,
4039 * such as IA-64). */
4041 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4046 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4047 * @adapter: address of board private structure
4050 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4051 struct e1000_rx_ring *rx_ring,
4054 struct e1000_hw *hw = &adapter->hw;
4055 struct net_device *netdev = adapter->netdev;
4056 struct pci_dev *pdev = adapter->pdev;
4057 struct e1000_rx_desc *rx_desc;
4058 struct e1000_buffer *buffer_info;
4059 struct sk_buff *skb;
4061 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4063 i = rx_ring->next_to_use;
4064 buffer_info = &rx_ring->buffer_info[i];
4066 while (cleaned_count--) {
4067 skb = buffer_info->skb;
4073 skb = netdev_alloc_skb(netdev, bufsz);
4074 if (unlikely(!skb)) {
4075 /* Better luck next round */
4076 adapter->alloc_rx_buff_failed++;
4080 /* Fix for errata 23, can't cross 64kB boundary */
4081 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4082 struct sk_buff *oldskb = skb;
4083 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4084 "at %p\n", bufsz, skb->data);
4085 /* Try again, without freeing the previous */
4086 skb = netdev_alloc_skb(netdev, bufsz);
4087 /* Failed allocation, critical failure */
4089 dev_kfree_skb(oldskb);
4090 adapter->alloc_rx_buff_failed++;
4094 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4097 dev_kfree_skb(oldskb);
4098 adapter->alloc_rx_buff_failed++;
4099 break; /* while !buffer_info->skb */
4102 /* Use new allocation */
4103 dev_kfree_skb(oldskb);
4105 /* Make buffer alignment 2 beyond a 16 byte boundary
4106 * this will result in a 16 byte aligned IP header after
4107 * the 14 byte MAC header is removed
4109 skb_reserve(skb, NET_IP_ALIGN);
4111 buffer_info->skb = skb;
4112 buffer_info->length = adapter->rx_buffer_len;
4114 buffer_info->dma = pci_map_single(pdev,
4116 buffer_info->length,
4117 PCI_DMA_FROMDEVICE);
4120 * XXX if it was allocated cleanly it will never map to a
4124 /* Fix for errata 23, can't cross 64kB boundary */
4125 if (!e1000_check_64k_bound(adapter,
4126 (void *)(unsigned long)buffer_info->dma,
4127 adapter->rx_buffer_len)) {
4128 DPRINTK(RX_ERR, ERR,
4129 "dma align check failed: %u bytes at %p\n",
4130 adapter->rx_buffer_len,
4131 (void *)(unsigned long)buffer_info->dma);
4133 buffer_info->skb = NULL;
4135 pci_unmap_single(pdev, buffer_info->dma,
4136 adapter->rx_buffer_len,
4137 PCI_DMA_FROMDEVICE);
4138 buffer_info->dma = 0;
4140 adapter->alloc_rx_buff_failed++;
4141 break; /* while !buffer_info->skb */
4143 rx_desc = E1000_RX_DESC(*rx_ring, i);
4144 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4146 if (unlikely(++i == rx_ring->count))
4148 buffer_info = &rx_ring->buffer_info[i];
4151 if (likely(rx_ring->next_to_use != i)) {
4152 rx_ring->next_to_use = i;
4153 if (unlikely(i-- == 0))
4154 i = (rx_ring->count - 1);
4156 /* Force memory writes to complete before letting h/w
4157 * know there are new descriptors to fetch. (Only
4158 * applicable for weak-ordered memory model archs,
4159 * such as IA-64). */
4161 writel(i, hw->hw_addr + rx_ring->rdt);
4166 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4170 static void e1000_smartspeed(struct e1000_adapter *adapter)
4172 struct e1000_hw *hw = &adapter->hw;
4176 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4177 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4180 if (adapter->smartspeed == 0) {
4181 /* If Master/Slave config fault is asserted twice,
4182 * we assume back-to-back */
4183 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4184 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4185 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4186 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4187 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4188 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4189 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4190 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4192 adapter->smartspeed++;
4193 if (!e1000_phy_setup_autoneg(hw) &&
4194 !e1000_read_phy_reg(hw, PHY_CTRL,
4196 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4197 MII_CR_RESTART_AUTO_NEG);
4198 e1000_write_phy_reg(hw, PHY_CTRL,
4203 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4204 /* If still no link, perhaps using 2/3 pair cable */
4205 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4206 phy_ctrl |= CR_1000T_MS_ENABLE;
4207 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4208 if (!e1000_phy_setup_autoneg(hw) &&
4209 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4210 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4211 MII_CR_RESTART_AUTO_NEG);
4212 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4215 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4216 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4217 adapter->smartspeed = 0;
4227 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4233 return e1000_mii_ioctl(netdev, ifr, cmd);
4246 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4249 struct e1000_adapter *adapter = netdev_priv(netdev);
4250 struct e1000_hw *hw = &adapter->hw;
4251 struct mii_ioctl_data *data = if_mii(ifr);
4255 unsigned long flags;
4257 if (hw->media_type != e1000_media_type_copper)
4262 data->phy_id = hw->phy_addr;
4265 spin_lock_irqsave(&adapter->stats_lock, flags);
4266 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4268 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4271 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4274 if (data->reg_num & ~(0x1F))
4276 mii_reg = data->val_in;
4277 spin_lock_irqsave(&adapter->stats_lock, flags);
4278 if (e1000_write_phy_reg(hw, data->reg_num,
4280 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4283 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4284 if (hw->media_type == e1000_media_type_copper) {
4285 switch (data->reg_num) {
4287 if (mii_reg & MII_CR_POWER_DOWN)
4289 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4291 hw->autoneg_advertised = 0x2F;
4294 spddplx = SPEED_1000;
4295 else if (mii_reg & 0x2000)
4296 spddplx = SPEED_100;
4299 spddplx += (mii_reg & 0x100)
4302 retval = e1000_set_spd_dplx(adapter,
4307 if (netif_running(adapter->netdev))
4308 e1000_reinit_locked(adapter);
4310 e1000_reset(adapter);
4312 case M88E1000_PHY_SPEC_CTRL:
4313 case M88E1000_EXT_PHY_SPEC_CTRL:
4314 if (e1000_phy_reset(hw))
4319 switch (data->reg_num) {
4321 if (mii_reg & MII_CR_POWER_DOWN)
4323 if (netif_running(adapter->netdev))
4324 e1000_reinit_locked(adapter);
4326 e1000_reset(adapter);
4334 return E1000_SUCCESS;
4337 void e1000_pci_set_mwi(struct e1000_hw *hw)
4339 struct e1000_adapter *adapter = hw->back;
4340 int ret_val = pci_set_mwi(adapter->pdev);
4343 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4346 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4348 struct e1000_adapter *adapter = hw->back;
4350 pci_clear_mwi(adapter->pdev);
4353 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4355 struct e1000_adapter *adapter = hw->back;
4356 return pcix_get_mmrbc(adapter->pdev);
4359 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4361 struct e1000_adapter *adapter = hw->back;
4362 pcix_set_mmrbc(adapter->pdev, mmrbc);
4365 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4370 static void e1000_vlan_rx_register(struct net_device *netdev,
4371 struct vlan_group *grp)
4373 struct e1000_adapter *adapter = netdev_priv(netdev);
4374 struct e1000_hw *hw = &adapter->hw;
4377 if (!test_bit(__E1000_DOWN, &adapter->flags))
4378 e1000_irq_disable(adapter);
4379 adapter->vlgrp = grp;
4382 /* enable VLAN tag insert/strip */
4384 ctrl |= E1000_CTRL_VME;
4387 /* enable VLAN receive filtering */
4389 rctl &= ~E1000_RCTL_CFIEN;
4390 if (!(netdev->flags & IFF_PROMISC))
4391 rctl |= E1000_RCTL_VFE;
4393 e1000_update_mng_vlan(adapter);
4395 /* disable VLAN tag insert/strip */
4397 ctrl &= ~E1000_CTRL_VME;
4400 /* disable VLAN receive filtering */
4402 rctl &= ~E1000_RCTL_VFE;
4405 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
4406 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4407 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4411 if (!test_bit(__E1000_DOWN, &adapter->flags))
4412 e1000_irq_enable(adapter);
4415 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4417 struct e1000_adapter *adapter = netdev_priv(netdev);
4418 struct e1000_hw *hw = &adapter->hw;
4421 if ((hw->mng_cookie.status &
4422 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4423 (vid == adapter->mng_vlan_id))
4425 /* add VID to filter table */
4426 index = (vid >> 5) & 0x7F;
4427 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4428 vfta |= (1 << (vid & 0x1F));
4429 e1000_write_vfta(hw, index, vfta);
4432 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4434 struct e1000_adapter *adapter = netdev_priv(netdev);
4435 struct e1000_hw *hw = &adapter->hw;
4438 if (!test_bit(__E1000_DOWN, &adapter->flags))
4439 e1000_irq_disable(adapter);
4440 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4441 if (!test_bit(__E1000_DOWN, &adapter->flags))
4442 e1000_irq_enable(adapter);
4444 /* remove VID from filter table */
4445 index = (vid >> 5) & 0x7F;
4446 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4447 vfta &= ~(1 << (vid & 0x1F));
4448 e1000_write_vfta(hw, index, vfta);
4451 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4453 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4455 if (adapter->vlgrp) {
4457 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4458 if (!vlan_group_get_device(adapter->vlgrp, vid))
4460 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4465 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
4467 struct e1000_hw *hw = &adapter->hw;
4471 /* Fiber NICs only allow 1000 gbps Full duplex */
4472 if ((hw->media_type == e1000_media_type_fiber) &&
4473 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4474 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4479 case SPEED_10 + DUPLEX_HALF:
4480 hw->forced_speed_duplex = e1000_10_half;
4482 case SPEED_10 + DUPLEX_FULL:
4483 hw->forced_speed_duplex = e1000_10_full;
4485 case SPEED_100 + DUPLEX_HALF:
4486 hw->forced_speed_duplex = e1000_100_half;
4488 case SPEED_100 + DUPLEX_FULL:
4489 hw->forced_speed_duplex = e1000_100_full;
4491 case SPEED_1000 + DUPLEX_FULL:
4493 hw->autoneg_advertised = ADVERTISE_1000_FULL;
4495 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4497 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4503 static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
4505 struct net_device *netdev = pci_get_drvdata(pdev);
4506 struct e1000_adapter *adapter = netdev_priv(netdev);
4507 struct e1000_hw *hw = &adapter->hw;
4508 u32 ctrl, ctrl_ext, rctl, status;
4509 u32 wufc = adapter->wol;
4514 netif_device_detach(netdev);
4516 if (netif_running(netdev)) {
4517 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4518 e1000_down(adapter);
4522 retval = pci_save_state(pdev);
4527 status = er32(STATUS);
4528 if (status & E1000_STATUS_LU)
4529 wufc &= ~E1000_WUFC_LNKC;
4532 e1000_setup_rctl(adapter);
4533 e1000_set_rx_mode(netdev);
4535 /* turn on all-multi mode if wake on multicast is enabled */
4536 if (wufc & E1000_WUFC_MC) {
4538 rctl |= E1000_RCTL_MPE;
4542 if (hw->mac_type >= e1000_82540) {
4544 /* advertise wake from D3Cold */
4545 #define E1000_CTRL_ADVD3WUC 0x00100000
4546 /* phy power management enable */
4547 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4548 ctrl |= E1000_CTRL_ADVD3WUC |
4549 E1000_CTRL_EN_PHY_PWR_MGMT;
4553 if (hw->media_type == e1000_media_type_fiber ||
4554 hw->media_type == e1000_media_type_internal_serdes) {
4555 /* keep the laser running in D3 */
4556 ctrl_ext = er32(CTRL_EXT);
4557 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4558 ew32(CTRL_EXT, ctrl_ext);
4561 ew32(WUC, E1000_WUC_PME_EN);
4568 e1000_release_manageability(adapter);
4570 *enable_wake = !!wufc;
4572 /* make sure adapter isn't asleep if manageability is enabled */
4573 if (adapter->en_mng_pt)
4574 *enable_wake = true;
4576 if (netif_running(netdev))
4577 e1000_free_irq(adapter);
4579 pci_disable_device(pdev);
4585 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4590 retval = __e1000_shutdown(pdev, &wake);
4595 pci_prepare_to_sleep(pdev);
4597 pci_wake_from_d3(pdev, false);
4598 pci_set_power_state(pdev, PCI_D3hot);
4604 static int e1000_resume(struct pci_dev *pdev)
4606 struct net_device *netdev = pci_get_drvdata(pdev);
4607 struct e1000_adapter *adapter = netdev_priv(netdev);
4608 struct e1000_hw *hw = &adapter->hw;
4611 pci_set_power_state(pdev, PCI_D0);
4612 pci_restore_state(pdev);
4614 if (adapter->need_ioport)
4615 err = pci_enable_device(pdev);
4617 err = pci_enable_device_mem(pdev);
4619 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4622 pci_set_master(pdev);
4624 pci_enable_wake(pdev, PCI_D3hot, 0);
4625 pci_enable_wake(pdev, PCI_D3cold, 0);
4627 if (netif_running(netdev)) {
4628 err = e1000_request_irq(adapter);
4633 e1000_power_up_phy(adapter);
4634 e1000_reset(adapter);
4637 e1000_init_manageability(adapter);
4639 if (netif_running(netdev))
4642 netif_device_attach(netdev);
4648 static void e1000_shutdown(struct pci_dev *pdev)
4652 __e1000_shutdown(pdev, &wake);
4654 if (system_state == SYSTEM_POWER_OFF) {
4655 pci_wake_from_d3(pdev, wake);
4656 pci_set_power_state(pdev, PCI_D3hot);
4660 #ifdef CONFIG_NET_POLL_CONTROLLER
4662 * Polling 'interrupt' - used by things like netconsole to send skbs
4663 * without having to re-enable interrupts. It's not called while
4664 * the interrupt routine is executing.
4666 static void e1000_netpoll(struct net_device *netdev)
4668 struct e1000_adapter *adapter = netdev_priv(netdev);
4670 disable_irq(adapter->pdev->irq);
4671 e1000_intr(adapter->pdev->irq, netdev);
4672 enable_irq(adapter->pdev->irq);
4677 * e1000_io_error_detected - called when PCI error is detected
4678 * @pdev: Pointer to PCI device
4679 * @state: The current pci connection state
4681 * This function is called after a PCI bus error affecting
4682 * this device has been detected.
4684 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
4685 pci_channel_state_t state)
4687 struct net_device *netdev = pci_get_drvdata(pdev);
4688 struct e1000_adapter *adapter = netdev_priv(netdev);
4690 netif_device_detach(netdev);
4692 if (state == pci_channel_io_perm_failure)
4693 return PCI_ERS_RESULT_DISCONNECT;
4695 if (netif_running(netdev))
4696 e1000_down(adapter);
4697 pci_disable_device(pdev);
4699 /* Request a slot slot reset. */
4700 return PCI_ERS_RESULT_NEED_RESET;
4704 * e1000_io_slot_reset - called after the pci bus has been reset.
4705 * @pdev: Pointer to PCI device
4707 * Restart the card from scratch, as if from a cold-boot. Implementation
4708 * resembles the first-half of the e1000_resume routine.
4710 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4712 struct net_device *netdev = pci_get_drvdata(pdev);
4713 struct e1000_adapter *adapter = netdev_priv(netdev);
4714 struct e1000_hw *hw = &adapter->hw;
4717 if (adapter->need_ioport)
4718 err = pci_enable_device(pdev);
4720 err = pci_enable_device_mem(pdev);
4722 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4723 return PCI_ERS_RESULT_DISCONNECT;
4725 pci_set_master(pdev);
4727 pci_enable_wake(pdev, PCI_D3hot, 0);
4728 pci_enable_wake(pdev, PCI_D3cold, 0);
4730 e1000_reset(adapter);
4733 return PCI_ERS_RESULT_RECOVERED;
4737 * e1000_io_resume - called when traffic can start flowing again.
4738 * @pdev: Pointer to PCI device
4740 * This callback is called when the error recovery driver tells us that
4741 * its OK to resume normal operation. Implementation resembles the
4742 * second-half of the e1000_resume routine.
4744 static void e1000_io_resume(struct pci_dev *pdev)
4746 struct net_device *netdev = pci_get_drvdata(pdev);
4747 struct e1000_adapter *adapter = netdev_priv(netdev);
4749 e1000_init_manageability(adapter);
4751 if (netif_running(netdev)) {
4752 if (e1000_up(adapter)) {
4753 printk("e1000: can't bring device back up after reset\n");
4758 netif_device_attach(netdev);