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 #ifndef CONFIG_E1000_NAPI
37 #define DRIVERNAPI "-NAPI"
39 #define DRV_VERSION "7.3.20-k2"DRIVERNAPI
40 const char e1000_driver_version[] = DRV_VERSION;
41 static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
43 /* e1000_pci_tbl - PCI Device ID Table
45 * Last entry must be all 0s
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
50 static struct pci_device_id e1000_pci_tbl[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
70 INTEL_E1000_ETHERNET_DEVICE(0x101A),
71 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
76 INTEL_E1000_ETHERNET_DEVICE(0x1075),
77 INTEL_E1000_ETHERNET_DEVICE(0x1076),
78 INTEL_E1000_ETHERNET_DEVICE(0x1077),
79 INTEL_E1000_ETHERNET_DEVICE(0x1078),
80 INTEL_E1000_ETHERNET_DEVICE(0x1079),
81 INTEL_E1000_ETHERNET_DEVICE(0x107A),
82 INTEL_E1000_ETHERNET_DEVICE(0x107B),
83 INTEL_E1000_ETHERNET_DEVICE(0x107C),
84 INTEL_E1000_ETHERNET_DEVICE(0x108A),
85 INTEL_E1000_ETHERNET_DEVICE(0x1099),
86 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
87 /* required last entry */
91 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
93 int e1000_up(struct e1000_adapter *adapter);
94 void e1000_down(struct e1000_adapter *adapter);
95 void e1000_reinit_locked(struct e1000_adapter *adapter);
96 void e1000_reset(struct e1000_adapter *adapter);
97 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
98 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
99 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
100 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
101 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
102 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
103 struct e1000_tx_ring *txdr);
104 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
105 struct e1000_rx_ring *rxdr);
106 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
107 struct e1000_tx_ring *tx_ring);
108 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
109 struct e1000_rx_ring *rx_ring);
110 void e1000_update_stats(struct e1000_adapter *adapter);
112 static int e1000_init_module(void);
113 static void e1000_exit_module(void);
114 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
115 static void __devexit e1000_remove(struct pci_dev *pdev);
116 static int e1000_alloc_queues(struct e1000_adapter *adapter);
117 static int e1000_sw_init(struct e1000_adapter *adapter);
118 static int e1000_open(struct net_device *netdev);
119 static int e1000_close(struct net_device *netdev);
120 static void e1000_configure_tx(struct e1000_adapter *adapter);
121 static void e1000_configure_rx(struct e1000_adapter *adapter);
122 static void e1000_setup_rctl(struct e1000_adapter *adapter);
123 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
124 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
125 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
126 struct e1000_tx_ring *tx_ring);
127 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
128 struct e1000_rx_ring *rx_ring);
129 static void e1000_set_rx_mode(struct net_device *netdev);
130 static void e1000_update_phy_info(unsigned long data);
131 static void e1000_watchdog(unsigned long data);
132 static void e1000_82547_tx_fifo_stall(unsigned long data);
133 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
134 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
135 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
136 static int e1000_set_mac(struct net_device *netdev, void *p);
137 static irqreturn_t e1000_intr(int irq, void *data);
138 static irqreturn_t e1000_intr_msi(int irq, void *data);
139 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
140 struct e1000_tx_ring *tx_ring);
141 #ifdef CONFIG_E1000_NAPI
142 static int e1000_clean(struct napi_struct *napi, int budget);
143 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
145 int *work_done, int work_to_do);
146 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int *work_done, int work_to_do);
150 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring);
152 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
153 struct e1000_rx_ring *rx_ring);
155 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
156 struct e1000_rx_ring *rx_ring,
158 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
159 struct e1000_rx_ring *rx_ring,
161 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
162 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
164 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
165 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
166 static void e1000_tx_timeout(struct net_device *dev);
167 static void e1000_reset_task(struct work_struct *work);
168 static void e1000_smartspeed(struct e1000_adapter *adapter);
169 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
170 struct sk_buff *skb);
172 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
173 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
174 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
175 static void e1000_restore_vlan(struct e1000_adapter *adapter);
177 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
179 static int e1000_resume(struct pci_dev *pdev);
181 static void e1000_shutdown(struct pci_dev *pdev);
183 #ifdef CONFIG_NET_POLL_CONTROLLER
184 /* for netdump / net console */
185 static void e1000_netpoll (struct net_device *netdev);
188 #define COPYBREAK_DEFAULT 256
189 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
190 module_param(copybreak, uint, 0644);
191 MODULE_PARM_DESC(copybreak,
192 "Maximum size of packet that is copied to a new buffer on receive");
194 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
195 pci_channel_state_t state);
196 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
197 static void e1000_io_resume(struct pci_dev *pdev);
199 static struct pci_error_handlers e1000_err_handler = {
200 .error_detected = e1000_io_error_detected,
201 .slot_reset = e1000_io_slot_reset,
202 .resume = e1000_io_resume,
205 static struct pci_driver e1000_driver = {
206 .name = e1000_driver_name,
207 .id_table = e1000_pci_tbl,
208 .probe = e1000_probe,
209 .remove = __devexit_p(e1000_remove),
211 /* Power Managment Hooks */
212 .suspend = e1000_suspend,
213 .resume = e1000_resume,
215 .shutdown = e1000_shutdown,
216 .err_handler = &e1000_err_handler
219 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
220 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
221 MODULE_LICENSE("GPL");
222 MODULE_VERSION(DRV_VERSION);
224 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
225 module_param(debug, int, 0);
226 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
229 * e1000_init_module - Driver Registration Routine
231 * e1000_init_module is the first routine called when the driver is
232 * loaded. All it does is register with the PCI subsystem.
235 static int __init e1000_init_module(void)
238 printk(KERN_INFO "%s - version %s\n",
239 e1000_driver_string, e1000_driver_version);
241 printk(KERN_INFO "%s\n", e1000_copyright);
243 ret = pci_register_driver(&e1000_driver);
244 if (copybreak != COPYBREAK_DEFAULT) {
246 printk(KERN_INFO "e1000: copybreak disabled\n");
248 printk(KERN_INFO "e1000: copybreak enabled for "
249 "packets <= %u bytes\n", copybreak);
254 module_init(e1000_init_module);
257 * e1000_exit_module - Driver Exit Cleanup Routine
259 * e1000_exit_module is called just before the driver is removed
263 static void __exit e1000_exit_module(void)
265 pci_unregister_driver(&e1000_driver);
268 module_exit(e1000_exit_module);
270 static int e1000_request_irq(struct e1000_adapter *adapter)
272 struct net_device *netdev = adapter->netdev;
273 irq_handler_t handler = e1000_intr;
274 int irq_flags = IRQF_SHARED;
277 if (adapter->hw.mac_type >= e1000_82571) {
278 adapter->have_msi = !pci_enable_msi(adapter->pdev);
279 if (adapter->have_msi) {
280 handler = e1000_intr_msi;
285 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
288 if (adapter->have_msi)
289 pci_disable_msi(adapter->pdev);
291 "Unable to allocate interrupt Error: %d\n", err);
297 static void e1000_free_irq(struct e1000_adapter *adapter)
299 struct net_device *netdev = adapter->netdev;
301 free_irq(adapter->pdev->irq, netdev);
303 if (adapter->have_msi)
304 pci_disable_msi(adapter->pdev);
308 * e1000_irq_disable - Mask off interrupt generation on the NIC
309 * @adapter: board private structure
312 static void e1000_irq_disable(struct e1000_adapter *adapter)
314 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
315 E1000_WRITE_FLUSH(&adapter->hw);
316 synchronize_irq(adapter->pdev->irq);
320 * e1000_irq_enable - Enable default interrupt generation settings
321 * @adapter: board private structure
324 static void e1000_irq_enable(struct e1000_adapter *adapter)
326 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
327 E1000_WRITE_FLUSH(&adapter->hw);
330 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
332 struct net_device *netdev = adapter->netdev;
333 u16 vid = adapter->hw.mng_cookie.vlan_id;
334 u16 old_vid = adapter->mng_vlan_id;
335 if (adapter->vlgrp) {
336 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
337 if (adapter->hw.mng_cookie.status &
338 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
339 e1000_vlan_rx_add_vid(netdev, vid);
340 adapter->mng_vlan_id = vid;
342 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
344 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
346 !vlan_group_get_device(adapter->vlgrp, old_vid))
347 e1000_vlan_rx_kill_vid(netdev, old_vid);
349 adapter->mng_vlan_id = vid;
354 * e1000_release_hw_control - release control of the h/w to f/w
355 * @adapter: address of board private structure
357 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
358 * For ASF and Pass Through versions of f/w this means that the
359 * driver is no longer loaded. For AMT version (only with 82573) i
360 * of the f/w this means that the network i/f is closed.
364 static void e1000_release_hw_control(struct e1000_adapter *adapter)
369 /* Let firmware taken over control of h/w */
370 switch (adapter->hw.mac_type) {
372 swsm = E1000_READ_REG(&adapter->hw, SWSM);
373 E1000_WRITE_REG(&adapter->hw, SWSM,
374 swsm & ~E1000_SWSM_DRV_LOAD);
378 case e1000_80003es2lan:
380 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
381 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
382 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
390 * e1000_get_hw_control - get control of the h/w from f/w
391 * @adapter: address of board private structure
393 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
394 * For ASF and Pass Through versions of f/w this means that
395 * the driver is loaded. For AMT version (only with 82573)
396 * of the f/w this means that the network i/f is open.
400 static void e1000_get_hw_control(struct e1000_adapter *adapter)
405 /* Let firmware know the driver has taken over */
406 switch (adapter->hw.mac_type) {
408 swsm = E1000_READ_REG(&adapter->hw, SWSM);
409 E1000_WRITE_REG(&adapter->hw, SWSM,
410 swsm | E1000_SWSM_DRV_LOAD);
414 case e1000_80003es2lan:
416 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
417 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
418 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
425 static void e1000_init_manageability(struct e1000_adapter *adapter)
427 if (adapter->en_mng_pt) {
428 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
430 /* disable hardware interception of ARP */
431 manc &= ~(E1000_MANC_ARP_EN);
433 /* enable receiving management packets to the host */
434 /* this will probably generate destination unreachable messages
435 * from the host OS, but the packets will be handled on SMBUS */
436 if (adapter->hw.has_manc2h) {
437 u32 manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
439 manc |= E1000_MANC_EN_MNG2HOST;
440 #define E1000_MNG2HOST_PORT_623 (1 << 5)
441 #define E1000_MNG2HOST_PORT_664 (1 << 6)
442 manc2h |= E1000_MNG2HOST_PORT_623;
443 manc2h |= E1000_MNG2HOST_PORT_664;
444 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
447 E1000_WRITE_REG(&adapter->hw, MANC, manc);
451 static void e1000_release_manageability(struct e1000_adapter *adapter)
453 if (adapter->en_mng_pt) {
454 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
456 /* re-enable hardware interception of ARP */
457 manc |= E1000_MANC_ARP_EN;
459 if (adapter->hw.has_manc2h)
460 manc &= ~E1000_MANC_EN_MNG2HOST;
462 /* don't explicitly have to mess with MANC2H since
463 * MANC has an enable disable that gates MANC2H */
465 E1000_WRITE_REG(&adapter->hw, MANC, manc);
470 * e1000_configure - configure the hardware for RX and TX
471 * @adapter = private board structure
473 static void e1000_configure(struct e1000_adapter *adapter)
475 struct net_device *netdev = adapter->netdev;
478 e1000_set_rx_mode(netdev);
480 e1000_restore_vlan(adapter);
481 e1000_init_manageability(adapter);
483 e1000_configure_tx(adapter);
484 e1000_setup_rctl(adapter);
485 e1000_configure_rx(adapter);
486 /* call E1000_DESC_UNUSED which always leaves
487 * at least 1 descriptor unused to make sure
488 * next_to_use != next_to_clean */
489 for (i = 0; i < adapter->num_rx_queues; i++) {
490 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
491 adapter->alloc_rx_buf(adapter, ring,
492 E1000_DESC_UNUSED(ring));
495 adapter->tx_queue_len = netdev->tx_queue_len;
498 int e1000_up(struct e1000_adapter *adapter)
500 /* hardware has been reset, we need to reload some things */
501 e1000_configure(adapter);
503 clear_bit(__E1000_DOWN, &adapter->flags);
505 #ifdef CONFIG_E1000_NAPI
506 napi_enable(&adapter->napi);
508 e1000_irq_enable(adapter);
510 /* fire a link change interrupt to start the watchdog */
511 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
516 * e1000_power_up_phy - restore link in case the phy was powered down
517 * @adapter: address of board private structure
519 * The phy may be powered down to save power and turn off link when the
520 * driver is unloaded and wake on lan is not enabled (among others)
521 * *** this routine MUST be followed by a call to e1000_reset ***
525 void e1000_power_up_phy(struct e1000_adapter *adapter)
529 /* Just clear the power down bit to wake the phy back up */
530 if (adapter->hw.media_type == e1000_media_type_copper) {
531 /* according to the manual, the phy will retain its
532 * settings across a power-down/up cycle */
533 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
534 mii_reg &= ~MII_CR_POWER_DOWN;
535 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
539 static void e1000_power_down_phy(struct e1000_adapter *adapter)
541 /* Power down the PHY so no link is implied when interface is down *
542 * The PHY cannot be powered down if any of the following is true *
545 * (c) SoL/IDER session is active */
546 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
547 adapter->hw.media_type == e1000_media_type_copper) {
550 switch (adapter->hw.mac_type) {
553 case e1000_82545_rev_3:
555 case e1000_82546_rev_3:
557 case e1000_82541_rev_2:
559 case e1000_82547_rev_2:
560 if (E1000_READ_REG(&adapter->hw, MANC) &
567 case e1000_80003es2lan:
569 if (e1000_check_mng_mode(&adapter->hw) ||
570 e1000_check_phy_reset_block(&adapter->hw))
576 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
577 mii_reg |= MII_CR_POWER_DOWN;
578 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
585 void e1000_down(struct e1000_adapter *adapter)
587 struct net_device *netdev = adapter->netdev;
589 /* signal that we're down so the interrupt handler does not
590 * reschedule our watchdog timer */
591 set_bit(__E1000_DOWN, &adapter->flags);
593 #ifdef CONFIG_E1000_NAPI
594 napi_disable(&adapter->napi);
596 e1000_irq_disable(adapter);
598 del_timer_sync(&adapter->tx_fifo_stall_timer);
599 del_timer_sync(&adapter->watchdog_timer);
600 del_timer_sync(&adapter->phy_info_timer);
602 netdev->tx_queue_len = adapter->tx_queue_len;
603 adapter->link_speed = 0;
604 adapter->link_duplex = 0;
605 netif_carrier_off(netdev);
606 netif_stop_queue(netdev);
608 e1000_reset(adapter);
609 e1000_clean_all_tx_rings(adapter);
610 e1000_clean_all_rx_rings(adapter);
613 void e1000_reinit_locked(struct e1000_adapter *adapter)
615 WARN_ON(in_interrupt());
616 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
620 clear_bit(__E1000_RESETTING, &adapter->flags);
623 void e1000_reset(struct e1000_adapter *adapter)
625 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
626 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
627 bool legacy_pba_adjust = false;
629 /* Repartition Pba for greater than 9k mtu
630 * To take effect CTRL.RST is required.
633 switch (adapter->hw.mac_type) {
634 case e1000_82542_rev2_0:
635 case e1000_82542_rev2_1:
640 case e1000_82541_rev_2:
641 legacy_pba_adjust = true;
645 case e1000_82545_rev_3:
647 case e1000_82546_rev_3:
651 case e1000_82547_rev_2:
652 legacy_pba_adjust = true;
657 case e1000_80003es2lan:
665 case e1000_undefined:
670 if (legacy_pba_adjust) {
671 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
672 pba -= 8; /* allocate more FIFO for Tx */
674 if (adapter->hw.mac_type == e1000_82547) {
675 adapter->tx_fifo_head = 0;
676 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
677 adapter->tx_fifo_size =
678 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
679 atomic_set(&adapter->tx_fifo_stall, 0);
681 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
682 /* adjust PBA for jumbo frames */
683 E1000_WRITE_REG(&adapter->hw, PBA, pba);
685 /* To maintain wire speed transmits, the Tx FIFO should be
686 * large enough to accomodate two full transmit packets,
687 * rounded up to the next 1KB and expressed in KB. Likewise,
688 * the Rx FIFO should be large enough to accomodate at least
689 * one full receive packet and is similarly rounded up and
690 * expressed in KB. */
691 pba = E1000_READ_REG(&adapter->hw, PBA);
692 /* upper 16 bits has Tx packet buffer allocation size in KB */
693 tx_space = pba >> 16;
694 /* lower 16 bits has Rx packet buffer allocation size in KB */
696 /* don't include ethernet FCS because hardware appends/strips */
697 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
699 min_tx_space = min_rx_space;
701 min_tx_space = ALIGN(min_tx_space, 1024);
703 min_rx_space = ALIGN(min_rx_space, 1024);
706 /* If current Tx allocation is less than the min Tx FIFO size,
707 * and the min Tx FIFO size is less than the current Rx FIFO
708 * allocation, take space away from current Rx allocation */
709 if (tx_space < min_tx_space &&
710 ((min_tx_space - tx_space) < pba)) {
711 pba = pba - (min_tx_space - tx_space);
713 /* PCI/PCIx hardware has PBA alignment constraints */
714 switch (adapter->hw.mac_type) {
715 case e1000_82545 ... e1000_82546_rev_3:
716 pba &= ~(E1000_PBA_8K - 1);
722 /* if short on rx space, rx wins and must trump tx
723 * adjustment or use Early Receive if available */
724 if (pba < min_rx_space) {
725 switch (adapter->hw.mac_type) {
727 /* ERT enabled in e1000_configure_rx */
737 E1000_WRITE_REG(&adapter->hw, PBA, pba);
739 /* flow control settings */
740 /* Set the FC high water mark to 90% of the FIFO size.
741 * Required to clear last 3 LSB */
742 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
743 /* We can't use 90% on small FIFOs because the remainder
744 * would be less than 1 full frame. In this case, we size
745 * it to allow at least a full frame above the high water
747 if (pba < E1000_PBA_16K)
748 fc_high_water_mark = (pba * 1024) - 1600;
750 adapter->hw.fc_high_water = fc_high_water_mark;
751 adapter->hw.fc_low_water = fc_high_water_mark - 8;
752 if (adapter->hw.mac_type == e1000_80003es2lan)
753 adapter->hw.fc_pause_time = 0xFFFF;
755 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
756 adapter->hw.fc_send_xon = 1;
757 adapter->hw.fc = adapter->hw.original_fc;
759 /* Allow time for pending master requests to run */
760 e1000_reset_hw(&adapter->hw);
761 if (adapter->hw.mac_type >= e1000_82544)
762 E1000_WRITE_REG(&adapter->hw, WUC, 0);
764 if (e1000_init_hw(&adapter->hw))
765 DPRINTK(PROBE, ERR, "Hardware Error\n");
766 e1000_update_mng_vlan(adapter);
768 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
769 if (adapter->hw.mac_type >= e1000_82544 &&
770 adapter->hw.mac_type <= e1000_82547_rev_2 &&
771 adapter->hw.autoneg == 1 &&
772 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
773 u32 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
774 /* clear phy power management bit if we are in gig only mode,
775 * which if enabled will attempt negotiation to 100Mb, which
776 * can cause a loss of link at power off or driver unload */
777 ctrl &= ~E1000_CTRL_SWDPIN3;
778 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
781 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
782 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
784 e1000_reset_adaptive(&adapter->hw);
785 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
787 if (!adapter->smart_power_down &&
788 (adapter->hw.mac_type == e1000_82571 ||
789 adapter->hw.mac_type == e1000_82572)) {
791 /* speed up time to link by disabling smart power down, ignore
792 * the return value of this function because there is nothing
793 * different we would do if it failed */
794 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
796 phy_data &= ~IGP02E1000_PM_SPD;
797 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
801 e1000_release_manageability(adapter);
805 * Dump the eeprom for users having checksum issues
807 static void e1000_dump_eeprom(struct e1000_adapter *adapter)
809 struct net_device *netdev = adapter->netdev;
810 struct ethtool_eeprom eeprom;
811 const struct ethtool_ops *ops = netdev->ethtool_ops;
814 u16 csum_old, csum_new = 0;
816 eeprom.len = ops->get_eeprom_len(netdev);
819 data = kmalloc(eeprom.len, GFP_KERNEL);
821 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
826 ops->get_eeprom(netdev, &eeprom, data);
828 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
829 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
830 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
831 csum_new += data[i] + (data[i + 1] << 8);
832 csum_new = EEPROM_SUM - csum_new;
834 printk(KERN_ERR "/*********************/\n");
835 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
836 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
838 printk(KERN_ERR "Offset Values\n");
839 printk(KERN_ERR "======== ======\n");
840 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
842 printk(KERN_ERR "Include this output when contacting your support "
844 printk(KERN_ERR "This is not a software error! Something bad "
845 "happened to your hardware or\n");
846 printk(KERN_ERR "EEPROM image. Ignoring this "
847 "problem could result in further problems,\n");
848 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
849 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
850 "which is invalid\n");
851 printk(KERN_ERR "and requires you to set the proper MAC "
852 "address manually before continuing\n");
853 printk(KERN_ERR "to enable this network device.\n");
854 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
855 "to your hardware vendor\n");
856 printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n");
857 printk(KERN_ERR "/*********************/\n");
863 * e1000_probe - Device Initialization Routine
864 * @pdev: PCI device information struct
865 * @ent: entry in e1000_pci_tbl
867 * Returns 0 on success, negative on failure
869 * e1000_probe initializes an adapter identified by a pci_dev structure.
870 * The OS initialization, configuring of the adapter private structure,
871 * and a hardware reset occur.
875 e1000_probe(struct pci_dev *pdev,
876 const struct pci_device_id *ent)
878 struct net_device *netdev;
879 struct e1000_adapter *adapter;
881 static int cards_found = 0;
882 static int global_quad_port_a = 0; /* global ksp3 port a indication */
883 int i, err, pci_using_dac;
885 u16 eeprom_apme_mask = E1000_EEPROM_APME;
886 DECLARE_MAC_BUF(mac);
888 if ((err = pci_enable_device(pdev)))
891 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
892 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
895 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
896 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
897 E1000_ERR("No usable DMA configuration, aborting\n");
903 if ((err = pci_request_regions(pdev, e1000_driver_name)))
906 pci_set_master(pdev);
909 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
911 goto err_alloc_etherdev;
913 SET_NETDEV_DEV(netdev, &pdev->dev);
915 pci_set_drvdata(pdev, netdev);
916 adapter = netdev_priv(netdev);
917 adapter->netdev = netdev;
918 adapter->pdev = pdev;
919 adapter->hw.back = adapter;
920 adapter->msg_enable = (1 << debug) - 1;
923 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
924 pci_resource_len(pdev, BAR_0));
925 if (!adapter->hw.hw_addr)
928 for (i = BAR_1; i <= BAR_5; i++) {
929 if (pci_resource_len(pdev, i) == 0)
931 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
932 adapter->hw.io_base = pci_resource_start(pdev, i);
937 netdev->open = &e1000_open;
938 netdev->stop = &e1000_close;
939 netdev->hard_start_xmit = &e1000_xmit_frame;
940 netdev->get_stats = &e1000_get_stats;
941 netdev->set_rx_mode = &e1000_set_rx_mode;
942 netdev->set_mac_address = &e1000_set_mac;
943 netdev->change_mtu = &e1000_change_mtu;
944 netdev->do_ioctl = &e1000_ioctl;
945 e1000_set_ethtool_ops(netdev);
946 netdev->tx_timeout = &e1000_tx_timeout;
947 netdev->watchdog_timeo = 5 * HZ;
948 #ifdef CONFIG_E1000_NAPI
949 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
951 netdev->vlan_rx_register = e1000_vlan_rx_register;
952 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
953 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
954 #ifdef CONFIG_NET_POLL_CONTROLLER
955 netdev->poll_controller = e1000_netpoll;
957 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
959 adapter->bd_number = cards_found;
961 /* setup the private structure */
963 if ((err = e1000_sw_init(adapter)))
967 /* Flash BAR mapping must happen after e1000_sw_init
968 * because it depends on mac_type */
969 if ((adapter->hw.mac_type == e1000_ich8lan) &&
970 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
971 adapter->hw.flash_address =
972 ioremap(pci_resource_start(pdev, 1),
973 pci_resource_len(pdev, 1));
974 if (!adapter->hw.flash_address)
978 if (e1000_check_phy_reset_block(&adapter->hw))
979 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
981 if (adapter->hw.mac_type >= e1000_82543) {
982 netdev->features = NETIF_F_SG |
986 NETIF_F_HW_VLAN_FILTER;
987 if (adapter->hw.mac_type == e1000_ich8lan)
988 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
991 if ((adapter->hw.mac_type >= e1000_82544) &&
992 (adapter->hw.mac_type != e1000_82547))
993 netdev->features |= NETIF_F_TSO;
995 if (adapter->hw.mac_type > e1000_82547_rev_2)
996 netdev->features |= NETIF_F_TSO6;
998 netdev->features |= NETIF_F_HIGHDMA;
1000 netdev->features |= NETIF_F_LLTX;
1002 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1004 /* initialize eeprom parameters */
1005 if (e1000_init_eeprom_params(&adapter->hw)) {
1006 E1000_ERR("EEPROM initialization failed\n");
1010 /* before reading the EEPROM, reset the controller to
1011 * put the device in a known good starting state */
1013 e1000_reset_hw(&adapter->hw);
1015 /* make sure the EEPROM is good */
1016 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
1017 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1018 e1000_dump_eeprom(adapter);
1020 * set MAC address to all zeroes to invalidate and temporary
1021 * disable this device for the user. This blocks regular
1022 * traffic while still permitting ethtool ioctls from reaching
1023 * the hardware as well as allowing the user to run the
1024 * interface after manually setting a hw addr using
1027 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1029 /* copy the MAC address out of the EEPROM */
1030 if (e1000_read_mac_addr(&adapter->hw))
1031 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1033 /* don't block initalization here due to bad MAC address */
1034 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
1035 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
1037 if (!is_valid_ether_addr(netdev->perm_addr))
1038 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1040 e1000_get_bus_info(&adapter->hw);
1042 init_timer(&adapter->tx_fifo_stall_timer);
1043 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1044 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1046 init_timer(&adapter->watchdog_timer);
1047 adapter->watchdog_timer.function = &e1000_watchdog;
1048 adapter->watchdog_timer.data = (unsigned long) adapter;
1050 init_timer(&adapter->phy_info_timer);
1051 adapter->phy_info_timer.function = &e1000_update_phy_info;
1052 adapter->phy_info_timer.data = (unsigned long) adapter;
1054 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1056 e1000_check_options(adapter);
1058 /* Initial Wake on LAN setting
1059 * If APM wake is enabled in the EEPROM,
1060 * enable the ACPI Magic Packet filter
1063 switch (adapter->hw.mac_type) {
1064 case e1000_82542_rev2_0:
1065 case e1000_82542_rev2_1:
1069 e1000_read_eeprom(&adapter->hw,
1070 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1071 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1074 e1000_read_eeprom(&adapter->hw,
1075 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1076 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1079 case e1000_82546_rev_3:
1081 case e1000_80003es2lan:
1082 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
1083 e1000_read_eeprom(&adapter->hw,
1084 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1089 e1000_read_eeprom(&adapter->hw,
1090 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1093 if (eeprom_data & eeprom_apme_mask)
1094 adapter->eeprom_wol |= E1000_WUFC_MAG;
1096 /* now that we have the eeprom settings, apply the special cases
1097 * where the eeprom may be wrong or the board simply won't support
1098 * wake on lan on a particular port */
1099 switch (pdev->device) {
1100 case E1000_DEV_ID_82546GB_PCIE:
1101 adapter->eeprom_wol = 0;
1103 case E1000_DEV_ID_82546EB_FIBER:
1104 case E1000_DEV_ID_82546GB_FIBER:
1105 case E1000_DEV_ID_82571EB_FIBER:
1106 /* Wake events only supported on port A for dual fiber
1107 * regardless of eeprom setting */
1108 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1109 adapter->eeprom_wol = 0;
1111 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1112 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1113 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1114 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1115 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1116 /* if quad port adapter, disable WoL on all but port A */
1117 if (global_quad_port_a != 0)
1118 adapter->eeprom_wol = 0;
1120 adapter->quad_port_a = 1;
1121 /* Reset for multiple quad port adapters */
1122 if (++global_quad_port_a == 4)
1123 global_quad_port_a = 0;
1127 /* initialize the wol settings based on the eeprom settings */
1128 adapter->wol = adapter->eeprom_wol;
1130 /* print bus type/speed/width info */
1132 struct e1000_hw *hw = &adapter->hw;
1133 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1134 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1135 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1136 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1137 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1138 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1139 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1140 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1141 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1142 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1143 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1147 printk("%s\n", print_mac(mac, netdev->dev_addr));
1149 if (adapter->hw.bus_type == e1000_bus_type_pci_express) {
1150 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1151 "longer be supported by this driver in the future.\n",
1152 pdev->vendor, pdev->device);
1153 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1154 "driver instead.\n");
1157 /* reset the hardware with the new settings */
1158 e1000_reset(adapter);
1160 /* If the controller is 82573 and f/w is AMT, do not set
1161 * DRV_LOAD until the interface is up. For all other cases,
1162 * let the f/w know that the h/w is now under the control
1164 if (adapter->hw.mac_type != e1000_82573 ||
1165 !e1000_check_mng_mode(&adapter->hw))
1166 e1000_get_hw_control(adapter);
1168 /* tell the stack to leave us alone until e1000_open() is called */
1169 netif_carrier_off(netdev);
1170 netif_stop_queue(netdev);
1172 strcpy(netdev->name, "eth%d");
1173 if ((err = register_netdev(netdev)))
1176 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1182 e1000_release_hw_control(adapter);
1184 if (!e1000_check_phy_reset_block(&adapter->hw))
1185 e1000_phy_hw_reset(&adapter->hw);
1187 if (adapter->hw.flash_address)
1188 iounmap(adapter->hw.flash_address);
1190 #ifdef CONFIG_E1000_NAPI
1191 for (i = 0; i < adapter->num_rx_queues; i++)
1192 dev_put(&adapter->polling_netdev[i]);
1195 kfree(adapter->tx_ring);
1196 kfree(adapter->rx_ring);
1197 #ifdef CONFIG_E1000_NAPI
1198 kfree(adapter->polling_netdev);
1201 iounmap(adapter->hw.hw_addr);
1203 free_netdev(netdev);
1205 pci_release_regions(pdev);
1208 pci_disable_device(pdev);
1213 * e1000_remove - Device Removal Routine
1214 * @pdev: PCI device information struct
1216 * e1000_remove is called by the PCI subsystem to alert the driver
1217 * that it should release a PCI device. The could be caused by a
1218 * Hot-Plug event, or because the driver is going to be removed from
1222 static void __devexit e1000_remove(struct pci_dev *pdev)
1224 struct net_device *netdev = pci_get_drvdata(pdev);
1225 struct e1000_adapter *adapter = netdev_priv(netdev);
1226 #ifdef CONFIG_E1000_NAPI
1230 cancel_work_sync(&adapter->reset_task);
1232 e1000_release_manageability(adapter);
1234 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1235 * would have already happened in close and is redundant. */
1236 e1000_release_hw_control(adapter);
1238 #ifdef CONFIG_E1000_NAPI
1239 for (i = 0; i < adapter->num_rx_queues; i++)
1240 dev_put(&adapter->polling_netdev[i]);
1243 unregister_netdev(netdev);
1245 if (!e1000_check_phy_reset_block(&adapter->hw))
1246 e1000_phy_hw_reset(&adapter->hw);
1248 kfree(adapter->tx_ring);
1249 kfree(adapter->rx_ring);
1250 #ifdef CONFIG_E1000_NAPI
1251 kfree(adapter->polling_netdev);
1254 iounmap(adapter->hw.hw_addr);
1255 if (adapter->hw.flash_address)
1256 iounmap(adapter->hw.flash_address);
1257 pci_release_regions(pdev);
1259 free_netdev(netdev);
1261 pci_disable_device(pdev);
1265 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1266 * @adapter: board private structure to initialize
1268 * e1000_sw_init initializes the Adapter private data structure.
1269 * Fields are initialized based on PCI device information and
1270 * OS network device settings (MTU size).
1273 static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
1275 struct e1000_hw *hw = &adapter->hw;
1276 struct net_device *netdev = adapter->netdev;
1277 struct pci_dev *pdev = adapter->pdev;
1278 #ifdef CONFIG_E1000_NAPI
1282 /* PCI config space info */
1284 hw->vendor_id = pdev->vendor;
1285 hw->device_id = pdev->device;
1286 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1287 hw->subsystem_id = pdev->subsystem_device;
1288 hw->revision_id = pdev->revision;
1290 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1292 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1293 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1294 hw->max_frame_size = netdev->mtu +
1295 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1296 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1298 /* identify the MAC */
1300 if (e1000_set_mac_type(hw)) {
1301 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1305 switch (hw->mac_type) {
1310 case e1000_82541_rev_2:
1311 case e1000_82547_rev_2:
1312 hw->phy_init_script = 1;
1316 e1000_set_media_type(hw);
1318 hw->wait_autoneg_complete = false;
1319 hw->tbi_compatibility_en = true;
1320 hw->adaptive_ifs = true;
1322 /* Copper options */
1324 if (hw->media_type == e1000_media_type_copper) {
1325 hw->mdix = AUTO_ALL_MODES;
1326 hw->disable_polarity_correction = false;
1327 hw->master_slave = E1000_MASTER_SLAVE;
1330 adapter->num_tx_queues = 1;
1331 adapter->num_rx_queues = 1;
1333 if (e1000_alloc_queues(adapter)) {
1334 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1338 #ifdef CONFIG_E1000_NAPI
1339 for (i = 0; i < adapter->num_rx_queues; i++) {
1340 adapter->polling_netdev[i].priv = adapter;
1341 dev_hold(&adapter->polling_netdev[i]);
1342 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1344 spin_lock_init(&adapter->tx_queue_lock);
1347 /* Explicitly disable IRQ since the NIC can be in any state. */
1348 e1000_irq_disable(adapter);
1350 spin_lock_init(&adapter->stats_lock);
1352 set_bit(__E1000_DOWN, &adapter->flags);
1358 * e1000_alloc_queues - Allocate memory for all rings
1359 * @adapter: board private structure to initialize
1361 * We allocate one ring per queue at run-time since we don't know the
1362 * number of queues at compile-time. The polling_netdev array is
1363 * intended for Multiqueue, but should work fine with a single queue.
1366 static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
1368 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1369 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1370 if (!adapter->tx_ring)
1373 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1374 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1375 if (!adapter->rx_ring) {
1376 kfree(adapter->tx_ring);
1380 #ifdef CONFIG_E1000_NAPI
1381 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1382 sizeof(struct net_device),
1384 if (!adapter->polling_netdev) {
1385 kfree(adapter->tx_ring);
1386 kfree(adapter->rx_ring);
1391 return E1000_SUCCESS;
1395 * e1000_open - Called when a network interface is made active
1396 * @netdev: network interface device structure
1398 * Returns 0 on success, negative value on failure
1400 * The open entry point is called when a network interface is made
1401 * active by the system (IFF_UP). At this point all resources needed
1402 * for transmit and receive operations are allocated, the interrupt
1403 * handler is registered with the OS, the watchdog timer is started,
1404 * and the stack is notified that the interface is ready.
1407 static int e1000_open(struct net_device *netdev)
1409 struct e1000_adapter *adapter = netdev_priv(netdev);
1412 /* disallow open during test */
1413 if (test_bit(__E1000_TESTING, &adapter->flags))
1416 /* allocate transmit descriptors */
1417 err = e1000_setup_all_tx_resources(adapter);
1421 /* allocate receive descriptors */
1422 err = e1000_setup_all_rx_resources(adapter);
1426 e1000_power_up_phy(adapter);
1428 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1429 if ((adapter->hw.mng_cookie.status &
1430 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1431 e1000_update_mng_vlan(adapter);
1434 /* If AMT is enabled, let the firmware know that the network
1435 * interface is now open */
1436 if (adapter->hw.mac_type == e1000_82573 &&
1437 e1000_check_mng_mode(&adapter->hw))
1438 e1000_get_hw_control(adapter);
1440 /* before we allocate an interrupt, we must be ready to handle it.
1441 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1442 * as soon as we call pci_request_irq, so we have to setup our
1443 * clean_rx handler before we do so. */
1444 e1000_configure(adapter);
1446 err = e1000_request_irq(adapter);
1450 /* From here on the code is the same as e1000_up() */
1451 clear_bit(__E1000_DOWN, &adapter->flags);
1453 #ifdef CONFIG_E1000_NAPI
1454 napi_enable(&adapter->napi);
1457 e1000_irq_enable(adapter);
1459 netif_start_queue(netdev);
1461 /* fire a link status change interrupt to start the watchdog */
1462 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1464 return E1000_SUCCESS;
1467 e1000_release_hw_control(adapter);
1468 e1000_power_down_phy(adapter);
1469 e1000_free_all_rx_resources(adapter);
1471 e1000_free_all_tx_resources(adapter);
1473 e1000_reset(adapter);
1479 * e1000_close - Disables a network interface
1480 * @netdev: network interface device structure
1482 * Returns 0, this is not allowed to fail
1484 * The close entry point is called when an interface is de-activated
1485 * by the OS. The hardware is still under the drivers control, but
1486 * needs to be disabled. A global MAC reset is issued to stop the
1487 * hardware, and all transmit and receive resources are freed.
1490 static int e1000_close(struct net_device *netdev)
1492 struct e1000_adapter *adapter = netdev_priv(netdev);
1494 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1495 e1000_down(adapter);
1496 e1000_power_down_phy(adapter);
1497 e1000_free_irq(adapter);
1499 e1000_free_all_tx_resources(adapter);
1500 e1000_free_all_rx_resources(adapter);
1502 /* kill manageability vlan ID if supported, but not if a vlan with
1503 * the same ID is registered on the host OS (let 8021q kill it) */
1504 if ((adapter->hw.mng_cookie.status &
1505 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1507 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1508 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1511 /* If AMT is enabled, let the firmware know that the network
1512 * interface is now closed */
1513 if (adapter->hw.mac_type == e1000_82573 &&
1514 e1000_check_mng_mode(&adapter->hw))
1515 e1000_release_hw_control(adapter);
1521 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1522 * @adapter: address of board private structure
1523 * @start: address of beginning of memory
1524 * @len: length of memory
1526 static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1529 unsigned long begin = (unsigned long) start;
1530 unsigned long end = begin + len;
1532 /* First rev 82545 and 82546 need to not allow any memory
1533 * write location to cross 64k boundary due to errata 23 */
1534 if (adapter->hw.mac_type == e1000_82545 ||
1535 adapter->hw.mac_type == e1000_82546) {
1536 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1543 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1544 * @adapter: board private structure
1545 * @txdr: tx descriptor ring (for a specific queue) to setup
1547 * Return 0 on success, negative on failure
1550 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1551 struct e1000_tx_ring *txdr)
1553 struct pci_dev *pdev = adapter->pdev;
1556 size = sizeof(struct e1000_buffer) * txdr->count;
1557 txdr->buffer_info = vmalloc(size);
1558 if (!txdr->buffer_info) {
1560 "Unable to allocate memory for the transmit descriptor ring\n");
1563 memset(txdr->buffer_info, 0, size);
1565 /* round up to nearest 4K */
1567 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1568 txdr->size = ALIGN(txdr->size, 4096);
1570 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1573 vfree(txdr->buffer_info);
1575 "Unable to allocate memory for the transmit descriptor ring\n");
1579 /* Fix for errata 23, can't cross 64kB boundary */
1580 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1581 void *olddesc = txdr->desc;
1582 dma_addr_t olddma = txdr->dma;
1583 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1584 "at %p\n", txdr->size, txdr->desc);
1585 /* Try again, without freeing the previous */
1586 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1587 /* Failed allocation, critical failure */
1589 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1590 goto setup_tx_desc_die;
1593 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1595 pci_free_consistent(pdev, txdr->size, txdr->desc,
1597 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1599 "Unable to allocate aligned memory "
1600 "for the transmit descriptor ring\n");
1601 vfree(txdr->buffer_info);
1604 /* Free old allocation, new allocation was successful */
1605 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1608 memset(txdr->desc, 0, txdr->size);
1610 txdr->next_to_use = 0;
1611 txdr->next_to_clean = 0;
1612 spin_lock_init(&txdr->tx_lock);
1618 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1619 * (Descriptors) for all queues
1620 * @adapter: board private structure
1622 * Return 0 on success, negative on failure
1625 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1629 for (i = 0; i < adapter->num_tx_queues; i++) {
1630 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1633 "Allocation for Tx Queue %u failed\n", i);
1634 for (i-- ; i >= 0; i--)
1635 e1000_free_tx_resources(adapter,
1636 &adapter->tx_ring[i]);
1645 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1646 * @adapter: board private structure
1648 * Configure the Tx unit of the MAC after a reset.
1651 static void e1000_configure_tx(struct e1000_adapter *adapter)
1654 struct e1000_hw *hw = &adapter->hw;
1655 u32 tdlen, tctl, tipg, tarc;
1658 /* Setup the HW Tx Head and Tail descriptor pointers */
1660 switch (adapter->num_tx_queues) {
1663 tdba = adapter->tx_ring[0].dma;
1664 tdlen = adapter->tx_ring[0].count *
1665 sizeof(struct e1000_tx_desc);
1666 E1000_WRITE_REG(hw, TDLEN, tdlen);
1667 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1668 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1669 E1000_WRITE_REG(hw, TDT, 0);
1670 E1000_WRITE_REG(hw, TDH, 0);
1671 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1672 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1676 /* Set the default values for the Tx Inter Packet Gap timer */
1677 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1678 (hw->media_type == e1000_media_type_fiber ||
1679 hw->media_type == e1000_media_type_internal_serdes))
1680 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1682 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1684 switch (hw->mac_type) {
1685 case e1000_82542_rev2_0:
1686 case e1000_82542_rev2_1:
1687 tipg = DEFAULT_82542_TIPG_IPGT;
1688 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1689 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1691 case e1000_80003es2lan:
1692 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1693 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1696 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1697 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1700 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1701 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1702 E1000_WRITE_REG(hw, TIPG, tipg);
1704 /* Set the Tx Interrupt Delay register */
1706 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1707 if (hw->mac_type >= e1000_82540)
1708 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1710 /* Program the Transmit Control Register */
1712 tctl = E1000_READ_REG(hw, TCTL);
1713 tctl &= ~E1000_TCTL_CT;
1714 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1715 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1717 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1718 tarc = E1000_READ_REG(hw, TARC0);
1719 /* set the speed mode bit, we'll clear it if we're not at
1720 * gigabit link later */
1722 E1000_WRITE_REG(hw, TARC0, tarc);
1723 } else if (hw->mac_type == e1000_80003es2lan) {
1724 tarc = E1000_READ_REG(hw, TARC0);
1726 E1000_WRITE_REG(hw, TARC0, tarc);
1727 tarc = E1000_READ_REG(hw, TARC1);
1729 E1000_WRITE_REG(hw, TARC1, tarc);
1732 e1000_config_collision_dist(hw);
1734 /* Setup Transmit Descriptor Settings for eop descriptor */
1735 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1737 /* only set IDE if we are delaying interrupts using the timers */
1738 if (adapter->tx_int_delay)
1739 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1741 if (hw->mac_type < e1000_82543)
1742 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1744 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1746 /* Cache if we're 82544 running in PCI-X because we'll
1747 * need this to apply a workaround later in the send path. */
1748 if (hw->mac_type == e1000_82544 &&
1749 hw->bus_type == e1000_bus_type_pcix)
1750 adapter->pcix_82544 = 1;
1752 E1000_WRITE_REG(hw, TCTL, tctl);
1757 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1758 * @adapter: board private structure
1759 * @rxdr: rx descriptor ring (for a specific queue) to setup
1761 * Returns 0 on success, negative on failure
1764 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1765 struct e1000_rx_ring *rxdr)
1767 struct pci_dev *pdev = adapter->pdev;
1770 size = sizeof(struct e1000_buffer) * rxdr->count;
1771 rxdr->buffer_info = vmalloc(size);
1772 if (!rxdr->buffer_info) {
1774 "Unable to allocate memory for the receive descriptor ring\n");
1777 memset(rxdr->buffer_info, 0, size);
1779 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1781 if (!rxdr->ps_page) {
1782 vfree(rxdr->buffer_info);
1784 "Unable to allocate memory for the receive descriptor ring\n");
1788 rxdr->ps_page_dma = kcalloc(rxdr->count,
1789 sizeof(struct e1000_ps_page_dma),
1791 if (!rxdr->ps_page_dma) {
1792 vfree(rxdr->buffer_info);
1793 kfree(rxdr->ps_page);
1795 "Unable to allocate memory for the receive descriptor ring\n");
1799 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1800 desc_len = sizeof(struct e1000_rx_desc);
1802 desc_len = sizeof(union e1000_rx_desc_packet_split);
1804 /* Round up to nearest 4K */
1806 rxdr->size = rxdr->count * desc_len;
1807 rxdr->size = ALIGN(rxdr->size, 4096);
1809 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1813 "Unable to allocate memory for the receive descriptor ring\n");
1815 vfree(rxdr->buffer_info);
1816 kfree(rxdr->ps_page);
1817 kfree(rxdr->ps_page_dma);
1821 /* Fix for errata 23, can't cross 64kB boundary */
1822 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1823 void *olddesc = rxdr->desc;
1824 dma_addr_t olddma = rxdr->dma;
1825 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1826 "at %p\n", rxdr->size, rxdr->desc);
1827 /* Try again, without freeing the previous */
1828 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1829 /* Failed allocation, critical failure */
1831 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1833 "Unable to allocate memory "
1834 "for the receive descriptor ring\n");
1835 goto setup_rx_desc_die;
1838 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1840 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1842 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1844 "Unable to allocate aligned memory "
1845 "for the receive descriptor ring\n");
1846 goto setup_rx_desc_die;
1848 /* Free old allocation, new allocation was successful */
1849 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1852 memset(rxdr->desc, 0, rxdr->size);
1854 rxdr->next_to_clean = 0;
1855 rxdr->next_to_use = 0;
1861 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1862 * (Descriptors) for all queues
1863 * @adapter: board private structure
1865 * Return 0 on success, negative on failure
1868 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1872 for (i = 0; i < adapter->num_rx_queues; i++) {
1873 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1876 "Allocation for Rx Queue %u failed\n", i);
1877 for (i-- ; i >= 0; i--)
1878 e1000_free_rx_resources(adapter,
1879 &adapter->rx_ring[i]);
1888 * e1000_setup_rctl - configure the receive control registers
1889 * @adapter: Board private structure
1891 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1892 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1893 static void e1000_setup_rctl(struct e1000_adapter *adapter)
1897 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1901 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1903 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1905 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1906 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1907 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1909 if (adapter->hw.tbi_compatibility_on == 1)
1910 rctl |= E1000_RCTL_SBP;
1912 rctl &= ~E1000_RCTL_SBP;
1914 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1915 rctl &= ~E1000_RCTL_LPE;
1917 rctl |= E1000_RCTL_LPE;
1919 /* Setup buffer sizes */
1920 rctl &= ~E1000_RCTL_SZ_4096;
1921 rctl |= E1000_RCTL_BSEX;
1922 switch (adapter->rx_buffer_len) {
1923 case E1000_RXBUFFER_256:
1924 rctl |= E1000_RCTL_SZ_256;
1925 rctl &= ~E1000_RCTL_BSEX;
1927 case E1000_RXBUFFER_512:
1928 rctl |= E1000_RCTL_SZ_512;
1929 rctl &= ~E1000_RCTL_BSEX;
1931 case E1000_RXBUFFER_1024:
1932 rctl |= E1000_RCTL_SZ_1024;
1933 rctl &= ~E1000_RCTL_BSEX;
1935 case E1000_RXBUFFER_2048:
1937 rctl |= E1000_RCTL_SZ_2048;
1938 rctl &= ~E1000_RCTL_BSEX;
1940 case E1000_RXBUFFER_4096:
1941 rctl |= E1000_RCTL_SZ_4096;
1943 case E1000_RXBUFFER_8192:
1944 rctl |= E1000_RCTL_SZ_8192;
1946 case E1000_RXBUFFER_16384:
1947 rctl |= E1000_RCTL_SZ_16384;
1951 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1952 /* 82571 and greater support packet-split where the protocol
1953 * header is placed in skb->data and the packet data is
1954 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1955 * In the case of a non-split, skb->data is linearly filled,
1956 * followed by the page buffers. Therefore, skb->data is
1957 * sized to hold the largest protocol header.
1959 /* allocations using alloc_page take too long for regular MTU
1960 * so only enable packet split for jumbo frames */
1961 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1962 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1963 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
1964 adapter->rx_ps_pages = pages;
1966 adapter->rx_ps_pages = 0;
1968 if (adapter->rx_ps_pages) {
1969 /* Configure extra packet-split registers */
1970 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1971 rfctl |= E1000_RFCTL_EXTEN;
1972 /* disable packet split support for IPv6 extension headers,
1973 * because some malformed IPv6 headers can hang the RX */
1974 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1975 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1977 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1979 rctl |= E1000_RCTL_DTYP_PS;
1981 psrctl |= adapter->rx_ps_bsize0 >>
1982 E1000_PSRCTL_BSIZE0_SHIFT;
1984 switch (adapter->rx_ps_pages) {
1986 psrctl |= PAGE_SIZE <<
1987 E1000_PSRCTL_BSIZE3_SHIFT;
1989 psrctl |= PAGE_SIZE <<
1990 E1000_PSRCTL_BSIZE2_SHIFT;
1992 psrctl |= PAGE_SIZE >>
1993 E1000_PSRCTL_BSIZE1_SHIFT;
1997 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
2000 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2004 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2005 * @adapter: board private structure
2007 * Configure the Rx unit of the MAC after a reset.
2010 static void e1000_configure_rx(struct e1000_adapter *adapter)
2013 struct e1000_hw *hw = &adapter->hw;
2014 u32 rdlen, rctl, rxcsum, ctrl_ext;
2016 if (adapter->rx_ps_pages) {
2017 /* this is a 32 byte descriptor */
2018 rdlen = adapter->rx_ring[0].count *
2019 sizeof(union e1000_rx_desc_packet_split);
2020 adapter->clean_rx = e1000_clean_rx_irq_ps;
2021 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2023 rdlen = adapter->rx_ring[0].count *
2024 sizeof(struct e1000_rx_desc);
2025 adapter->clean_rx = e1000_clean_rx_irq;
2026 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2029 /* disable receives while setting up the descriptors */
2030 rctl = E1000_READ_REG(hw, RCTL);
2031 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
2033 /* set the Receive Delay Timer Register */
2034 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
2036 if (hw->mac_type >= e1000_82540) {
2037 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
2038 if (adapter->itr_setting != 0)
2039 E1000_WRITE_REG(hw, ITR,
2040 1000000000 / (adapter->itr * 256));
2043 if (hw->mac_type >= e1000_82571) {
2044 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2045 /* Reset delay timers after every interrupt */
2046 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
2047 #ifdef CONFIG_E1000_NAPI
2048 /* Auto-Mask interrupts upon ICR access */
2049 ctrl_ext |= E1000_CTRL_EXT_IAME;
2050 E1000_WRITE_REG(hw, IAM, 0xffffffff);
2052 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2053 E1000_WRITE_FLUSH(hw);
2056 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2057 * the Base and Length of the Rx Descriptor Ring */
2058 switch (adapter->num_rx_queues) {
2061 rdba = adapter->rx_ring[0].dma;
2062 E1000_WRITE_REG(hw, RDLEN, rdlen);
2063 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2064 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
2065 E1000_WRITE_REG(hw, RDT, 0);
2066 E1000_WRITE_REG(hw, RDH, 0);
2067 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2068 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
2072 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2073 if (hw->mac_type >= e1000_82543) {
2074 rxcsum = E1000_READ_REG(hw, RXCSUM);
2075 if (adapter->rx_csum) {
2076 rxcsum |= E1000_RXCSUM_TUOFL;
2078 /* Enable 82571 IPv4 payload checksum for UDP fragments
2079 * Must be used in conjunction with packet-split. */
2080 if ((hw->mac_type >= e1000_82571) &&
2081 (adapter->rx_ps_pages)) {
2082 rxcsum |= E1000_RXCSUM_IPPCSE;
2085 rxcsum &= ~E1000_RXCSUM_TUOFL;
2086 /* don't need to clear IPPCSE as it defaults to 0 */
2088 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
2091 /* enable early receives on 82573, only takes effect if using > 2048
2092 * byte total frame size. for example only for jumbo frames */
2093 #define E1000_ERT_2048 0x100
2094 if (hw->mac_type == e1000_82573)
2095 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2097 /* Enable Receives */
2098 E1000_WRITE_REG(hw, RCTL, rctl);
2102 * e1000_free_tx_resources - Free Tx Resources per Queue
2103 * @adapter: board private structure
2104 * @tx_ring: Tx descriptor ring for a specific queue
2106 * Free all transmit software resources
2109 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2110 struct e1000_tx_ring *tx_ring)
2112 struct pci_dev *pdev = adapter->pdev;
2114 e1000_clean_tx_ring(adapter, tx_ring);
2116 vfree(tx_ring->buffer_info);
2117 tx_ring->buffer_info = NULL;
2119 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2121 tx_ring->desc = NULL;
2125 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2126 * @adapter: board private structure
2128 * Free all transmit software resources
2131 void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
2135 for (i = 0; i < adapter->num_tx_queues; i++)
2136 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
2139 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2140 struct e1000_buffer *buffer_info)
2142 if (buffer_info->dma) {
2143 pci_unmap_page(adapter->pdev,
2145 buffer_info->length,
2147 buffer_info->dma = 0;
2149 if (buffer_info->skb) {
2150 dev_kfree_skb_any(buffer_info->skb);
2151 buffer_info->skb = NULL;
2153 /* buffer_info must be completely set up in the transmit path */
2157 * e1000_clean_tx_ring - Free Tx Buffers
2158 * @adapter: board private structure
2159 * @tx_ring: ring to be cleaned
2162 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2163 struct e1000_tx_ring *tx_ring)
2165 struct e1000_buffer *buffer_info;
2169 /* Free all the Tx ring sk_buffs */
2171 for (i = 0; i < tx_ring->count; i++) {
2172 buffer_info = &tx_ring->buffer_info[i];
2173 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2176 size = sizeof(struct e1000_buffer) * tx_ring->count;
2177 memset(tx_ring->buffer_info, 0, size);
2179 /* Zero out the descriptor ring */
2181 memset(tx_ring->desc, 0, tx_ring->size);
2183 tx_ring->next_to_use = 0;
2184 tx_ring->next_to_clean = 0;
2185 tx_ring->last_tx_tso = 0;
2187 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2188 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2192 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2193 * @adapter: board private structure
2196 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2200 for (i = 0; i < adapter->num_tx_queues; i++)
2201 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2205 * e1000_free_rx_resources - Free Rx Resources
2206 * @adapter: board private structure
2207 * @rx_ring: ring to clean the resources from
2209 * Free all receive software resources
2212 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2213 struct e1000_rx_ring *rx_ring)
2215 struct pci_dev *pdev = adapter->pdev;
2217 e1000_clean_rx_ring(adapter, rx_ring);
2219 vfree(rx_ring->buffer_info);
2220 rx_ring->buffer_info = NULL;
2221 kfree(rx_ring->ps_page);
2222 rx_ring->ps_page = NULL;
2223 kfree(rx_ring->ps_page_dma);
2224 rx_ring->ps_page_dma = NULL;
2226 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2228 rx_ring->desc = NULL;
2232 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2233 * @adapter: board private structure
2235 * Free all receive software resources
2238 void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2242 for (i = 0; i < adapter->num_rx_queues; i++)
2243 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2247 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2248 * @adapter: board private structure
2249 * @rx_ring: ring to free buffers from
2252 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2253 struct e1000_rx_ring *rx_ring)
2255 struct e1000_buffer *buffer_info;
2256 struct e1000_ps_page *ps_page;
2257 struct e1000_ps_page_dma *ps_page_dma;
2258 struct pci_dev *pdev = adapter->pdev;
2262 /* Free all the Rx ring sk_buffs */
2263 for (i = 0; i < rx_ring->count; i++) {
2264 buffer_info = &rx_ring->buffer_info[i];
2265 if (buffer_info->skb) {
2266 pci_unmap_single(pdev,
2268 buffer_info->length,
2269 PCI_DMA_FROMDEVICE);
2271 dev_kfree_skb(buffer_info->skb);
2272 buffer_info->skb = NULL;
2274 ps_page = &rx_ring->ps_page[i];
2275 ps_page_dma = &rx_ring->ps_page_dma[i];
2276 for (j = 0; j < adapter->rx_ps_pages; j++) {
2277 if (!ps_page->ps_page[j]) break;
2278 pci_unmap_page(pdev,
2279 ps_page_dma->ps_page_dma[j],
2280 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2281 ps_page_dma->ps_page_dma[j] = 0;
2282 put_page(ps_page->ps_page[j]);
2283 ps_page->ps_page[j] = NULL;
2287 size = sizeof(struct e1000_buffer) * rx_ring->count;
2288 memset(rx_ring->buffer_info, 0, size);
2289 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2290 memset(rx_ring->ps_page, 0, size);
2291 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2292 memset(rx_ring->ps_page_dma, 0, size);
2294 /* Zero out the descriptor ring */
2296 memset(rx_ring->desc, 0, rx_ring->size);
2298 rx_ring->next_to_clean = 0;
2299 rx_ring->next_to_use = 0;
2301 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2302 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2306 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2307 * @adapter: board private structure
2310 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2314 for (i = 0; i < adapter->num_rx_queues; i++)
2315 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2318 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2319 * and memory write and invalidate disabled for certain operations
2321 static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2323 struct net_device *netdev = adapter->netdev;
2326 e1000_pci_clear_mwi(&adapter->hw);
2328 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2329 rctl |= E1000_RCTL_RST;
2330 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2331 E1000_WRITE_FLUSH(&adapter->hw);
2334 if (netif_running(netdev))
2335 e1000_clean_all_rx_rings(adapter);
2338 static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2340 struct net_device *netdev = adapter->netdev;
2343 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2344 rctl &= ~E1000_RCTL_RST;
2345 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2346 E1000_WRITE_FLUSH(&adapter->hw);
2349 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2350 e1000_pci_set_mwi(&adapter->hw);
2352 if (netif_running(netdev)) {
2353 /* No need to loop, because 82542 supports only 1 queue */
2354 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2355 e1000_configure_rx(adapter);
2356 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2361 * e1000_set_mac - Change the Ethernet Address of the NIC
2362 * @netdev: network interface device structure
2363 * @p: pointer to an address structure
2365 * Returns 0 on success, negative on failure
2368 static int e1000_set_mac(struct net_device *netdev, void *p)
2370 struct e1000_adapter *adapter = netdev_priv(netdev);
2371 struct sockaddr *addr = p;
2373 if (!is_valid_ether_addr(addr->sa_data))
2374 return -EADDRNOTAVAIL;
2376 /* 82542 2.0 needs to be in reset to write receive address registers */
2378 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2379 e1000_enter_82542_rst(adapter);
2381 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2382 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2384 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2386 /* With 82571 controllers, LAA may be overwritten (with the default)
2387 * due to controller reset from the other port. */
2388 if (adapter->hw.mac_type == e1000_82571) {
2389 /* activate the work around */
2390 adapter->hw.laa_is_present = 1;
2392 /* Hold a copy of the LAA in RAR[14] This is done so that
2393 * between the time RAR[0] gets clobbered and the time it
2394 * gets fixed (in e1000_watchdog), the actual LAA is in one
2395 * of the RARs and no incoming packets directed to this port
2396 * are dropped. Eventaully the LAA will be in RAR[0] and
2398 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2399 E1000_RAR_ENTRIES - 1);
2402 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2403 e1000_leave_82542_rst(adapter);
2409 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2410 * @netdev: network interface device structure
2412 * The set_rx_mode entry point is called whenever the unicast or multicast
2413 * address lists or the network interface flags are updated. This routine is
2414 * responsible for configuring the hardware for proper unicast, multicast,
2415 * promiscuous mode, and all-multi behavior.
2418 static void e1000_set_rx_mode(struct net_device *netdev)
2420 struct e1000_adapter *adapter = netdev_priv(netdev);
2421 struct e1000_hw *hw = &adapter->hw;
2422 struct dev_addr_list *uc_ptr;
2423 struct dev_addr_list *mc_ptr;
2426 int i, rar_entries = E1000_RAR_ENTRIES;
2427 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2428 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2429 E1000_NUM_MTA_REGISTERS;
2431 if (adapter->hw.mac_type == e1000_ich8lan)
2432 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2434 /* reserve RAR[14] for LAA over-write work-around */
2435 if (adapter->hw.mac_type == e1000_82571)
2438 /* Check for Promiscuous and All Multicast modes */
2440 rctl = E1000_READ_REG(hw, RCTL);
2442 if (netdev->flags & IFF_PROMISC) {
2443 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2444 rctl &= ~E1000_RCTL_VFE;
2446 if (netdev->flags & IFF_ALLMULTI) {
2447 rctl |= E1000_RCTL_MPE;
2449 rctl &= ~E1000_RCTL_MPE;
2451 if (adapter->hw.mac_type != e1000_ich8lan)
2452 rctl |= E1000_RCTL_VFE;
2456 if (netdev->uc_count > rar_entries - 1) {
2457 rctl |= E1000_RCTL_UPE;
2458 } else if (!(netdev->flags & IFF_PROMISC)) {
2459 rctl &= ~E1000_RCTL_UPE;
2460 uc_ptr = netdev->uc_list;
2463 E1000_WRITE_REG(hw, RCTL, rctl);
2465 /* 82542 2.0 needs to be in reset to write receive address registers */
2467 if (hw->mac_type == e1000_82542_rev2_0)
2468 e1000_enter_82542_rst(adapter);
2470 /* load the first 14 addresses into the exact filters 1-14. Unicast
2471 * addresses take precedence to avoid disabling unicast filtering
2474 * RAR 0 is used for the station MAC adddress
2475 * if there are not 14 addresses, go ahead and clear the filters
2476 * -- with 82571 controllers only 0-13 entries are filled here
2478 mc_ptr = netdev->mc_list;
2480 for (i = 1; i < rar_entries; i++) {
2482 e1000_rar_set(hw, uc_ptr->da_addr, i);
2483 uc_ptr = uc_ptr->next;
2484 } else if (mc_ptr) {
2485 e1000_rar_set(hw, mc_ptr->da_addr, i);
2486 mc_ptr = mc_ptr->next;
2488 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2489 E1000_WRITE_FLUSH(hw);
2490 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2491 E1000_WRITE_FLUSH(hw);
2494 WARN_ON(uc_ptr != NULL);
2496 /* clear the old settings from the multicast hash table */
2498 for (i = 0; i < mta_reg_count; i++) {
2499 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2500 E1000_WRITE_FLUSH(hw);
2503 /* load any remaining addresses into the hash table */
2505 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2506 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
2507 e1000_mta_set(hw, hash_value);
2510 if (hw->mac_type == e1000_82542_rev2_0)
2511 e1000_leave_82542_rst(adapter);
2514 /* Need to wait a few seconds after link up to get diagnostic information from
2517 static void e1000_update_phy_info(unsigned long data)
2519 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2520 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2524 * e1000_82547_tx_fifo_stall - Timer Call-back
2525 * @data: pointer to adapter cast into an unsigned long
2528 static void e1000_82547_tx_fifo_stall(unsigned long data)
2530 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2531 struct net_device *netdev = adapter->netdev;
2534 if (atomic_read(&adapter->tx_fifo_stall)) {
2535 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2536 E1000_READ_REG(&adapter->hw, TDH)) &&
2537 (E1000_READ_REG(&adapter->hw, TDFT) ==
2538 E1000_READ_REG(&adapter->hw, TDFH)) &&
2539 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2540 E1000_READ_REG(&adapter->hw, TDFHS))) {
2541 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2542 E1000_WRITE_REG(&adapter->hw, TCTL,
2543 tctl & ~E1000_TCTL_EN);
2544 E1000_WRITE_REG(&adapter->hw, TDFT,
2545 adapter->tx_head_addr);
2546 E1000_WRITE_REG(&adapter->hw, TDFH,
2547 adapter->tx_head_addr);
2548 E1000_WRITE_REG(&adapter->hw, TDFTS,
2549 adapter->tx_head_addr);
2550 E1000_WRITE_REG(&adapter->hw, TDFHS,
2551 adapter->tx_head_addr);
2552 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2553 E1000_WRITE_FLUSH(&adapter->hw);
2555 adapter->tx_fifo_head = 0;
2556 atomic_set(&adapter->tx_fifo_stall, 0);
2557 netif_wake_queue(netdev);
2559 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2565 * e1000_watchdog - Timer Call-back
2566 * @data: pointer to adapter cast into an unsigned long
2568 static void e1000_watchdog(unsigned long data)
2570 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2571 struct net_device *netdev = adapter->netdev;
2572 struct e1000_tx_ring *txdr = adapter->tx_ring;
2576 ret_val = e1000_check_for_link(&adapter->hw);
2577 if ((ret_val == E1000_ERR_PHY) &&
2578 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2579 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2580 /* See e1000_kumeran_lock_loss_workaround() */
2582 "Gigabit has been disabled, downgrading speed\n");
2585 if (adapter->hw.mac_type == e1000_82573) {
2586 e1000_enable_tx_pkt_filtering(&adapter->hw);
2587 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2588 e1000_update_mng_vlan(adapter);
2591 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2592 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2593 link = !adapter->hw.serdes_link_down;
2595 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2598 if (!netif_carrier_ok(netdev)) {
2601 e1000_get_speed_and_duplex(&adapter->hw,
2602 &adapter->link_speed,
2603 &adapter->link_duplex);
2605 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2606 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2607 "Flow Control: %s\n",
2608 adapter->link_speed,
2609 adapter->link_duplex == FULL_DUPLEX ?
2610 "Full Duplex" : "Half Duplex",
2611 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2612 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2613 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2614 E1000_CTRL_TFCE) ? "TX" : "None" )));
2616 /* tweak tx_queue_len according to speed/duplex
2617 * and adjust the timeout factor */
2618 netdev->tx_queue_len = adapter->tx_queue_len;
2619 adapter->tx_timeout_factor = 1;
2620 switch (adapter->link_speed) {
2623 netdev->tx_queue_len = 10;
2624 adapter->tx_timeout_factor = 8;
2628 netdev->tx_queue_len = 100;
2629 /* maybe add some timeout factor ? */
2633 if ((adapter->hw.mac_type == e1000_82571 ||
2634 adapter->hw.mac_type == e1000_82572) &&
2637 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2638 tarc0 &= ~(1 << 21);
2639 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2642 /* disable TSO for pcie and 10/100 speeds, to avoid
2643 * some hardware issues */
2644 if (!adapter->tso_force &&
2645 adapter->hw.bus_type == e1000_bus_type_pci_express){
2646 switch (adapter->link_speed) {
2650 "10/100 speed: disabling TSO\n");
2651 netdev->features &= ~NETIF_F_TSO;
2652 netdev->features &= ~NETIF_F_TSO6;
2655 netdev->features |= NETIF_F_TSO;
2656 netdev->features |= NETIF_F_TSO6;
2664 /* enable transmits in the hardware, need to do this
2665 * after setting TARC0 */
2666 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2667 tctl |= E1000_TCTL_EN;
2668 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2670 netif_carrier_on(netdev);
2671 netif_wake_queue(netdev);
2672 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2673 adapter->smartspeed = 0;
2675 /* make sure the receive unit is started */
2676 if (adapter->hw.rx_needs_kicking) {
2677 struct e1000_hw *hw = &adapter->hw;
2678 u32 rctl = E1000_READ_REG(hw, RCTL);
2679 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2683 if (netif_carrier_ok(netdev)) {
2684 adapter->link_speed = 0;
2685 adapter->link_duplex = 0;
2686 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2687 netif_carrier_off(netdev);
2688 netif_stop_queue(netdev);
2689 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
2691 /* 80003ES2LAN workaround--
2692 * For packet buffer work-around on link down event;
2693 * disable receives in the ISR and
2694 * reset device here in the watchdog
2696 if (adapter->hw.mac_type == e1000_80003es2lan)
2698 schedule_work(&adapter->reset_task);
2701 e1000_smartspeed(adapter);
2704 e1000_update_stats(adapter);
2706 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2707 adapter->tpt_old = adapter->stats.tpt;
2708 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2709 adapter->colc_old = adapter->stats.colc;
2711 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2712 adapter->gorcl_old = adapter->stats.gorcl;
2713 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2714 adapter->gotcl_old = adapter->stats.gotcl;
2716 e1000_update_adaptive(&adapter->hw);
2718 if (!netif_carrier_ok(netdev)) {
2719 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2720 /* We've lost link, so the controller stops DMA,
2721 * but we've got queued Tx work that's never going
2722 * to get done, so reset controller to flush Tx.
2723 * (Do the reset outside of interrupt context). */
2724 adapter->tx_timeout_count++;
2725 schedule_work(&adapter->reset_task);
2729 /* Cause software interrupt to ensure rx ring is cleaned */
2730 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2732 /* Force detection of hung controller every watchdog period */
2733 adapter->detect_tx_hung = true;
2735 /* With 82571 controllers, LAA may be overwritten due to controller
2736 * reset from the other port. Set the appropriate LAA in RAR[0] */
2737 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2738 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2740 /* Reset the timer */
2741 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
2744 enum latency_range {
2748 latency_invalid = 255
2752 * e1000_update_itr - update the dynamic ITR value based on statistics
2753 * Stores a new ITR value based on packets and byte
2754 * counts during the last interrupt. The advantage of per interrupt
2755 * computation is faster updates and more accurate ITR for the current
2756 * traffic pattern. Constants in this function were computed
2757 * based on theoretical maximum wire speed and thresholds were set based
2758 * on testing data as well as attempting to minimize response time
2759 * while increasing bulk throughput.
2760 * this functionality is controlled by the InterruptThrottleRate module
2761 * parameter (see e1000_param.c)
2762 * @adapter: pointer to adapter
2763 * @itr_setting: current adapter->itr
2764 * @packets: the number of packets during this measurement interval
2765 * @bytes: the number of bytes during this measurement interval
2767 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2768 u16 itr_setting, int packets, int bytes)
2770 unsigned int retval = itr_setting;
2771 struct e1000_hw *hw = &adapter->hw;
2773 if (unlikely(hw->mac_type < e1000_82540))
2774 goto update_itr_done;
2777 goto update_itr_done;
2779 switch (itr_setting) {
2780 case lowest_latency:
2781 /* jumbo frames get bulk treatment*/
2782 if (bytes/packets > 8000)
2783 retval = bulk_latency;
2784 else if ((packets < 5) && (bytes > 512))
2785 retval = low_latency;
2787 case low_latency: /* 50 usec aka 20000 ints/s */
2788 if (bytes > 10000) {
2789 /* jumbo frames need bulk latency setting */
2790 if (bytes/packets > 8000)
2791 retval = bulk_latency;
2792 else if ((packets < 10) || ((bytes/packets) > 1200))
2793 retval = bulk_latency;
2794 else if ((packets > 35))
2795 retval = lowest_latency;
2796 } else if (bytes/packets > 2000)
2797 retval = bulk_latency;
2798 else if (packets <= 2 && bytes < 512)
2799 retval = lowest_latency;
2801 case bulk_latency: /* 250 usec aka 4000 ints/s */
2802 if (bytes > 25000) {
2804 retval = low_latency;
2805 } else if (bytes < 6000) {
2806 retval = low_latency;
2815 static void e1000_set_itr(struct e1000_adapter *adapter)
2817 struct e1000_hw *hw = &adapter->hw;
2819 u32 new_itr = adapter->itr;
2821 if (unlikely(hw->mac_type < e1000_82540))
2824 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2825 if (unlikely(adapter->link_speed != SPEED_1000)) {
2831 adapter->tx_itr = e1000_update_itr(adapter,
2833 adapter->total_tx_packets,
2834 adapter->total_tx_bytes);
2835 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2836 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2837 adapter->tx_itr = low_latency;
2839 adapter->rx_itr = e1000_update_itr(adapter,
2841 adapter->total_rx_packets,
2842 adapter->total_rx_bytes);
2843 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2844 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2845 adapter->rx_itr = low_latency;
2847 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2849 switch (current_itr) {
2850 /* counts and packets in update_itr are dependent on these numbers */
2851 case lowest_latency:
2855 new_itr = 20000; /* aka hwitr = ~200 */
2865 if (new_itr != adapter->itr) {
2866 /* this attempts to bias the interrupt rate towards Bulk
2867 * by adding intermediate steps when interrupt rate is
2869 new_itr = new_itr > adapter->itr ?
2870 min(adapter->itr + (new_itr >> 2), new_itr) :
2872 adapter->itr = new_itr;
2873 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2879 #define E1000_TX_FLAGS_CSUM 0x00000001
2880 #define E1000_TX_FLAGS_VLAN 0x00000002
2881 #define E1000_TX_FLAGS_TSO 0x00000004
2882 #define E1000_TX_FLAGS_IPV4 0x00000008
2883 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2884 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2886 static int e1000_tso(struct e1000_adapter *adapter,
2887 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2889 struct e1000_context_desc *context_desc;
2890 struct e1000_buffer *buffer_info;
2893 u16 ipcse = 0, tucse, mss;
2894 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2897 if (skb_is_gso(skb)) {
2898 if (skb_header_cloned(skb)) {
2899 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2904 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2905 mss = skb_shinfo(skb)->gso_size;
2906 if (skb->protocol == htons(ETH_P_IP)) {
2907 struct iphdr *iph = ip_hdr(skb);
2910 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2914 cmd_length = E1000_TXD_CMD_IP;
2915 ipcse = skb_transport_offset(skb) - 1;
2916 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2917 ipv6_hdr(skb)->payload_len = 0;
2918 tcp_hdr(skb)->check =
2919 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2920 &ipv6_hdr(skb)->daddr,
2924 ipcss = skb_network_offset(skb);
2925 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2926 tucss = skb_transport_offset(skb);
2927 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2930 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2931 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2933 i = tx_ring->next_to_use;
2934 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2935 buffer_info = &tx_ring->buffer_info[i];
2937 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2938 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2939 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2940 context_desc->upper_setup.tcp_fields.tucss = tucss;
2941 context_desc->upper_setup.tcp_fields.tucso = tucso;
2942 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2943 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2944 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2945 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2947 buffer_info->time_stamp = jiffies;
2948 buffer_info->next_to_watch = i;
2950 if (++i == tx_ring->count) i = 0;
2951 tx_ring->next_to_use = i;
2958 static bool e1000_tx_csum(struct e1000_adapter *adapter,
2959 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
2961 struct e1000_context_desc *context_desc;
2962 struct e1000_buffer *buffer_info;
2966 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
2967 css = skb_transport_offset(skb);
2969 i = tx_ring->next_to_use;
2970 buffer_info = &tx_ring->buffer_info[i];
2971 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2973 context_desc->lower_setup.ip_config = 0;
2974 context_desc->upper_setup.tcp_fields.tucss = css;
2975 context_desc->upper_setup.tcp_fields.tucso =
2976 css + skb->csum_offset;
2977 context_desc->upper_setup.tcp_fields.tucse = 0;
2978 context_desc->tcp_seg_setup.data = 0;
2979 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2981 buffer_info->time_stamp = jiffies;
2982 buffer_info->next_to_watch = i;
2984 if (unlikely(++i == tx_ring->count)) i = 0;
2985 tx_ring->next_to_use = i;
2993 #define E1000_MAX_TXD_PWR 12
2994 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2996 static int e1000_tx_map(struct e1000_adapter *adapter,
2997 struct e1000_tx_ring *tx_ring,
2998 struct sk_buff *skb, unsigned int first,
2999 unsigned int max_per_txd, unsigned int nr_frags,
3002 struct e1000_buffer *buffer_info;
3003 unsigned int len = skb->len;
3004 unsigned int offset = 0, size, count = 0, i;
3006 len -= skb->data_len;
3008 i = tx_ring->next_to_use;
3011 buffer_info = &tx_ring->buffer_info[i];
3012 size = min(len, max_per_txd);
3013 /* Workaround for Controller erratum --
3014 * descriptor for non-tso packet in a linear SKB that follows a
3015 * tso gets written back prematurely before the data is fully
3016 * DMA'd to the controller */
3017 if (!skb->data_len && tx_ring->last_tx_tso &&
3019 tx_ring->last_tx_tso = 0;
3023 /* Workaround for premature desc write-backs
3024 * in TSO mode. Append 4-byte sentinel desc */
3025 if (unlikely(mss && !nr_frags && size == len && size > 8))
3027 /* work-around for errata 10 and it applies
3028 * to all controllers in PCI-X mode
3029 * The fix is to make sure that the first descriptor of a
3030 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3032 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
3033 (size > 2015) && count == 0))
3036 /* Workaround for potential 82544 hang in PCI-X. Avoid
3037 * terminating buffers within evenly-aligned dwords. */
3038 if (unlikely(adapter->pcix_82544 &&
3039 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3043 buffer_info->length = size;
3045 pci_map_single(adapter->pdev,
3049 buffer_info->time_stamp = jiffies;
3050 buffer_info->next_to_watch = i;
3055 if (unlikely(++i == tx_ring->count)) i = 0;
3058 for (f = 0; f < nr_frags; f++) {
3059 struct skb_frag_struct *frag;
3061 frag = &skb_shinfo(skb)->frags[f];
3063 offset = frag->page_offset;
3066 buffer_info = &tx_ring->buffer_info[i];
3067 size = min(len, max_per_txd);
3068 /* Workaround for premature desc write-backs
3069 * in TSO mode. Append 4-byte sentinel desc */
3070 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
3072 /* Workaround for potential 82544 hang in PCI-X.
3073 * Avoid terminating buffers within evenly-aligned
3075 if (unlikely(adapter->pcix_82544 &&
3076 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3080 buffer_info->length = size;
3082 pci_map_page(adapter->pdev,
3087 buffer_info->time_stamp = jiffies;
3088 buffer_info->next_to_watch = i;
3093 if (unlikely(++i == tx_ring->count)) i = 0;
3097 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3098 tx_ring->buffer_info[i].skb = skb;
3099 tx_ring->buffer_info[first].next_to_watch = i;
3104 static void e1000_tx_queue(struct e1000_adapter *adapter,
3105 struct e1000_tx_ring *tx_ring, int tx_flags,
3108 struct e1000_tx_desc *tx_desc = NULL;
3109 struct e1000_buffer *buffer_info;
3110 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3113 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
3114 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3116 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3118 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3119 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3122 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3123 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3124 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3127 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3128 txd_lower |= E1000_TXD_CMD_VLE;
3129 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3132 i = tx_ring->next_to_use;
3135 buffer_info = &tx_ring->buffer_info[i];
3136 tx_desc = E1000_TX_DESC(*tx_ring, i);
3137 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3138 tx_desc->lower.data =
3139 cpu_to_le32(txd_lower | buffer_info->length);
3140 tx_desc->upper.data = cpu_to_le32(txd_upper);
3141 if (unlikely(++i == tx_ring->count)) i = 0;
3144 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3146 /* Force memory writes to complete before letting h/w
3147 * know there are new descriptors to fetch. (Only
3148 * applicable for weak-ordered memory model archs,
3149 * such as IA-64). */
3152 tx_ring->next_to_use = i;
3153 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
3154 /* we need this if more than one processor can write to our tail
3155 * at a time, it syncronizes IO on IA64/Altix systems */
3160 * 82547 workaround to avoid controller hang in half-duplex environment.
3161 * The workaround is to avoid queuing a large packet that would span
3162 * the internal Tx FIFO ring boundary by notifying the stack to resend
3163 * the packet at a later time. This gives the Tx FIFO an opportunity to
3164 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3165 * to the beginning of the Tx FIFO.
3168 #define E1000_FIFO_HDR 0x10
3169 #define E1000_82547_PAD_LEN 0x3E0
3171 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3172 struct sk_buff *skb)
3174 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3175 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3177 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3179 if (adapter->link_duplex != HALF_DUPLEX)
3180 goto no_fifo_stall_required;
3182 if (atomic_read(&adapter->tx_fifo_stall))
3185 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3186 atomic_set(&adapter->tx_fifo_stall, 1);
3190 no_fifo_stall_required:
3191 adapter->tx_fifo_head += skb_fifo_len;
3192 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3193 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3197 #define MINIMUM_DHCP_PACKET_SIZE 282
3198 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3199 struct sk_buff *skb)
3201 struct e1000_hw *hw = &adapter->hw;
3203 if (vlan_tx_tag_present(skb)) {
3204 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
3205 ( adapter->hw.mng_cookie.status &
3206 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3209 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
3210 struct ethhdr *eth = (struct ethhdr *) skb->data;
3211 if ((htons(ETH_P_IP) == eth->h_proto)) {
3212 const struct iphdr *ip =
3213 (struct iphdr *)((u8 *)skb->data+14);
3214 if (IPPROTO_UDP == ip->protocol) {
3215 struct udphdr *udp =
3216 (struct udphdr *)((u8 *)ip +
3218 if (ntohs(udp->dest) == 67) {
3219 offset = (u8 *)udp + 8 - skb->data;
3220 length = skb->len - offset;
3222 return e1000_mng_write_dhcp_info(hw,
3232 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3234 struct e1000_adapter *adapter = netdev_priv(netdev);
3235 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3237 netif_stop_queue(netdev);
3238 /* Herbert's original patch had:
3239 * smp_mb__after_netif_stop_queue();
3240 * but since that doesn't exist yet, just open code it. */
3243 /* We need to check again in a case another CPU has just
3244 * made room available. */
3245 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3249 netif_start_queue(netdev);
3250 ++adapter->restart_queue;
3254 static int e1000_maybe_stop_tx(struct net_device *netdev,
3255 struct e1000_tx_ring *tx_ring, int size)
3257 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3259 return __e1000_maybe_stop_tx(netdev, size);
3262 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3263 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3265 struct e1000_adapter *adapter = netdev_priv(netdev);
3266 struct e1000_tx_ring *tx_ring;
3267 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3268 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3269 unsigned int tx_flags = 0;
3270 unsigned int len = skb->len - skb->data_len;
3271 unsigned long flags;
3272 unsigned int nr_frags;
3278 /* This goes back to the question of how to logically map a tx queue
3279 * to a flow. Right now, performance is impacted slightly negatively
3280 * if using multiple tx queues. If the stack breaks away from a
3281 * single qdisc implementation, we can look at this again. */
3282 tx_ring = adapter->tx_ring;
3284 if (unlikely(skb->len <= 0)) {
3285 dev_kfree_skb_any(skb);
3286 return NETDEV_TX_OK;
3289 /* 82571 and newer doesn't need the workaround that limited descriptor
3291 if (adapter->hw.mac_type >= e1000_82571)
3294 mss = skb_shinfo(skb)->gso_size;
3295 /* The controller does a simple calculation to
3296 * make sure there is enough room in the FIFO before
3297 * initiating the DMA for each buffer. The calc is:
3298 * 4 = ceil(buffer len/mss). To make sure we don't
3299 * overrun the FIFO, adjust the max buffer len if mss
3303 max_per_txd = min(mss << 2, max_per_txd);
3304 max_txd_pwr = fls(max_per_txd) - 1;
3306 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3307 * points to just header, pull a few bytes of payload from
3308 * frags into skb->data */
3309 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3310 if (skb->data_len && hdr_len == len) {
3311 switch (adapter->hw.mac_type) {
3312 unsigned int pull_size;
3314 /* Make sure we have room to chop off 4 bytes,
3315 * and that the end alignment will work out to
3316 * this hardware's requirements
3317 * NOTE: this is a TSO only workaround
3318 * if end byte alignment not correct move us
3319 * into the next dword */
3320 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
3327 pull_size = min((unsigned int)4, skb->data_len);
3328 if (!__pskb_pull_tail(skb, pull_size)) {
3330 "__pskb_pull_tail failed.\n");
3331 dev_kfree_skb_any(skb);
3332 return NETDEV_TX_OK;
3334 len = skb->len - skb->data_len;
3343 /* reserve a descriptor for the offload context */
3344 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3348 /* Controller Erratum workaround */
3349 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3352 count += TXD_USE_COUNT(len, max_txd_pwr);
3354 if (adapter->pcix_82544)
3357 /* work-around for errata 10 and it applies to all controllers
3358 * in PCI-X mode, so add one more descriptor to the count
3360 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
3364 nr_frags = skb_shinfo(skb)->nr_frags;
3365 for (f = 0; f < nr_frags; f++)
3366 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3368 if (adapter->pcix_82544)
3372 if (adapter->hw.tx_pkt_filtering &&
3373 (adapter->hw.mac_type == e1000_82573))
3374 e1000_transfer_dhcp_info(adapter, skb);
3376 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
3377 /* Collision - tell upper layer to requeue */
3378 return NETDEV_TX_LOCKED;
3380 /* need: count + 2 desc gap to keep tail from touching
3381 * head, otherwise try next time */
3382 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
3383 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3384 return NETDEV_TX_BUSY;
3387 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3388 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3389 netif_stop_queue(netdev);
3390 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3391 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3392 return NETDEV_TX_BUSY;
3396 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3397 tx_flags |= E1000_TX_FLAGS_VLAN;
3398 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3401 first = tx_ring->next_to_use;
3403 tso = e1000_tso(adapter, tx_ring, skb);
3405 dev_kfree_skb_any(skb);
3406 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3407 return NETDEV_TX_OK;
3411 tx_ring->last_tx_tso = 1;
3412 tx_flags |= E1000_TX_FLAGS_TSO;
3413 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3414 tx_flags |= E1000_TX_FLAGS_CSUM;
3416 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3417 * 82571 hardware supports TSO capabilities for IPv6 as well...
3418 * no longer assume, we must. */
3419 if (likely(skb->protocol == htons(ETH_P_IP)))
3420 tx_flags |= E1000_TX_FLAGS_IPV4;
3422 e1000_tx_queue(adapter, tx_ring, tx_flags,
3423 e1000_tx_map(adapter, tx_ring, skb, first,
3424 max_per_txd, nr_frags, mss));
3426 netdev->trans_start = jiffies;
3428 /* Make sure there is space in the ring for the next send. */
3429 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3431 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3432 return NETDEV_TX_OK;
3436 * e1000_tx_timeout - Respond to a Tx Hang
3437 * @netdev: network interface device structure
3440 static void e1000_tx_timeout(struct net_device *netdev)
3442 struct e1000_adapter *adapter = netdev_priv(netdev);
3444 /* Do the reset outside of interrupt context */
3445 adapter->tx_timeout_count++;
3446 schedule_work(&adapter->reset_task);
3449 static void e1000_reset_task(struct work_struct *work)
3451 struct e1000_adapter *adapter =
3452 container_of(work, struct e1000_adapter, reset_task);
3454 e1000_reinit_locked(adapter);
3458 * e1000_get_stats - Get System Network Statistics
3459 * @netdev: network interface device structure
3461 * Returns the address of the device statistics structure.
3462 * The statistics are actually updated from the timer callback.
3465 static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
3467 struct e1000_adapter *adapter = netdev_priv(netdev);
3469 /* only return the current stats */
3470 return &adapter->net_stats;
3474 * e1000_change_mtu - Change the Maximum Transfer Unit
3475 * @netdev: network interface device structure
3476 * @new_mtu: new value for maximum frame size
3478 * Returns 0 on success, negative on failure
3481 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3483 struct e1000_adapter *adapter = netdev_priv(netdev);
3484 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3485 u16 eeprom_data = 0;
3487 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3488 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3489 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3493 /* Adapter-specific max frame size limits. */
3494 switch (adapter->hw.mac_type) {
3495 case e1000_undefined ... e1000_82542_rev2_1:
3497 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3498 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3503 /* Jumbo Frames not supported if:
3504 * - this is not an 82573L device
3505 * - ASPM is enabled in any way (0x1A bits 3:2) */
3506 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3508 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3509 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3510 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3512 "Jumbo Frames not supported.\n");
3517 /* ERT will be enabled later to enable wire speed receives */
3519 /* fall through to get support */
3522 case e1000_80003es2lan:
3523 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3524 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3525 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3530 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3534 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3535 * means we reserve 2 more, this pushes us to allocate from the next
3537 * i.e. RXBUFFER_2048 --> size-4096 slab */
3539 if (max_frame <= E1000_RXBUFFER_256)
3540 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3541 else if (max_frame <= E1000_RXBUFFER_512)
3542 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3543 else if (max_frame <= E1000_RXBUFFER_1024)
3544 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3545 else if (max_frame <= E1000_RXBUFFER_2048)
3546 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3547 else if (max_frame <= E1000_RXBUFFER_4096)
3548 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3549 else if (max_frame <= E1000_RXBUFFER_8192)
3550 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3551 else if (max_frame <= E1000_RXBUFFER_16384)
3552 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3554 /* adjust allocation if LPE protects us, and we aren't using SBP */
3555 if (!adapter->hw.tbi_compatibility_on &&
3556 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3557 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3558 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3560 netdev->mtu = new_mtu;
3561 adapter->hw.max_frame_size = max_frame;
3563 if (netif_running(netdev))
3564 e1000_reinit_locked(adapter);
3570 * e1000_update_stats - Update the board statistics counters
3571 * @adapter: board private structure
3574 void e1000_update_stats(struct e1000_adapter *adapter)
3576 struct e1000_hw *hw = &adapter->hw;
3577 struct pci_dev *pdev = adapter->pdev;
3578 unsigned long flags;
3581 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3584 * Prevent stats update while adapter is being reset, or if the pci
3585 * connection is down.
3587 if (adapter->link_speed == 0)
3589 if (pci_channel_offline(pdev))
3592 spin_lock_irqsave(&adapter->stats_lock, flags);
3594 /* these counters are modified from e1000_tbi_adjust_stats,
3595 * called from the interrupt context, so they must only
3596 * be written while holding adapter->stats_lock
3599 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3600 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3601 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3602 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3603 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3604 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3605 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3607 if (adapter->hw.mac_type != e1000_ich8lan) {
3608 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3609 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3610 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3611 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3612 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3613 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3616 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3617 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3618 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3619 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3620 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3621 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3622 adapter->stats.dc += E1000_READ_REG(hw, DC);
3623 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3624 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3625 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3626 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3627 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3628 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3629 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3630 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3631 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3632 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3633 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3634 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3635 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3636 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3637 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3638 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3639 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3640 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3641 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3643 if (adapter->hw.mac_type != e1000_ich8lan) {
3644 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3645 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3646 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3647 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3648 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3649 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3652 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3653 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3655 /* used for adaptive IFS */
3657 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3658 adapter->stats.tpt += hw->tx_packet_delta;
3659 hw->collision_delta = E1000_READ_REG(hw, COLC);
3660 adapter->stats.colc += hw->collision_delta;
3662 if (hw->mac_type >= e1000_82543) {
3663 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3664 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3665 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3666 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3667 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3668 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3670 if (hw->mac_type > e1000_82547_rev_2) {
3671 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3672 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3674 if (adapter->hw.mac_type != e1000_ich8lan) {
3675 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3676 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3677 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3678 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3679 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3680 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3681 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3685 /* Fill out the OS statistics structure */
3686 adapter->net_stats.multicast = adapter->stats.mprc;
3687 adapter->net_stats.collisions = adapter->stats.colc;
3691 /* RLEC on some newer hardware can be incorrect so build
3692 * our own version based on RUC and ROC */
3693 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3694 adapter->stats.crcerrs + adapter->stats.algnerrc +
3695 adapter->stats.ruc + adapter->stats.roc +
3696 adapter->stats.cexterr;
3697 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3698 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3699 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3700 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3701 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3704 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3705 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3706 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3707 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3708 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3709 if (adapter->hw.bad_tx_carr_stats_fd &&
3710 adapter->link_duplex == FULL_DUPLEX) {
3711 adapter->net_stats.tx_carrier_errors = 0;
3712 adapter->stats.tncrs = 0;
3715 /* Tx Dropped needs to be maintained elsewhere */
3718 if (hw->media_type == e1000_media_type_copper) {
3719 if ((adapter->link_speed == SPEED_1000) &&
3720 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3721 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3722 adapter->phy_stats.idle_errors += phy_tmp;
3725 if ((hw->mac_type <= e1000_82546) &&
3726 (hw->phy_type == e1000_phy_m88) &&
3727 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3728 adapter->phy_stats.receive_errors += phy_tmp;
3731 /* Management Stats */
3732 if (adapter->hw.has_smbus) {
3733 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3734 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3735 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3738 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3742 * e1000_intr_msi - Interrupt Handler
3743 * @irq: interrupt number
3744 * @data: pointer to a network interface device structure
3747 static irqreturn_t e1000_intr_msi(int irq, void *data)
3749 struct net_device *netdev = data;
3750 struct e1000_adapter *adapter = netdev_priv(netdev);
3751 struct e1000_hw *hw = &adapter->hw;
3752 #ifndef CONFIG_E1000_NAPI
3755 u32 icr = E1000_READ_REG(hw, ICR);
3757 /* in NAPI mode read ICR disables interrupts using IAM */
3759 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3760 hw->get_link_status = 1;
3761 /* 80003ES2LAN workaround-- For packet buffer work-around on
3762 * link down event; disable receives here in the ISR and reset
3763 * adapter in watchdog */
3764 if (netif_carrier_ok(netdev) &&
3765 (adapter->hw.mac_type == e1000_80003es2lan)) {
3766 /* disable receives */
3767 u32 rctl = E1000_READ_REG(hw, RCTL);
3768 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3770 /* guard against interrupt when we're going down */
3771 if (!test_bit(__E1000_DOWN, &adapter->flags))
3772 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3775 #ifdef CONFIG_E1000_NAPI
3776 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3777 adapter->total_tx_bytes = 0;
3778 adapter->total_tx_packets = 0;
3779 adapter->total_rx_bytes = 0;
3780 adapter->total_rx_packets = 0;
3781 __netif_rx_schedule(netdev, &adapter->napi);
3783 e1000_irq_enable(adapter);
3785 adapter->total_tx_bytes = 0;
3786 adapter->total_rx_bytes = 0;
3787 adapter->total_tx_packets = 0;
3788 adapter->total_rx_packets = 0;
3790 for (i = 0; i < E1000_MAX_INTR; i++)
3791 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3792 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3795 if (likely(adapter->itr_setting & 3))
3796 e1000_set_itr(adapter);
3803 * e1000_intr - Interrupt Handler
3804 * @irq: interrupt number
3805 * @data: pointer to a network interface device structure
3808 static irqreturn_t e1000_intr(int irq, void *data)
3810 struct net_device *netdev = data;
3811 struct e1000_adapter *adapter = netdev_priv(netdev);
3812 struct e1000_hw *hw = &adapter->hw;
3813 u32 rctl, icr = E1000_READ_REG(hw, ICR);
3814 #ifndef CONFIG_E1000_NAPI
3818 return IRQ_NONE; /* Not our interrupt */
3820 #ifdef CONFIG_E1000_NAPI
3821 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3822 * not set, then the adapter didn't send an interrupt */
3823 if (unlikely(hw->mac_type >= e1000_82571 &&
3824 !(icr & E1000_ICR_INT_ASSERTED)))
3827 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3828 * need for the IMC write */
3831 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3832 hw->get_link_status = 1;
3833 /* 80003ES2LAN workaround--
3834 * For packet buffer work-around on link down event;
3835 * disable receives here in the ISR and
3836 * reset adapter in watchdog
3838 if (netif_carrier_ok(netdev) &&
3839 (adapter->hw.mac_type == e1000_80003es2lan)) {
3840 /* disable receives */
3841 rctl = E1000_READ_REG(hw, RCTL);
3842 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3844 /* guard against interrupt when we're going down */
3845 if (!test_bit(__E1000_DOWN, &adapter->flags))
3846 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3849 #ifdef CONFIG_E1000_NAPI
3850 if (unlikely(hw->mac_type < e1000_82571)) {
3851 /* disable interrupts, without the synchronize_irq bit */
3852 E1000_WRITE_REG(hw, IMC, ~0);
3853 E1000_WRITE_FLUSH(hw);
3855 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3856 adapter->total_tx_bytes = 0;
3857 adapter->total_tx_packets = 0;
3858 adapter->total_rx_bytes = 0;
3859 adapter->total_rx_packets = 0;
3860 __netif_rx_schedule(netdev, &adapter->napi);
3862 /* this really should not happen! if it does it is basically a
3863 * bug, but not a hard error, so enable ints and continue */
3864 e1000_irq_enable(adapter);
3866 /* Writing IMC and IMS is needed for 82547.
3867 * Due to Hub Link bus being occupied, an interrupt
3868 * de-assertion message is not able to be sent.
3869 * When an interrupt assertion message is generated later,
3870 * two messages are re-ordered and sent out.
3871 * That causes APIC to think 82547 is in de-assertion
3872 * state, while 82547 is in assertion state, resulting
3873 * in dead lock. Writing IMC forces 82547 into
3874 * de-assertion state.
3876 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3877 E1000_WRITE_REG(hw, IMC, ~0);
3879 adapter->total_tx_bytes = 0;
3880 adapter->total_rx_bytes = 0;
3881 adapter->total_tx_packets = 0;
3882 adapter->total_rx_packets = 0;
3884 for (i = 0; i < E1000_MAX_INTR; i++)
3885 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3886 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3889 if (likely(adapter->itr_setting & 3))
3890 e1000_set_itr(adapter);
3892 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3893 e1000_irq_enable(adapter);
3899 #ifdef CONFIG_E1000_NAPI
3901 * e1000_clean - NAPI Rx polling callback
3902 * @adapter: board private structure
3905 static int e1000_clean(struct napi_struct *napi, int budget)
3907 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3908 struct net_device *poll_dev = adapter->netdev;
3909 int tx_cleaned = 0, work_done = 0;
3911 /* Must NOT use netdev_priv macro here. */
3912 adapter = poll_dev->priv;
3914 /* e1000_clean is called per-cpu. This lock protects
3915 * tx_ring[0] from being cleaned by multiple cpus
3916 * simultaneously. A failure obtaining the lock means
3917 * tx_ring[0] is currently being cleaned anyway. */
3918 if (spin_trylock(&adapter->tx_queue_lock)) {
3919 tx_cleaned = e1000_clean_tx_irq(adapter,
3920 &adapter->tx_ring[0]);
3921 spin_unlock(&adapter->tx_queue_lock);
3924 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3925 &work_done, budget);
3930 /* If budget not fully consumed, exit the polling mode */
3931 if (work_done < budget) {
3932 if (likely(adapter->itr_setting & 3))
3933 e1000_set_itr(adapter);
3934 netif_rx_complete(poll_dev, napi);
3935 e1000_irq_enable(adapter);
3943 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3944 * @adapter: board private structure
3947 static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3948 struct e1000_tx_ring *tx_ring)
3950 struct net_device *netdev = adapter->netdev;
3951 struct e1000_tx_desc *tx_desc, *eop_desc;
3952 struct e1000_buffer *buffer_info;
3953 unsigned int i, eop;
3954 #ifdef CONFIG_E1000_NAPI
3955 unsigned int count = 0;
3957 bool cleaned = false;
3958 unsigned int total_tx_bytes=0, total_tx_packets=0;
3960 i = tx_ring->next_to_clean;
3961 eop = tx_ring->buffer_info[i].next_to_watch;
3962 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3964 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3965 for (cleaned = false; !cleaned; ) {
3966 tx_desc = E1000_TX_DESC(*tx_ring, i);
3967 buffer_info = &tx_ring->buffer_info[i];
3968 cleaned = (i == eop);
3971 struct sk_buff *skb = buffer_info->skb;
3972 unsigned int segs, bytecount;
3973 segs = skb_shinfo(skb)->gso_segs ?: 1;
3974 /* multiply data chunks by size of headers */
3975 bytecount = ((segs - 1) * skb_headlen(skb)) +
3977 total_tx_packets += segs;
3978 total_tx_bytes += bytecount;
3980 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3981 tx_desc->upper.data = 0;
3983 if (unlikely(++i == tx_ring->count)) i = 0;
3986 eop = tx_ring->buffer_info[i].next_to_watch;
3987 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3988 #ifdef CONFIG_E1000_NAPI
3989 #define E1000_TX_WEIGHT 64
3990 /* weight of a sort for tx, to avoid endless transmit cleanup */
3991 if (count++ == E1000_TX_WEIGHT) break;
3995 tx_ring->next_to_clean = i;
3997 #define TX_WAKE_THRESHOLD 32
3998 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3999 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4000 /* Make sure that anybody stopping the queue after this
4001 * sees the new next_to_clean.
4004 if (netif_queue_stopped(netdev)) {
4005 netif_wake_queue(netdev);
4006 ++adapter->restart_queue;
4010 if (adapter->detect_tx_hung) {
4011 /* Detect a transmit hang in hardware, this serializes the
4012 * check with the clearing of time_stamp and movement of i */
4013 adapter->detect_tx_hung = false;
4014 if (tx_ring->buffer_info[eop].dma &&
4015 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
4016 (adapter->tx_timeout_factor * HZ))
4017 && !(E1000_READ_REG(&adapter->hw, STATUS) &
4018 E1000_STATUS_TXOFF)) {
4020 /* detected Tx unit hang */
4021 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
4025 " next_to_use <%x>\n"
4026 " next_to_clean <%x>\n"
4027 "buffer_info[next_to_clean]\n"
4028 " time_stamp <%lx>\n"
4029 " next_to_watch <%x>\n"
4031 " next_to_watch.status <%x>\n",
4032 (unsigned long)((tx_ring - adapter->tx_ring) /
4033 sizeof(struct e1000_tx_ring)),
4034 readl(adapter->hw.hw_addr + tx_ring->tdh),
4035 readl(adapter->hw.hw_addr + tx_ring->tdt),
4036 tx_ring->next_to_use,
4037 tx_ring->next_to_clean,
4038 tx_ring->buffer_info[eop].time_stamp,
4041 eop_desc->upper.fields.status);
4042 netif_stop_queue(netdev);
4045 adapter->total_tx_bytes += total_tx_bytes;
4046 adapter->total_tx_packets += total_tx_packets;
4047 adapter->net_stats.tx_bytes += total_tx_bytes;
4048 adapter->net_stats.tx_packets += total_tx_packets;
4053 * e1000_rx_checksum - Receive Checksum Offload for 82543
4054 * @adapter: board private structure
4055 * @status_err: receive descriptor status and error fields
4056 * @csum: receive descriptor csum field
4057 * @sk_buff: socket buffer with received data
4060 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
4061 u32 csum, struct sk_buff *skb)
4063 u16 status = (u16)status_err;
4064 u8 errors = (u8)(status_err >> 24);
4065 skb->ip_summed = CHECKSUM_NONE;
4067 /* 82543 or newer only */
4068 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
4069 /* Ignore Checksum bit is set */
4070 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
4071 /* TCP/UDP checksum error bit is set */
4072 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
4073 /* let the stack verify checksum errors */
4074 adapter->hw_csum_err++;
4077 /* TCP/UDP Checksum has not been calculated */
4078 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4079 if (!(status & E1000_RXD_STAT_TCPCS))
4082 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
4085 /* It must be a TCP or UDP packet with a valid checksum */
4086 if (likely(status & E1000_RXD_STAT_TCPCS)) {
4087 /* TCP checksum is good */
4088 skb->ip_summed = CHECKSUM_UNNECESSARY;
4089 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4090 /* IP fragment with UDP payload */
4091 /* Hardware complements the payload checksum, so we undo it
4092 * and then put the value in host order for further stack use.
4094 __sum16 sum = (__force __sum16)htons(csum);
4095 skb->csum = csum_unfold(~sum);
4096 skb->ip_summed = CHECKSUM_COMPLETE;
4098 adapter->hw_csum_good++;
4102 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4103 * @adapter: board private structure
4105 #ifdef CONFIG_E1000_NAPI
4106 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4107 struct e1000_rx_ring *rx_ring,
4108 int *work_done, int work_to_do)
4110 static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4111 struct e1000_rx_ring *rx_ring)
4114 struct net_device *netdev = adapter->netdev;
4115 struct pci_dev *pdev = adapter->pdev;
4116 struct e1000_rx_desc *rx_desc, *next_rxd;
4117 struct e1000_buffer *buffer_info, *next_buffer;
4118 unsigned long flags;
4122 int cleaned_count = 0;
4123 bool cleaned = false;
4124 unsigned int total_rx_bytes=0, total_rx_packets=0;
4126 i = rx_ring->next_to_clean;
4127 rx_desc = E1000_RX_DESC(*rx_ring, i);
4128 buffer_info = &rx_ring->buffer_info[i];
4130 while (rx_desc->status & E1000_RXD_STAT_DD) {
4131 struct sk_buff *skb;
4134 #ifdef CONFIG_E1000_NAPI
4135 if (*work_done >= work_to_do)
4139 status = rx_desc->status;
4140 skb = buffer_info->skb;
4141 buffer_info->skb = NULL;
4143 prefetch(skb->data - NET_IP_ALIGN);
4145 if (++i == rx_ring->count) i = 0;
4146 next_rxd = E1000_RX_DESC(*rx_ring, i);
4149 next_buffer = &rx_ring->buffer_info[i];
4153 pci_unmap_single(pdev,
4155 buffer_info->length,
4156 PCI_DMA_FROMDEVICE);
4158 length = le16_to_cpu(rx_desc->length);
4160 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4161 /* All receives must fit into a single buffer */
4162 E1000_DBG("%s: Receive packet consumed multiple"
4163 " buffers\n", netdev->name);
4165 buffer_info->skb = skb;
4169 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4170 last_byte = *(skb->data + length - 1);
4171 if (TBI_ACCEPT(&adapter->hw, status,
4172 rx_desc->errors, length, last_byte)) {
4173 spin_lock_irqsave(&adapter->stats_lock, flags);
4174 e1000_tbi_adjust_stats(&adapter->hw,
4177 spin_unlock_irqrestore(&adapter->stats_lock,
4182 buffer_info->skb = skb;
4187 /* adjust length to remove Ethernet CRC, this must be
4188 * done after the TBI_ACCEPT workaround above */
4191 /* probably a little skewed due to removing CRC */
4192 total_rx_bytes += length;
4195 /* code added for copybreak, this should improve
4196 * performance for small packets with large amounts
4197 * of reassembly being done in the stack */
4198 if (length < copybreak) {
4199 struct sk_buff *new_skb =
4200 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4202 skb_reserve(new_skb, NET_IP_ALIGN);
4203 skb_copy_to_linear_data_offset(new_skb,
4209 /* save the skb in buffer_info as good */
4210 buffer_info->skb = skb;
4213 /* else just continue with the old one */
4215 /* end copybreak code */
4216 skb_put(skb, length);
4218 /* Receive Checksum Offload */
4219 e1000_rx_checksum(adapter,
4221 ((u32)(rx_desc->errors) << 24),
4222 le16_to_cpu(rx_desc->csum), skb);
4224 skb->protocol = eth_type_trans(skb, netdev);
4225 #ifdef CONFIG_E1000_NAPI
4226 if (unlikely(adapter->vlgrp &&
4227 (status & E1000_RXD_STAT_VP))) {
4228 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4229 le16_to_cpu(rx_desc->special));
4231 netif_receive_skb(skb);
4233 #else /* CONFIG_E1000_NAPI */
4234 if (unlikely(adapter->vlgrp &&
4235 (status & E1000_RXD_STAT_VP))) {
4236 vlan_hwaccel_rx(skb, adapter->vlgrp,
4237 le16_to_cpu(rx_desc->special));
4241 #endif /* CONFIG_E1000_NAPI */
4242 netdev->last_rx = jiffies;
4245 rx_desc->status = 0;
4247 /* return some buffers to hardware, one at a time is too slow */
4248 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4249 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4253 /* use prefetched values */
4255 buffer_info = next_buffer;
4257 rx_ring->next_to_clean = i;
4259 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4261 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4263 adapter->total_rx_packets += total_rx_packets;
4264 adapter->total_rx_bytes += total_rx_bytes;
4265 adapter->net_stats.rx_bytes += total_rx_bytes;
4266 adapter->net_stats.rx_packets += total_rx_packets;
4271 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4272 * @adapter: board private structure
4275 #ifdef CONFIG_E1000_NAPI
4276 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4277 struct e1000_rx_ring *rx_ring,
4278 int *work_done, int work_to_do)
4280 static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4281 struct e1000_rx_ring *rx_ring)
4284 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
4285 struct net_device *netdev = adapter->netdev;
4286 struct pci_dev *pdev = adapter->pdev;
4287 struct e1000_buffer *buffer_info, *next_buffer;
4288 struct e1000_ps_page *ps_page;
4289 struct e1000_ps_page_dma *ps_page_dma;
4290 struct sk_buff *skb;
4292 u32 length, staterr;
4293 int cleaned_count = 0;
4294 bool cleaned = false;
4295 unsigned int total_rx_bytes=0, total_rx_packets=0;
4297 i = rx_ring->next_to_clean;
4298 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4299 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4300 buffer_info = &rx_ring->buffer_info[i];
4302 while (staterr & E1000_RXD_STAT_DD) {
4303 ps_page = &rx_ring->ps_page[i];
4304 ps_page_dma = &rx_ring->ps_page_dma[i];
4305 #ifdef CONFIG_E1000_NAPI
4306 if (unlikely(*work_done >= work_to_do))
4310 skb = buffer_info->skb;
4312 /* in the packet split case this is header only */
4313 prefetch(skb->data - NET_IP_ALIGN);
4315 if (++i == rx_ring->count) i = 0;
4316 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
4319 next_buffer = &rx_ring->buffer_info[i];
4323 pci_unmap_single(pdev, buffer_info->dma,
4324 buffer_info->length,
4325 PCI_DMA_FROMDEVICE);
4327 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
4328 E1000_DBG("%s: Packet Split buffers didn't pick up"
4329 " the full packet\n", netdev->name);
4330 dev_kfree_skb_irq(skb);
4334 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
4335 dev_kfree_skb_irq(skb);
4339 length = le16_to_cpu(rx_desc->wb.middle.length0);
4341 if (unlikely(!length)) {
4342 E1000_DBG("%s: Last part of the packet spanning"
4343 " multiple descriptors\n", netdev->name);
4344 dev_kfree_skb_irq(skb);
4349 skb_put(skb, length);
4352 /* this looks ugly, but it seems compiler issues make it
4353 more efficient than reusing j */
4354 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4356 /* page alloc/put takes too long and effects small packet
4357 * throughput, so unsplit small packets and save the alloc/put*/
4358 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
4360 /* there is no documentation about how to call
4361 * kmap_atomic, so we can't hold the mapping
4363 pci_dma_sync_single_for_cpu(pdev,
4364 ps_page_dma->ps_page_dma[0],
4366 PCI_DMA_FROMDEVICE);
4367 vaddr = kmap_atomic(ps_page->ps_page[0],
4368 KM_SKB_DATA_SOFTIRQ);
4369 memcpy(skb_tail_pointer(skb), vaddr, l1);
4370 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4371 pci_dma_sync_single_for_device(pdev,
4372 ps_page_dma->ps_page_dma[0],
4373 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4374 /* remove the CRC */
4381 for (j = 0; j < adapter->rx_ps_pages; j++) {
4382 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
4384 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4385 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4386 ps_page_dma->ps_page_dma[j] = 0;
4387 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4389 ps_page->ps_page[j] = NULL;
4391 skb->data_len += length;
4392 skb->truesize += length;
4395 /* strip the ethernet crc, problem is we're using pages now so
4396 * this whole operation can get a little cpu intensive */
4397 pskb_trim(skb, skb->len - 4);
4400 total_rx_bytes += skb->len;
4403 e1000_rx_checksum(adapter, staterr,
4404 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
4405 skb->protocol = eth_type_trans(skb, netdev);
4407 if (likely(rx_desc->wb.upper.header_status &
4408 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
4409 adapter->rx_hdr_split++;
4410 #ifdef CONFIG_E1000_NAPI
4411 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4412 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4413 le16_to_cpu(rx_desc->wb.middle.vlan));
4415 netif_receive_skb(skb);
4417 #else /* CONFIG_E1000_NAPI */
4418 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4419 vlan_hwaccel_rx(skb, adapter->vlgrp,
4420 le16_to_cpu(rx_desc->wb.middle.vlan));
4424 #endif /* CONFIG_E1000_NAPI */
4425 netdev->last_rx = jiffies;
4428 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
4429 buffer_info->skb = NULL;
4431 /* return some buffers to hardware, one at a time is too slow */
4432 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4433 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4437 /* use prefetched values */
4439 buffer_info = next_buffer;
4441 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4443 rx_ring->next_to_clean = i;
4445 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4447 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4449 adapter->total_rx_packets += total_rx_packets;
4450 adapter->total_rx_bytes += total_rx_bytes;
4451 adapter->net_stats.rx_bytes += total_rx_bytes;
4452 adapter->net_stats.rx_packets += total_rx_packets;
4457 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4458 * @adapter: address of board private structure
4461 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4462 struct e1000_rx_ring *rx_ring,
4465 struct net_device *netdev = adapter->netdev;
4466 struct pci_dev *pdev = adapter->pdev;
4467 struct e1000_rx_desc *rx_desc;
4468 struct e1000_buffer *buffer_info;
4469 struct sk_buff *skb;
4471 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4473 i = rx_ring->next_to_use;
4474 buffer_info = &rx_ring->buffer_info[i];
4476 while (cleaned_count--) {
4477 skb = buffer_info->skb;
4483 skb = netdev_alloc_skb(netdev, bufsz);
4484 if (unlikely(!skb)) {
4485 /* Better luck next round */
4486 adapter->alloc_rx_buff_failed++;
4490 /* Fix for errata 23, can't cross 64kB boundary */
4491 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4492 struct sk_buff *oldskb = skb;
4493 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4494 "at %p\n", bufsz, skb->data);
4495 /* Try again, without freeing the previous */
4496 skb = netdev_alloc_skb(netdev, bufsz);
4497 /* Failed allocation, critical failure */
4499 dev_kfree_skb(oldskb);
4503 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4506 dev_kfree_skb(oldskb);
4507 break; /* while !buffer_info->skb */
4510 /* Use new allocation */
4511 dev_kfree_skb(oldskb);
4513 /* Make buffer alignment 2 beyond a 16 byte boundary
4514 * this will result in a 16 byte aligned IP header after
4515 * the 14 byte MAC header is removed
4517 skb_reserve(skb, NET_IP_ALIGN);
4519 buffer_info->skb = skb;
4520 buffer_info->length = adapter->rx_buffer_len;
4522 buffer_info->dma = pci_map_single(pdev,
4524 adapter->rx_buffer_len,
4525 PCI_DMA_FROMDEVICE);
4527 /* Fix for errata 23, can't cross 64kB boundary */
4528 if (!e1000_check_64k_bound(adapter,
4529 (void *)(unsigned long)buffer_info->dma,
4530 adapter->rx_buffer_len)) {
4531 DPRINTK(RX_ERR, ERR,
4532 "dma align check failed: %u bytes at %p\n",
4533 adapter->rx_buffer_len,
4534 (void *)(unsigned long)buffer_info->dma);
4536 buffer_info->skb = NULL;
4538 pci_unmap_single(pdev, buffer_info->dma,
4539 adapter->rx_buffer_len,
4540 PCI_DMA_FROMDEVICE);
4542 break; /* while !buffer_info->skb */
4544 rx_desc = E1000_RX_DESC(*rx_ring, i);
4545 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4547 if (unlikely(++i == rx_ring->count))
4549 buffer_info = &rx_ring->buffer_info[i];
4552 if (likely(rx_ring->next_to_use != i)) {
4553 rx_ring->next_to_use = i;
4554 if (unlikely(i-- == 0))
4555 i = (rx_ring->count - 1);
4557 /* Force memory writes to complete before letting h/w
4558 * know there are new descriptors to fetch. (Only
4559 * applicable for weak-ordered memory model archs,
4560 * such as IA-64). */
4562 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4567 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4568 * @adapter: address of board private structure
4571 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4572 struct e1000_rx_ring *rx_ring,
4575 struct net_device *netdev = adapter->netdev;
4576 struct pci_dev *pdev = adapter->pdev;
4577 union e1000_rx_desc_packet_split *rx_desc;
4578 struct e1000_buffer *buffer_info;
4579 struct e1000_ps_page *ps_page;
4580 struct e1000_ps_page_dma *ps_page_dma;
4581 struct sk_buff *skb;
4584 i = rx_ring->next_to_use;
4585 buffer_info = &rx_ring->buffer_info[i];
4586 ps_page = &rx_ring->ps_page[i];
4587 ps_page_dma = &rx_ring->ps_page_dma[i];
4589 while (cleaned_count--) {
4590 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4592 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4593 if (j < adapter->rx_ps_pages) {
4594 if (likely(!ps_page->ps_page[j])) {
4595 ps_page->ps_page[j] =
4596 alloc_page(GFP_ATOMIC);
4597 if (unlikely(!ps_page->ps_page[j])) {
4598 adapter->alloc_rx_buff_failed++;
4601 ps_page_dma->ps_page_dma[j] =
4603 ps_page->ps_page[j],
4605 PCI_DMA_FROMDEVICE);
4607 /* Refresh the desc even if buffer_addrs didn't
4608 * change because each write-back erases
4611 rx_desc->read.buffer_addr[j+1] =
4612 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4614 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
4617 skb = netdev_alloc_skb(netdev,
4618 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4620 if (unlikely(!skb)) {
4621 adapter->alloc_rx_buff_failed++;
4625 /* Make buffer alignment 2 beyond a 16 byte boundary
4626 * this will result in a 16 byte aligned IP header after
4627 * the 14 byte MAC header is removed
4629 skb_reserve(skb, NET_IP_ALIGN);
4631 buffer_info->skb = skb;
4632 buffer_info->length = adapter->rx_ps_bsize0;
4633 buffer_info->dma = pci_map_single(pdev, skb->data,
4634 adapter->rx_ps_bsize0,
4635 PCI_DMA_FROMDEVICE);
4637 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4639 if (unlikely(++i == rx_ring->count)) i = 0;
4640 buffer_info = &rx_ring->buffer_info[i];
4641 ps_page = &rx_ring->ps_page[i];
4642 ps_page_dma = &rx_ring->ps_page_dma[i];
4646 if (likely(rx_ring->next_to_use != i)) {
4647 rx_ring->next_to_use = i;
4648 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4650 /* Force memory writes to complete before letting h/w
4651 * know there are new descriptors to fetch. (Only
4652 * applicable for weak-ordered memory model archs,
4653 * such as IA-64). */
4655 /* Hardware increments by 16 bytes, but packet split
4656 * descriptors are 32 bytes...so we increment tail
4659 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4664 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4668 static void e1000_smartspeed(struct e1000_adapter *adapter)
4673 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4674 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4677 if (adapter->smartspeed == 0) {
4678 /* If Master/Slave config fault is asserted twice,
4679 * we assume back-to-back */
4680 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4681 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4682 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4683 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4684 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4685 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4686 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4687 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4689 adapter->smartspeed++;
4690 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4691 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4693 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4694 MII_CR_RESTART_AUTO_NEG);
4695 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4700 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4701 /* If still no link, perhaps using 2/3 pair cable */
4702 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4703 phy_ctrl |= CR_1000T_MS_ENABLE;
4704 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4705 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4706 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4707 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4708 MII_CR_RESTART_AUTO_NEG);
4709 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4712 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4713 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4714 adapter->smartspeed = 0;
4724 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4730 return e1000_mii_ioctl(netdev, ifr, cmd);
4743 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4746 struct e1000_adapter *adapter = netdev_priv(netdev);
4747 struct mii_ioctl_data *data = if_mii(ifr);
4751 unsigned long flags;
4753 if (adapter->hw.media_type != e1000_media_type_copper)
4758 data->phy_id = adapter->hw.phy_addr;
4761 if (!capable(CAP_NET_ADMIN))
4763 spin_lock_irqsave(&adapter->stats_lock, flags);
4764 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4766 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4769 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4772 if (!capable(CAP_NET_ADMIN))
4774 if (data->reg_num & ~(0x1F))
4776 mii_reg = data->val_in;
4777 spin_lock_irqsave(&adapter->stats_lock, flags);
4778 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4780 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4783 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4784 if (adapter->hw.media_type == e1000_media_type_copper) {
4785 switch (data->reg_num) {
4787 if (mii_reg & MII_CR_POWER_DOWN)
4789 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4790 adapter->hw.autoneg = 1;
4791 adapter->hw.autoneg_advertised = 0x2F;
4794 spddplx = SPEED_1000;
4795 else if (mii_reg & 0x2000)
4796 spddplx = SPEED_100;
4799 spddplx += (mii_reg & 0x100)
4802 retval = e1000_set_spd_dplx(adapter,
4807 if (netif_running(adapter->netdev))
4808 e1000_reinit_locked(adapter);
4810 e1000_reset(adapter);
4812 case M88E1000_PHY_SPEC_CTRL:
4813 case M88E1000_EXT_PHY_SPEC_CTRL:
4814 if (e1000_phy_reset(&adapter->hw))
4819 switch (data->reg_num) {
4821 if (mii_reg & MII_CR_POWER_DOWN)
4823 if (netif_running(adapter->netdev))
4824 e1000_reinit_locked(adapter);
4826 e1000_reset(adapter);
4834 return E1000_SUCCESS;
4837 void e1000_pci_set_mwi(struct e1000_hw *hw)
4839 struct e1000_adapter *adapter = hw->back;
4840 int ret_val = pci_set_mwi(adapter->pdev);
4843 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4846 void e1000_pci_clear_mwi(struct e1000_hw *hw)
4848 struct e1000_adapter *adapter = hw->back;
4850 pci_clear_mwi(adapter->pdev);
4853 int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4855 struct e1000_adapter *adapter = hw->back;
4856 return pcix_get_mmrbc(adapter->pdev);
4859 void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4861 struct e1000_adapter *adapter = hw->back;
4862 pcix_set_mmrbc(adapter->pdev, mmrbc);
4865 s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
4867 struct e1000_adapter *adapter = hw->back;
4870 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4872 return -E1000_ERR_CONFIG;
4874 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4876 return E1000_SUCCESS;
4879 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4884 static void e1000_vlan_rx_register(struct net_device *netdev,
4885 struct vlan_group *grp)
4887 struct e1000_adapter *adapter = netdev_priv(netdev);
4890 if (!test_bit(__E1000_DOWN, &adapter->flags))
4891 e1000_irq_disable(adapter);
4892 adapter->vlgrp = grp;
4895 /* enable VLAN tag insert/strip */
4896 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4897 ctrl |= E1000_CTRL_VME;
4898 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4900 if (adapter->hw.mac_type != e1000_ich8lan) {
4901 /* enable VLAN receive filtering */
4902 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4903 rctl &= ~E1000_RCTL_CFIEN;
4904 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4905 e1000_update_mng_vlan(adapter);
4908 /* disable VLAN tag insert/strip */
4909 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4910 ctrl &= ~E1000_CTRL_VME;
4911 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4913 if (adapter->hw.mac_type != e1000_ich8lan) {
4914 if (adapter->mng_vlan_id !=
4915 (u16)E1000_MNG_VLAN_NONE) {
4916 e1000_vlan_rx_kill_vid(netdev,
4917 adapter->mng_vlan_id);
4918 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4923 if (!test_bit(__E1000_DOWN, &adapter->flags))
4924 e1000_irq_enable(adapter);
4927 static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4929 struct e1000_adapter *adapter = netdev_priv(netdev);
4932 if ((adapter->hw.mng_cookie.status &
4933 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4934 (vid == adapter->mng_vlan_id))
4936 /* add VID to filter table */
4937 index = (vid >> 5) & 0x7F;
4938 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4939 vfta |= (1 << (vid & 0x1F));
4940 e1000_write_vfta(&adapter->hw, index, vfta);
4943 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4945 struct e1000_adapter *adapter = netdev_priv(netdev);
4948 if (!test_bit(__E1000_DOWN, &adapter->flags))
4949 e1000_irq_disable(adapter);
4950 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4951 if (!test_bit(__E1000_DOWN, &adapter->flags))
4952 e1000_irq_enable(adapter);
4954 if ((adapter->hw.mng_cookie.status &
4955 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4956 (vid == adapter->mng_vlan_id)) {
4957 /* release control to f/w */
4958 e1000_release_hw_control(adapter);
4962 /* remove VID from filter table */
4963 index = (vid >> 5) & 0x7F;
4964 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4965 vfta &= ~(1 << (vid & 0x1F));
4966 e1000_write_vfta(&adapter->hw, index, vfta);
4969 static void e1000_restore_vlan(struct e1000_adapter *adapter)
4971 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4973 if (adapter->vlgrp) {
4975 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4976 if (!vlan_group_get_device(adapter->vlgrp, vid))
4978 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4983 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
4985 adapter->hw.autoneg = 0;
4987 /* Fiber NICs only allow 1000 gbps Full duplex */
4988 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4989 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4990 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4995 case SPEED_10 + DUPLEX_HALF:
4996 adapter->hw.forced_speed_duplex = e1000_10_half;
4998 case SPEED_10 + DUPLEX_FULL:
4999 adapter->hw.forced_speed_duplex = e1000_10_full;
5001 case SPEED_100 + DUPLEX_HALF:
5002 adapter->hw.forced_speed_duplex = e1000_100_half;
5004 case SPEED_100 + DUPLEX_FULL:
5005 adapter->hw.forced_speed_duplex = e1000_100_full;
5007 case SPEED_1000 + DUPLEX_FULL:
5008 adapter->hw.autoneg = 1;
5009 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5011 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5013 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5019 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5021 struct net_device *netdev = pci_get_drvdata(pdev);
5022 struct e1000_adapter *adapter = netdev_priv(netdev);
5023 u32 ctrl, ctrl_ext, rctl, status;
5024 u32 wufc = adapter->wol;
5029 netif_device_detach(netdev);
5031 if (netif_running(netdev)) {
5032 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
5033 e1000_down(adapter);
5037 retval = pci_save_state(pdev);
5042 status = E1000_READ_REG(&adapter->hw, STATUS);
5043 if (status & E1000_STATUS_LU)
5044 wufc &= ~E1000_WUFC_LNKC;
5047 e1000_setup_rctl(adapter);
5048 e1000_set_rx_mode(netdev);
5050 /* turn on all-multi mode if wake on multicast is enabled */
5051 if (wufc & E1000_WUFC_MC) {
5052 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5053 rctl |= E1000_RCTL_MPE;
5054 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5057 if (adapter->hw.mac_type >= e1000_82540) {
5058 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5059 /* advertise wake from D3Cold */
5060 #define E1000_CTRL_ADVD3WUC 0x00100000
5061 /* phy power management enable */
5062 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5063 ctrl |= E1000_CTRL_ADVD3WUC |
5064 E1000_CTRL_EN_PHY_PWR_MGMT;
5065 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5068 if (adapter->hw.media_type == e1000_media_type_fiber ||
5069 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5070 /* keep the laser running in D3 */
5071 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5072 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5073 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5076 /* Allow time for pending master requests to run */
5077 e1000_disable_pciex_master(&adapter->hw);
5079 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5080 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
5081 pci_enable_wake(pdev, PCI_D3hot, 1);
5082 pci_enable_wake(pdev, PCI_D3cold, 1);
5084 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5085 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
5086 pci_enable_wake(pdev, PCI_D3hot, 0);
5087 pci_enable_wake(pdev, PCI_D3cold, 0);
5090 e1000_release_manageability(adapter);
5092 /* make sure adapter isn't asleep if manageability is enabled */
5093 if (adapter->en_mng_pt) {
5094 pci_enable_wake(pdev, PCI_D3hot, 1);
5095 pci_enable_wake(pdev, PCI_D3cold, 1);
5098 if (adapter->hw.phy_type == e1000_phy_igp_3)
5099 e1000_phy_powerdown_workaround(&adapter->hw);
5101 if (netif_running(netdev))
5102 e1000_free_irq(adapter);
5104 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5105 * would have already happened in close and is redundant. */
5106 e1000_release_hw_control(adapter);
5108 pci_disable_device(pdev);
5110 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5116 static int e1000_resume(struct pci_dev *pdev)
5118 struct net_device *netdev = pci_get_drvdata(pdev);
5119 struct e1000_adapter *adapter = netdev_priv(netdev);
5122 pci_set_power_state(pdev, PCI_D0);
5123 pci_restore_state(pdev);
5124 if ((err = pci_enable_device(pdev))) {
5125 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5128 pci_set_master(pdev);
5130 pci_enable_wake(pdev, PCI_D3hot, 0);
5131 pci_enable_wake(pdev, PCI_D3cold, 0);
5133 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5136 e1000_power_up_phy(adapter);
5137 e1000_reset(adapter);
5138 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5140 e1000_init_manageability(adapter);
5142 if (netif_running(netdev))
5145 netif_device_attach(netdev);
5147 /* If the controller is 82573 and f/w is AMT, do not set
5148 * DRV_LOAD until the interface is up. For all other cases,
5149 * let the f/w know that the h/w is now under the control
5151 if (adapter->hw.mac_type != e1000_82573 ||
5152 !e1000_check_mng_mode(&adapter->hw))
5153 e1000_get_hw_control(adapter);
5159 static void e1000_shutdown(struct pci_dev *pdev)
5161 e1000_suspend(pdev, PMSG_SUSPEND);
5164 #ifdef CONFIG_NET_POLL_CONTROLLER
5166 * Polling 'interrupt' - used by things like netconsole to send skbs
5167 * without having to re-enable interrupts. It's not called while
5168 * the interrupt routine is executing.
5170 static void e1000_netpoll(struct net_device *netdev)
5172 struct e1000_adapter *adapter = netdev_priv(netdev);
5174 disable_irq(adapter->pdev->irq);
5175 e1000_intr(adapter->pdev->irq, netdev);
5176 #ifndef CONFIG_E1000_NAPI
5177 adapter->clean_rx(adapter, adapter->rx_ring);
5179 enable_irq(adapter->pdev->irq);
5184 * e1000_io_error_detected - called when PCI error is detected
5185 * @pdev: Pointer to PCI device
5186 * @state: The current pci conneection state
5188 * This function is called after a PCI bus error affecting
5189 * this device has been detected.
5191 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5192 pci_channel_state_t state)
5194 struct net_device *netdev = pci_get_drvdata(pdev);
5195 struct e1000_adapter *adapter = netdev->priv;
5197 netif_device_detach(netdev);
5199 if (netif_running(netdev))
5200 e1000_down(adapter);
5201 pci_disable_device(pdev);
5203 /* Request a slot slot reset. */
5204 return PCI_ERS_RESULT_NEED_RESET;
5208 * e1000_io_slot_reset - called after the pci bus has been reset.
5209 * @pdev: Pointer to PCI device
5211 * Restart the card from scratch, as if from a cold-boot. Implementation
5212 * resembles the first-half of the e1000_resume routine.
5214 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5216 struct net_device *netdev = pci_get_drvdata(pdev);
5217 struct e1000_adapter *adapter = netdev->priv;
5219 if (pci_enable_device(pdev)) {
5220 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5221 return PCI_ERS_RESULT_DISCONNECT;
5223 pci_set_master(pdev);
5225 pci_enable_wake(pdev, PCI_D3hot, 0);
5226 pci_enable_wake(pdev, PCI_D3cold, 0);
5228 e1000_reset(adapter);
5229 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5231 return PCI_ERS_RESULT_RECOVERED;
5235 * e1000_io_resume - called when traffic can start flowing again.
5236 * @pdev: Pointer to PCI device
5238 * This callback is called when the error recovery driver tells us that
5239 * its OK to resume normal operation. Implementation resembles the
5240 * second-half of the e1000_resume routine.
5242 static void e1000_io_resume(struct pci_dev *pdev)
5244 struct net_device *netdev = pci_get_drvdata(pdev);
5245 struct e1000_adapter *adapter = netdev->priv;
5247 e1000_init_manageability(adapter);
5249 if (netif_running(netdev)) {
5250 if (e1000_up(adapter)) {
5251 printk("e1000: can't bring device back up after reset\n");
5256 netif_device_attach(netdev);
5258 /* If the controller is 82573 and f/w is AMT, do not set
5259 * DRV_LOAD until the interface is up. For all other cases,
5260 * let the f/w know that the h/w is now under the control
5262 if (adapter->hw.mac_type != e1000_82573 ||
5263 !e1000_check_mng_mode(&adapter->hw))
5264 e1000_get_hw_control(adapter);