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.15-k2"DRIVERNAPI
40 char e1000_driver_version[] = DRV_VERSION;
41 static 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(0x1049),
77 INTEL_E1000_ETHERNET_DEVICE(0x104A),
78 INTEL_E1000_ETHERNET_DEVICE(0x104B),
79 INTEL_E1000_ETHERNET_DEVICE(0x104C),
80 INTEL_E1000_ETHERNET_DEVICE(0x104D),
81 INTEL_E1000_ETHERNET_DEVICE(0x105E),
82 INTEL_E1000_ETHERNET_DEVICE(0x105F),
83 INTEL_E1000_ETHERNET_DEVICE(0x1060),
84 INTEL_E1000_ETHERNET_DEVICE(0x1075),
85 INTEL_E1000_ETHERNET_DEVICE(0x1076),
86 INTEL_E1000_ETHERNET_DEVICE(0x1077),
87 INTEL_E1000_ETHERNET_DEVICE(0x1078),
88 INTEL_E1000_ETHERNET_DEVICE(0x1079),
89 INTEL_E1000_ETHERNET_DEVICE(0x107A),
90 INTEL_E1000_ETHERNET_DEVICE(0x107B),
91 INTEL_E1000_ETHERNET_DEVICE(0x107C),
92 INTEL_E1000_ETHERNET_DEVICE(0x107D),
93 INTEL_E1000_ETHERNET_DEVICE(0x107E),
94 INTEL_E1000_ETHERNET_DEVICE(0x107F),
95 INTEL_E1000_ETHERNET_DEVICE(0x108A),
96 INTEL_E1000_ETHERNET_DEVICE(0x108B),
97 INTEL_E1000_ETHERNET_DEVICE(0x108C),
98 INTEL_E1000_ETHERNET_DEVICE(0x1096),
99 INTEL_E1000_ETHERNET_DEVICE(0x1098),
100 INTEL_E1000_ETHERNET_DEVICE(0x1099),
101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
102 INTEL_E1000_ETHERNET_DEVICE(0x10A4),
103 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
104 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
106 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
107 INTEL_E1000_ETHERNET_DEVICE(0x10BC),
108 INTEL_E1000_ETHERNET_DEVICE(0x10C4),
109 INTEL_E1000_ETHERNET_DEVICE(0x10C5),
110 /* required last entry */
114 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
116 int e1000_up(struct e1000_adapter *adapter);
117 void e1000_down(struct e1000_adapter *adapter);
118 void e1000_reinit_locked(struct e1000_adapter *adapter);
119 void e1000_reset(struct e1000_adapter *adapter);
120 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
121 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
122 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
123 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
124 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
125 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
126 struct e1000_tx_ring *txdr);
127 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
128 struct e1000_rx_ring *rxdr);
129 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
130 struct e1000_tx_ring *tx_ring);
131 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
132 struct e1000_rx_ring *rx_ring);
133 void e1000_update_stats(struct e1000_adapter *adapter);
135 static int e1000_init_module(void);
136 static void e1000_exit_module(void);
137 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
138 static void __devexit e1000_remove(struct pci_dev *pdev);
139 static int e1000_alloc_queues(struct e1000_adapter *adapter);
140 static int e1000_sw_init(struct e1000_adapter *adapter);
141 static int e1000_open(struct net_device *netdev);
142 static int e1000_close(struct net_device *netdev);
143 static void e1000_configure_tx(struct e1000_adapter *adapter);
144 static void e1000_configure_rx(struct e1000_adapter *adapter);
145 static void e1000_setup_rctl(struct e1000_adapter *adapter);
146 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
147 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
148 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
149 struct e1000_tx_ring *tx_ring);
150 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring);
152 static void e1000_set_multi(struct net_device *netdev);
153 static void e1000_update_phy_info(unsigned long data);
154 static void e1000_watchdog(unsigned long data);
155 static void e1000_82547_tx_fifo_stall(unsigned long data);
156 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
157 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
158 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
159 static int e1000_set_mac(struct net_device *netdev, void *p);
160 static irqreturn_t e1000_intr(int irq, void *data);
161 #ifdef CONFIG_PCI_MSI
162 static irqreturn_t e1000_intr_msi(int irq, void *data);
164 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
165 struct e1000_tx_ring *tx_ring);
166 #ifdef CONFIG_E1000_NAPI
167 static int e1000_clean(struct net_device *poll_dev, int *budget);
168 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring,
170 int *work_done, int work_to_do);
171 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
172 struct e1000_rx_ring *rx_ring,
173 int *work_done, int work_to_do);
175 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
176 struct e1000_rx_ring *rx_ring);
177 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
178 struct e1000_rx_ring *rx_ring);
180 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
181 struct e1000_rx_ring *rx_ring,
183 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
184 struct e1000_rx_ring *rx_ring,
186 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
187 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
189 void e1000_set_ethtool_ops(struct net_device *netdev);
190 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
191 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
192 static void e1000_tx_timeout(struct net_device *dev);
193 static void e1000_reset_task(struct work_struct *work);
194 static void e1000_smartspeed(struct e1000_adapter *adapter);
195 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
196 struct sk_buff *skb);
198 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
199 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
200 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
201 static void e1000_restore_vlan(struct e1000_adapter *adapter);
203 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
205 static int e1000_resume(struct pci_dev *pdev);
207 static void e1000_shutdown(struct pci_dev *pdev);
209 #ifdef CONFIG_NET_POLL_CONTROLLER
210 /* for netdump / net console */
211 static void e1000_netpoll (struct net_device *netdev);
214 extern void e1000_check_options(struct e1000_adapter *adapter);
216 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
217 pci_channel_state_t state);
218 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
219 static void e1000_io_resume(struct pci_dev *pdev);
221 static struct pci_error_handlers e1000_err_handler = {
222 .error_detected = e1000_io_error_detected,
223 .slot_reset = e1000_io_slot_reset,
224 .resume = e1000_io_resume,
227 static struct pci_driver e1000_driver = {
228 .name = e1000_driver_name,
229 .id_table = e1000_pci_tbl,
230 .probe = e1000_probe,
231 .remove = __devexit_p(e1000_remove),
233 /* Power Managment Hooks */
234 .suspend = e1000_suspend,
235 .resume = e1000_resume,
237 .shutdown = e1000_shutdown,
238 .err_handler = &e1000_err_handler
241 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
242 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
243 MODULE_LICENSE("GPL");
244 MODULE_VERSION(DRV_VERSION);
246 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
247 module_param(debug, int, 0);
248 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
251 * e1000_init_module - Driver Registration Routine
253 * e1000_init_module is the first routine called when the driver is
254 * loaded. All it does is register with the PCI subsystem.
258 e1000_init_module(void)
261 printk(KERN_INFO "%s - version %s\n",
262 e1000_driver_string, e1000_driver_version);
264 printk(KERN_INFO "%s\n", e1000_copyright);
266 ret = pci_register_driver(&e1000_driver);
271 module_init(e1000_init_module);
274 * e1000_exit_module - Driver Exit Cleanup Routine
276 * e1000_exit_module is called just before the driver is removed
281 e1000_exit_module(void)
283 pci_unregister_driver(&e1000_driver);
286 module_exit(e1000_exit_module);
288 static int e1000_request_irq(struct e1000_adapter *adapter)
290 struct net_device *netdev = adapter->netdev;
294 #ifdef CONFIG_PCI_MSI
295 if (adapter->hw.mac_type >= e1000_82571) {
296 adapter->have_msi = TRUE;
297 if ((err = pci_enable_msi(adapter->pdev))) {
299 "Unable to allocate MSI interrupt Error: %d\n", err);
300 adapter->have_msi = FALSE;
303 if (adapter->have_msi) {
304 flags &= ~IRQF_SHARED;
305 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, flags,
306 netdev->name, netdev);
309 "Unable to allocate interrupt Error: %d\n", err);
312 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
313 netdev->name, netdev)))
315 "Unable to allocate interrupt Error: %d\n", err);
320 static void e1000_free_irq(struct e1000_adapter *adapter)
322 struct net_device *netdev = adapter->netdev;
324 free_irq(adapter->pdev->irq, netdev);
326 #ifdef CONFIG_PCI_MSI
327 if (adapter->have_msi)
328 pci_disable_msi(adapter->pdev);
333 * e1000_irq_disable - Mask off interrupt generation on the NIC
334 * @adapter: board private structure
338 e1000_irq_disable(struct e1000_adapter *adapter)
340 atomic_inc(&adapter->irq_sem);
341 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
342 E1000_WRITE_FLUSH(&adapter->hw);
343 synchronize_irq(adapter->pdev->irq);
347 * e1000_irq_enable - Enable default interrupt generation settings
348 * @adapter: board private structure
352 e1000_irq_enable(struct e1000_adapter *adapter)
354 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
355 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
356 E1000_WRITE_FLUSH(&adapter->hw);
361 e1000_update_mng_vlan(struct e1000_adapter *adapter)
363 struct net_device *netdev = adapter->netdev;
364 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
365 uint16_t old_vid = adapter->mng_vlan_id;
366 if (adapter->vlgrp) {
367 if (!adapter->vlgrp->vlan_devices[vid]) {
368 if (adapter->hw.mng_cookie.status &
369 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
370 e1000_vlan_rx_add_vid(netdev, vid);
371 adapter->mng_vlan_id = vid;
373 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
375 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
377 !adapter->vlgrp->vlan_devices[old_vid])
378 e1000_vlan_rx_kill_vid(netdev, old_vid);
380 adapter->mng_vlan_id = vid;
385 * e1000_release_hw_control - release control of the h/w to f/w
386 * @adapter: address of board private structure
388 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
389 * For ASF and Pass Through versions of f/w this means that the
390 * driver is no longer loaded. For AMT version (only with 82573) i
391 * of the f/w this means that the network i/f is closed.
396 e1000_release_hw_control(struct e1000_adapter *adapter)
402 /* Let firmware taken over control of h/w */
403 switch (adapter->hw.mac_type) {
406 case e1000_80003es2lan:
407 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
408 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
409 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
412 swsm = E1000_READ_REG(&adapter->hw, SWSM);
413 E1000_WRITE_REG(&adapter->hw, SWSM,
414 swsm & ~E1000_SWSM_DRV_LOAD);
416 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
417 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
418 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
426 * e1000_get_hw_control - get control of the h/w from f/w
427 * @adapter: address of board private structure
429 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
430 * For ASF and Pass Through versions of f/w this means that
431 * the driver is loaded. For AMT version (only with 82573)
432 * of the f/w this means that the network i/f is open.
437 e1000_get_hw_control(struct e1000_adapter *adapter)
443 /* Let firmware know the driver has taken over */
444 switch (adapter->hw.mac_type) {
447 case e1000_80003es2lan:
448 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
449 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
450 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
453 swsm = E1000_READ_REG(&adapter->hw, SWSM);
454 E1000_WRITE_REG(&adapter->hw, SWSM,
455 swsm | E1000_SWSM_DRV_LOAD);
458 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
459 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
460 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
468 e1000_init_manageability(struct e1000_adapter *adapter)
470 if (adapter->en_mng_pt) {
471 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
473 /* disable hardware interception of ARP */
474 manc &= ~(E1000_MANC_ARP_EN);
476 /* enable receiving management packets to the host */
477 /* this will probably generate destination unreachable messages
478 * from the host OS, but the packets will be handled on SMBUS */
479 if (adapter->hw.has_manc2h) {
480 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
482 manc |= E1000_MANC_EN_MNG2HOST;
483 #define E1000_MNG2HOST_PORT_623 (1 << 5)
484 #define E1000_MNG2HOST_PORT_664 (1 << 6)
485 manc2h |= E1000_MNG2HOST_PORT_623;
486 manc2h |= E1000_MNG2HOST_PORT_664;
487 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
490 E1000_WRITE_REG(&adapter->hw, MANC, manc);
495 e1000_release_manageability(struct e1000_adapter *adapter)
497 if (adapter->en_mng_pt) {
498 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
500 /* re-enable hardware interception of ARP */
501 manc |= E1000_MANC_ARP_EN;
503 if (adapter->hw.has_manc2h)
504 manc &= ~E1000_MANC_EN_MNG2HOST;
506 /* don't explicitly have to mess with MANC2H since
507 * MANC has an enable disable that gates MANC2H */
509 E1000_WRITE_REG(&adapter->hw, MANC, manc);
514 e1000_up(struct e1000_adapter *adapter)
516 struct net_device *netdev = adapter->netdev;
519 /* hardware has been reset, we need to reload some things */
521 e1000_set_multi(netdev);
523 e1000_restore_vlan(adapter);
524 e1000_init_manageability(adapter);
526 e1000_configure_tx(adapter);
527 e1000_setup_rctl(adapter);
528 e1000_configure_rx(adapter);
529 /* call E1000_DESC_UNUSED which always leaves
530 * at least 1 descriptor unused to make sure
531 * next_to_use != next_to_clean */
532 for (i = 0; i < adapter->num_rx_queues; i++) {
533 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
534 adapter->alloc_rx_buf(adapter, ring,
535 E1000_DESC_UNUSED(ring));
538 adapter->tx_queue_len = netdev->tx_queue_len;
540 #ifdef CONFIG_E1000_NAPI
541 netif_poll_enable(netdev);
543 e1000_irq_enable(adapter);
545 clear_bit(__E1000_DOWN, &adapter->flags);
547 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
552 * e1000_power_up_phy - restore link in case the phy was powered down
553 * @adapter: address of board private structure
555 * The phy may be powered down to save power and turn off link when the
556 * driver is unloaded and wake on lan is not enabled (among others)
557 * *** this routine MUST be followed by a call to e1000_reset ***
561 void e1000_power_up_phy(struct e1000_adapter *adapter)
563 uint16_t mii_reg = 0;
565 /* Just clear the power down bit to wake the phy back up */
566 if (adapter->hw.media_type == e1000_media_type_copper) {
567 /* according to the manual, the phy will retain its
568 * settings across a power-down/up cycle */
569 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
570 mii_reg &= ~MII_CR_POWER_DOWN;
571 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
575 static void e1000_power_down_phy(struct e1000_adapter *adapter)
577 /* Power down the PHY so no link is implied when interface is down *
578 * The PHY cannot be powered down if any of the following is TRUE *
581 * (c) SoL/IDER session is active */
582 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
583 adapter->hw.media_type == e1000_media_type_copper) {
584 uint16_t mii_reg = 0;
586 switch (adapter->hw.mac_type) {
589 case e1000_82545_rev_3:
591 case e1000_82546_rev_3:
593 case e1000_82541_rev_2:
595 case e1000_82547_rev_2:
596 if (E1000_READ_REG(&adapter->hw, MANC) &
603 case e1000_80003es2lan:
605 if (e1000_check_mng_mode(&adapter->hw) ||
606 e1000_check_phy_reset_block(&adapter->hw))
612 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
613 mii_reg |= MII_CR_POWER_DOWN;
614 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
622 e1000_down(struct e1000_adapter *adapter)
624 struct net_device *netdev = adapter->netdev;
626 /* signal that we're down so the interrupt handler does not
627 * reschedule our watchdog timer */
628 set_bit(__E1000_DOWN, &adapter->flags);
630 e1000_irq_disable(adapter);
632 del_timer_sync(&adapter->tx_fifo_stall_timer);
633 del_timer_sync(&adapter->watchdog_timer);
634 del_timer_sync(&adapter->phy_info_timer);
636 #ifdef CONFIG_E1000_NAPI
637 netif_poll_disable(netdev);
639 netdev->tx_queue_len = adapter->tx_queue_len;
640 adapter->link_speed = 0;
641 adapter->link_duplex = 0;
642 netif_carrier_off(netdev);
643 netif_stop_queue(netdev);
645 e1000_reset(adapter);
646 e1000_clean_all_tx_rings(adapter);
647 e1000_clean_all_rx_rings(adapter);
651 e1000_reinit_locked(struct e1000_adapter *adapter)
653 WARN_ON(in_interrupt());
654 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
658 clear_bit(__E1000_RESETTING, &adapter->flags);
662 e1000_reset(struct e1000_adapter *adapter)
665 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
667 /* Repartition Pba for greater than 9k mtu
668 * To take effect CTRL.RST is required.
671 switch (adapter->hw.mac_type) {
673 case e1000_82547_rev_2:
678 case e1000_80003es2lan:
692 if ((adapter->hw.mac_type != e1000_82573) &&
693 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
694 pba -= 8; /* allocate more FIFO for Tx */
697 if (adapter->hw.mac_type == e1000_82547) {
698 adapter->tx_fifo_head = 0;
699 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
700 adapter->tx_fifo_size =
701 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
702 atomic_set(&adapter->tx_fifo_stall, 0);
705 E1000_WRITE_REG(&adapter->hw, PBA, pba);
707 /* flow control settings */
708 /* Set the FC high water mark to 90% of the FIFO size.
709 * Required to clear last 3 LSB */
710 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
711 /* We can't use 90% on small FIFOs because the remainder
712 * would be less than 1 full frame. In this case, we size
713 * it to allow at least a full frame above the high water
715 if (pba < E1000_PBA_16K)
716 fc_high_water_mark = (pba * 1024) - 1600;
718 adapter->hw.fc_high_water = fc_high_water_mark;
719 adapter->hw.fc_low_water = fc_high_water_mark - 8;
720 if (adapter->hw.mac_type == e1000_80003es2lan)
721 adapter->hw.fc_pause_time = 0xFFFF;
723 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
724 adapter->hw.fc_send_xon = 1;
725 adapter->hw.fc = adapter->hw.original_fc;
727 /* Allow time for pending master requests to run */
728 e1000_reset_hw(&adapter->hw);
729 if (adapter->hw.mac_type >= e1000_82544)
730 E1000_WRITE_REG(&adapter->hw, WUC, 0);
732 if (e1000_init_hw(&adapter->hw))
733 DPRINTK(PROBE, ERR, "Hardware Error\n");
734 e1000_update_mng_vlan(adapter);
736 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
737 if (adapter->hw.mac_type >= e1000_82544 &&
738 adapter->hw.mac_type <= e1000_82547_rev_2 &&
739 adapter->hw.autoneg == 1 &&
740 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
741 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
742 /* clear phy power management bit if we are in gig only mode,
743 * which if enabled will attempt negotiation to 100Mb, which
744 * can cause a loss of link at power off or driver unload */
745 ctrl &= ~E1000_CTRL_SWDPIN3;
746 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
749 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
750 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
752 e1000_reset_adaptive(&adapter->hw);
753 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
755 if (!adapter->smart_power_down &&
756 (adapter->hw.mac_type == e1000_82571 ||
757 adapter->hw.mac_type == e1000_82572)) {
758 uint16_t phy_data = 0;
759 /* speed up time to link by disabling smart power down, ignore
760 * the return value of this function because there is nothing
761 * different we would do if it failed */
762 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
764 phy_data &= ~IGP02E1000_PM_SPD;
765 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
769 e1000_release_manageability(adapter);
773 * e1000_probe - Device Initialization Routine
774 * @pdev: PCI device information struct
775 * @ent: entry in e1000_pci_tbl
777 * Returns 0 on success, negative on failure
779 * e1000_probe initializes an adapter identified by a pci_dev structure.
780 * The OS initialization, configuring of the adapter private structure,
781 * and a hardware reset occur.
785 e1000_probe(struct pci_dev *pdev,
786 const struct pci_device_id *ent)
788 struct net_device *netdev;
789 struct e1000_adapter *adapter;
790 unsigned long mmio_start, mmio_len;
791 unsigned long flash_start, flash_len;
793 static int cards_found = 0;
794 static int global_quad_port_a = 0; /* global ksp3 port a indication */
795 int i, err, pci_using_dac;
796 uint16_t eeprom_data = 0;
797 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
798 if ((err = pci_enable_device(pdev)))
801 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
802 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
805 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
806 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
807 E1000_ERR("No usable DMA configuration, aborting\n");
813 if ((err = pci_request_regions(pdev, e1000_driver_name)))
816 pci_set_master(pdev);
819 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
821 goto err_alloc_etherdev;
823 SET_MODULE_OWNER(netdev);
824 SET_NETDEV_DEV(netdev, &pdev->dev);
826 pci_set_drvdata(pdev, netdev);
827 adapter = netdev_priv(netdev);
828 adapter->netdev = netdev;
829 adapter->pdev = pdev;
830 adapter->hw.back = adapter;
831 adapter->msg_enable = (1 << debug) - 1;
833 mmio_start = pci_resource_start(pdev, BAR_0);
834 mmio_len = pci_resource_len(pdev, BAR_0);
837 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
838 if (!adapter->hw.hw_addr)
841 for (i = BAR_1; i <= BAR_5; i++) {
842 if (pci_resource_len(pdev, i) == 0)
844 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
845 adapter->hw.io_base = pci_resource_start(pdev, i);
850 netdev->open = &e1000_open;
851 netdev->stop = &e1000_close;
852 netdev->hard_start_xmit = &e1000_xmit_frame;
853 netdev->get_stats = &e1000_get_stats;
854 netdev->set_multicast_list = &e1000_set_multi;
855 netdev->set_mac_address = &e1000_set_mac;
856 netdev->change_mtu = &e1000_change_mtu;
857 netdev->do_ioctl = &e1000_ioctl;
858 e1000_set_ethtool_ops(netdev);
859 netdev->tx_timeout = &e1000_tx_timeout;
860 netdev->watchdog_timeo = 5 * HZ;
861 #ifdef CONFIG_E1000_NAPI
862 netdev->poll = &e1000_clean;
865 netdev->vlan_rx_register = e1000_vlan_rx_register;
866 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
867 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
868 #ifdef CONFIG_NET_POLL_CONTROLLER
869 netdev->poll_controller = e1000_netpoll;
871 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
873 netdev->mem_start = mmio_start;
874 netdev->mem_end = mmio_start + mmio_len;
875 netdev->base_addr = adapter->hw.io_base;
877 adapter->bd_number = cards_found;
879 /* setup the private structure */
881 if ((err = e1000_sw_init(adapter)))
885 /* Flash BAR mapping must happen after e1000_sw_init
886 * because it depends on mac_type */
887 if ((adapter->hw.mac_type == e1000_ich8lan) &&
888 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
889 flash_start = pci_resource_start(pdev, 1);
890 flash_len = pci_resource_len(pdev, 1);
891 adapter->hw.flash_address = ioremap(flash_start, flash_len);
892 if (!adapter->hw.flash_address)
896 if (e1000_check_phy_reset_block(&adapter->hw))
897 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
899 if (adapter->hw.mac_type >= e1000_82543) {
900 netdev->features = NETIF_F_SG |
904 NETIF_F_HW_VLAN_FILTER;
905 if (adapter->hw.mac_type == e1000_ich8lan)
906 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
910 if ((adapter->hw.mac_type >= e1000_82544) &&
911 (adapter->hw.mac_type != e1000_82547))
912 netdev->features |= NETIF_F_TSO;
914 #ifdef CONFIG_DEBUG_SLAB
915 /* 82544's work arounds do not play nicely with DEBUG SLAB */
916 if (adapter->hw.mac_type == e1000_82544)
917 netdev->features &= ~NETIF_F_TSO;
921 if (adapter->hw.mac_type > e1000_82547_rev_2)
922 netdev->features |= NETIF_F_TSO6;
926 netdev->features |= NETIF_F_HIGHDMA;
928 netdev->features |= NETIF_F_LLTX;
930 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
932 /* initialize eeprom parameters */
934 if (e1000_init_eeprom_params(&adapter->hw)) {
935 E1000_ERR("EEPROM initialization failed\n");
939 /* before reading the EEPROM, reset the controller to
940 * put the device in a known good starting state */
942 e1000_reset_hw(&adapter->hw);
944 /* make sure the EEPROM is good */
946 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
947 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
951 /* copy the MAC address out of the EEPROM */
953 if (e1000_read_mac_addr(&adapter->hw))
954 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
955 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
956 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
958 if (!is_valid_ether_addr(netdev->perm_addr)) {
959 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
963 e1000_get_bus_info(&adapter->hw);
965 init_timer(&adapter->tx_fifo_stall_timer);
966 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
967 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
969 init_timer(&adapter->watchdog_timer);
970 adapter->watchdog_timer.function = &e1000_watchdog;
971 adapter->watchdog_timer.data = (unsigned long) adapter;
973 init_timer(&adapter->phy_info_timer);
974 adapter->phy_info_timer.function = &e1000_update_phy_info;
975 adapter->phy_info_timer.data = (unsigned long) adapter;
977 INIT_WORK(&adapter->reset_task, e1000_reset_task);
979 e1000_check_options(adapter);
981 /* Initial Wake on LAN setting
982 * If APM wake is enabled in the EEPROM,
983 * enable the ACPI Magic Packet filter
986 switch (adapter->hw.mac_type) {
987 case e1000_82542_rev2_0:
988 case e1000_82542_rev2_1:
992 e1000_read_eeprom(&adapter->hw,
993 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
994 eeprom_apme_mask = E1000_EEPROM_82544_APM;
997 e1000_read_eeprom(&adapter->hw,
998 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
999 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1002 case e1000_82546_rev_3:
1004 case e1000_80003es2lan:
1005 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
1006 e1000_read_eeprom(&adapter->hw,
1007 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1012 e1000_read_eeprom(&adapter->hw,
1013 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1016 if (eeprom_data & eeprom_apme_mask)
1017 adapter->eeprom_wol |= E1000_WUFC_MAG;
1019 /* now that we have the eeprom settings, apply the special cases
1020 * where the eeprom may be wrong or the board simply won't support
1021 * wake on lan on a particular port */
1022 switch (pdev->device) {
1023 case E1000_DEV_ID_82546GB_PCIE:
1024 adapter->eeprom_wol = 0;
1026 case E1000_DEV_ID_82546EB_FIBER:
1027 case E1000_DEV_ID_82546GB_FIBER:
1028 case E1000_DEV_ID_82571EB_FIBER:
1029 /* Wake events only supported on port A for dual fiber
1030 * regardless of eeprom setting */
1031 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1032 adapter->eeprom_wol = 0;
1034 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1035 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1036 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1037 /* if quad port adapter, disable WoL on all but port A */
1038 if (global_quad_port_a != 0)
1039 adapter->eeprom_wol = 0;
1041 adapter->quad_port_a = 1;
1042 /* Reset for multiple quad port adapters */
1043 if (++global_quad_port_a == 4)
1044 global_quad_port_a = 0;
1048 /* initialize the wol settings based on the eeprom settings */
1049 adapter->wol = adapter->eeprom_wol;
1051 /* print bus type/speed/width info */
1053 struct e1000_hw *hw = &adapter->hw;
1054 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1055 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1056 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1057 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1058 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1059 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1060 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1061 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1062 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1063 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1064 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1068 for (i = 0; i < 6; i++)
1069 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
1071 /* reset the hardware with the new settings */
1072 e1000_reset(adapter);
1074 /* If the controller is 82573 and f/w is AMT, do not set
1075 * DRV_LOAD until the interface is up. For all other cases,
1076 * let the f/w know that the h/w is now under the control
1078 if (adapter->hw.mac_type != e1000_82573 ||
1079 !e1000_check_mng_mode(&adapter->hw))
1080 e1000_get_hw_control(adapter);
1082 strcpy(netdev->name, "eth%d");
1083 if ((err = register_netdev(netdev)))
1086 /* tell the stack to leave us alone until e1000_open() is called */
1087 netif_carrier_off(netdev);
1088 netif_stop_queue(netdev);
1090 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1096 e1000_release_hw_control(adapter);
1098 if (!e1000_check_phy_reset_block(&adapter->hw))
1099 e1000_phy_hw_reset(&adapter->hw);
1101 if (adapter->hw.flash_address)
1102 iounmap(adapter->hw.flash_address);
1104 #ifdef CONFIG_E1000_NAPI
1105 for (i = 0; i < adapter->num_rx_queues; i++)
1106 dev_put(&adapter->polling_netdev[i]);
1109 kfree(adapter->tx_ring);
1110 kfree(adapter->rx_ring);
1111 #ifdef CONFIG_E1000_NAPI
1112 kfree(adapter->polling_netdev);
1115 iounmap(adapter->hw.hw_addr);
1117 free_netdev(netdev);
1119 pci_release_regions(pdev);
1122 pci_disable_device(pdev);
1127 * e1000_remove - Device Removal Routine
1128 * @pdev: PCI device information struct
1130 * e1000_remove is called by the PCI subsystem to alert the driver
1131 * that it should release a PCI device. The could be caused by a
1132 * Hot-Plug event, or because the driver is going to be removed from
1136 static void __devexit
1137 e1000_remove(struct pci_dev *pdev)
1139 struct net_device *netdev = pci_get_drvdata(pdev);
1140 struct e1000_adapter *adapter = netdev_priv(netdev);
1141 #ifdef CONFIG_E1000_NAPI
1145 flush_scheduled_work();
1147 e1000_release_manageability(adapter);
1149 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1150 * would have already happened in close and is redundant. */
1151 e1000_release_hw_control(adapter);
1153 unregister_netdev(netdev);
1154 #ifdef CONFIG_E1000_NAPI
1155 for (i = 0; i < adapter->num_rx_queues; i++)
1156 dev_put(&adapter->polling_netdev[i]);
1159 if (!e1000_check_phy_reset_block(&adapter->hw))
1160 e1000_phy_hw_reset(&adapter->hw);
1162 kfree(adapter->tx_ring);
1163 kfree(adapter->rx_ring);
1164 #ifdef CONFIG_E1000_NAPI
1165 kfree(adapter->polling_netdev);
1168 iounmap(adapter->hw.hw_addr);
1169 if (adapter->hw.flash_address)
1170 iounmap(adapter->hw.flash_address);
1171 pci_release_regions(pdev);
1173 free_netdev(netdev);
1175 pci_disable_device(pdev);
1179 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1180 * @adapter: board private structure to initialize
1182 * e1000_sw_init initializes the Adapter private data structure.
1183 * Fields are initialized based on PCI device information and
1184 * OS network device settings (MTU size).
1187 static int __devinit
1188 e1000_sw_init(struct e1000_adapter *adapter)
1190 struct e1000_hw *hw = &adapter->hw;
1191 struct net_device *netdev = adapter->netdev;
1192 struct pci_dev *pdev = adapter->pdev;
1193 #ifdef CONFIG_E1000_NAPI
1197 /* PCI config space info */
1199 hw->vendor_id = pdev->vendor;
1200 hw->device_id = pdev->device;
1201 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1202 hw->subsystem_id = pdev->subsystem_device;
1204 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1206 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1208 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1209 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1210 hw->max_frame_size = netdev->mtu +
1211 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1212 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1214 /* identify the MAC */
1216 if (e1000_set_mac_type(hw)) {
1217 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1221 switch (hw->mac_type) {
1226 case e1000_82541_rev_2:
1227 case e1000_82547_rev_2:
1228 hw->phy_init_script = 1;
1232 e1000_set_media_type(hw);
1234 hw->wait_autoneg_complete = FALSE;
1235 hw->tbi_compatibility_en = TRUE;
1236 hw->adaptive_ifs = TRUE;
1238 /* Copper options */
1240 if (hw->media_type == e1000_media_type_copper) {
1241 hw->mdix = AUTO_ALL_MODES;
1242 hw->disable_polarity_correction = FALSE;
1243 hw->master_slave = E1000_MASTER_SLAVE;
1246 adapter->num_tx_queues = 1;
1247 adapter->num_rx_queues = 1;
1249 if (e1000_alloc_queues(adapter)) {
1250 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1254 #ifdef CONFIG_E1000_NAPI
1255 for (i = 0; i < adapter->num_rx_queues; i++) {
1256 adapter->polling_netdev[i].priv = adapter;
1257 adapter->polling_netdev[i].poll = &e1000_clean;
1258 adapter->polling_netdev[i].weight = 64;
1259 dev_hold(&adapter->polling_netdev[i]);
1260 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1262 spin_lock_init(&adapter->tx_queue_lock);
1265 atomic_set(&adapter->irq_sem, 1);
1266 spin_lock_init(&adapter->stats_lock);
1268 set_bit(__E1000_DOWN, &adapter->flags);
1274 * e1000_alloc_queues - Allocate memory for all rings
1275 * @adapter: board private structure to initialize
1277 * We allocate one ring per queue at run-time since we don't know the
1278 * number of queues at compile-time. The polling_netdev array is
1279 * intended for Multiqueue, but should work fine with a single queue.
1282 static int __devinit
1283 e1000_alloc_queues(struct e1000_adapter *adapter)
1287 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1288 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1289 if (!adapter->tx_ring)
1291 memset(adapter->tx_ring, 0, size);
1293 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1294 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1295 if (!adapter->rx_ring) {
1296 kfree(adapter->tx_ring);
1299 memset(adapter->rx_ring, 0, size);
1301 #ifdef CONFIG_E1000_NAPI
1302 size = sizeof(struct net_device) * adapter->num_rx_queues;
1303 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1304 if (!adapter->polling_netdev) {
1305 kfree(adapter->tx_ring);
1306 kfree(adapter->rx_ring);
1309 memset(adapter->polling_netdev, 0, size);
1312 return E1000_SUCCESS;
1316 * e1000_open - Called when a network interface is made active
1317 * @netdev: network interface device structure
1319 * Returns 0 on success, negative value on failure
1321 * The open entry point is called when a network interface is made
1322 * active by the system (IFF_UP). At this point all resources needed
1323 * for transmit and receive operations are allocated, the interrupt
1324 * handler is registered with the OS, the watchdog timer is started,
1325 * and the stack is notified that the interface is ready.
1329 e1000_open(struct net_device *netdev)
1331 struct e1000_adapter *adapter = netdev_priv(netdev);
1334 /* disallow open during test */
1335 if (test_bit(__E1000_TESTING, &adapter->flags))
1338 /* allocate transmit descriptors */
1339 if ((err = e1000_setup_all_tx_resources(adapter)))
1342 /* allocate receive descriptors */
1343 if ((err = e1000_setup_all_rx_resources(adapter)))
1346 err = e1000_request_irq(adapter);
1350 e1000_power_up_phy(adapter);
1352 if ((err = e1000_up(adapter)))
1354 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1355 if ((adapter->hw.mng_cookie.status &
1356 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1357 e1000_update_mng_vlan(adapter);
1360 /* If AMT is enabled, let the firmware know that the network
1361 * interface is now open */
1362 if (adapter->hw.mac_type == e1000_82573 &&
1363 e1000_check_mng_mode(&adapter->hw))
1364 e1000_get_hw_control(adapter);
1366 return E1000_SUCCESS;
1369 e1000_power_down_phy(adapter);
1370 e1000_free_irq(adapter);
1372 e1000_free_all_rx_resources(adapter);
1374 e1000_free_all_tx_resources(adapter);
1376 e1000_reset(adapter);
1382 * e1000_close - Disables a network interface
1383 * @netdev: network interface device structure
1385 * Returns 0, this is not allowed to fail
1387 * The close entry point is called when an interface is de-activated
1388 * by the OS. The hardware is still under the drivers control, but
1389 * needs to be disabled. A global MAC reset is issued to stop the
1390 * hardware, and all transmit and receive resources are freed.
1394 e1000_close(struct net_device *netdev)
1396 struct e1000_adapter *adapter = netdev_priv(netdev);
1398 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1399 e1000_down(adapter);
1400 e1000_power_down_phy(adapter);
1401 e1000_free_irq(adapter);
1403 e1000_free_all_tx_resources(adapter);
1404 e1000_free_all_rx_resources(adapter);
1406 /* kill manageability vlan ID if supported, but not if a vlan with
1407 * the same ID is registered on the host OS (let 8021q kill it) */
1408 if ((adapter->hw.mng_cookie.status &
1409 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1411 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
1412 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1415 /* If AMT is enabled, let the firmware know that the network
1416 * interface is now closed */
1417 if (adapter->hw.mac_type == e1000_82573 &&
1418 e1000_check_mng_mode(&adapter->hw))
1419 e1000_release_hw_control(adapter);
1425 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1426 * @adapter: address of board private structure
1427 * @start: address of beginning of memory
1428 * @len: length of memory
1431 e1000_check_64k_bound(struct e1000_adapter *adapter,
1432 void *start, unsigned long len)
1434 unsigned long begin = (unsigned long) start;
1435 unsigned long end = begin + len;
1437 /* First rev 82545 and 82546 need to not allow any memory
1438 * write location to cross 64k boundary due to errata 23 */
1439 if (adapter->hw.mac_type == e1000_82545 ||
1440 adapter->hw.mac_type == e1000_82546) {
1441 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1448 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1449 * @adapter: board private structure
1450 * @txdr: tx descriptor ring (for a specific queue) to setup
1452 * Return 0 on success, negative on failure
1456 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1457 struct e1000_tx_ring *txdr)
1459 struct pci_dev *pdev = adapter->pdev;
1462 size = sizeof(struct e1000_buffer) * txdr->count;
1463 txdr->buffer_info = vmalloc(size);
1464 if (!txdr->buffer_info) {
1466 "Unable to allocate memory for the transmit descriptor ring\n");
1469 memset(txdr->buffer_info, 0, size);
1471 /* round up to nearest 4K */
1473 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1474 E1000_ROUNDUP(txdr->size, 4096);
1476 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1479 vfree(txdr->buffer_info);
1481 "Unable to allocate memory for the transmit descriptor ring\n");
1485 /* Fix for errata 23, can't cross 64kB boundary */
1486 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1487 void *olddesc = txdr->desc;
1488 dma_addr_t olddma = txdr->dma;
1489 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1490 "at %p\n", txdr->size, txdr->desc);
1491 /* Try again, without freeing the previous */
1492 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1493 /* Failed allocation, critical failure */
1495 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1496 goto setup_tx_desc_die;
1499 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1501 pci_free_consistent(pdev, txdr->size, txdr->desc,
1503 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1505 "Unable to allocate aligned memory "
1506 "for the transmit descriptor ring\n");
1507 vfree(txdr->buffer_info);
1510 /* Free old allocation, new allocation was successful */
1511 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1514 memset(txdr->desc, 0, txdr->size);
1516 txdr->next_to_use = 0;
1517 txdr->next_to_clean = 0;
1518 spin_lock_init(&txdr->tx_lock);
1524 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1525 * (Descriptors) for all queues
1526 * @adapter: board private structure
1528 * Return 0 on success, negative on failure
1532 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1536 for (i = 0; i < adapter->num_tx_queues; i++) {
1537 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1540 "Allocation for Tx Queue %u failed\n", i);
1541 for (i-- ; i >= 0; i--)
1542 e1000_free_tx_resources(adapter,
1543 &adapter->tx_ring[i]);
1552 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1553 * @adapter: board private structure
1555 * Configure the Tx unit of the MAC after a reset.
1559 e1000_configure_tx(struct e1000_adapter *adapter)
1562 struct e1000_hw *hw = &adapter->hw;
1563 uint32_t tdlen, tctl, tipg, tarc;
1564 uint32_t ipgr1, ipgr2;
1566 /* Setup the HW Tx Head and Tail descriptor pointers */
1568 switch (adapter->num_tx_queues) {
1571 tdba = adapter->tx_ring[0].dma;
1572 tdlen = adapter->tx_ring[0].count *
1573 sizeof(struct e1000_tx_desc);
1574 E1000_WRITE_REG(hw, TDLEN, tdlen);
1575 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1576 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1577 E1000_WRITE_REG(hw, TDT, 0);
1578 E1000_WRITE_REG(hw, TDH, 0);
1579 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1580 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1584 /* Set the default values for the Tx Inter Packet Gap timer */
1586 if (hw->media_type == e1000_media_type_fiber ||
1587 hw->media_type == e1000_media_type_internal_serdes)
1588 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1590 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1592 switch (hw->mac_type) {
1593 case e1000_82542_rev2_0:
1594 case e1000_82542_rev2_1:
1595 tipg = DEFAULT_82542_TIPG_IPGT;
1596 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1597 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1599 case e1000_80003es2lan:
1600 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1601 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1604 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1605 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1608 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1609 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1610 E1000_WRITE_REG(hw, TIPG, tipg);
1612 /* Set the Tx Interrupt Delay register */
1614 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1615 if (hw->mac_type >= e1000_82540)
1616 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1618 /* Program the Transmit Control Register */
1620 tctl = E1000_READ_REG(hw, TCTL);
1621 tctl &= ~E1000_TCTL_CT;
1622 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1623 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1625 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1626 tarc = E1000_READ_REG(hw, TARC0);
1627 /* set the speed mode bit, we'll clear it if we're not at
1628 * gigabit link later */
1630 E1000_WRITE_REG(hw, TARC0, tarc);
1631 } else if (hw->mac_type == e1000_80003es2lan) {
1632 tarc = E1000_READ_REG(hw, TARC0);
1634 E1000_WRITE_REG(hw, TARC0, tarc);
1635 tarc = E1000_READ_REG(hw, TARC1);
1637 E1000_WRITE_REG(hw, TARC1, tarc);
1640 e1000_config_collision_dist(hw);
1642 /* Setup Transmit Descriptor Settings for eop descriptor */
1643 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1645 /* only set IDE if we are delaying interrupts using the timers */
1646 if (adapter->tx_int_delay)
1647 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1649 if (hw->mac_type < e1000_82543)
1650 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1652 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1654 /* Cache if we're 82544 running in PCI-X because we'll
1655 * need this to apply a workaround later in the send path. */
1656 if (hw->mac_type == e1000_82544 &&
1657 hw->bus_type == e1000_bus_type_pcix)
1658 adapter->pcix_82544 = 1;
1660 E1000_WRITE_REG(hw, TCTL, tctl);
1665 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1666 * @adapter: board private structure
1667 * @rxdr: rx descriptor ring (for a specific queue) to setup
1669 * Returns 0 on success, negative on failure
1673 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1674 struct e1000_rx_ring *rxdr)
1676 struct pci_dev *pdev = adapter->pdev;
1679 size = sizeof(struct e1000_buffer) * rxdr->count;
1680 rxdr->buffer_info = vmalloc(size);
1681 if (!rxdr->buffer_info) {
1683 "Unable to allocate memory for the receive descriptor ring\n");
1686 memset(rxdr->buffer_info, 0, size);
1688 size = sizeof(struct e1000_ps_page) * rxdr->count;
1689 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1690 if (!rxdr->ps_page) {
1691 vfree(rxdr->buffer_info);
1693 "Unable to allocate memory for the receive descriptor ring\n");
1696 memset(rxdr->ps_page, 0, size);
1698 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1699 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1700 if (!rxdr->ps_page_dma) {
1701 vfree(rxdr->buffer_info);
1702 kfree(rxdr->ps_page);
1704 "Unable to allocate memory for the receive descriptor ring\n");
1707 memset(rxdr->ps_page_dma, 0, size);
1709 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1710 desc_len = sizeof(struct e1000_rx_desc);
1712 desc_len = sizeof(union e1000_rx_desc_packet_split);
1714 /* Round up to nearest 4K */
1716 rxdr->size = rxdr->count * desc_len;
1717 E1000_ROUNDUP(rxdr->size, 4096);
1719 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1723 "Unable to allocate memory for the receive descriptor ring\n");
1725 vfree(rxdr->buffer_info);
1726 kfree(rxdr->ps_page);
1727 kfree(rxdr->ps_page_dma);
1731 /* Fix for errata 23, can't cross 64kB boundary */
1732 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1733 void *olddesc = rxdr->desc;
1734 dma_addr_t olddma = rxdr->dma;
1735 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1736 "at %p\n", rxdr->size, rxdr->desc);
1737 /* Try again, without freeing the previous */
1738 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1739 /* Failed allocation, critical failure */
1741 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1743 "Unable to allocate memory "
1744 "for the receive descriptor ring\n");
1745 goto setup_rx_desc_die;
1748 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1750 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1752 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1754 "Unable to allocate aligned memory "
1755 "for the receive descriptor ring\n");
1756 goto setup_rx_desc_die;
1758 /* Free old allocation, new allocation was successful */
1759 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1762 memset(rxdr->desc, 0, rxdr->size);
1764 rxdr->next_to_clean = 0;
1765 rxdr->next_to_use = 0;
1771 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1772 * (Descriptors) for all queues
1773 * @adapter: board private structure
1775 * Return 0 on success, negative on failure
1779 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1783 for (i = 0; i < adapter->num_rx_queues; i++) {
1784 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1787 "Allocation for Rx Queue %u failed\n", i);
1788 for (i-- ; i >= 0; i--)
1789 e1000_free_rx_resources(adapter,
1790 &adapter->rx_ring[i]);
1799 * e1000_setup_rctl - configure the receive control registers
1800 * @adapter: Board private structure
1802 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1803 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1805 e1000_setup_rctl(struct e1000_adapter *adapter)
1807 uint32_t rctl, rfctl;
1808 uint32_t psrctl = 0;
1809 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1813 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1815 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1817 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1818 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1819 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1821 if (adapter->hw.tbi_compatibility_on == 1)
1822 rctl |= E1000_RCTL_SBP;
1824 rctl &= ~E1000_RCTL_SBP;
1826 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1827 rctl &= ~E1000_RCTL_LPE;
1829 rctl |= E1000_RCTL_LPE;
1831 /* Setup buffer sizes */
1832 rctl &= ~E1000_RCTL_SZ_4096;
1833 rctl |= E1000_RCTL_BSEX;
1834 switch (adapter->rx_buffer_len) {
1835 case E1000_RXBUFFER_256:
1836 rctl |= E1000_RCTL_SZ_256;
1837 rctl &= ~E1000_RCTL_BSEX;
1839 case E1000_RXBUFFER_512:
1840 rctl |= E1000_RCTL_SZ_512;
1841 rctl &= ~E1000_RCTL_BSEX;
1843 case E1000_RXBUFFER_1024:
1844 rctl |= E1000_RCTL_SZ_1024;
1845 rctl &= ~E1000_RCTL_BSEX;
1847 case E1000_RXBUFFER_2048:
1849 rctl |= E1000_RCTL_SZ_2048;
1850 rctl &= ~E1000_RCTL_BSEX;
1852 case E1000_RXBUFFER_4096:
1853 rctl |= E1000_RCTL_SZ_4096;
1855 case E1000_RXBUFFER_8192:
1856 rctl |= E1000_RCTL_SZ_8192;
1858 case E1000_RXBUFFER_16384:
1859 rctl |= E1000_RCTL_SZ_16384;
1863 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1864 /* 82571 and greater support packet-split where the protocol
1865 * header is placed in skb->data and the packet data is
1866 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1867 * In the case of a non-split, skb->data is linearly filled,
1868 * followed by the page buffers. Therefore, skb->data is
1869 * sized to hold the largest protocol header.
1871 /* allocations using alloc_page take too long for regular MTU
1872 * so only enable packet split for jumbo frames */
1873 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1874 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1875 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
1876 adapter->rx_ps_pages = pages;
1878 adapter->rx_ps_pages = 0;
1880 if (adapter->rx_ps_pages) {
1881 /* Configure extra packet-split registers */
1882 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1883 rfctl |= E1000_RFCTL_EXTEN;
1884 /* disable packet split support for IPv6 extension headers,
1885 * because some malformed IPv6 headers can hang the RX */
1886 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1887 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1889 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1891 rctl |= E1000_RCTL_DTYP_PS;
1893 psrctl |= adapter->rx_ps_bsize0 >>
1894 E1000_PSRCTL_BSIZE0_SHIFT;
1896 switch (adapter->rx_ps_pages) {
1898 psrctl |= PAGE_SIZE <<
1899 E1000_PSRCTL_BSIZE3_SHIFT;
1901 psrctl |= PAGE_SIZE <<
1902 E1000_PSRCTL_BSIZE2_SHIFT;
1904 psrctl |= PAGE_SIZE >>
1905 E1000_PSRCTL_BSIZE1_SHIFT;
1909 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1912 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1916 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1917 * @adapter: board private structure
1919 * Configure the Rx unit of the MAC after a reset.
1923 e1000_configure_rx(struct e1000_adapter *adapter)
1926 struct e1000_hw *hw = &adapter->hw;
1927 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1929 if (adapter->rx_ps_pages) {
1930 /* this is a 32 byte descriptor */
1931 rdlen = adapter->rx_ring[0].count *
1932 sizeof(union e1000_rx_desc_packet_split);
1933 adapter->clean_rx = e1000_clean_rx_irq_ps;
1934 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1936 rdlen = adapter->rx_ring[0].count *
1937 sizeof(struct e1000_rx_desc);
1938 adapter->clean_rx = e1000_clean_rx_irq;
1939 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1942 /* disable receives while setting up the descriptors */
1943 rctl = E1000_READ_REG(hw, RCTL);
1944 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1946 /* set the Receive Delay Timer Register */
1947 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1949 if (hw->mac_type >= e1000_82540) {
1950 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1951 if (adapter->itr_setting != 0)
1952 E1000_WRITE_REG(hw, ITR,
1953 1000000000 / (adapter->itr * 256));
1956 if (hw->mac_type >= e1000_82571) {
1957 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1958 /* Reset delay timers after every interrupt */
1959 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
1960 #ifdef CONFIG_E1000_NAPI
1961 /* Auto-Mask interrupts upon ICR access */
1962 ctrl_ext |= E1000_CTRL_EXT_IAME;
1963 E1000_WRITE_REG(hw, IAM, 0xffffffff);
1965 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1966 E1000_WRITE_FLUSH(hw);
1969 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1970 * the Base and Length of the Rx Descriptor Ring */
1971 switch (adapter->num_rx_queues) {
1974 rdba = adapter->rx_ring[0].dma;
1975 E1000_WRITE_REG(hw, RDLEN, rdlen);
1976 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1977 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1978 E1000_WRITE_REG(hw, RDT, 0);
1979 E1000_WRITE_REG(hw, RDH, 0);
1980 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1981 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
1985 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1986 if (hw->mac_type >= e1000_82543) {
1987 rxcsum = E1000_READ_REG(hw, RXCSUM);
1988 if (adapter->rx_csum == TRUE) {
1989 rxcsum |= E1000_RXCSUM_TUOFL;
1991 /* Enable 82571 IPv4 payload checksum for UDP fragments
1992 * Must be used in conjunction with packet-split. */
1993 if ((hw->mac_type >= e1000_82571) &&
1994 (adapter->rx_ps_pages)) {
1995 rxcsum |= E1000_RXCSUM_IPPCSE;
1998 rxcsum &= ~E1000_RXCSUM_TUOFL;
1999 /* don't need to clear IPPCSE as it defaults to 0 */
2001 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
2004 /* enable early receives on 82573, only takes effect if using > 2048
2005 * byte total frame size. for example only for jumbo frames */
2006 #define E1000_ERT_2048 0x100
2007 if (hw->mac_type == e1000_82573)
2008 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2010 /* Enable Receives */
2011 E1000_WRITE_REG(hw, RCTL, rctl);
2015 * e1000_free_tx_resources - Free Tx Resources per Queue
2016 * @adapter: board private structure
2017 * @tx_ring: Tx descriptor ring for a specific queue
2019 * Free all transmit software resources
2023 e1000_free_tx_resources(struct e1000_adapter *adapter,
2024 struct e1000_tx_ring *tx_ring)
2026 struct pci_dev *pdev = adapter->pdev;
2028 e1000_clean_tx_ring(adapter, tx_ring);
2030 vfree(tx_ring->buffer_info);
2031 tx_ring->buffer_info = NULL;
2033 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2035 tx_ring->desc = NULL;
2039 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2040 * @adapter: board private structure
2042 * Free all transmit software resources
2046 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
2050 for (i = 0; i < adapter->num_tx_queues; i++)
2051 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
2055 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2056 struct e1000_buffer *buffer_info)
2058 if (buffer_info->dma) {
2059 pci_unmap_page(adapter->pdev,
2061 buffer_info->length,
2063 buffer_info->dma = 0;
2065 if (buffer_info->skb) {
2066 dev_kfree_skb_any(buffer_info->skb);
2067 buffer_info->skb = NULL;
2069 /* buffer_info must be completely set up in the transmit path */
2073 * e1000_clean_tx_ring - Free Tx Buffers
2074 * @adapter: board private structure
2075 * @tx_ring: ring to be cleaned
2079 e1000_clean_tx_ring(struct e1000_adapter *adapter,
2080 struct e1000_tx_ring *tx_ring)
2082 struct e1000_buffer *buffer_info;
2086 /* Free all the Tx ring sk_buffs */
2088 for (i = 0; i < tx_ring->count; i++) {
2089 buffer_info = &tx_ring->buffer_info[i];
2090 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2093 size = sizeof(struct e1000_buffer) * tx_ring->count;
2094 memset(tx_ring->buffer_info, 0, size);
2096 /* Zero out the descriptor ring */
2098 memset(tx_ring->desc, 0, tx_ring->size);
2100 tx_ring->next_to_use = 0;
2101 tx_ring->next_to_clean = 0;
2102 tx_ring->last_tx_tso = 0;
2104 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2105 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2109 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2110 * @adapter: board private structure
2114 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2118 for (i = 0; i < adapter->num_tx_queues; i++)
2119 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2123 * e1000_free_rx_resources - Free Rx Resources
2124 * @adapter: board private structure
2125 * @rx_ring: ring to clean the resources from
2127 * Free all receive software resources
2131 e1000_free_rx_resources(struct e1000_adapter *adapter,
2132 struct e1000_rx_ring *rx_ring)
2134 struct pci_dev *pdev = adapter->pdev;
2136 e1000_clean_rx_ring(adapter, rx_ring);
2138 vfree(rx_ring->buffer_info);
2139 rx_ring->buffer_info = NULL;
2140 kfree(rx_ring->ps_page);
2141 rx_ring->ps_page = NULL;
2142 kfree(rx_ring->ps_page_dma);
2143 rx_ring->ps_page_dma = NULL;
2145 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2147 rx_ring->desc = NULL;
2151 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2152 * @adapter: board private structure
2154 * Free all receive software resources
2158 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2162 for (i = 0; i < adapter->num_rx_queues; i++)
2163 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2167 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2168 * @adapter: board private structure
2169 * @rx_ring: ring to free buffers from
2173 e1000_clean_rx_ring(struct e1000_adapter *adapter,
2174 struct e1000_rx_ring *rx_ring)
2176 struct e1000_buffer *buffer_info;
2177 struct e1000_ps_page *ps_page;
2178 struct e1000_ps_page_dma *ps_page_dma;
2179 struct pci_dev *pdev = adapter->pdev;
2183 /* Free all the Rx ring sk_buffs */
2184 for (i = 0; i < rx_ring->count; i++) {
2185 buffer_info = &rx_ring->buffer_info[i];
2186 if (buffer_info->skb) {
2187 pci_unmap_single(pdev,
2189 buffer_info->length,
2190 PCI_DMA_FROMDEVICE);
2192 dev_kfree_skb(buffer_info->skb);
2193 buffer_info->skb = NULL;
2195 ps_page = &rx_ring->ps_page[i];
2196 ps_page_dma = &rx_ring->ps_page_dma[i];
2197 for (j = 0; j < adapter->rx_ps_pages; j++) {
2198 if (!ps_page->ps_page[j]) break;
2199 pci_unmap_page(pdev,
2200 ps_page_dma->ps_page_dma[j],
2201 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2202 ps_page_dma->ps_page_dma[j] = 0;
2203 put_page(ps_page->ps_page[j]);
2204 ps_page->ps_page[j] = NULL;
2208 size = sizeof(struct e1000_buffer) * rx_ring->count;
2209 memset(rx_ring->buffer_info, 0, size);
2210 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2211 memset(rx_ring->ps_page, 0, size);
2212 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2213 memset(rx_ring->ps_page_dma, 0, size);
2215 /* Zero out the descriptor ring */
2217 memset(rx_ring->desc, 0, rx_ring->size);
2219 rx_ring->next_to_clean = 0;
2220 rx_ring->next_to_use = 0;
2222 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2223 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2227 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2228 * @adapter: board private structure
2232 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2236 for (i = 0; i < adapter->num_rx_queues; i++)
2237 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2240 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2241 * and memory write and invalidate disabled for certain operations
2244 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2246 struct net_device *netdev = adapter->netdev;
2249 e1000_pci_clear_mwi(&adapter->hw);
2251 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2252 rctl |= E1000_RCTL_RST;
2253 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2254 E1000_WRITE_FLUSH(&adapter->hw);
2257 if (netif_running(netdev))
2258 e1000_clean_all_rx_rings(adapter);
2262 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2264 struct net_device *netdev = adapter->netdev;
2267 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2268 rctl &= ~E1000_RCTL_RST;
2269 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2270 E1000_WRITE_FLUSH(&adapter->hw);
2273 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2274 e1000_pci_set_mwi(&adapter->hw);
2276 if (netif_running(netdev)) {
2277 /* No need to loop, because 82542 supports only 1 queue */
2278 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2279 e1000_configure_rx(adapter);
2280 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2285 * e1000_set_mac - Change the Ethernet Address of the NIC
2286 * @netdev: network interface device structure
2287 * @p: pointer to an address structure
2289 * Returns 0 on success, negative on failure
2293 e1000_set_mac(struct net_device *netdev, void *p)
2295 struct e1000_adapter *adapter = netdev_priv(netdev);
2296 struct sockaddr *addr = p;
2298 if (!is_valid_ether_addr(addr->sa_data))
2299 return -EADDRNOTAVAIL;
2301 /* 82542 2.0 needs to be in reset to write receive address registers */
2303 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2304 e1000_enter_82542_rst(adapter);
2306 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2307 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2309 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2311 /* With 82571 controllers, LAA may be overwritten (with the default)
2312 * due to controller reset from the other port. */
2313 if (adapter->hw.mac_type == e1000_82571) {
2314 /* activate the work around */
2315 adapter->hw.laa_is_present = 1;
2317 /* Hold a copy of the LAA in RAR[14] This is done so that
2318 * between the time RAR[0] gets clobbered and the time it
2319 * gets fixed (in e1000_watchdog), the actual LAA is in one
2320 * of the RARs and no incoming packets directed to this port
2321 * are dropped. Eventaully the LAA will be in RAR[0] and
2323 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2324 E1000_RAR_ENTRIES - 1);
2327 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2328 e1000_leave_82542_rst(adapter);
2334 * e1000_set_multi - Multicast and Promiscuous mode set
2335 * @netdev: network interface device structure
2337 * The set_multi entry point is called whenever the multicast address
2338 * list or the network interface flags are updated. This routine is
2339 * responsible for configuring the hardware for proper multicast,
2340 * promiscuous mode, and all-multi behavior.
2344 e1000_set_multi(struct net_device *netdev)
2346 struct e1000_adapter *adapter = netdev_priv(netdev);
2347 struct e1000_hw *hw = &adapter->hw;
2348 struct dev_mc_list *mc_ptr;
2350 uint32_t hash_value;
2351 int i, rar_entries = E1000_RAR_ENTRIES;
2352 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2353 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2354 E1000_NUM_MTA_REGISTERS;
2356 if (adapter->hw.mac_type == e1000_ich8lan)
2357 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2359 /* reserve RAR[14] for LAA over-write work-around */
2360 if (adapter->hw.mac_type == e1000_82571)
2363 /* Check for Promiscuous and All Multicast modes */
2365 rctl = E1000_READ_REG(hw, RCTL);
2367 if (netdev->flags & IFF_PROMISC) {
2368 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2369 } else if (netdev->flags & IFF_ALLMULTI) {
2370 rctl |= E1000_RCTL_MPE;
2371 rctl &= ~E1000_RCTL_UPE;
2373 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2376 E1000_WRITE_REG(hw, RCTL, rctl);
2378 /* 82542 2.0 needs to be in reset to write receive address registers */
2380 if (hw->mac_type == e1000_82542_rev2_0)
2381 e1000_enter_82542_rst(adapter);
2383 /* load the first 14 multicast address into the exact filters 1-14
2384 * RAR 0 is used for the station MAC adddress
2385 * if there are not 14 addresses, go ahead and clear the filters
2386 * -- with 82571 controllers only 0-13 entries are filled here
2388 mc_ptr = netdev->mc_list;
2390 for (i = 1; i < rar_entries; i++) {
2392 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2393 mc_ptr = mc_ptr->next;
2395 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2396 E1000_WRITE_FLUSH(hw);
2397 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2398 E1000_WRITE_FLUSH(hw);
2402 /* clear the old settings from the multicast hash table */
2404 for (i = 0; i < mta_reg_count; i++) {
2405 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2406 E1000_WRITE_FLUSH(hw);
2409 /* load any remaining addresses into the hash table */
2411 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2412 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2413 e1000_mta_set(hw, hash_value);
2416 if (hw->mac_type == e1000_82542_rev2_0)
2417 e1000_leave_82542_rst(adapter);
2420 /* Need to wait a few seconds after link up to get diagnostic information from
2424 e1000_update_phy_info(unsigned long data)
2426 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2427 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2431 * e1000_82547_tx_fifo_stall - Timer Call-back
2432 * @data: pointer to adapter cast into an unsigned long
2436 e1000_82547_tx_fifo_stall(unsigned long data)
2438 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2439 struct net_device *netdev = adapter->netdev;
2442 if (atomic_read(&adapter->tx_fifo_stall)) {
2443 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2444 E1000_READ_REG(&adapter->hw, TDH)) &&
2445 (E1000_READ_REG(&adapter->hw, TDFT) ==
2446 E1000_READ_REG(&adapter->hw, TDFH)) &&
2447 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2448 E1000_READ_REG(&adapter->hw, TDFHS))) {
2449 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2450 E1000_WRITE_REG(&adapter->hw, TCTL,
2451 tctl & ~E1000_TCTL_EN);
2452 E1000_WRITE_REG(&adapter->hw, TDFT,
2453 adapter->tx_head_addr);
2454 E1000_WRITE_REG(&adapter->hw, TDFH,
2455 adapter->tx_head_addr);
2456 E1000_WRITE_REG(&adapter->hw, TDFTS,
2457 adapter->tx_head_addr);
2458 E1000_WRITE_REG(&adapter->hw, TDFHS,
2459 adapter->tx_head_addr);
2460 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2461 E1000_WRITE_FLUSH(&adapter->hw);
2463 adapter->tx_fifo_head = 0;
2464 atomic_set(&adapter->tx_fifo_stall, 0);
2465 netif_wake_queue(netdev);
2467 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2473 * e1000_watchdog - Timer Call-back
2474 * @data: pointer to adapter cast into an unsigned long
2477 e1000_watchdog(unsigned long data)
2479 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2480 struct net_device *netdev = adapter->netdev;
2481 struct e1000_tx_ring *txdr = adapter->tx_ring;
2482 uint32_t link, tctl;
2485 ret_val = e1000_check_for_link(&adapter->hw);
2486 if ((ret_val == E1000_ERR_PHY) &&
2487 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2488 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2489 /* See e1000_kumeran_lock_loss_workaround() */
2491 "Gigabit has been disabled, downgrading speed\n");
2494 if (adapter->hw.mac_type == e1000_82573) {
2495 e1000_enable_tx_pkt_filtering(&adapter->hw);
2496 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2497 e1000_update_mng_vlan(adapter);
2500 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2501 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2502 link = !adapter->hw.serdes_link_down;
2504 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2507 if (!netif_carrier_ok(netdev)) {
2508 boolean_t txb2b = 1;
2509 e1000_get_speed_and_duplex(&adapter->hw,
2510 &adapter->link_speed,
2511 &adapter->link_duplex);
2513 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2514 adapter->link_speed,
2515 adapter->link_duplex == FULL_DUPLEX ?
2516 "Full Duplex" : "Half Duplex");
2518 /* tweak tx_queue_len according to speed/duplex
2519 * and adjust the timeout factor */
2520 netdev->tx_queue_len = adapter->tx_queue_len;
2521 adapter->tx_timeout_factor = 1;
2522 switch (adapter->link_speed) {
2525 netdev->tx_queue_len = 10;
2526 adapter->tx_timeout_factor = 8;
2530 netdev->tx_queue_len = 100;
2531 /* maybe add some timeout factor ? */
2535 if ((adapter->hw.mac_type == e1000_82571 ||
2536 adapter->hw.mac_type == e1000_82572) &&
2539 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2540 tarc0 &= ~(1 << 21);
2541 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2545 /* disable TSO for pcie and 10/100 speeds, to avoid
2546 * some hardware issues */
2547 if (!adapter->tso_force &&
2548 adapter->hw.bus_type == e1000_bus_type_pci_express){
2549 switch (adapter->link_speed) {
2553 "10/100 speed: disabling TSO\n");
2554 netdev->features &= ~NETIF_F_TSO;
2556 netdev->features &= ~NETIF_F_TSO6;
2560 netdev->features |= NETIF_F_TSO;
2562 netdev->features |= NETIF_F_TSO6;
2572 /* enable transmits in the hardware, need to do this
2573 * after setting TARC0 */
2574 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2575 tctl |= E1000_TCTL_EN;
2576 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2578 netif_carrier_on(netdev);
2579 netif_wake_queue(netdev);
2580 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2581 adapter->smartspeed = 0;
2584 if (netif_carrier_ok(netdev)) {
2585 adapter->link_speed = 0;
2586 adapter->link_duplex = 0;
2587 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2588 netif_carrier_off(netdev);
2589 netif_stop_queue(netdev);
2590 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2592 /* 80003ES2LAN workaround--
2593 * For packet buffer work-around on link down event;
2594 * disable receives in the ISR and
2595 * reset device here in the watchdog
2597 if (adapter->hw.mac_type == e1000_80003es2lan)
2599 schedule_work(&adapter->reset_task);
2602 e1000_smartspeed(adapter);
2605 e1000_update_stats(adapter);
2607 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2608 adapter->tpt_old = adapter->stats.tpt;
2609 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2610 adapter->colc_old = adapter->stats.colc;
2612 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2613 adapter->gorcl_old = adapter->stats.gorcl;
2614 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2615 adapter->gotcl_old = adapter->stats.gotcl;
2617 e1000_update_adaptive(&adapter->hw);
2619 if (!netif_carrier_ok(netdev)) {
2620 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2621 /* We've lost link, so the controller stops DMA,
2622 * but we've got queued Tx work that's never going
2623 * to get done, so reset controller to flush Tx.
2624 * (Do the reset outside of interrupt context). */
2625 adapter->tx_timeout_count++;
2626 schedule_work(&adapter->reset_task);
2630 /* Cause software interrupt to ensure rx ring is cleaned */
2631 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2633 /* Force detection of hung controller every watchdog period */
2634 adapter->detect_tx_hung = TRUE;
2636 /* With 82571 controllers, LAA may be overwritten due to controller
2637 * reset from the other port. Set the appropriate LAA in RAR[0] */
2638 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2639 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2641 /* Reset the timer */
2642 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2645 enum latency_range {
2649 latency_invalid = 255
2653 * e1000_update_itr - update the dynamic ITR value based on statistics
2654 * Stores a new ITR value based on packets and byte
2655 * counts during the last interrupt. The advantage of per interrupt
2656 * computation is faster updates and more accurate ITR for the current
2657 * traffic pattern. Constants in this function were computed
2658 * based on theoretical maximum wire speed and thresholds were set based
2659 * on testing data as well as attempting to minimize response time
2660 * while increasing bulk throughput.
2661 * this functionality is controlled by the InterruptThrottleRate module
2662 * parameter (see e1000_param.c)
2663 * @adapter: pointer to adapter
2664 * @itr_setting: current adapter->itr
2665 * @packets: the number of packets during this measurement interval
2666 * @bytes: the number of bytes during this measurement interval
2668 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2669 uint16_t itr_setting,
2673 unsigned int retval = itr_setting;
2674 struct e1000_hw *hw = &adapter->hw;
2676 if (unlikely(hw->mac_type < e1000_82540))
2677 goto update_itr_done;
2680 goto update_itr_done;
2682 switch (itr_setting) {
2683 case lowest_latency:
2684 /* jumbo frames get bulk treatment*/
2685 if (bytes/packets > 8000)
2686 retval = bulk_latency;
2687 else if ((packets < 5) && (bytes > 512))
2688 retval = low_latency;
2690 case low_latency: /* 50 usec aka 20000 ints/s */
2691 if (bytes > 10000) {
2692 /* jumbo frames need bulk latency setting */
2693 if (bytes/packets > 8000)
2694 retval = bulk_latency;
2695 else if ((packets < 10) || ((bytes/packets) > 1200))
2696 retval = bulk_latency;
2697 else if ((packets > 35))
2698 retval = lowest_latency;
2699 } else if (bytes/packets > 2000)
2700 retval = bulk_latency;
2701 else if (packets <= 2 && bytes < 512)
2702 retval = lowest_latency;
2704 case bulk_latency: /* 250 usec aka 4000 ints/s */
2705 if (bytes > 25000) {
2707 retval = low_latency;
2708 } else if (bytes < 6000) {
2709 retval = low_latency;
2718 static void e1000_set_itr(struct e1000_adapter *adapter)
2720 struct e1000_hw *hw = &adapter->hw;
2721 uint16_t current_itr;
2722 uint32_t new_itr = adapter->itr;
2724 if (unlikely(hw->mac_type < e1000_82540))
2727 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2728 if (unlikely(adapter->link_speed != SPEED_1000)) {
2734 adapter->tx_itr = e1000_update_itr(adapter,
2736 adapter->total_tx_packets,
2737 adapter->total_tx_bytes);
2738 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2739 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2740 adapter->tx_itr = low_latency;
2742 adapter->rx_itr = e1000_update_itr(adapter,
2744 adapter->total_rx_packets,
2745 adapter->total_rx_bytes);
2746 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2747 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2748 adapter->rx_itr = low_latency;
2750 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2752 switch (current_itr) {
2753 /* counts and packets in update_itr are dependent on these numbers */
2754 case lowest_latency:
2758 new_itr = 20000; /* aka hwitr = ~200 */
2768 if (new_itr != adapter->itr) {
2769 /* this attempts to bias the interrupt rate towards Bulk
2770 * by adding intermediate steps when interrupt rate is
2772 new_itr = new_itr > adapter->itr ?
2773 min(adapter->itr + (new_itr >> 2), new_itr) :
2775 adapter->itr = new_itr;
2776 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2782 #define E1000_TX_FLAGS_CSUM 0x00000001
2783 #define E1000_TX_FLAGS_VLAN 0x00000002
2784 #define E1000_TX_FLAGS_TSO 0x00000004
2785 #define E1000_TX_FLAGS_IPV4 0x00000008
2786 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2787 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2790 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2791 struct sk_buff *skb)
2794 struct e1000_context_desc *context_desc;
2795 struct e1000_buffer *buffer_info;
2797 uint32_t cmd_length = 0;
2798 uint16_t ipcse = 0, tucse, mss;
2799 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2802 if (skb_is_gso(skb)) {
2803 if (skb_header_cloned(skb)) {
2804 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2809 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2810 mss = skb_shinfo(skb)->gso_size;
2811 if (skb->protocol == htons(ETH_P_IP)) {
2812 skb->nh.iph->tot_len = 0;
2813 skb->nh.iph->check = 0;
2815 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2820 cmd_length = E1000_TXD_CMD_IP;
2821 ipcse = skb->h.raw - skb->data - 1;
2823 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2824 skb->nh.ipv6h->payload_len = 0;
2826 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2827 &skb->nh.ipv6h->daddr,
2834 ipcss = skb->nh.raw - skb->data;
2835 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2836 tucss = skb->h.raw - skb->data;
2837 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2840 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2841 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2843 i = tx_ring->next_to_use;
2844 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2845 buffer_info = &tx_ring->buffer_info[i];
2847 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2848 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2849 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2850 context_desc->upper_setup.tcp_fields.tucss = tucss;
2851 context_desc->upper_setup.tcp_fields.tucso = tucso;
2852 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2853 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2854 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2855 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2857 buffer_info->time_stamp = jiffies;
2858 buffer_info->next_to_watch = i;
2860 if (++i == tx_ring->count) i = 0;
2861 tx_ring->next_to_use = i;
2871 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2872 struct sk_buff *skb)
2874 struct e1000_context_desc *context_desc;
2875 struct e1000_buffer *buffer_info;
2879 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
2880 css = skb->h.raw - skb->data;
2882 i = tx_ring->next_to_use;
2883 buffer_info = &tx_ring->buffer_info[i];
2884 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2886 context_desc->upper_setup.tcp_fields.tucss = css;
2887 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
2888 context_desc->upper_setup.tcp_fields.tucse = 0;
2889 context_desc->tcp_seg_setup.data = 0;
2890 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2892 buffer_info->time_stamp = jiffies;
2893 buffer_info->next_to_watch = i;
2895 if (unlikely(++i == tx_ring->count)) i = 0;
2896 tx_ring->next_to_use = i;
2904 #define E1000_MAX_TXD_PWR 12
2905 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2908 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2909 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2910 unsigned int nr_frags, unsigned int mss)
2912 struct e1000_buffer *buffer_info;
2913 unsigned int len = skb->len;
2914 unsigned int offset = 0, size, count = 0, i;
2916 len -= skb->data_len;
2918 i = tx_ring->next_to_use;
2921 buffer_info = &tx_ring->buffer_info[i];
2922 size = min(len, max_per_txd);
2924 /* Workaround for Controller erratum --
2925 * descriptor for non-tso packet in a linear SKB that follows a
2926 * tso gets written back prematurely before the data is fully
2927 * DMA'd to the controller */
2928 if (!skb->data_len && tx_ring->last_tx_tso &&
2930 tx_ring->last_tx_tso = 0;
2934 /* Workaround for premature desc write-backs
2935 * in TSO mode. Append 4-byte sentinel desc */
2936 if (unlikely(mss && !nr_frags && size == len && size > 8))
2939 /* work-around for errata 10 and it applies
2940 * to all controllers in PCI-X mode
2941 * The fix is to make sure that the first descriptor of a
2942 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2944 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2945 (size > 2015) && count == 0))
2948 /* Workaround for potential 82544 hang in PCI-X. Avoid
2949 * terminating buffers within evenly-aligned dwords. */
2950 if (unlikely(adapter->pcix_82544 &&
2951 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2955 buffer_info->length = size;
2957 pci_map_single(adapter->pdev,
2961 buffer_info->time_stamp = jiffies;
2962 buffer_info->next_to_watch = i;
2967 if (unlikely(++i == tx_ring->count)) i = 0;
2970 for (f = 0; f < nr_frags; f++) {
2971 struct skb_frag_struct *frag;
2973 frag = &skb_shinfo(skb)->frags[f];
2975 offset = frag->page_offset;
2978 buffer_info = &tx_ring->buffer_info[i];
2979 size = min(len, max_per_txd);
2981 /* Workaround for premature desc write-backs
2982 * in TSO mode. Append 4-byte sentinel desc */
2983 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2986 /* Workaround for potential 82544 hang in PCI-X.
2987 * Avoid terminating buffers within evenly-aligned
2989 if (unlikely(adapter->pcix_82544 &&
2990 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2994 buffer_info->length = size;
2996 pci_map_page(adapter->pdev,
3001 buffer_info->time_stamp = jiffies;
3002 buffer_info->next_to_watch = i;
3007 if (unlikely(++i == tx_ring->count)) i = 0;
3011 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3012 tx_ring->buffer_info[i].skb = skb;
3013 tx_ring->buffer_info[first].next_to_watch = i;
3019 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3020 int tx_flags, int count)
3022 struct e1000_tx_desc *tx_desc = NULL;
3023 struct e1000_buffer *buffer_info;
3024 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3027 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
3028 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3030 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3032 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3033 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3036 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3037 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3038 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3041 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3042 txd_lower |= E1000_TXD_CMD_VLE;
3043 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3046 i = tx_ring->next_to_use;
3049 buffer_info = &tx_ring->buffer_info[i];
3050 tx_desc = E1000_TX_DESC(*tx_ring, i);
3051 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3052 tx_desc->lower.data =
3053 cpu_to_le32(txd_lower | buffer_info->length);
3054 tx_desc->upper.data = cpu_to_le32(txd_upper);
3055 if (unlikely(++i == tx_ring->count)) i = 0;
3058 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3060 /* Force memory writes to complete before letting h/w
3061 * know there are new descriptors to fetch. (Only
3062 * applicable for weak-ordered memory model archs,
3063 * such as IA-64). */
3066 tx_ring->next_to_use = i;
3067 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
3068 /* we need this if more than one processor can write to our tail
3069 * at a time, it syncronizes IO on IA64/Altix systems */
3074 * 82547 workaround to avoid controller hang in half-duplex environment.
3075 * The workaround is to avoid queuing a large packet that would span
3076 * the internal Tx FIFO ring boundary by notifying the stack to resend
3077 * the packet at a later time. This gives the Tx FIFO an opportunity to
3078 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3079 * to the beginning of the Tx FIFO.
3082 #define E1000_FIFO_HDR 0x10
3083 #define E1000_82547_PAD_LEN 0x3E0
3086 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3088 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3089 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3091 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
3093 if (adapter->link_duplex != HALF_DUPLEX)
3094 goto no_fifo_stall_required;
3096 if (atomic_read(&adapter->tx_fifo_stall))
3099 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3100 atomic_set(&adapter->tx_fifo_stall, 1);
3104 no_fifo_stall_required:
3105 adapter->tx_fifo_head += skb_fifo_len;
3106 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3107 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3111 #define MINIMUM_DHCP_PACKET_SIZE 282
3113 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3115 struct e1000_hw *hw = &adapter->hw;
3116 uint16_t length, offset;
3117 if (vlan_tx_tag_present(skb)) {
3118 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
3119 ( adapter->hw.mng_cookie.status &
3120 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3123 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
3124 struct ethhdr *eth = (struct ethhdr *) skb->data;
3125 if ((htons(ETH_P_IP) == eth->h_proto)) {
3126 const struct iphdr *ip =
3127 (struct iphdr *)((uint8_t *)skb->data+14);
3128 if (IPPROTO_UDP == ip->protocol) {
3129 struct udphdr *udp =
3130 (struct udphdr *)((uint8_t *)ip +
3132 if (ntohs(udp->dest) == 67) {
3133 offset = (uint8_t *)udp + 8 - skb->data;
3134 length = skb->len - offset;
3136 return e1000_mng_write_dhcp_info(hw,
3146 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3148 struct e1000_adapter *adapter = netdev_priv(netdev);
3149 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3151 netif_stop_queue(netdev);
3152 /* Herbert's original patch had:
3153 * smp_mb__after_netif_stop_queue();
3154 * but since that doesn't exist yet, just open code it. */
3157 /* We need to check again in a case another CPU has just
3158 * made room available. */
3159 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3163 netif_start_queue(netdev);
3164 ++adapter->restart_queue;
3168 static int e1000_maybe_stop_tx(struct net_device *netdev,
3169 struct e1000_tx_ring *tx_ring, int size)
3171 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3173 return __e1000_maybe_stop_tx(netdev, size);
3176 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3178 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3180 struct e1000_adapter *adapter = netdev_priv(netdev);
3181 struct e1000_tx_ring *tx_ring;
3182 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3183 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3184 unsigned int tx_flags = 0;
3185 unsigned int len = skb->len;
3186 unsigned long flags;
3187 unsigned int nr_frags = 0;
3188 unsigned int mss = 0;
3192 len -= skb->data_len;
3194 /* This goes back to the question of how to logically map a tx queue
3195 * to a flow. Right now, performance is impacted slightly negatively
3196 * if using multiple tx queues. If the stack breaks away from a
3197 * single qdisc implementation, we can look at this again. */
3198 tx_ring = adapter->tx_ring;
3200 if (unlikely(skb->len <= 0)) {
3201 dev_kfree_skb_any(skb);
3202 return NETDEV_TX_OK;
3205 /* 82571 and newer doesn't need the workaround that limited descriptor
3207 if (adapter->hw.mac_type >= e1000_82571)
3211 mss = skb_shinfo(skb)->gso_size;
3212 /* The controller does a simple calculation to
3213 * make sure there is enough room in the FIFO before
3214 * initiating the DMA for each buffer. The calc is:
3215 * 4 = ceil(buffer len/mss). To make sure we don't
3216 * overrun the FIFO, adjust the max buffer len if mss
3220 max_per_txd = min(mss << 2, max_per_txd);
3221 max_txd_pwr = fls(max_per_txd) - 1;
3223 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3224 * points to just header, pull a few bytes of payload from
3225 * frags into skb->data */
3226 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
3227 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3228 switch (adapter->hw.mac_type) {
3229 unsigned int pull_size;
3234 pull_size = min((unsigned int)4, skb->data_len);
3235 if (!__pskb_pull_tail(skb, pull_size)) {
3237 "__pskb_pull_tail failed.\n");
3238 dev_kfree_skb_any(skb);
3239 return NETDEV_TX_OK;
3241 len = skb->len - skb->data_len;
3250 /* reserve a descriptor for the offload context */
3251 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3255 if (skb->ip_summed == CHECKSUM_PARTIAL)
3260 /* Controller Erratum workaround */
3261 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3265 count += TXD_USE_COUNT(len, max_txd_pwr);
3267 if (adapter->pcix_82544)
3270 /* work-around for errata 10 and it applies to all controllers
3271 * in PCI-X mode, so add one more descriptor to the count
3273 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
3277 nr_frags = skb_shinfo(skb)->nr_frags;
3278 for (f = 0; f < nr_frags; f++)
3279 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3281 if (adapter->pcix_82544)
3285 if (adapter->hw.tx_pkt_filtering &&
3286 (adapter->hw.mac_type == e1000_82573))
3287 e1000_transfer_dhcp_info(adapter, skb);
3289 local_irq_save(flags);
3290 if (!spin_trylock(&tx_ring->tx_lock)) {
3291 /* Collision - tell upper layer to requeue */
3292 local_irq_restore(flags);
3293 return NETDEV_TX_LOCKED;
3296 /* need: count + 2 desc gap to keep tail from touching
3297 * head, otherwise try next time */
3298 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
3299 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3300 return NETDEV_TX_BUSY;
3303 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3304 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3305 netif_stop_queue(netdev);
3306 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3307 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3308 return NETDEV_TX_BUSY;
3312 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
3313 tx_flags |= E1000_TX_FLAGS_VLAN;
3314 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3317 first = tx_ring->next_to_use;
3319 tso = e1000_tso(adapter, tx_ring, skb);
3321 dev_kfree_skb_any(skb);
3322 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3323 return NETDEV_TX_OK;
3327 tx_ring->last_tx_tso = 1;
3328 tx_flags |= E1000_TX_FLAGS_TSO;
3329 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3330 tx_flags |= E1000_TX_FLAGS_CSUM;
3332 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3333 * 82571 hardware supports TSO capabilities for IPv6 as well...
3334 * no longer assume, we must. */
3335 if (likely(skb->protocol == htons(ETH_P_IP)))
3336 tx_flags |= E1000_TX_FLAGS_IPV4;
3338 e1000_tx_queue(adapter, tx_ring, tx_flags,
3339 e1000_tx_map(adapter, tx_ring, skb, first,
3340 max_per_txd, nr_frags, mss));
3342 netdev->trans_start = jiffies;
3344 /* Make sure there is space in the ring for the next send. */
3345 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3347 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3348 return NETDEV_TX_OK;
3352 * e1000_tx_timeout - Respond to a Tx Hang
3353 * @netdev: network interface device structure
3357 e1000_tx_timeout(struct net_device *netdev)
3359 struct e1000_adapter *adapter = netdev_priv(netdev);
3361 /* Do the reset outside of interrupt context */
3362 adapter->tx_timeout_count++;
3363 schedule_work(&adapter->reset_task);
3367 e1000_reset_task(struct work_struct *work)
3369 struct e1000_adapter *adapter =
3370 container_of(work, struct e1000_adapter, reset_task);
3372 e1000_reinit_locked(adapter);
3376 * e1000_get_stats - Get System Network Statistics
3377 * @netdev: network interface device structure
3379 * Returns the address of the device statistics structure.
3380 * The statistics are actually updated from the timer callback.
3383 static struct net_device_stats *
3384 e1000_get_stats(struct net_device *netdev)
3386 struct e1000_adapter *adapter = netdev_priv(netdev);
3388 /* only return the current stats */
3389 return &adapter->net_stats;
3393 * e1000_change_mtu - Change the Maximum Transfer Unit
3394 * @netdev: network interface device structure
3395 * @new_mtu: new value for maximum frame size
3397 * Returns 0 on success, negative on failure
3401 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3403 struct e1000_adapter *adapter = netdev_priv(netdev);
3404 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3405 uint16_t eeprom_data = 0;
3407 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3408 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3409 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3413 /* Adapter-specific max frame size limits. */
3414 switch (adapter->hw.mac_type) {
3415 case e1000_undefined ... e1000_82542_rev2_1:
3417 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3418 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3423 /* Jumbo Frames not supported if:
3424 * - this is not an 82573L device
3425 * - ASPM is enabled in any way (0x1A bits 3:2) */
3426 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3428 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3429 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3430 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3432 "Jumbo Frames not supported.\n");
3437 /* ERT will be enabled later to enable wire speed receives */
3439 /* fall through to get support */
3442 case e1000_80003es2lan:
3443 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3444 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3445 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3450 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3454 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3455 * means we reserve 2 more, this pushes us to allocate from the next
3457 * i.e. RXBUFFER_2048 --> size-4096 slab */
3459 if (max_frame <= E1000_RXBUFFER_256)
3460 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3461 else if (max_frame <= E1000_RXBUFFER_512)
3462 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3463 else if (max_frame <= E1000_RXBUFFER_1024)
3464 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3465 else if (max_frame <= E1000_RXBUFFER_2048)
3466 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3467 else if (max_frame <= E1000_RXBUFFER_4096)
3468 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3469 else if (max_frame <= E1000_RXBUFFER_8192)
3470 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3471 else if (max_frame <= E1000_RXBUFFER_16384)
3472 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3474 /* adjust allocation if LPE protects us, and we aren't using SBP */
3475 if (!adapter->hw.tbi_compatibility_on &&
3476 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3477 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3478 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3480 netdev->mtu = new_mtu;
3482 if (netif_running(netdev))
3483 e1000_reinit_locked(adapter);
3485 adapter->hw.max_frame_size = max_frame;
3491 * e1000_update_stats - Update the board statistics counters
3492 * @adapter: board private structure
3496 e1000_update_stats(struct e1000_adapter *adapter)
3498 struct e1000_hw *hw = &adapter->hw;
3499 struct pci_dev *pdev = adapter->pdev;
3500 unsigned long flags;
3503 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3506 * Prevent stats update while adapter is being reset, or if the pci
3507 * connection is down.
3509 if (adapter->link_speed == 0)
3511 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3514 spin_lock_irqsave(&adapter->stats_lock, flags);
3516 /* these counters are modified from e1000_adjust_tbi_stats,
3517 * called from the interrupt context, so they must only
3518 * be written while holding adapter->stats_lock
3521 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3522 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3523 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3524 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3525 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3526 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3527 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3529 if (adapter->hw.mac_type != e1000_ich8lan) {
3530 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3531 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3532 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3533 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3534 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3535 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3538 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3539 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3540 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3541 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3542 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3543 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3544 adapter->stats.dc += E1000_READ_REG(hw, DC);
3545 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3546 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3547 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3548 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3549 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3550 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3551 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3552 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3553 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3554 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3555 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3556 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3557 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3558 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3559 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3560 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3561 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3562 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3563 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3565 if (adapter->hw.mac_type != e1000_ich8lan) {
3566 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3567 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3568 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3569 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3570 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3571 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3574 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3575 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3577 /* used for adaptive IFS */
3579 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3580 adapter->stats.tpt += hw->tx_packet_delta;
3581 hw->collision_delta = E1000_READ_REG(hw, COLC);
3582 adapter->stats.colc += hw->collision_delta;
3584 if (hw->mac_type >= e1000_82543) {
3585 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3586 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3587 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3588 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3589 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3590 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3592 if (hw->mac_type > e1000_82547_rev_2) {
3593 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3594 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3596 if (adapter->hw.mac_type != e1000_ich8lan) {
3597 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3598 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3599 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3600 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3601 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3602 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3603 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3607 /* Fill out the OS statistics structure */
3608 adapter->net_stats.rx_packets = adapter->stats.gprc;
3609 adapter->net_stats.tx_packets = adapter->stats.gptc;
3610 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3611 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3612 adapter->net_stats.multicast = adapter->stats.mprc;
3613 adapter->net_stats.collisions = adapter->stats.colc;
3617 /* RLEC on some newer hardware can be incorrect so build
3618 * our own version based on RUC and ROC */
3619 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3620 adapter->stats.crcerrs + adapter->stats.algnerrc +
3621 adapter->stats.ruc + adapter->stats.roc +
3622 adapter->stats.cexterr;
3623 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3624 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3625 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3626 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3627 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3630 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3631 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3632 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3633 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3634 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3635 if (adapter->hw.bad_tx_carr_stats_fd &&
3636 adapter->link_duplex == FULL_DUPLEX) {
3637 adapter->net_stats.tx_carrier_errors = 0;
3638 adapter->stats.tncrs = 0;
3641 /* Tx Dropped needs to be maintained elsewhere */
3644 if (hw->media_type == e1000_media_type_copper) {
3645 if ((adapter->link_speed == SPEED_1000) &&
3646 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3647 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3648 adapter->phy_stats.idle_errors += phy_tmp;
3651 if ((hw->mac_type <= e1000_82546) &&
3652 (hw->phy_type == e1000_phy_m88) &&
3653 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3654 adapter->phy_stats.receive_errors += phy_tmp;
3657 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3659 #ifdef CONFIG_PCI_MSI
3662 * e1000_intr_msi - Interrupt Handler
3663 * @irq: interrupt number
3664 * @data: pointer to a network interface device structure
3668 irqreturn_t e1000_intr_msi(int irq, void *data)
3670 struct net_device *netdev = data;
3671 struct e1000_adapter *adapter = netdev_priv(netdev);
3672 struct e1000_hw *hw = &adapter->hw;
3673 #ifndef CONFIG_E1000_NAPI
3677 /* this code avoids the read of ICR but has to get 1000 interrupts
3678 * at every link change event before it will notice the change */
3679 if (++adapter->detect_link >= 1000) {
3680 uint32_t icr = E1000_READ_REG(hw, ICR);
3681 #ifdef CONFIG_E1000_NAPI
3682 /* read ICR disables interrupts using IAM, so keep up with our
3683 * enable/disable accounting */
3684 atomic_inc(&adapter->irq_sem);
3686 adapter->detect_link = 0;
3687 if ((icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) &&
3688 (icr & E1000_ICR_INT_ASSERTED)) {
3689 hw->get_link_status = 1;
3690 /* 80003ES2LAN workaround--
3691 * For packet buffer work-around on link down event;
3692 * disable receives here in the ISR and
3693 * reset adapter in watchdog
3695 if (netif_carrier_ok(netdev) &&
3696 (adapter->hw.mac_type == e1000_80003es2lan)) {
3697 /* disable receives */
3698 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3699 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3701 /* guard against interrupt when we're going down */
3702 if (!test_bit(__E1000_DOWN, &adapter->flags))
3703 mod_timer(&adapter->watchdog_timer,
3707 E1000_WRITE_REG(hw, ICR, (0xffffffff & ~(E1000_ICR_RXSEQ |
3709 /* bummer we have to flush here, but things break otherwise as
3710 * some event appears to be lost or delayed and throughput
3711 * drops. In almost all tests this flush is un-necessary */
3712 E1000_WRITE_FLUSH(hw);
3713 #ifdef CONFIG_E1000_NAPI
3714 /* Interrupt Auto-Mask (IAM)...upon writing ICR, interrupts are
3715 * masked. No need for the IMC write, but it does mean we
3716 * should account for it ASAP. */
3717 atomic_inc(&adapter->irq_sem);
3721 #ifdef CONFIG_E1000_NAPI
3722 if (likely(netif_rx_schedule_prep(netdev))) {
3723 adapter->total_tx_bytes = 0;
3724 adapter->total_tx_packets = 0;
3725 adapter->total_rx_bytes = 0;
3726 adapter->total_rx_packets = 0;
3727 __netif_rx_schedule(netdev);
3729 e1000_irq_enable(adapter);
3731 adapter->total_tx_bytes = 0;
3732 adapter->total_rx_bytes = 0;
3733 adapter->total_tx_packets = 0;
3734 adapter->total_rx_packets = 0;
3736 for (i = 0; i < E1000_MAX_INTR; i++)
3737 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3738 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3741 if (likely(adapter->itr_setting & 3))
3742 e1000_set_itr(adapter);
3750 * e1000_intr - Interrupt Handler
3751 * @irq: interrupt number
3752 * @data: pointer to a network interface device structure
3756 e1000_intr(int irq, void *data)
3758 struct net_device *netdev = data;
3759 struct e1000_adapter *adapter = netdev_priv(netdev);
3760 struct e1000_hw *hw = &adapter->hw;
3761 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
3762 #ifndef CONFIG_E1000_NAPI
3766 return IRQ_NONE; /* Not our interrupt */
3768 #ifdef CONFIG_E1000_NAPI
3769 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3770 * not set, then the adapter didn't send an interrupt */
3771 if (unlikely(hw->mac_type >= e1000_82571 &&
3772 !(icr & E1000_ICR_INT_ASSERTED)))
3775 /* Interrupt Auto-Mask...upon reading ICR,
3776 * interrupts are masked. No need for the
3777 * IMC write, but it does mean we should
3778 * account for it ASAP. */
3779 if (likely(hw->mac_type >= e1000_82571))
3780 atomic_inc(&adapter->irq_sem);
3783 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3784 hw->get_link_status = 1;
3785 /* 80003ES2LAN workaround--
3786 * For packet buffer work-around on link down event;
3787 * disable receives here in the ISR and
3788 * reset adapter in watchdog
3790 if (netif_carrier_ok(netdev) &&
3791 (adapter->hw.mac_type == e1000_80003es2lan)) {
3792 /* disable receives */
3793 rctl = E1000_READ_REG(hw, RCTL);
3794 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3796 /* guard against interrupt when we're going down */
3797 if (!test_bit(__E1000_DOWN, &adapter->flags))
3798 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3801 #ifdef CONFIG_E1000_NAPI
3802 if (unlikely(hw->mac_type < e1000_82571)) {
3803 /* disable interrupts, without the synchronize_irq bit */
3804 atomic_inc(&adapter->irq_sem);
3805 E1000_WRITE_REG(hw, IMC, ~0);
3806 E1000_WRITE_FLUSH(hw);
3808 if (likely(netif_rx_schedule_prep(netdev))) {
3809 adapter->total_tx_bytes = 0;
3810 adapter->total_tx_packets = 0;
3811 adapter->total_rx_bytes = 0;
3812 adapter->total_rx_packets = 0;
3813 __netif_rx_schedule(netdev);
3815 /* this really should not happen! if it does it is basically a
3816 * bug, but not a hard error, so enable ints and continue */
3817 e1000_irq_enable(adapter);
3819 /* Writing IMC and IMS is needed for 82547.
3820 * Due to Hub Link bus being occupied, an interrupt
3821 * de-assertion message is not able to be sent.
3822 * When an interrupt assertion message is generated later,
3823 * two messages are re-ordered and sent out.
3824 * That causes APIC to think 82547 is in de-assertion
3825 * state, while 82547 is in assertion state, resulting
3826 * in dead lock. Writing IMC forces 82547 into
3827 * de-assertion state.
3829 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3830 atomic_inc(&adapter->irq_sem);
3831 E1000_WRITE_REG(hw, IMC, ~0);
3834 adapter->total_tx_bytes = 0;
3835 adapter->total_rx_bytes = 0;
3836 adapter->total_tx_packets = 0;
3837 adapter->total_rx_packets = 0;
3839 for (i = 0; i < E1000_MAX_INTR; i++)
3840 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3841 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3844 if (likely(adapter->itr_setting & 3))
3845 e1000_set_itr(adapter);
3847 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3848 e1000_irq_enable(adapter);
3854 #ifdef CONFIG_E1000_NAPI
3856 * e1000_clean - NAPI Rx polling callback
3857 * @adapter: board private structure
3861 e1000_clean(struct net_device *poll_dev, int *budget)
3863 struct e1000_adapter *adapter;
3864 int work_to_do = min(*budget, poll_dev->quota);
3865 int tx_cleaned = 0, work_done = 0;
3867 /* Must NOT use netdev_priv macro here. */
3868 adapter = poll_dev->priv;
3870 /* Keep link state information with original netdev */
3871 if (!netif_carrier_ok(poll_dev))
3874 /* e1000_clean is called per-cpu. This lock protects
3875 * tx_ring[0] from being cleaned by multiple cpus
3876 * simultaneously. A failure obtaining the lock means
3877 * tx_ring[0] is currently being cleaned anyway. */
3878 if (spin_trylock(&adapter->tx_queue_lock)) {
3879 tx_cleaned = e1000_clean_tx_irq(adapter,
3880 &adapter->tx_ring[0]);
3881 spin_unlock(&adapter->tx_queue_lock);
3884 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3885 &work_done, work_to_do);
3887 *budget -= work_done;
3888 poll_dev->quota -= work_done;
3890 /* If no Tx and not enough Rx work done, exit the polling mode */
3891 if ((!tx_cleaned && (work_done == 0)) ||
3892 !netif_running(poll_dev)) {
3894 if (likely(adapter->itr_setting & 3))
3895 e1000_set_itr(adapter);
3896 netif_rx_complete(poll_dev);
3897 e1000_irq_enable(adapter);
3906 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3907 * @adapter: board private structure
3911 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3912 struct e1000_tx_ring *tx_ring)
3914 struct net_device *netdev = adapter->netdev;
3915 struct e1000_tx_desc *tx_desc, *eop_desc;
3916 struct e1000_buffer *buffer_info;
3917 unsigned int i, eop;
3918 #ifdef CONFIG_E1000_NAPI
3919 unsigned int count = 0;
3921 boolean_t cleaned = FALSE;
3922 unsigned int total_tx_bytes=0, total_tx_packets=0;
3924 i = tx_ring->next_to_clean;
3925 eop = tx_ring->buffer_info[i].next_to_watch;
3926 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3928 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3929 for (cleaned = FALSE; !cleaned; ) {
3930 tx_desc = E1000_TX_DESC(*tx_ring, i);
3931 buffer_info = &tx_ring->buffer_info[i];
3932 cleaned = (i == eop);
3935 struct sk_buff *skb = buffer_info->skb;
3936 unsigned int segs = skb_shinfo(skb)->gso_segs;
3937 total_tx_packets += segs;
3939 total_tx_bytes += skb->len;
3941 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3942 tx_desc->upper.data = 0;
3944 if (unlikely(++i == tx_ring->count)) i = 0;
3947 eop = tx_ring->buffer_info[i].next_to_watch;
3948 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3949 #ifdef CONFIG_E1000_NAPI
3950 #define E1000_TX_WEIGHT 64
3951 /* weight of a sort for tx, to avoid endless transmit cleanup */
3952 if (count++ == E1000_TX_WEIGHT) break;
3956 tx_ring->next_to_clean = i;
3958 #define TX_WAKE_THRESHOLD 32
3959 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3960 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3961 /* Make sure that anybody stopping the queue after this
3962 * sees the new next_to_clean.
3965 if (netif_queue_stopped(netdev)) {
3966 netif_wake_queue(netdev);
3967 ++adapter->restart_queue;
3971 if (adapter->detect_tx_hung) {
3972 /* Detect a transmit hang in hardware, this serializes the
3973 * check with the clearing of time_stamp and movement of i */
3974 adapter->detect_tx_hung = FALSE;
3975 if (tx_ring->buffer_info[eop].dma &&
3976 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3977 (adapter->tx_timeout_factor * HZ))
3978 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3979 E1000_STATUS_TXOFF)) {
3981 /* detected Tx unit hang */
3982 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3986 " next_to_use <%x>\n"
3987 " next_to_clean <%x>\n"
3988 "buffer_info[next_to_clean]\n"
3989 " time_stamp <%lx>\n"
3990 " next_to_watch <%x>\n"
3992 " next_to_watch.status <%x>\n",
3993 (unsigned long)((tx_ring - adapter->tx_ring) /
3994 sizeof(struct e1000_tx_ring)),
3995 readl(adapter->hw.hw_addr + tx_ring->tdh),
3996 readl(adapter->hw.hw_addr + tx_ring->tdt),
3997 tx_ring->next_to_use,
3998 tx_ring->next_to_clean,
3999 tx_ring->buffer_info[eop].time_stamp,
4002 eop_desc->upper.fields.status);
4003 netif_stop_queue(netdev);
4006 adapter->total_tx_bytes += total_tx_bytes;
4007 adapter->total_tx_packets += total_tx_packets;
4012 * e1000_rx_checksum - Receive Checksum Offload for 82543
4013 * @adapter: board private structure
4014 * @status_err: receive descriptor status and error fields
4015 * @csum: receive descriptor csum field
4016 * @sk_buff: socket buffer with received data
4020 e1000_rx_checksum(struct e1000_adapter *adapter,
4021 uint32_t status_err, uint32_t csum,
4022 struct sk_buff *skb)
4024 uint16_t status = (uint16_t)status_err;
4025 uint8_t errors = (uint8_t)(status_err >> 24);
4026 skb->ip_summed = CHECKSUM_NONE;
4028 /* 82543 or newer only */
4029 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
4030 /* Ignore Checksum bit is set */
4031 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
4032 /* TCP/UDP checksum error bit is set */
4033 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
4034 /* let the stack verify checksum errors */
4035 adapter->hw_csum_err++;
4038 /* TCP/UDP Checksum has not been calculated */
4039 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4040 if (!(status & E1000_RXD_STAT_TCPCS))
4043 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
4046 /* It must be a TCP or UDP packet with a valid checksum */
4047 if (likely(status & E1000_RXD_STAT_TCPCS)) {
4048 /* TCP checksum is good */
4049 skb->ip_summed = CHECKSUM_UNNECESSARY;
4050 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4051 /* IP fragment with UDP payload */
4052 /* Hardware complements the payload checksum, so we undo it
4053 * and then put the value in host order for further stack use.
4055 csum = ntohl(csum ^ 0xFFFF);
4057 skb->ip_summed = CHECKSUM_COMPLETE;
4059 adapter->hw_csum_good++;
4063 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4064 * @adapter: board private structure
4068 #ifdef CONFIG_E1000_NAPI
4069 e1000_clean_rx_irq(struct e1000_adapter *adapter,
4070 struct e1000_rx_ring *rx_ring,
4071 int *work_done, int work_to_do)
4073 e1000_clean_rx_irq(struct e1000_adapter *adapter,
4074 struct e1000_rx_ring *rx_ring)
4077 struct net_device *netdev = adapter->netdev;
4078 struct pci_dev *pdev = adapter->pdev;
4079 struct e1000_rx_desc *rx_desc, *next_rxd;
4080 struct e1000_buffer *buffer_info, *next_buffer;
4081 unsigned long flags;
4085 int cleaned_count = 0;
4086 boolean_t cleaned = FALSE;
4087 unsigned int total_rx_bytes=0, total_rx_packets=0;
4089 i = rx_ring->next_to_clean;
4090 rx_desc = E1000_RX_DESC(*rx_ring, i);
4091 buffer_info = &rx_ring->buffer_info[i];
4093 while (rx_desc->status & E1000_RXD_STAT_DD) {
4094 struct sk_buff *skb;
4097 #ifdef CONFIG_E1000_NAPI
4098 if (*work_done >= work_to_do)
4102 status = rx_desc->status;
4103 skb = buffer_info->skb;
4104 buffer_info->skb = NULL;
4106 prefetch(skb->data - NET_IP_ALIGN);
4108 if (++i == rx_ring->count) i = 0;
4109 next_rxd = E1000_RX_DESC(*rx_ring, i);
4112 next_buffer = &rx_ring->buffer_info[i];
4116 pci_unmap_single(pdev,
4118 buffer_info->length,
4119 PCI_DMA_FROMDEVICE);
4121 length = le16_to_cpu(rx_desc->length);
4123 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4124 /* All receives must fit into a single buffer */
4125 E1000_DBG("%s: Receive packet consumed multiple"
4126 " buffers\n", netdev->name);
4128 buffer_info->skb = skb;
4132 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4133 last_byte = *(skb->data + length - 1);
4134 if (TBI_ACCEPT(&adapter->hw, status,
4135 rx_desc->errors, length, last_byte)) {
4136 spin_lock_irqsave(&adapter->stats_lock, flags);
4137 e1000_tbi_adjust_stats(&adapter->hw,
4140 spin_unlock_irqrestore(&adapter->stats_lock,
4145 buffer_info->skb = skb;
4150 /* adjust length to remove Ethernet CRC, this must be
4151 * done after the TBI_ACCEPT workaround above */
4154 /* probably a little skewed due to removing CRC */
4155 total_rx_bytes += length;
4158 /* code added for copybreak, this should improve
4159 * performance for small packets with large amounts
4160 * of reassembly being done in the stack */
4161 #define E1000_CB_LENGTH 256
4162 if (length < E1000_CB_LENGTH) {
4163 struct sk_buff *new_skb =
4164 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4166 skb_reserve(new_skb, NET_IP_ALIGN);
4167 memcpy(new_skb->data - NET_IP_ALIGN,
4168 skb->data - NET_IP_ALIGN,
4169 length + NET_IP_ALIGN);
4170 /* save the skb in buffer_info as good */
4171 buffer_info->skb = skb;
4174 /* else just continue with the old one */
4176 /* end copybreak code */
4177 skb_put(skb, length);
4179 /* Receive Checksum Offload */
4180 e1000_rx_checksum(adapter,
4181 (uint32_t)(status) |
4182 ((uint32_t)(rx_desc->errors) << 24),
4183 le16_to_cpu(rx_desc->csum), skb);
4185 skb->protocol = eth_type_trans(skb, netdev);
4186 #ifdef CONFIG_E1000_NAPI
4187 if (unlikely(adapter->vlgrp &&
4188 (status & E1000_RXD_STAT_VP))) {
4189 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4190 le16_to_cpu(rx_desc->special) &
4191 E1000_RXD_SPC_VLAN_MASK);
4193 netif_receive_skb(skb);
4195 #else /* CONFIG_E1000_NAPI */
4196 if (unlikely(adapter->vlgrp &&
4197 (status & E1000_RXD_STAT_VP))) {
4198 vlan_hwaccel_rx(skb, adapter->vlgrp,
4199 le16_to_cpu(rx_desc->special) &
4200 E1000_RXD_SPC_VLAN_MASK);
4204 #endif /* CONFIG_E1000_NAPI */
4205 netdev->last_rx = jiffies;
4208 rx_desc->status = 0;
4210 /* return some buffers to hardware, one at a time is too slow */
4211 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4212 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4216 /* use prefetched values */
4218 buffer_info = next_buffer;
4220 rx_ring->next_to_clean = i;
4222 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4224 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4226 adapter->total_rx_packets += total_rx_packets;
4227 adapter->total_rx_bytes += total_rx_bytes;
4232 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4233 * @adapter: board private structure
4237 #ifdef CONFIG_E1000_NAPI
4238 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4239 struct e1000_rx_ring *rx_ring,
4240 int *work_done, int work_to_do)
4242 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4243 struct e1000_rx_ring *rx_ring)
4246 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
4247 struct net_device *netdev = adapter->netdev;
4248 struct pci_dev *pdev = adapter->pdev;
4249 struct e1000_buffer *buffer_info, *next_buffer;
4250 struct e1000_ps_page *ps_page;
4251 struct e1000_ps_page_dma *ps_page_dma;
4252 struct sk_buff *skb;
4254 uint32_t length, staterr;
4255 int cleaned_count = 0;
4256 boolean_t cleaned = FALSE;
4257 unsigned int total_rx_bytes=0, total_rx_packets=0;
4259 i = rx_ring->next_to_clean;
4260 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4261 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4262 buffer_info = &rx_ring->buffer_info[i];
4264 while (staterr & E1000_RXD_STAT_DD) {
4265 ps_page = &rx_ring->ps_page[i];
4266 ps_page_dma = &rx_ring->ps_page_dma[i];
4267 #ifdef CONFIG_E1000_NAPI
4268 if (unlikely(*work_done >= work_to_do))
4272 skb = buffer_info->skb;
4274 /* in the packet split case this is header only */
4275 prefetch(skb->data - NET_IP_ALIGN);
4277 if (++i == rx_ring->count) i = 0;
4278 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
4281 next_buffer = &rx_ring->buffer_info[i];
4285 pci_unmap_single(pdev, buffer_info->dma,
4286 buffer_info->length,
4287 PCI_DMA_FROMDEVICE);
4289 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
4290 E1000_DBG("%s: Packet Split buffers didn't pick up"
4291 " the full packet\n", netdev->name);
4292 dev_kfree_skb_irq(skb);
4296 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
4297 dev_kfree_skb_irq(skb);
4301 length = le16_to_cpu(rx_desc->wb.middle.length0);
4303 if (unlikely(!length)) {
4304 E1000_DBG("%s: Last part of the packet spanning"
4305 " multiple descriptors\n", netdev->name);
4306 dev_kfree_skb_irq(skb);
4311 skb_put(skb, length);
4314 /* this looks ugly, but it seems compiler issues make it
4315 more efficient than reusing j */
4316 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4318 /* page alloc/put takes too long and effects small packet
4319 * throughput, so unsplit small packets and save the alloc/put*/
4320 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
4322 /* there is no documentation about how to call
4323 * kmap_atomic, so we can't hold the mapping
4325 pci_dma_sync_single_for_cpu(pdev,
4326 ps_page_dma->ps_page_dma[0],
4328 PCI_DMA_FROMDEVICE);
4329 vaddr = kmap_atomic(ps_page->ps_page[0],
4330 KM_SKB_DATA_SOFTIRQ);
4331 memcpy(skb->tail, vaddr, l1);
4332 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4333 pci_dma_sync_single_for_device(pdev,
4334 ps_page_dma->ps_page_dma[0],
4335 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4336 /* remove the CRC */
4343 for (j = 0; j < adapter->rx_ps_pages; j++) {
4344 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
4346 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4347 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4348 ps_page_dma->ps_page_dma[j] = 0;
4349 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4351 ps_page->ps_page[j] = NULL;
4353 skb->data_len += length;
4354 skb->truesize += length;
4357 /* strip the ethernet crc, problem is we're using pages now so
4358 * this whole operation can get a little cpu intensive */
4359 pskb_trim(skb, skb->len - 4);
4362 total_rx_bytes += skb->len;
4365 e1000_rx_checksum(adapter, staterr,
4366 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
4367 skb->protocol = eth_type_trans(skb, netdev);
4369 if (likely(rx_desc->wb.upper.header_status &
4370 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
4371 adapter->rx_hdr_split++;
4372 #ifdef CONFIG_E1000_NAPI
4373 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4374 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4375 le16_to_cpu(rx_desc->wb.middle.vlan) &
4376 E1000_RXD_SPC_VLAN_MASK);
4378 netif_receive_skb(skb);
4380 #else /* CONFIG_E1000_NAPI */
4381 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
4382 vlan_hwaccel_rx(skb, adapter->vlgrp,
4383 le16_to_cpu(rx_desc->wb.middle.vlan) &
4384 E1000_RXD_SPC_VLAN_MASK);
4388 #endif /* CONFIG_E1000_NAPI */
4389 netdev->last_rx = jiffies;
4392 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
4393 buffer_info->skb = NULL;
4395 /* return some buffers to hardware, one at a time is too slow */
4396 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4397 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4401 /* use prefetched values */
4403 buffer_info = next_buffer;
4405 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
4407 rx_ring->next_to_clean = i;
4409 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4411 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4413 adapter->total_rx_packets += total_rx_packets;
4414 adapter->total_rx_bytes += total_rx_bytes;
4419 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4420 * @adapter: address of board private structure
4424 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4425 struct e1000_rx_ring *rx_ring,
4428 struct net_device *netdev = adapter->netdev;
4429 struct pci_dev *pdev = adapter->pdev;
4430 struct e1000_rx_desc *rx_desc;
4431 struct e1000_buffer *buffer_info;
4432 struct sk_buff *skb;
4434 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
4436 i = rx_ring->next_to_use;
4437 buffer_info = &rx_ring->buffer_info[i];
4439 while (cleaned_count--) {
4440 skb = buffer_info->skb;
4446 skb = netdev_alloc_skb(netdev, bufsz);
4447 if (unlikely(!skb)) {
4448 /* Better luck next round */
4449 adapter->alloc_rx_buff_failed++;
4453 /* Fix for errata 23, can't cross 64kB boundary */
4454 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4455 struct sk_buff *oldskb = skb;
4456 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4457 "at %p\n", bufsz, skb->data);
4458 /* Try again, without freeing the previous */
4459 skb = netdev_alloc_skb(netdev, bufsz);
4460 /* Failed allocation, critical failure */
4462 dev_kfree_skb(oldskb);
4466 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4469 dev_kfree_skb(oldskb);
4470 break; /* while !buffer_info->skb */
4473 /* Use new allocation */
4474 dev_kfree_skb(oldskb);
4476 /* Make buffer alignment 2 beyond a 16 byte boundary
4477 * this will result in a 16 byte aligned IP header after
4478 * the 14 byte MAC header is removed
4480 skb_reserve(skb, NET_IP_ALIGN);
4482 buffer_info->skb = skb;
4483 buffer_info->length = adapter->rx_buffer_len;
4485 buffer_info->dma = pci_map_single(pdev,
4487 adapter->rx_buffer_len,
4488 PCI_DMA_FROMDEVICE);
4490 /* Fix for errata 23, can't cross 64kB boundary */
4491 if (!e1000_check_64k_bound(adapter,
4492 (void *)(unsigned long)buffer_info->dma,
4493 adapter->rx_buffer_len)) {
4494 DPRINTK(RX_ERR, ERR,
4495 "dma align check failed: %u bytes at %p\n",
4496 adapter->rx_buffer_len,
4497 (void *)(unsigned long)buffer_info->dma);
4499 buffer_info->skb = NULL;
4501 pci_unmap_single(pdev, buffer_info->dma,
4502 adapter->rx_buffer_len,
4503 PCI_DMA_FROMDEVICE);
4505 break; /* while !buffer_info->skb */
4507 rx_desc = E1000_RX_DESC(*rx_ring, i);
4508 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4510 if (unlikely(++i == rx_ring->count))
4512 buffer_info = &rx_ring->buffer_info[i];
4515 if (likely(rx_ring->next_to_use != i)) {
4516 rx_ring->next_to_use = i;
4517 if (unlikely(i-- == 0))
4518 i = (rx_ring->count - 1);
4520 /* Force memory writes to complete before letting h/w
4521 * know there are new descriptors to fetch. (Only
4522 * applicable for weak-ordered memory model archs,
4523 * such as IA-64). */
4525 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4530 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4531 * @adapter: address of board private structure
4535 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4536 struct e1000_rx_ring *rx_ring,
4539 struct net_device *netdev = adapter->netdev;
4540 struct pci_dev *pdev = adapter->pdev;
4541 union e1000_rx_desc_packet_split *rx_desc;
4542 struct e1000_buffer *buffer_info;
4543 struct e1000_ps_page *ps_page;
4544 struct e1000_ps_page_dma *ps_page_dma;
4545 struct sk_buff *skb;
4548 i = rx_ring->next_to_use;
4549 buffer_info = &rx_ring->buffer_info[i];
4550 ps_page = &rx_ring->ps_page[i];
4551 ps_page_dma = &rx_ring->ps_page_dma[i];
4553 while (cleaned_count--) {
4554 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4556 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4557 if (j < adapter->rx_ps_pages) {
4558 if (likely(!ps_page->ps_page[j])) {
4559 ps_page->ps_page[j] =
4560 alloc_page(GFP_ATOMIC);
4561 if (unlikely(!ps_page->ps_page[j])) {
4562 adapter->alloc_rx_buff_failed++;
4565 ps_page_dma->ps_page_dma[j] =
4567 ps_page->ps_page[j],
4569 PCI_DMA_FROMDEVICE);
4571 /* Refresh the desc even if buffer_addrs didn't
4572 * change because each write-back erases
4575 rx_desc->read.buffer_addr[j+1] =
4576 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4578 rx_desc->read.buffer_addr[j+1] = ~0;
4581 skb = netdev_alloc_skb(netdev,
4582 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4584 if (unlikely(!skb)) {
4585 adapter->alloc_rx_buff_failed++;
4589 /* Make buffer alignment 2 beyond a 16 byte boundary
4590 * this will result in a 16 byte aligned IP header after
4591 * the 14 byte MAC header is removed
4593 skb_reserve(skb, NET_IP_ALIGN);
4595 buffer_info->skb = skb;
4596 buffer_info->length = adapter->rx_ps_bsize0;
4597 buffer_info->dma = pci_map_single(pdev, skb->data,
4598 adapter->rx_ps_bsize0,
4599 PCI_DMA_FROMDEVICE);
4601 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4603 if (unlikely(++i == rx_ring->count)) i = 0;
4604 buffer_info = &rx_ring->buffer_info[i];
4605 ps_page = &rx_ring->ps_page[i];
4606 ps_page_dma = &rx_ring->ps_page_dma[i];
4610 if (likely(rx_ring->next_to_use != i)) {
4611 rx_ring->next_to_use = i;
4612 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4614 /* Force memory writes to complete before letting h/w
4615 * know there are new descriptors to fetch. (Only
4616 * applicable for weak-ordered memory model archs,
4617 * such as IA-64). */
4619 /* Hardware increments by 16 bytes, but packet split
4620 * descriptors are 32 bytes...so we increment tail
4623 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4628 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4633 e1000_smartspeed(struct e1000_adapter *adapter)
4635 uint16_t phy_status;
4638 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4639 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4642 if (adapter->smartspeed == 0) {
4643 /* If Master/Slave config fault is asserted twice,
4644 * we assume back-to-back */
4645 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4646 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4647 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4648 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4649 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4650 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4651 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4652 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4654 adapter->smartspeed++;
4655 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4656 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4658 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4659 MII_CR_RESTART_AUTO_NEG);
4660 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4665 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4666 /* If still no link, perhaps using 2/3 pair cable */
4667 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4668 phy_ctrl |= CR_1000T_MS_ENABLE;
4669 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4670 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4671 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4672 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4673 MII_CR_RESTART_AUTO_NEG);
4674 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4677 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4678 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4679 adapter->smartspeed = 0;
4690 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4696 return e1000_mii_ioctl(netdev, ifr, cmd);
4710 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4712 struct e1000_adapter *adapter = netdev_priv(netdev);
4713 struct mii_ioctl_data *data = if_mii(ifr);
4717 unsigned long flags;
4719 if (adapter->hw.media_type != e1000_media_type_copper)
4724 data->phy_id = adapter->hw.phy_addr;
4727 if (!capable(CAP_NET_ADMIN))
4729 spin_lock_irqsave(&adapter->stats_lock, flags);
4730 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4732 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4735 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4738 if (!capable(CAP_NET_ADMIN))
4740 if (data->reg_num & ~(0x1F))
4742 mii_reg = data->val_in;
4743 spin_lock_irqsave(&adapter->stats_lock, flags);
4744 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4746 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4749 if (adapter->hw.media_type == e1000_media_type_copper) {
4750 switch (data->reg_num) {
4752 if (mii_reg & MII_CR_POWER_DOWN)
4754 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4755 adapter->hw.autoneg = 1;
4756 adapter->hw.autoneg_advertised = 0x2F;
4759 spddplx = SPEED_1000;
4760 else if (mii_reg & 0x2000)
4761 spddplx = SPEED_100;
4764 spddplx += (mii_reg & 0x100)
4767 retval = e1000_set_spd_dplx(adapter,
4770 spin_unlock_irqrestore(
4771 &adapter->stats_lock,
4776 if (netif_running(adapter->netdev))
4777 e1000_reinit_locked(adapter);
4779 e1000_reset(adapter);
4781 case M88E1000_PHY_SPEC_CTRL:
4782 case M88E1000_EXT_PHY_SPEC_CTRL:
4783 if (e1000_phy_reset(&adapter->hw)) {
4784 spin_unlock_irqrestore(
4785 &adapter->stats_lock, flags);
4791 switch (data->reg_num) {
4793 if (mii_reg & MII_CR_POWER_DOWN)
4795 if (netif_running(adapter->netdev))
4796 e1000_reinit_locked(adapter);
4798 e1000_reset(adapter);
4802 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4807 return E1000_SUCCESS;
4811 e1000_pci_set_mwi(struct e1000_hw *hw)
4813 struct e1000_adapter *adapter = hw->back;
4814 int ret_val = pci_set_mwi(adapter->pdev);
4817 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4821 e1000_pci_clear_mwi(struct e1000_hw *hw)
4823 struct e1000_adapter *adapter = hw->back;
4825 pci_clear_mwi(adapter->pdev);
4829 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4831 struct e1000_adapter *adapter = hw->back;
4833 pci_read_config_word(adapter->pdev, reg, value);
4837 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4839 struct e1000_adapter *adapter = hw->back;
4841 pci_write_config_word(adapter->pdev, reg, *value);
4845 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4847 struct e1000_adapter *adapter = hw->back;
4848 uint16_t cap_offset;
4850 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4852 return -E1000_ERR_CONFIG;
4854 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4856 return E1000_SUCCESS;
4860 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4866 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4868 struct e1000_adapter *adapter = netdev_priv(netdev);
4869 uint32_t ctrl, rctl;
4871 e1000_irq_disable(adapter);
4872 adapter->vlgrp = grp;
4875 /* enable VLAN tag insert/strip */
4876 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4877 ctrl |= E1000_CTRL_VME;
4878 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4880 if (adapter->hw.mac_type != e1000_ich8lan) {
4881 /* enable VLAN receive filtering */
4882 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4883 rctl |= E1000_RCTL_VFE;
4884 rctl &= ~E1000_RCTL_CFIEN;
4885 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4886 e1000_update_mng_vlan(adapter);
4889 /* disable VLAN tag insert/strip */
4890 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4891 ctrl &= ~E1000_CTRL_VME;
4892 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4894 if (adapter->hw.mac_type != e1000_ich8lan) {
4895 /* disable VLAN filtering */
4896 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4897 rctl &= ~E1000_RCTL_VFE;
4898 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4899 if (adapter->mng_vlan_id !=
4900 (uint16_t)E1000_MNG_VLAN_NONE) {
4901 e1000_vlan_rx_kill_vid(netdev,
4902 adapter->mng_vlan_id);
4903 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4908 e1000_irq_enable(adapter);
4912 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4914 struct e1000_adapter *adapter = netdev_priv(netdev);
4915 uint32_t vfta, index;
4917 if ((adapter->hw.mng_cookie.status &
4918 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4919 (vid == adapter->mng_vlan_id))
4921 /* add VID to filter table */
4922 index = (vid >> 5) & 0x7F;
4923 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4924 vfta |= (1 << (vid & 0x1F));
4925 e1000_write_vfta(&adapter->hw, index, vfta);
4929 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4931 struct e1000_adapter *adapter = netdev_priv(netdev);
4932 uint32_t vfta, index;
4934 e1000_irq_disable(adapter);
4937 adapter->vlgrp->vlan_devices[vid] = NULL;
4939 e1000_irq_enable(adapter);
4941 if ((adapter->hw.mng_cookie.status &
4942 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4943 (vid == adapter->mng_vlan_id)) {
4944 /* release control to f/w */
4945 e1000_release_hw_control(adapter);
4949 /* remove VID from filter table */
4950 index = (vid >> 5) & 0x7F;
4951 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4952 vfta &= ~(1 << (vid & 0x1F));
4953 e1000_write_vfta(&adapter->hw, index, vfta);
4957 e1000_restore_vlan(struct e1000_adapter *adapter)
4959 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4961 if (adapter->vlgrp) {
4963 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4964 if (!adapter->vlgrp->vlan_devices[vid])
4966 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4972 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4974 adapter->hw.autoneg = 0;
4976 /* Fiber NICs only allow 1000 gbps Full duplex */
4977 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4978 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4979 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4984 case SPEED_10 + DUPLEX_HALF:
4985 adapter->hw.forced_speed_duplex = e1000_10_half;
4987 case SPEED_10 + DUPLEX_FULL:
4988 adapter->hw.forced_speed_duplex = e1000_10_full;
4990 case SPEED_100 + DUPLEX_HALF:
4991 adapter->hw.forced_speed_duplex = e1000_100_half;
4993 case SPEED_100 + DUPLEX_FULL:
4994 adapter->hw.forced_speed_duplex = e1000_100_full;
4996 case SPEED_1000 + DUPLEX_FULL:
4997 adapter->hw.autoneg = 1;
4998 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5000 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5002 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5009 /* Save/restore 16 or 64 dwords of PCI config space depending on which
5010 * bus we're on (PCI(X) vs. PCI-E)
5012 #define PCIE_CONFIG_SPACE_LEN 256
5013 #define PCI_CONFIG_SPACE_LEN 64
5015 e1000_pci_save_state(struct e1000_adapter *adapter)
5017 struct pci_dev *dev = adapter->pdev;
5021 if (adapter->hw.mac_type >= e1000_82571)
5022 size = PCIE_CONFIG_SPACE_LEN;
5024 size = PCI_CONFIG_SPACE_LEN;
5026 WARN_ON(adapter->config_space != NULL);
5028 adapter->config_space = kmalloc(size, GFP_KERNEL);
5029 if (!adapter->config_space) {
5030 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
5033 for (i = 0; i < (size / 4); i++)
5034 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
5039 e1000_pci_restore_state(struct e1000_adapter *adapter)
5041 struct pci_dev *dev = adapter->pdev;
5045 if (adapter->config_space == NULL)
5048 if (adapter->hw.mac_type >= e1000_82571)
5049 size = PCIE_CONFIG_SPACE_LEN;
5051 size = PCI_CONFIG_SPACE_LEN;
5052 for (i = 0; i < (size / 4); i++)
5053 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
5054 kfree(adapter->config_space);
5055 adapter->config_space = NULL;
5058 #endif /* CONFIG_PM */
5061 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5063 struct net_device *netdev = pci_get_drvdata(pdev);
5064 struct e1000_adapter *adapter = netdev_priv(netdev);
5065 uint32_t ctrl, ctrl_ext, rctl, status;
5066 uint32_t wufc = adapter->wol;
5071 netif_device_detach(netdev);
5073 if (netif_running(netdev)) {
5074 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
5075 e1000_down(adapter);
5079 /* Implement our own version of pci_save_state(pdev) because pci-
5080 * express adapters have 256-byte config spaces. */
5081 retval = e1000_pci_save_state(adapter);
5086 status = E1000_READ_REG(&adapter->hw, STATUS);
5087 if (status & E1000_STATUS_LU)
5088 wufc &= ~E1000_WUFC_LNKC;
5091 e1000_setup_rctl(adapter);
5092 e1000_set_multi(netdev);
5094 /* turn on all-multi mode if wake on multicast is enabled */
5095 if (wufc & E1000_WUFC_MC) {
5096 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5097 rctl |= E1000_RCTL_MPE;
5098 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5101 if (adapter->hw.mac_type >= e1000_82540) {
5102 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5103 /* advertise wake from D3Cold */
5104 #define E1000_CTRL_ADVD3WUC 0x00100000
5105 /* phy power management enable */
5106 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5107 ctrl |= E1000_CTRL_ADVD3WUC |
5108 E1000_CTRL_EN_PHY_PWR_MGMT;
5109 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5112 if (adapter->hw.media_type == e1000_media_type_fiber ||
5113 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5114 /* keep the laser running in D3 */
5115 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5116 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5117 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5120 /* Allow time for pending master requests to run */
5121 e1000_disable_pciex_master(&adapter->hw);
5123 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5124 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
5125 pci_enable_wake(pdev, PCI_D3hot, 1);
5126 pci_enable_wake(pdev, PCI_D3cold, 1);
5128 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5129 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
5130 pci_enable_wake(pdev, PCI_D3hot, 0);
5131 pci_enable_wake(pdev, PCI_D3cold, 0);
5134 e1000_release_manageability(adapter);
5136 /* make sure adapter isn't asleep if manageability is enabled */
5137 if (adapter->en_mng_pt) {
5138 pci_enable_wake(pdev, PCI_D3hot, 1);
5139 pci_enable_wake(pdev, PCI_D3cold, 1);
5142 if (adapter->hw.phy_type == e1000_phy_igp_3)
5143 e1000_phy_powerdown_workaround(&adapter->hw);
5145 if (netif_running(netdev))
5146 e1000_free_irq(adapter);
5148 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5149 * would have already happened in close and is redundant. */
5150 e1000_release_hw_control(adapter);
5152 pci_disable_device(pdev);
5154 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5161 e1000_resume(struct pci_dev *pdev)
5163 struct net_device *netdev = pci_get_drvdata(pdev);
5164 struct e1000_adapter *adapter = netdev_priv(netdev);
5167 pci_set_power_state(pdev, PCI_D0);
5168 e1000_pci_restore_state(adapter);
5169 if ((err = pci_enable_device(pdev))) {
5170 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5173 pci_set_master(pdev);
5175 pci_enable_wake(pdev, PCI_D3hot, 0);
5176 pci_enable_wake(pdev, PCI_D3cold, 0);
5178 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5181 e1000_power_up_phy(adapter);
5182 e1000_reset(adapter);
5183 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5185 e1000_init_manageability(adapter);
5187 if (netif_running(netdev))
5190 netif_device_attach(netdev);
5192 /* If the controller is 82573 and f/w is AMT, do not set
5193 * DRV_LOAD until the interface is up. For all other cases,
5194 * let the f/w know that the h/w is now under the control
5196 if (adapter->hw.mac_type != e1000_82573 ||
5197 !e1000_check_mng_mode(&adapter->hw))
5198 e1000_get_hw_control(adapter);
5204 static void e1000_shutdown(struct pci_dev *pdev)
5206 e1000_suspend(pdev, PMSG_SUSPEND);
5209 #ifdef CONFIG_NET_POLL_CONTROLLER
5211 * Polling 'interrupt' - used by things like netconsole to send skbs
5212 * without having to re-enable interrupts. It's not called while
5213 * the interrupt routine is executing.
5216 e1000_netpoll(struct net_device *netdev)
5218 struct e1000_adapter *adapter = netdev_priv(netdev);
5220 disable_irq(adapter->pdev->irq);
5221 e1000_intr(adapter->pdev->irq, netdev);
5222 e1000_clean_tx_irq(adapter, adapter->tx_ring);
5223 #ifndef CONFIG_E1000_NAPI
5224 adapter->clean_rx(adapter, adapter->rx_ring);
5226 enable_irq(adapter->pdev->irq);
5231 * e1000_io_error_detected - called when PCI error is detected
5232 * @pdev: Pointer to PCI device
5233 * @state: The current pci conneection state
5235 * This function is called after a PCI bus error affecting
5236 * this device has been detected.
5238 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5240 struct net_device *netdev = pci_get_drvdata(pdev);
5241 struct e1000_adapter *adapter = netdev->priv;
5243 netif_device_detach(netdev);
5245 if (netif_running(netdev))
5246 e1000_down(adapter);
5247 pci_disable_device(pdev);
5249 /* Request a slot slot reset. */
5250 return PCI_ERS_RESULT_NEED_RESET;
5254 * e1000_io_slot_reset - called after the pci bus has been reset.
5255 * @pdev: Pointer to PCI device
5257 * Restart the card from scratch, as if from a cold-boot. Implementation
5258 * resembles the first-half of the e1000_resume routine.
5260 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5262 struct net_device *netdev = pci_get_drvdata(pdev);
5263 struct e1000_adapter *adapter = netdev->priv;
5265 if (pci_enable_device(pdev)) {
5266 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5267 return PCI_ERS_RESULT_DISCONNECT;
5269 pci_set_master(pdev);
5271 pci_enable_wake(pdev, PCI_D3hot, 0);
5272 pci_enable_wake(pdev, PCI_D3cold, 0);
5274 e1000_reset(adapter);
5275 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5277 return PCI_ERS_RESULT_RECOVERED;
5281 * e1000_io_resume - called when traffic can start flowing again.
5282 * @pdev: Pointer to PCI device
5284 * This callback is called when the error recovery driver tells us that
5285 * its OK to resume normal operation. Implementation resembles the
5286 * second-half of the e1000_resume routine.
5288 static void e1000_io_resume(struct pci_dev *pdev)
5290 struct net_device *netdev = pci_get_drvdata(pdev);
5291 struct e1000_adapter *adapter = netdev->priv;
5293 e1000_init_manageability(adapter);
5295 if (netif_running(netdev)) {
5296 if (e1000_up(adapter)) {
5297 printk("e1000: can't bring device back up after reset\n");
5302 netif_device_attach(netdev);
5304 /* If the controller is 82573 and f/w is AMT, do not set
5305 * DRV_LOAD until the interface is up. For all other cases,
5306 * let the f/w know that the h/w is now under the control
5308 if (adapter->hw.mac_type != e1000_82573 ||
5309 !e1000_check_mng_mode(&adapter->hw))
5310 e1000_get_hw_control(adapter);