1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
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.1.9-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(0x10B5),
103 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
104 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
106 /* required last entry */
110 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
112 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
113 struct e1000_tx_ring *txdr);
114 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
115 struct e1000_rx_ring *rxdr);
116 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
117 struct e1000_tx_ring *tx_ring);
118 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
119 struct e1000_rx_ring *rx_ring);
121 /* Local Function Prototypes */
123 static int e1000_init_module(void);
124 static void e1000_exit_module(void);
125 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
126 static void __devexit e1000_remove(struct pci_dev *pdev);
127 static int e1000_alloc_queues(struct e1000_adapter *adapter);
128 static int e1000_sw_init(struct e1000_adapter *adapter);
129 static int e1000_open(struct net_device *netdev);
130 static int e1000_close(struct net_device *netdev);
131 static void e1000_configure_tx(struct e1000_adapter *adapter);
132 static void e1000_configure_rx(struct e1000_adapter *adapter);
133 static void e1000_setup_rctl(struct e1000_adapter *adapter);
134 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
135 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
136 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
137 struct e1000_tx_ring *tx_ring);
138 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
139 struct e1000_rx_ring *rx_ring);
140 static void e1000_set_multi(struct net_device *netdev);
141 static void e1000_update_phy_info(unsigned long data);
142 static void e1000_watchdog(unsigned long data);
143 static void e1000_82547_tx_fifo_stall(unsigned long data);
144 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
145 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
146 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
147 static int e1000_set_mac(struct net_device *netdev, void *p);
148 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
149 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
150 struct e1000_tx_ring *tx_ring);
151 #ifdef CONFIG_E1000_NAPI
152 static int e1000_clean(struct net_device *poll_dev, int *budget);
153 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
154 struct e1000_rx_ring *rx_ring,
155 int *work_done, int work_to_do);
156 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
157 struct e1000_rx_ring *rx_ring,
158 int *work_done, int work_to_do);
160 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
161 struct e1000_rx_ring *rx_ring);
162 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
163 struct e1000_rx_ring *rx_ring);
165 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
166 struct e1000_rx_ring *rx_ring,
168 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring,
171 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
172 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
174 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
175 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
176 static void e1000_tx_timeout(struct net_device *dev);
177 static void e1000_reset_task(struct net_device *dev);
178 static void e1000_smartspeed(struct e1000_adapter *adapter);
179 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
180 struct sk_buff *skb);
182 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
183 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
184 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
185 static void e1000_restore_vlan(struct e1000_adapter *adapter);
187 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
189 static int e1000_resume(struct pci_dev *pdev);
191 static void e1000_shutdown(struct pci_dev *pdev);
193 #ifdef CONFIG_NET_POLL_CONTROLLER
194 /* for netdump / net console */
195 static void e1000_netpoll (struct net_device *netdev);
198 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
199 pci_channel_state_t state);
200 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
201 static void e1000_io_resume(struct pci_dev *pdev);
203 static struct pci_error_handlers e1000_err_handler = {
204 .error_detected = e1000_io_error_detected,
205 .slot_reset = e1000_io_slot_reset,
206 .resume = e1000_io_resume,
209 static struct pci_driver e1000_driver = {
210 .name = e1000_driver_name,
211 .id_table = e1000_pci_tbl,
212 .probe = e1000_probe,
213 .remove = __devexit_p(e1000_remove),
214 /* Power Managment Hooks */
215 .suspend = e1000_suspend,
217 .resume = e1000_resume,
219 .shutdown = e1000_shutdown,
220 .err_handler = &e1000_err_handler
223 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
224 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
225 MODULE_LICENSE("GPL");
226 MODULE_VERSION(DRV_VERSION);
228 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
229 module_param(debug, int, 0);
230 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
233 * e1000_init_module - Driver Registration Routine
235 * e1000_init_module is the first routine called when the driver is
236 * loaded. All it does is register with the PCI subsystem.
240 e1000_init_module(void)
243 printk(KERN_INFO "%s - version %s\n",
244 e1000_driver_string, e1000_driver_version);
246 printk(KERN_INFO "%s\n", e1000_copyright);
248 ret = pci_module_init(&e1000_driver);
253 module_init(e1000_init_module);
256 * e1000_exit_module - Driver Exit Cleanup Routine
258 * e1000_exit_module is called just before the driver is removed
263 e1000_exit_module(void)
265 pci_unregister_driver(&e1000_driver);
268 module_exit(e1000_exit_module);
270 static int e1000_request_irq(struct e1000_adapter *adapter)
272 struct net_device *netdev = adapter->netdev;
275 flags = SA_SHIRQ | SA_SAMPLE_RANDOM;
276 #ifdef CONFIG_PCI_MSI
277 if (adapter->hw.mac_type > e1000_82547_rev_2) {
278 adapter->have_msi = TRUE;
279 if ((err = pci_enable_msi(adapter->pdev))) {
281 "Unable to allocate MSI interrupt Error: %d\n", err);
282 adapter->have_msi = FALSE;
285 if (adapter->have_msi)
288 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
289 netdev->name, netdev)))
291 "Unable to allocate interrupt Error: %d\n", err);
296 static void e1000_free_irq(struct e1000_adapter *adapter)
298 struct net_device *netdev = adapter->netdev;
300 free_irq(adapter->pdev->irq, netdev);
302 #ifdef CONFIG_PCI_MSI
303 if (adapter->have_msi)
304 pci_disable_msi(adapter->pdev);
309 * e1000_irq_disable - Mask off interrupt generation on the NIC
310 * @adapter: board private structure
314 e1000_irq_disable(struct e1000_adapter *adapter)
316 atomic_inc(&adapter->irq_sem);
317 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
318 E1000_WRITE_FLUSH(&adapter->hw);
319 synchronize_irq(adapter->pdev->irq);
323 * e1000_irq_enable - Enable default interrupt generation settings
324 * @adapter: board private structure
328 e1000_irq_enable(struct e1000_adapter *adapter)
330 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
331 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
332 E1000_WRITE_FLUSH(&adapter->hw);
337 e1000_update_mng_vlan(struct e1000_adapter *adapter)
339 struct net_device *netdev = adapter->netdev;
340 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
341 uint16_t old_vid = adapter->mng_vlan_id;
342 if (adapter->vlgrp) {
343 if (!adapter->vlgrp->vlan_devices[vid]) {
344 if (adapter->hw.mng_cookie.status &
345 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
346 e1000_vlan_rx_add_vid(netdev, vid);
347 adapter->mng_vlan_id = vid;
349 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
351 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
353 !adapter->vlgrp->vlan_devices[old_vid])
354 e1000_vlan_rx_kill_vid(netdev, old_vid);
356 adapter->mng_vlan_id = vid;
361 * e1000_release_hw_control - release control of the h/w to f/w
362 * @adapter: address of board private structure
364 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
365 * For ASF and Pass Through versions of f/w this means that the
366 * driver is no longer loaded. For AMT version (only with 82573) i
367 * of the f/w this means that the netowrk i/f is closed.
372 e1000_release_hw_control(struct e1000_adapter *adapter)
378 /* Let firmware taken over control of h/w */
379 switch (adapter->hw.mac_type) {
382 case e1000_80003es2lan:
383 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
384 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
385 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
388 swsm = E1000_READ_REG(&adapter->hw, SWSM);
389 E1000_WRITE_REG(&adapter->hw, SWSM,
390 swsm & ~E1000_SWSM_DRV_LOAD);
392 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
393 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
394 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
402 * e1000_get_hw_control - get control of the h/w from f/w
403 * @adapter: address of board private structure
405 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
406 * For ASF and Pass Through versions of f/w this means that
407 * the driver is loaded. For AMT version (only with 82573)
408 * of the f/w this means that the netowrk i/f is open.
413 e1000_get_hw_control(struct e1000_adapter *adapter)
418 /* Let firmware know the driver has taken over */
419 switch (adapter->hw.mac_type) {
422 case e1000_80003es2lan:
423 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
424 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
425 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
428 swsm = E1000_READ_REG(&adapter->hw, SWSM);
429 E1000_WRITE_REG(&adapter->hw, SWSM,
430 swsm | E1000_SWSM_DRV_LOAD);
433 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
434 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
435 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
443 e1000_up(struct e1000_adapter *adapter)
445 struct net_device *netdev = adapter->netdev;
448 /* hardware has been reset, we need to reload some things */
450 e1000_set_multi(netdev);
452 e1000_restore_vlan(adapter);
454 e1000_configure_tx(adapter);
455 e1000_setup_rctl(adapter);
456 e1000_configure_rx(adapter);
457 /* call E1000_DESC_UNUSED which always leaves
458 * at least 1 descriptor unused to make sure
459 * next_to_use != next_to_clean */
460 for (i = 0; i < adapter->num_rx_queues; i++) {
461 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
462 adapter->alloc_rx_buf(adapter, ring,
463 E1000_DESC_UNUSED(ring));
466 adapter->tx_queue_len = netdev->tx_queue_len;
468 mod_timer(&adapter->watchdog_timer, jiffies);
470 #ifdef CONFIG_E1000_NAPI
471 netif_poll_enable(netdev);
473 e1000_irq_enable(adapter);
479 * e1000_power_up_phy - restore link in case the phy was powered down
480 * @adapter: address of board private structure
482 * The phy may be powered down to save power and turn off link when the
483 * driver is unloaded and wake on lan is not enabled (among others)
484 * *** this routine MUST be followed by a call to e1000_reset ***
488 static void e1000_power_up_phy(struct e1000_adapter *adapter)
490 uint16_t mii_reg = 0;
492 /* Just clear the power down bit to wake the phy back up */
493 if (adapter->hw.media_type == e1000_media_type_copper) {
494 /* according to the manual, the phy will retain its
495 * settings across a power-down/up cycle */
496 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
497 mii_reg &= ~MII_CR_POWER_DOWN;
498 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
502 static void e1000_power_down_phy(struct e1000_adapter *adapter)
504 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
505 e1000_check_mng_mode(&adapter->hw);
506 /* Power down the PHY so no link is implied when interface is down
507 * The PHY cannot be powered down if any of the following is TRUE
510 * (c) SoL/IDER session is active */
511 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
512 adapter->hw.mac_type != e1000_ich8lan &&
513 adapter->hw.media_type == e1000_media_type_copper &&
514 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
516 !e1000_check_phy_reset_block(&adapter->hw)) {
517 uint16_t mii_reg = 0;
518 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
519 mii_reg |= MII_CR_POWER_DOWN;
520 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
526 e1000_down(struct e1000_adapter *adapter)
528 struct net_device *netdev = adapter->netdev;
530 e1000_irq_disable(adapter);
532 del_timer_sync(&adapter->tx_fifo_stall_timer);
533 del_timer_sync(&adapter->watchdog_timer);
534 del_timer_sync(&adapter->phy_info_timer);
536 #ifdef CONFIG_E1000_NAPI
537 netif_poll_disable(netdev);
539 netdev->tx_queue_len = adapter->tx_queue_len;
540 adapter->link_speed = 0;
541 adapter->link_duplex = 0;
542 netif_carrier_off(netdev);
543 netif_stop_queue(netdev);
545 e1000_reset(adapter);
546 e1000_clean_all_tx_rings(adapter);
547 e1000_clean_all_rx_rings(adapter);
551 e1000_reinit_locked(struct e1000_adapter *adapter)
553 WARN_ON(in_interrupt());
554 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
558 clear_bit(__E1000_RESETTING, &adapter->flags);
562 e1000_reset(struct e1000_adapter *adapter)
565 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
567 /* Repartition Pba for greater than 9k mtu
568 * To take effect CTRL.RST is required.
571 switch (adapter->hw.mac_type) {
573 case e1000_82547_rev_2:
578 case e1000_80003es2lan:
592 if ((adapter->hw.mac_type != e1000_82573) &&
593 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
594 pba -= 8; /* allocate more FIFO for Tx */
597 if (adapter->hw.mac_type == e1000_82547) {
598 adapter->tx_fifo_head = 0;
599 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
600 adapter->tx_fifo_size =
601 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
602 atomic_set(&adapter->tx_fifo_stall, 0);
605 E1000_WRITE_REG(&adapter->hw, PBA, pba);
607 /* flow control settings */
608 /* Set the FC high water mark to 90% of the FIFO size.
609 * Required to clear last 3 LSB */
610 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
611 /* We can't use 90% on small FIFOs because the remainder
612 * would be less than 1 full frame. In this case, we size
613 * it to allow at least a full frame above the high water
615 if (pba < E1000_PBA_16K)
616 fc_high_water_mark = (pba * 1024) - 1600;
618 adapter->hw.fc_high_water = fc_high_water_mark;
619 adapter->hw.fc_low_water = fc_high_water_mark - 8;
620 if (adapter->hw.mac_type == e1000_80003es2lan)
621 adapter->hw.fc_pause_time = 0xFFFF;
623 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
624 adapter->hw.fc_send_xon = 1;
625 adapter->hw.fc = adapter->hw.original_fc;
627 /* Allow time for pending master requests to run */
628 e1000_reset_hw(&adapter->hw);
629 if (adapter->hw.mac_type >= e1000_82544)
630 E1000_WRITE_REG(&adapter->hw, WUC, 0);
631 if (e1000_init_hw(&adapter->hw))
632 DPRINTK(PROBE, ERR, "Hardware Error\n");
633 e1000_update_mng_vlan(adapter);
634 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
635 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
637 e1000_reset_adaptive(&adapter->hw);
638 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
640 if (!adapter->smart_power_down &&
641 (adapter->hw.mac_type == e1000_82571 ||
642 adapter->hw.mac_type == e1000_82572)) {
643 uint16_t phy_data = 0;
644 /* speed up time to link by disabling smart power down, ignore
645 * the return value of this function because there is nothing
646 * different we would do if it failed */
647 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
649 phy_data &= ~IGP02E1000_PM_SPD;
650 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
654 if (adapter->hw.mac_type < e1000_ich8lan)
655 /* FIXME: this code is duplicate and wrong for PCI Express */
656 if (adapter->en_mng_pt) {
657 manc = E1000_READ_REG(&adapter->hw, MANC);
658 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
659 E1000_WRITE_REG(&adapter->hw, MANC, manc);
664 * e1000_probe - Device Initialization Routine
665 * @pdev: PCI device information struct
666 * @ent: entry in e1000_pci_tbl
668 * Returns 0 on success, negative on failure
670 * e1000_probe initializes an adapter identified by a pci_dev structure.
671 * The OS initialization, configuring of the adapter private structure,
672 * and a hardware reset occur.
676 e1000_probe(struct pci_dev *pdev,
677 const struct pci_device_id *ent)
679 struct net_device *netdev;
680 struct e1000_adapter *adapter;
681 unsigned long mmio_start, mmio_len;
682 unsigned long flash_start, flash_len;
684 static int cards_found = 0;
685 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
686 int i, err, pci_using_dac;
687 uint16_t eeprom_data;
688 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
689 if ((err = pci_enable_device(pdev)))
692 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
693 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
696 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
697 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
698 E1000_ERR("No usable DMA configuration, aborting\n");
704 if ((err = pci_request_regions(pdev, e1000_driver_name)))
707 pci_set_master(pdev);
709 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
712 goto err_alloc_etherdev;
715 SET_MODULE_OWNER(netdev);
716 SET_NETDEV_DEV(netdev, &pdev->dev);
718 pci_set_drvdata(pdev, netdev);
719 adapter = netdev_priv(netdev);
720 adapter->netdev = netdev;
721 adapter->pdev = pdev;
722 adapter->hw.back = adapter;
723 adapter->msg_enable = (1 << debug) - 1;
725 mmio_start = pci_resource_start(pdev, BAR_0);
726 mmio_len = pci_resource_len(pdev, BAR_0);
728 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
729 if (!adapter->hw.hw_addr) {
734 for (i = BAR_1; i <= BAR_5; i++) {
735 if (pci_resource_len(pdev, i) == 0)
737 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
738 adapter->hw.io_base = pci_resource_start(pdev, i);
743 netdev->open = &e1000_open;
744 netdev->stop = &e1000_close;
745 netdev->hard_start_xmit = &e1000_xmit_frame;
746 netdev->get_stats = &e1000_get_stats;
747 netdev->set_multicast_list = &e1000_set_multi;
748 netdev->set_mac_address = &e1000_set_mac;
749 netdev->change_mtu = &e1000_change_mtu;
750 netdev->do_ioctl = &e1000_ioctl;
751 e1000_set_ethtool_ops(netdev);
752 netdev->tx_timeout = &e1000_tx_timeout;
753 netdev->watchdog_timeo = 5 * HZ;
754 #ifdef CONFIG_E1000_NAPI
755 netdev->poll = &e1000_clean;
758 netdev->vlan_rx_register = e1000_vlan_rx_register;
759 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
760 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
761 #ifdef CONFIG_NET_POLL_CONTROLLER
762 netdev->poll_controller = e1000_netpoll;
764 strcpy(netdev->name, pci_name(pdev));
766 netdev->mem_start = mmio_start;
767 netdev->mem_end = mmio_start + mmio_len;
768 netdev->base_addr = adapter->hw.io_base;
770 adapter->bd_number = cards_found;
772 /* setup the private structure */
774 if ((err = e1000_sw_init(adapter)))
777 /* Flash BAR mapping must happen after e1000_sw_init
778 * because it depends on mac_type */
779 if ((adapter->hw.mac_type == e1000_ich8lan) &&
780 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
781 flash_start = pci_resource_start(pdev, 1);
782 flash_len = pci_resource_len(pdev, 1);
783 adapter->hw.flash_address = ioremap(flash_start, flash_len);
784 if (!adapter->hw.flash_address) {
790 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
791 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
793 /* if ksp3, indicate if it's port a being setup */
794 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
795 e1000_ksp3_port_a == 0)
796 adapter->ksp3_port_a = 1;
798 /* Reset for multiple KP3 adapters */
799 if (e1000_ksp3_port_a == 4)
800 e1000_ksp3_port_a = 0;
802 if (adapter->hw.mac_type >= e1000_82543) {
803 netdev->features = NETIF_F_SG |
807 NETIF_F_HW_VLAN_FILTER;
808 if (adapter->hw.mac_type == e1000_ich8lan)
809 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
813 if ((adapter->hw.mac_type >= e1000_82544) &&
814 (adapter->hw.mac_type != e1000_82547))
815 netdev->features |= NETIF_F_TSO;
817 #ifdef NETIF_F_TSO_IPV6
818 if (adapter->hw.mac_type > e1000_82547_rev_2)
819 netdev->features |= NETIF_F_TSO_IPV6;
823 netdev->features |= NETIF_F_HIGHDMA;
825 netdev->features |= NETIF_F_LLTX;
827 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
829 /* initialize eeprom parameters */
831 if (e1000_init_eeprom_params(&adapter->hw)) {
832 E1000_ERR("EEPROM initialization failed\n");
836 /* before reading the EEPROM, reset the controller to
837 * put the device in a known good starting state */
839 e1000_reset_hw(&adapter->hw);
841 /* make sure the EEPROM is good */
843 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
844 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
849 /* copy the MAC address out of the EEPROM */
851 if (e1000_read_mac_addr(&adapter->hw))
852 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
853 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
854 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
856 if (!is_valid_ether_addr(netdev->perm_addr)) {
857 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
862 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
864 e1000_get_bus_info(&adapter->hw);
866 init_timer(&adapter->tx_fifo_stall_timer);
867 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
868 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
870 init_timer(&adapter->watchdog_timer);
871 adapter->watchdog_timer.function = &e1000_watchdog;
872 adapter->watchdog_timer.data = (unsigned long) adapter;
874 init_timer(&adapter->phy_info_timer);
875 adapter->phy_info_timer.function = &e1000_update_phy_info;
876 adapter->phy_info_timer.data = (unsigned long) adapter;
878 INIT_WORK(&adapter->reset_task,
879 (void (*)(void *))e1000_reset_task, netdev);
881 /* we're going to reset, so assume we have no link for now */
883 netif_carrier_off(netdev);
884 netif_stop_queue(netdev);
886 e1000_check_options(adapter);
888 /* Initial Wake on LAN setting
889 * If APM wake is enabled in the EEPROM,
890 * enable the ACPI Magic Packet filter
893 switch (adapter->hw.mac_type) {
894 case e1000_82542_rev2_0:
895 case e1000_82542_rev2_1:
899 e1000_read_eeprom(&adapter->hw,
900 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
901 eeprom_apme_mask = E1000_EEPROM_82544_APM;
904 e1000_read_eeprom(&adapter->hw,
905 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
906 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
909 case e1000_82546_rev_3:
911 case e1000_80003es2lan:
912 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
913 e1000_read_eeprom(&adapter->hw,
914 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
919 e1000_read_eeprom(&adapter->hw,
920 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
923 if (eeprom_data & eeprom_apme_mask)
924 adapter->wol |= E1000_WUFC_MAG;
926 /* print bus type/speed/width info */
928 struct e1000_hw *hw = &adapter->hw;
929 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
930 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
931 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
932 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
933 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
934 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
935 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
936 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
937 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
938 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
939 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
943 for (i = 0; i < 6; i++)
944 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
946 /* reset the hardware with the new settings */
947 e1000_reset(adapter);
949 /* If the controller is 82573 and f/w is AMT, do not set
950 * DRV_LOAD until the interface is up. For all other cases,
951 * let the f/w know that the h/w is now under the control
953 if (adapter->hw.mac_type != e1000_82573 ||
954 !e1000_check_mng_mode(&adapter->hw))
955 e1000_get_hw_control(adapter);
957 strcpy(netdev->name, "eth%d");
958 if ((err = register_netdev(netdev)))
961 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
967 if (adapter->hw.flash_address)
968 iounmap(adapter->hw.flash_address);
972 iounmap(adapter->hw.hw_addr);
976 pci_release_regions(pdev);
981 * e1000_remove - Device Removal Routine
982 * @pdev: PCI device information struct
984 * e1000_remove is called by the PCI subsystem to alert the driver
985 * that it should release a PCI device. The could be caused by a
986 * Hot-Plug event, or because the driver is going to be removed from
990 static void __devexit
991 e1000_remove(struct pci_dev *pdev)
993 struct net_device *netdev = pci_get_drvdata(pdev);
994 struct e1000_adapter *adapter = netdev_priv(netdev);
996 #ifdef CONFIG_E1000_NAPI
1000 flush_scheduled_work();
1002 if (adapter->hw.mac_type >= e1000_82540 &&
1003 adapter->hw.mac_type != e1000_ich8lan &&
1004 adapter->hw.media_type == e1000_media_type_copper) {
1005 manc = E1000_READ_REG(&adapter->hw, MANC);
1006 if (manc & E1000_MANC_SMBUS_EN) {
1007 manc |= E1000_MANC_ARP_EN;
1008 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1012 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1013 * would have already happened in close and is redundant. */
1014 e1000_release_hw_control(adapter);
1016 unregister_netdev(netdev);
1017 #ifdef CONFIG_E1000_NAPI
1018 for (i = 0; i < adapter->num_rx_queues; i++)
1019 dev_put(&adapter->polling_netdev[i]);
1022 if (!e1000_check_phy_reset_block(&adapter->hw))
1023 e1000_phy_hw_reset(&adapter->hw);
1025 kfree(adapter->tx_ring);
1026 kfree(adapter->rx_ring);
1027 #ifdef CONFIG_E1000_NAPI
1028 kfree(adapter->polling_netdev);
1031 iounmap(adapter->hw.hw_addr);
1032 if (adapter->hw.flash_address)
1033 iounmap(adapter->hw.flash_address);
1034 pci_release_regions(pdev);
1036 free_netdev(netdev);
1038 pci_disable_device(pdev);
1042 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1043 * @adapter: board private structure to initialize
1045 * e1000_sw_init initializes the Adapter private data structure.
1046 * Fields are initialized based on PCI device information and
1047 * OS network device settings (MTU size).
1050 static int __devinit
1051 e1000_sw_init(struct e1000_adapter *adapter)
1053 struct e1000_hw *hw = &adapter->hw;
1054 struct net_device *netdev = adapter->netdev;
1055 struct pci_dev *pdev = adapter->pdev;
1056 #ifdef CONFIG_E1000_NAPI
1060 /* PCI config space info */
1062 hw->vendor_id = pdev->vendor;
1063 hw->device_id = pdev->device;
1064 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1065 hw->subsystem_id = pdev->subsystem_device;
1067 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1069 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1071 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE;
1072 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1073 hw->max_frame_size = netdev->mtu +
1074 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1075 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1077 /* identify the MAC */
1079 if (e1000_set_mac_type(hw)) {
1080 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1084 switch (hw->mac_type) {
1089 case e1000_82541_rev_2:
1090 case e1000_82547_rev_2:
1091 hw->phy_init_script = 1;
1095 e1000_set_media_type(hw);
1097 hw->wait_autoneg_complete = FALSE;
1098 hw->tbi_compatibility_en = TRUE;
1099 hw->adaptive_ifs = TRUE;
1101 /* Copper options */
1103 if (hw->media_type == e1000_media_type_copper) {
1104 hw->mdix = AUTO_ALL_MODES;
1105 hw->disable_polarity_correction = FALSE;
1106 hw->master_slave = E1000_MASTER_SLAVE;
1109 adapter->num_tx_queues = 1;
1110 adapter->num_rx_queues = 1;
1112 if (e1000_alloc_queues(adapter)) {
1113 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1117 #ifdef CONFIG_E1000_NAPI
1118 for (i = 0; i < adapter->num_rx_queues; i++) {
1119 adapter->polling_netdev[i].priv = adapter;
1120 adapter->polling_netdev[i].poll = &e1000_clean;
1121 adapter->polling_netdev[i].weight = 64;
1122 dev_hold(&adapter->polling_netdev[i]);
1123 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1125 spin_lock_init(&adapter->tx_queue_lock);
1128 atomic_set(&adapter->irq_sem, 1);
1129 spin_lock_init(&adapter->stats_lock);
1135 * e1000_alloc_queues - Allocate memory for all rings
1136 * @adapter: board private structure to initialize
1138 * We allocate one ring per queue at run-time since we don't know the
1139 * number of queues at compile-time. The polling_netdev array is
1140 * intended for Multiqueue, but should work fine with a single queue.
1143 static int __devinit
1144 e1000_alloc_queues(struct e1000_adapter *adapter)
1148 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1149 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1150 if (!adapter->tx_ring)
1152 memset(adapter->tx_ring, 0, size);
1154 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1155 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1156 if (!adapter->rx_ring) {
1157 kfree(adapter->tx_ring);
1160 memset(adapter->rx_ring, 0, size);
1162 #ifdef CONFIG_E1000_NAPI
1163 size = sizeof(struct net_device) * adapter->num_rx_queues;
1164 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1165 if (!adapter->polling_netdev) {
1166 kfree(adapter->tx_ring);
1167 kfree(adapter->rx_ring);
1170 memset(adapter->polling_netdev, 0, size);
1173 return E1000_SUCCESS;
1177 * e1000_open - Called when a network interface is made active
1178 * @netdev: network interface device structure
1180 * Returns 0 on success, negative value on failure
1182 * The open entry point is called when a network interface is made
1183 * active by the system (IFF_UP). At this point all resources needed
1184 * for transmit and receive operations are allocated, the interrupt
1185 * handler is registered with the OS, the watchdog timer is started,
1186 * and the stack is notified that the interface is ready.
1190 e1000_open(struct net_device *netdev)
1192 struct e1000_adapter *adapter = netdev_priv(netdev);
1195 /* disallow open during test */
1196 if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
1199 /* allocate transmit descriptors */
1201 if ((err = e1000_setup_all_tx_resources(adapter)))
1204 /* allocate receive descriptors */
1206 if ((err = e1000_setup_all_rx_resources(adapter)))
1209 err = e1000_request_irq(adapter);
1213 e1000_power_up_phy(adapter);
1215 if ((err = e1000_up(adapter)))
1217 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1218 if ((adapter->hw.mng_cookie.status &
1219 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1220 e1000_update_mng_vlan(adapter);
1223 /* If AMT is enabled, let the firmware know that the network
1224 * interface is now open */
1225 if (adapter->hw.mac_type == e1000_82573 &&
1226 e1000_check_mng_mode(&adapter->hw))
1227 e1000_get_hw_control(adapter);
1229 return E1000_SUCCESS;
1232 e1000_free_all_rx_resources(adapter);
1234 e1000_free_all_tx_resources(adapter);
1236 e1000_reset(adapter);
1242 * e1000_close - Disables a network interface
1243 * @netdev: network interface device structure
1245 * Returns 0, this is not allowed to fail
1247 * The close entry point is called when an interface is de-activated
1248 * by the OS. The hardware is still under the drivers control, but
1249 * needs to be disabled. A global MAC reset is issued to stop the
1250 * hardware, and all transmit and receive resources are freed.
1254 e1000_close(struct net_device *netdev)
1256 struct e1000_adapter *adapter = netdev_priv(netdev);
1258 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1259 e1000_down(adapter);
1260 e1000_power_down_phy(adapter);
1261 e1000_free_irq(adapter);
1263 e1000_free_all_tx_resources(adapter);
1264 e1000_free_all_rx_resources(adapter);
1266 if ((adapter->hw.mng_cookie.status &
1267 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1268 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1271 /* If AMT is enabled, let the firmware know that the network
1272 * interface is now closed */
1273 if (adapter->hw.mac_type == e1000_82573 &&
1274 e1000_check_mng_mode(&adapter->hw))
1275 e1000_release_hw_control(adapter);
1281 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1282 * @adapter: address of board private structure
1283 * @start: address of beginning of memory
1284 * @len: length of memory
1287 e1000_check_64k_bound(struct e1000_adapter *adapter,
1288 void *start, unsigned long len)
1290 unsigned long begin = (unsigned long) start;
1291 unsigned long end = begin + len;
1293 /* First rev 82545 and 82546 need to not allow any memory
1294 * write location to cross 64k boundary due to errata 23 */
1295 if (adapter->hw.mac_type == e1000_82545 ||
1296 adapter->hw.mac_type == e1000_82546) {
1297 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1304 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1305 * @adapter: board private structure
1306 * @txdr: tx descriptor ring (for a specific queue) to setup
1308 * Return 0 on success, negative on failure
1312 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1313 struct e1000_tx_ring *txdr)
1315 struct pci_dev *pdev = adapter->pdev;
1318 size = sizeof(struct e1000_buffer) * txdr->count;
1319 txdr->buffer_info = vmalloc(size);
1320 if (!txdr->buffer_info) {
1322 "Unable to allocate memory for the transmit descriptor ring\n");
1325 memset(txdr->buffer_info, 0, size);
1327 /* round up to nearest 4K */
1329 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1330 E1000_ROUNDUP(txdr->size, 4096);
1332 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1335 vfree(txdr->buffer_info);
1337 "Unable to allocate memory for the transmit descriptor ring\n");
1341 /* Fix for errata 23, can't cross 64kB boundary */
1342 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1343 void *olddesc = txdr->desc;
1344 dma_addr_t olddma = txdr->dma;
1345 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1346 "at %p\n", txdr->size, txdr->desc);
1347 /* Try again, without freeing the previous */
1348 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1349 /* Failed allocation, critical failure */
1351 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1352 goto setup_tx_desc_die;
1355 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1357 pci_free_consistent(pdev, txdr->size, txdr->desc,
1359 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1361 "Unable to allocate aligned memory "
1362 "for the transmit descriptor ring\n");
1363 vfree(txdr->buffer_info);
1366 /* Free old allocation, new allocation was successful */
1367 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1370 memset(txdr->desc, 0, txdr->size);
1372 txdr->next_to_use = 0;
1373 txdr->next_to_clean = 0;
1374 spin_lock_init(&txdr->tx_lock);
1380 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1381 * (Descriptors) for all queues
1382 * @adapter: board private structure
1384 * If this function returns with an error, then it's possible one or
1385 * more of the rings is populated (while the rest are not). It is the
1386 * callers duty to clean those orphaned rings.
1388 * Return 0 on success, negative on failure
1392 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1396 for (i = 0; i < adapter->num_tx_queues; i++) {
1397 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1400 "Allocation for Tx Queue %u failed\n", i);
1409 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1410 * @adapter: board private structure
1412 * Configure the Tx unit of the MAC after a reset.
1416 e1000_configure_tx(struct e1000_adapter *adapter)
1419 struct e1000_hw *hw = &adapter->hw;
1420 uint32_t tdlen, tctl, tipg, tarc;
1421 uint32_t ipgr1, ipgr2;
1423 /* Setup the HW Tx Head and Tail descriptor pointers */
1425 switch (adapter->num_tx_queues) {
1428 tdba = adapter->tx_ring[0].dma;
1429 tdlen = adapter->tx_ring[0].count *
1430 sizeof(struct e1000_tx_desc);
1431 E1000_WRITE_REG(hw, TDLEN, tdlen);
1432 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1433 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1434 E1000_WRITE_REG(hw, TDT, 0);
1435 E1000_WRITE_REG(hw, TDH, 0);
1436 adapter->tx_ring[0].tdh = E1000_TDH;
1437 adapter->tx_ring[0].tdt = E1000_TDT;
1441 /* Set the default values for the Tx Inter Packet Gap timer */
1443 if (hw->media_type == e1000_media_type_fiber ||
1444 hw->media_type == e1000_media_type_internal_serdes)
1445 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1447 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1449 switch (hw->mac_type) {
1450 case e1000_82542_rev2_0:
1451 case e1000_82542_rev2_1:
1452 tipg = DEFAULT_82542_TIPG_IPGT;
1453 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1454 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1456 case e1000_80003es2lan:
1457 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1458 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1461 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1462 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1465 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1466 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1467 E1000_WRITE_REG(hw, TIPG, tipg);
1469 /* Set the Tx Interrupt Delay register */
1471 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1472 if (hw->mac_type >= e1000_82540)
1473 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1475 /* Program the Transmit Control Register */
1477 tctl = E1000_READ_REG(hw, TCTL);
1479 tctl &= ~E1000_TCTL_CT;
1480 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1481 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1484 /* disable Multiple Reads for debugging */
1485 tctl &= ~E1000_TCTL_MULR;
1488 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1489 tarc = E1000_READ_REG(hw, TARC0);
1490 tarc |= ((1 << 25) | (1 << 21));
1491 E1000_WRITE_REG(hw, TARC0, tarc);
1492 tarc = E1000_READ_REG(hw, TARC1);
1494 if (tctl & E1000_TCTL_MULR)
1498 E1000_WRITE_REG(hw, TARC1, tarc);
1499 } else if (hw->mac_type == e1000_80003es2lan) {
1500 tarc = E1000_READ_REG(hw, TARC0);
1502 if (hw->media_type == e1000_media_type_internal_serdes)
1504 E1000_WRITE_REG(hw, TARC0, tarc);
1505 tarc = E1000_READ_REG(hw, TARC1);
1507 E1000_WRITE_REG(hw, TARC1, tarc);
1510 e1000_config_collision_dist(hw);
1512 /* Setup Transmit Descriptor Settings for eop descriptor */
1513 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1516 if (hw->mac_type < e1000_82543)
1517 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1519 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1521 /* Cache if we're 82544 running in PCI-X because we'll
1522 * need this to apply a workaround later in the send path. */
1523 if (hw->mac_type == e1000_82544 &&
1524 hw->bus_type == e1000_bus_type_pcix)
1525 adapter->pcix_82544 = 1;
1527 E1000_WRITE_REG(hw, TCTL, tctl);
1532 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1533 * @adapter: board private structure
1534 * @rxdr: rx descriptor ring (for a specific queue) to setup
1536 * Returns 0 on success, negative on failure
1540 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1541 struct e1000_rx_ring *rxdr)
1543 struct pci_dev *pdev = adapter->pdev;
1546 size = sizeof(struct e1000_buffer) * rxdr->count;
1547 rxdr->buffer_info = vmalloc(size);
1548 if (!rxdr->buffer_info) {
1550 "Unable to allocate memory for the receive descriptor ring\n");
1553 memset(rxdr->buffer_info, 0, size);
1555 size = sizeof(struct e1000_ps_page) * rxdr->count;
1556 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1557 if (!rxdr->ps_page) {
1558 vfree(rxdr->buffer_info);
1560 "Unable to allocate memory for the receive descriptor ring\n");
1563 memset(rxdr->ps_page, 0, size);
1565 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1566 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1567 if (!rxdr->ps_page_dma) {
1568 vfree(rxdr->buffer_info);
1569 kfree(rxdr->ps_page);
1571 "Unable to allocate memory for the receive descriptor ring\n");
1574 memset(rxdr->ps_page_dma, 0, size);
1576 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1577 desc_len = sizeof(struct e1000_rx_desc);
1579 desc_len = sizeof(union e1000_rx_desc_packet_split);
1581 /* Round up to nearest 4K */
1583 rxdr->size = rxdr->count * desc_len;
1584 E1000_ROUNDUP(rxdr->size, 4096);
1586 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1590 "Unable to allocate memory for the receive descriptor ring\n");
1592 vfree(rxdr->buffer_info);
1593 kfree(rxdr->ps_page);
1594 kfree(rxdr->ps_page_dma);
1598 /* Fix for errata 23, can't cross 64kB boundary */
1599 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1600 void *olddesc = rxdr->desc;
1601 dma_addr_t olddma = rxdr->dma;
1602 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1603 "at %p\n", rxdr->size, rxdr->desc);
1604 /* Try again, without freeing the previous */
1605 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1606 /* Failed allocation, critical failure */
1608 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1610 "Unable to allocate memory "
1611 "for the receive descriptor ring\n");
1612 goto setup_rx_desc_die;
1615 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1617 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1619 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1621 "Unable to allocate aligned memory "
1622 "for the receive descriptor ring\n");
1623 goto setup_rx_desc_die;
1625 /* Free old allocation, new allocation was successful */
1626 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1629 memset(rxdr->desc, 0, rxdr->size);
1631 rxdr->next_to_clean = 0;
1632 rxdr->next_to_use = 0;
1638 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1639 * (Descriptors) for all queues
1640 * @adapter: board private structure
1642 * If this function returns with an error, then it's possible one or
1643 * more of the rings is populated (while the rest are not). It is the
1644 * callers duty to clean those orphaned rings.
1646 * Return 0 on success, negative on failure
1650 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1654 for (i = 0; i < adapter->num_rx_queues; i++) {
1655 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1658 "Allocation for Rx Queue %u failed\n", i);
1667 * e1000_setup_rctl - configure the receive control registers
1668 * @adapter: Board private structure
1670 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1671 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1673 e1000_setup_rctl(struct e1000_adapter *adapter)
1675 uint32_t rctl, rfctl;
1676 uint32_t psrctl = 0;
1677 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1681 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1683 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1685 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1686 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1687 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1689 if (adapter->hw.tbi_compatibility_on == 1)
1690 rctl |= E1000_RCTL_SBP;
1692 rctl &= ~E1000_RCTL_SBP;
1694 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1695 rctl &= ~E1000_RCTL_LPE;
1697 rctl |= E1000_RCTL_LPE;
1699 /* Setup buffer sizes */
1700 rctl &= ~E1000_RCTL_SZ_4096;
1701 rctl |= E1000_RCTL_BSEX;
1702 switch (adapter->rx_buffer_len) {
1703 case E1000_RXBUFFER_256:
1704 rctl |= E1000_RCTL_SZ_256;
1705 rctl &= ~E1000_RCTL_BSEX;
1707 case E1000_RXBUFFER_512:
1708 rctl |= E1000_RCTL_SZ_512;
1709 rctl &= ~E1000_RCTL_BSEX;
1711 case E1000_RXBUFFER_1024:
1712 rctl |= E1000_RCTL_SZ_1024;
1713 rctl &= ~E1000_RCTL_BSEX;
1715 case E1000_RXBUFFER_2048:
1717 rctl |= E1000_RCTL_SZ_2048;
1718 rctl &= ~E1000_RCTL_BSEX;
1720 case E1000_RXBUFFER_4096:
1721 rctl |= E1000_RCTL_SZ_4096;
1723 case E1000_RXBUFFER_8192:
1724 rctl |= E1000_RCTL_SZ_8192;
1726 case E1000_RXBUFFER_16384:
1727 rctl |= E1000_RCTL_SZ_16384;
1731 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1732 /* 82571 and greater support packet-split where the protocol
1733 * header is placed in skb->data and the packet data is
1734 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1735 * In the case of a non-split, skb->data is linearly filled,
1736 * followed by the page buffers. Therefore, skb->data is
1737 * sized to hold the largest protocol header.
1739 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1740 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1742 adapter->rx_ps_pages = pages;
1744 adapter->rx_ps_pages = 0;
1746 if (adapter->rx_ps_pages) {
1747 /* Configure extra packet-split registers */
1748 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1749 rfctl |= E1000_RFCTL_EXTEN;
1750 /* disable IPv6 packet split support */
1751 rfctl |= E1000_RFCTL_IPV6_DIS;
1752 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1754 rctl |= E1000_RCTL_DTYP_PS;
1756 psrctl |= adapter->rx_ps_bsize0 >>
1757 E1000_PSRCTL_BSIZE0_SHIFT;
1759 switch (adapter->rx_ps_pages) {
1761 psrctl |= PAGE_SIZE <<
1762 E1000_PSRCTL_BSIZE3_SHIFT;
1764 psrctl |= PAGE_SIZE <<
1765 E1000_PSRCTL_BSIZE2_SHIFT;
1767 psrctl |= PAGE_SIZE >>
1768 E1000_PSRCTL_BSIZE1_SHIFT;
1772 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1775 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1779 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1780 * @adapter: board private structure
1782 * Configure the Rx unit of the MAC after a reset.
1786 e1000_configure_rx(struct e1000_adapter *adapter)
1789 struct e1000_hw *hw = &adapter->hw;
1790 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1792 if (adapter->rx_ps_pages) {
1793 /* this is a 32 byte descriptor */
1794 rdlen = adapter->rx_ring[0].count *
1795 sizeof(union e1000_rx_desc_packet_split);
1796 adapter->clean_rx = e1000_clean_rx_irq_ps;
1797 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1799 rdlen = adapter->rx_ring[0].count *
1800 sizeof(struct e1000_rx_desc);
1801 adapter->clean_rx = e1000_clean_rx_irq;
1802 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1805 /* disable receives while setting up the descriptors */
1806 rctl = E1000_READ_REG(hw, RCTL);
1807 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1809 /* set the Receive Delay Timer Register */
1810 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1812 if (hw->mac_type >= e1000_82540) {
1813 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1814 if (adapter->itr > 1)
1815 E1000_WRITE_REG(hw, ITR,
1816 1000000000 / (adapter->itr * 256));
1819 if (hw->mac_type >= e1000_82571) {
1820 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1821 /* Reset delay timers after every interrupt */
1822 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
1823 #ifdef CONFIG_E1000_NAPI
1824 /* Auto-Mask interrupts upon ICR read. */
1825 ctrl_ext |= E1000_CTRL_EXT_IAME;
1827 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1828 E1000_WRITE_REG(hw, IAM, ~0);
1829 E1000_WRITE_FLUSH(hw);
1832 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1833 * the Base and Length of the Rx Descriptor Ring */
1834 switch (adapter->num_rx_queues) {
1837 rdba = adapter->rx_ring[0].dma;
1838 E1000_WRITE_REG(hw, RDLEN, rdlen);
1839 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1840 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1841 E1000_WRITE_REG(hw, RDT, 0);
1842 E1000_WRITE_REG(hw, RDH, 0);
1843 adapter->rx_ring[0].rdh = E1000_RDH;
1844 adapter->rx_ring[0].rdt = E1000_RDT;
1848 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1849 if (hw->mac_type >= e1000_82543) {
1850 rxcsum = E1000_READ_REG(hw, RXCSUM);
1851 if (adapter->rx_csum == TRUE) {
1852 rxcsum |= E1000_RXCSUM_TUOFL;
1854 /* Enable 82571 IPv4 payload checksum for UDP fragments
1855 * Must be used in conjunction with packet-split. */
1856 if ((hw->mac_type >= e1000_82571) &&
1857 (adapter->rx_ps_pages)) {
1858 rxcsum |= E1000_RXCSUM_IPPCSE;
1861 rxcsum &= ~E1000_RXCSUM_TUOFL;
1862 /* don't need to clear IPPCSE as it defaults to 0 */
1864 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1867 /* Enable Receives */
1868 E1000_WRITE_REG(hw, RCTL, rctl);
1872 * e1000_free_tx_resources - Free Tx Resources per Queue
1873 * @adapter: board private structure
1874 * @tx_ring: Tx descriptor ring for a specific queue
1876 * Free all transmit software resources
1880 e1000_free_tx_resources(struct e1000_adapter *adapter,
1881 struct e1000_tx_ring *tx_ring)
1883 struct pci_dev *pdev = adapter->pdev;
1885 e1000_clean_tx_ring(adapter, tx_ring);
1887 vfree(tx_ring->buffer_info);
1888 tx_ring->buffer_info = NULL;
1890 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1892 tx_ring->desc = NULL;
1896 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1897 * @adapter: board private structure
1899 * Free all transmit software resources
1903 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1907 for (i = 0; i < adapter->num_tx_queues; i++)
1908 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1912 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1913 struct e1000_buffer *buffer_info)
1915 if (buffer_info->dma) {
1916 pci_unmap_page(adapter->pdev,
1918 buffer_info->length,
1921 if (buffer_info->skb)
1922 dev_kfree_skb_any(buffer_info->skb);
1923 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1927 * e1000_clean_tx_ring - Free Tx Buffers
1928 * @adapter: board private structure
1929 * @tx_ring: ring to be cleaned
1933 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1934 struct e1000_tx_ring *tx_ring)
1936 struct e1000_buffer *buffer_info;
1940 /* Free all the Tx ring sk_buffs */
1942 for (i = 0; i < tx_ring->count; i++) {
1943 buffer_info = &tx_ring->buffer_info[i];
1944 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1947 size = sizeof(struct e1000_buffer) * tx_ring->count;
1948 memset(tx_ring->buffer_info, 0, size);
1950 /* Zero out the descriptor ring */
1952 memset(tx_ring->desc, 0, tx_ring->size);
1954 tx_ring->next_to_use = 0;
1955 tx_ring->next_to_clean = 0;
1956 tx_ring->last_tx_tso = 0;
1958 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1959 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1963 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1964 * @adapter: board private structure
1968 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1972 for (i = 0; i < adapter->num_tx_queues; i++)
1973 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1977 * e1000_free_rx_resources - Free Rx Resources
1978 * @adapter: board private structure
1979 * @rx_ring: ring to clean the resources from
1981 * Free all receive software resources
1985 e1000_free_rx_resources(struct e1000_adapter *adapter,
1986 struct e1000_rx_ring *rx_ring)
1988 struct pci_dev *pdev = adapter->pdev;
1990 e1000_clean_rx_ring(adapter, rx_ring);
1992 vfree(rx_ring->buffer_info);
1993 rx_ring->buffer_info = NULL;
1994 kfree(rx_ring->ps_page);
1995 rx_ring->ps_page = NULL;
1996 kfree(rx_ring->ps_page_dma);
1997 rx_ring->ps_page_dma = NULL;
1999 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2001 rx_ring->desc = NULL;
2005 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2006 * @adapter: board private structure
2008 * Free all receive software resources
2012 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2016 for (i = 0; i < adapter->num_rx_queues; i++)
2017 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2021 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2022 * @adapter: board private structure
2023 * @rx_ring: ring to free buffers from
2027 e1000_clean_rx_ring(struct e1000_adapter *adapter,
2028 struct e1000_rx_ring *rx_ring)
2030 struct e1000_buffer *buffer_info;
2031 struct e1000_ps_page *ps_page;
2032 struct e1000_ps_page_dma *ps_page_dma;
2033 struct pci_dev *pdev = adapter->pdev;
2037 /* Free all the Rx ring sk_buffs */
2038 for (i = 0; i < rx_ring->count; i++) {
2039 buffer_info = &rx_ring->buffer_info[i];
2040 if (buffer_info->skb) {
2041 pci_unmap_single(pdev,
2043 buffer_info->length,
2044 PCI_DMA_FROMDEVICE);
2046 dev_kfree_skb(buffer_info->skb);
2047 buffer_info->skb = NULL;
2049 ps_page = &rx_ring->ps_page[i];
2050 ps_page_dma = &rx_ring->ps_page_dma[i];
2051 for (j = 0; j < adapter->rx_ps_pages; j++) {
2052 if (!ps_page->ps_page[j]) break;
2053 pci_unmap_page(pdev,
2054 ps_page_dma->ps_page_dma[j],
2055 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2056 ps_page_dma->ps_page_dma[j] = 0;
2057 put_page(ps_page->ps_page[j]);
2058 ps_page->ps_page[j] = NULL;
2062 size = sizeof(struct e1000_buffer) * rx_ring->count;
2063 memset(rx_ring->buffer_info, 0, size);
2064 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2065 memset(rx_ring->ps_page, 0, size);
2066 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2067 memset(rx_ring->ps_page_dma, 0, size);
2069 /* Zero out the descriptor ring */
2071 memset(rx_ring->desc, 0, rx_ring->size);
2073 rx_ring->next_to_clean = 0;
2074 rx_ring->next_to_use = 0;
2076 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2077 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2081 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2082 * @adapter: board private structure
2086 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2090 for (i = 0; i < adapter->num_rx_queues; i++)
2091 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2094 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2095 * and memory write and invalidate disabled for certain operations
2098 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2100 struct net_device *netdev = adapter->netdev;
2103 e1000_pci_clear_mwi(&adapter->hw);
2105 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2106 rctl |= E1000_RCTL_RST;
2107 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2108 E1000_WRITE_FLUSH(&adapter->hw);
2111 if (netif_running(netdev))
2112 e1000_clean_all_rx_rings(adapter);
2116 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2118 struct net_device *netdev = adapter->netdev;
2121 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2122 rctl &= ~E1000_RCTL_RST;
2123 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2124 E1000_WRITE_FLUSH(&adapter->hw);
2127 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2128 e1000_pci_set_mwi(&adapter->hw);
2130 if (netif_running(netdev)) {
2131 /* No need to loop, because 82542 supports only 1 queue */
2132 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2133 e1000_configure_rx(adapter);
2134 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2139 * e1000_set_mac - Change the Ethernet Address of the NIC
2140 * @netdev: network interface device structure
2141 * @p: pointer to an address structure
2143 * Returns 0 on success, negative on failure
2147 e1000_set_mac(struct net_device *netdev, void *p)
2149 struct e1000_adapter *adapter = netdev_priv(netdev);
2150 struct sockaddr *addr = p;
2152 if (!is_valid_ether_addr(addr->sa_data))
2153 return -EADDRNOTAVAIL;
2155 /* 82542 2.0 needs to be in reset to write receive address registers */
2157 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2158 e1000_enter_82542_rst(adapter);
2160 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2161 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2163 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2165 /* With 82571 controllers, LAA may be overwritten (with the default)
2166 * due to controller reset from the other port. */
2167 if (adapter->hw.mac_type == e1000_82571) {
2168 /* activate the work around */
2169 adapter->hw.laa_is_present = 1;
2171 /* Hold a copy of the LAA in RAR[14] This is done so that
2172 * between the time RAR[0] gets clobbered and the time it
2173 * gets fixed (in e1000_watchdog), the actual LAA is in one
2174 * of the RARs and no incoming packets directed to this port
2175 * are dropped. Eventaully the LAA will be in RAR[0] and
2177 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2178 E1000_RAR_ENTRIES - 1);
2181 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2182 e1000_leave_82542_rst(adapter);
2188 * e1000_set_multi - Multicast and Promiscuous mode set
2189 * @netdev: network interface device structure
2191 * The set_multi entry point is called whenever the multicast address
2192 * list or the network interface flags are updated. This routine is
2193 * responsible for configuring the hardware for proper multicast,
2194 * promiscuous mode, and all-multi behavior.
2198 e1000_set_multi(struct net_device *netdev)
2200 struct e1000_adapter *adapter = netdev_priv(netdev);
2201 struct e1000_hw *hw = &adapter->hw;
2202 struct dev_mc_list *mc_ptr;
2204 uint32_t hash_value;
2205 int i, rar_entries = E1000_RAR_ENTRIES;
2206 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2207 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2208 E1000_NUM_MTA_REGISTERS;
2210 if (adapter->hw.mac_type == e1000_ich8lan)
2211 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2213 /* reserve RAR[14] for LAA over-write work-around */
2214 if (adapter->hw.mac_type == e1000_82571)
2217 /* Check for Promiscuous and All Multicast modes */
2219 rctl = E1000_READ_REG(hw, RCTL);
2221 if (netdev->flags & IFF_PROMISC) {
2222 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2223 } else if (netdev->flags & IFF_ALLMULTI) {
2224 rctl |= E1000_RCTL_MPE;
2225 rctl &= ~E1000_RCTL_UPE;
2227 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2230 E1000_WRITE_REG(hw, RCTL, rctl);
2232 /* 82542 2.0 needs to be in reset to write receive address registers */
2234 if (hw->mac_type == e1000_82542_rev2_0)
2235 e1000_enter_82542_rst(adapter);
2237 /* load the first 14 multicast address into the exact filters 1-14
2238 * RAR 0 is used for the station MAC adddress
2239 * if there are not 14 addresses, go ahead and clear the filters
2240 * -- with 82571 controllers only 0-13 entries are filled here
2242 mc_ptr = netdev->mc_list;
2244 for (i = 1; i < rar_entries; i++) {
2246 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2247 mc_ptr = mc_ptr->next;
2249 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2250 E1000_WRITE_FLUSH(hw);
2251 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2252 E1000_WRITE_FLUSH(hw);
2256 /* clear the old settings from the multicast hash table */
2258 for (i = 0; i < mta_reg_count; i++) {
2259 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2260 E1000_WRITE_FLUSH(hw);
2263 /* load any remaining addresses into the hash table */
2265 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2266 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2267 e1000_mta_set(hw, hash_value);
2270 if (hw->mac_type == e1000_82542_rev2_0)
2271 e1000_leave_82542_rst(adapter);
2274 /* Need to wait a few seconds after link up to get diagnostic information from
2278 e1000_update_phy_info(unsigned long data)
2280 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2281 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2285 * e1000_82547_tx_fifo_stall - Timer Call-back
2286 * @data: pointer to adapter cast into an unsigned long
2290 e1000_82547_tx_fifo_stall(unsigned long data)
2292 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2293 struct net_device *netdev = adapter->netdev;
2296 if (atomic_read(&adapter->tx_fifo_stall)) {
2297 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2298 E1000_READ_REG(&adapter->hw, TDH)) &&
2299 (E1000_READ_REG(&adapter->hw, TDFT) ==
2300 E1000_READ_REG(&adapter->hw, TDFH)) &&
2301 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2302 E1000_READ_REG(&adapter->hw, TDFHS))) {
2303 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2304 E1000_WRITE_REG(&adapter->hw, TCTL,
2305 tctl & ~E1000_TCTL_EN);
2306 E1000_WRITE_REG(&adapter->hw, TDFT,
2307 adapter->tx_head_addr);
2308 E1000_WRITE_REG(&adapter->hw, TDFH,
2309 adapter->tx_head_addr);
2310 E1000_WRITE_REG(&adapter->hw, TDFTS,
2311 adapter->tx_head_addr);
2312 E1000_WRITE_REG(&adapter->hw, TDFHS,
2313 adapter->tx_head_addr);
2314 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2315 E1000_WRITE_FLUSH(&adapter->hw);
2317 adapter->tx_fifo_head = 0;
2318 atomic_set(&adapter->tx_fifo_stall, 0);
2319 netif_wake_queue(netdev);
2321 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2327 * e1000_watchdog - Timer Call-back
2328 * @data: pointer to adapter cast into an unsigned long
2331 e1000_watchdog(unsigned long data)
2333 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2334 struct net_device *netdev = adapter->netdev;
2335 struct e1000_tx_ring *txdr = adapter->tx_ring;
2336 uint32_t link, tctl;
2339 ret_val = e1000_check_for_link(&adapter->hw);
2340 if ((ret_val == E1000_ERR_PHY) &&
2341 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2342 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2343 /* See e1000_kumeran_lock_loss_workaround() */
2345 "Gigabit has been disabled, downgrading speed\n");
2347 if (adapter->hw.mac_type == e1000_82573) {
2348 e1000_enable_tx_pkt_filtering(&adapter->hw);
2349 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2350 e1000_update_mng_vlan(adapter);
2353 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2354 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2355 link = !adapter->hw.serdes_link_down;
2357 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2360 if (!netif_carrier_ok(netdev)) {
2361 boolean_t txb2b = 1;
2362 e1000_get_speed_and_duplex(&adapter->hw,
2363 &adapter->link_speed,
2364 &adapter->link_duplex);
2366 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2367 adapter->link_speed,
2368 adapter->link_duplex == FULL_DUPLEX ?
2369 "Full Duplex" : "Half Duplex");
2371 /* tweak tx_queue_len according to speed/duplex
2372 * and adjust the timeout factor */
2373 netdev->tx_queue_len = adapter->tx_queue_len;
2374 adapter->tx_timeout_factor = 1;
2375 switch (adapter->link_speed) {
2378 netdev->tx_queue_len = 10;
2379 adapter->tx_timeout_factor = 8;
2383 netdev->tx_queue_len = 100;
2384 /* maybe add some timeout factor ? */
2388 if ((adapter->hw.mac_type == e1000_82571 ||
2389 adapter->hw.mac_type == e1000_82572) &&
2391 #define SPEED_MODE_BIT (1 << 21)
2393 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2394 tarc0 &= ~SPEED_MODE_BIT;
2395 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2399 /* disable TSO for pcie and 10/100 speeds, to avoid
2400 * some hardware issues */
2401 if (!adapter->tso_force &&
2402 adapter->hw.bus_type == e1000_bus_type_pci_express){
2403 switch (adapter->link_speed) {
2407 "10/100 speed: disabling TSO\n");
2408 netdev->features &= ~NETIF_F_TSO;
2411 netdev->features |= NETIF_F_TSO;
2420 /* enable transmits in the hardware, need to do this
2421 * after setting TARC0 */
2422 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2423 tctl |= E1000_TCTL_EN;
2424 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2426 netif_carrier_on(netdev);
2427 netif_wake_queue(netdev);
2428 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2429 adapter->smartspeed = 0;
2432 if (netif_carrier_ok(netdev)) {
2433 adapter->link_speed = 0;
2434 adapter->link_duplex = 0;
2435 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2436 netif_carrier_off(netdev);
2437 netif_stop_queue(netdev);
2438 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2440 /* 80003ES2LAN workaround--
2441 * For packet buffer work-around on link down event;
2442 * disable receives in the ISR and
2443 * reset device here in the watchdog
2445 if (adapter->hw.mac_type == e1000_80003es2lan) {
2447 schedule_work(&adapter->reset_task);
2451 e1000_smartspeed(adapter);
2454 e1000_update_stats(adapter);
2456 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2457 adapter->tpt_old = adapter->stats.tpt;
2458 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2459 adapter->colc_old = adapter->stats.colc;
2461 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2462 adapter->gorcl_old = adapter->stats.gorcl;
2463 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2464 adapter->gotcl_old = adapter->stats.gotcl;
2466 e1000_update_adaptive(&adapter->hw);
2468 if (!netif_carrier_ok(netdev)) {
2469 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2470 /* We've lost link, so the controller stops DMA,
2471 * but we've got queued Tx work that's never going
2472 * to get done, so reset controller to flush Tx.
2473 * (Do the reset outside of interrupt context). */
2474 adapter->tx_timeout_count++;
2475 schedule_work(&adapter->reset_task);
2479 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2480 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2481 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2482 * asymmetrical Tx or Rx gets ITR=8000; everyone
2483 * else is between 2000-8000. */
2484 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2485 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2486 adapter->gotcl - adapter->gorcl :
2487 adapter->gorcl - adapter->gotcl) / 10000;
2488 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2489 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2492 /* Cause software interrupt to ensure rx ring is cleaned */
2493 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2495 /* Force detection of hung controller every watchdog period */
2496 adapter->detect_tx_hung = TRUE;
2498 /* With 82571 controllers, LAA may be overwritten due to controller
2499 * reset from the other port. Set the appropriate LAA in RAR[0] */
2500 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2501 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2503 /* Reset the timer */
2504 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2507 #define E1000_TX_FLAGS_CSUM 0x00000001
2508 #define E1000_TX_FLAGS_VLAN 0x00000002
2509 #define E1000_TX_FLAGS_TSO 0x00000004
2510 #define E1000_TX_FLAGS_IPV4 0x00000008
2511 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2512 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2515 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2516 struct sk_buff *skb)
2519 struct e1000_context_desc *context_desc;
2520 struct e1000_buffer *buffer_info;
2522 uint32_t cmd_length = 0;
2523 uint16_t ipcse = 0, tucse, mss;
2524 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2527 if (skb_shinfo(skb)->tso_size) {
2528 if (skb_header_cloned(skb)) {
2529 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2534 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2535 mss = skb_shinfo(skb)->tso_size;
2536 if (skb->protocol == htons(ETH_P_IP)) {
2537 skb->nh.iph->tot_len = 0;
2538 skb->nh.iph->check = 0;
2540 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2545 cmd_length = E1000_TXD_CMD_IP;
2546 ipcse = skb->h.raw - skb->data - 1;
2547 #ifdef NETIF_F_TSO_IPV6
2548 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2549 skb->nh.ipv6h->payload_len = 0;
2551 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2552 &skb->nh.ipv6h->daddr,
2559 ipcss = skb->nh.raw - skb->data;
2560 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2561 tucss = skb->h.raw - skb->data;
2562 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2565 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2566 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2568 i = tx_ring->next_to_use;
2569 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2570 buffer_info = &tx_ring->buffer_info[i];
2572 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2573 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2574 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2575 context_desc->upper_setup.tcp_fields.tucss = tucss;
2576 context_desc->upper_setup.tcp_fields.tucso = tucso;
2577 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2578 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2579 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2580 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2582 buffer_info->time_stamp = jiffies;
2584 if (++i == tx_ring->count) i = 0;
2585 tx_ring->next_to_use = i;
2595 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2596 struct sk_buff *skb)
2598 struct e1000_context_desc *context_desc;
2599 struct e1000_buffer *buffer_info;
2603 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2604 css = skb->h.raw - skb->data;
2606 i = tx_ring->next_to_use;
2607 buffer_info = &tx_ring->buffer_info[i];
2608 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2610 context_desc->upper_setup.tcp_fields.tucss = css;
2611 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2612 context_desc->upper_setup.tcp_fields.tucse = 0;
2613 context_desc->tcp_seg_setup.data = 0;
2614 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2616 buffer_info->time_stamp = jiffies;
2618 if (unlikely(++i == tx_ring->count)) i = 0;
2619 tx_ring->next_to_use = i;
2627 #define E1000_MAX_TXD_PWR 12
2628 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2631 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2632 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2633 unsigned int nr_frags, unsigned int mss)
2635 struct e1000_buffer *buffer_info;
2636 unsigned int len = skb->len;
2637 unsigned int offset = 0, size, count = 0, i;
2639 len -= skb->data_len;
2641 i = tx_ring->next_to_use;
2644 buffer_info = &tx_ring->buffer_info[i];
2645 size = min(len, max_per_txd);
2647 /* Workaround for Controller erratum --
2648 * descriptor for non-tso packet in a linear SKB that follows a
2649 * tso gets written back prematurely before the data is fully
2650 * DMA'd to the controller */
2651 if (!skb->data_len && tx_ring->last_tx_tso &&
2652 !skb_shinfo(skb)->tso_size) {
2653 tx_ring->last_tx_tso = 0;
2657 /* Workaround for premature desc write-backs
2658 * in TSO mode. Append 4-byte sentinel desc */
2659 if (unlikely(mss && !nr_frags && size == len && size > 8))
2662 /* work-around for errata 10 and it applies
2663 * to all controllers in PCI-X mode
2664 * The fix is to make sure that the first descriptor of a
2665 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2667 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2668 (size > 2015) && count == 0))
2671 /* Workaround for potential 82544 hang in PCI-X. Avoid
2672 * terminating buffers within evenly-aligned dwords. */
2673 if (unlikely(adapter->pcix_82544 &&
2674 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2678 buffer_info->length = size;
2680 pci_map_single(adapter->pdev,
2684 buffer_info->time_stamp = jiffies;
2689 if (unlikely(++i == tx_ring->count)) i = 0;
2692 for (f = 0; f < nr_frags; f++) {
2693 struct skb_frag_struct *frag;
2695 frag = &skb_shinfo(skb)->frags[f];
2697 offset = frag->page_offset;
2700 buffer_info = &tx_ring->buffer_info[i];
2701 size = min(len, max_per_txd);
2703 /* Workaround for premature desc write-backs
2704 * in TSO mode. Append 4-byte sentinel desc */
2705 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2708 /* Workaround for potential 82544 hang in PCI-X.
2709 * Avoid terminating buffers within evenly-aligned
2711 if (unlikely(adapter->pcix_82544 &&
2712 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2716 buffer_info->length = size;
2718 pci_map_page(adapter->pdev,
2723 buffer_info->time_stamp = jiffies;
2728 if (unlikely(++i == tx_ring->count)) i = 0;
2732 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2733 tx_ring->buffer_info[i].skb = skb;
2734 tx_ring->buffer_info[first].next_to_watch = i;
2740 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2741 int tx_flags, int count)
2743 struct e1000_tx_desc *tx_desc = NULL;
2744 struct e1000_buffer *buffer_info;
2745 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2748 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2749 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2751 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2753 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2754 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2757 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2758 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2759 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2762 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2763 txd_lower |= E1000_TXD_CMD_VLE;
2764 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2767 i = tx_ring->next_to_use;
2770 buffer_info = &tx_ring->buffer_info[i];
2771 tx_desc = E1000_TX_DESC(*tx_ring, i);
2772 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2773 tx_desc->lower.data =
2774 cpu_to_le32(txd_lower | buffer_info->length);
2775 tx_desc->upper.data = cpu_to_le32(txd_upper);
2776 if (unlikely(++i == tx_ring->count)) i = 0;
2779 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2781 /* Force memory writes to complete before letting h/w
2782 * know there are new descriptors to fetch. (Only
2783 * applicable for weak-ordered memory model archs,
2784 * such as IA-64). */
2787 tx_ring->next_to_use = i;
2788 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2792 * 82547 workaround to avoid controller hang in half-duplex environment.
2793 * The workaround is to avoid queuing a large packet that would span
2794 * the internal Tx FIFO ring boundary by notifying the stack to resend
2795 * the packet at a later time. This gives the Tx FIFO an opportunity to
2796 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2797 * to the beginning of the Tx FIFO.
2800 #define E1000_FIFO_HDR 0x10
2801 #define E1000_82547_PAD_LEN 0x3E0
2804 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2806 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2807 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2809 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2811 if (adapter->link_duplex != HALF_DUPLEX)
2812 goto no_fifo_stall_required;
2814 if (atomic_read(&adapter->tx_fifo_stall))
2817 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2818 atomic_set(&adapter->tx_fifo_stall, 1);
2822 no_fifo_stall_required:
2823 adapter->tx_fifo_head += skb_fifo_len;
2824 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2825 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2829 #define MINIMUM_DHCP_PACKET_SIZE 282
2831 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2833 struct e1000_hw *hw = &adapter->hw;
2834 uint16_t length, offset;
2835 if (vlan_tx_tag_present(skb)) {
2836 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2837 ( adapter->hw.mng_cookie.status &
2838 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2841 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
2842 struct ethhdr *eth = (struct ethhdr *) skb->data;
2843 if ((htons(ETH_P_IP) == eth->h_proto)) {
2844 const struct iphdr *ip =
2845 (struct iphdr *)((uint8_t *)skb->data+14);
2846 if (IPPROTO_UDP == ip->protocol) {
2847 struct udphdr *udp =
2848 (struct udphdr *)((uint8_t *)ip +
2850 if (ntohs(udp->dest) == 67) {
2851 offset = (uint8_t *)udp + 8 - skb->data;
2852 length = skb->len - offset;
2854 return e1000_mng_write_dhcp_info(hw,
2864 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2866 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2868 struct e1000_adapter *adapter = netdev_priv(netdev);
2869 struct e1000_tx_ring *tx_ring;
2870 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2871 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2872 unsigned int tx_flags = 0;
2873 unsigned int len = skb->len;
2874 unsigned long flags;
2875 unsigned int nr_frags = 0;
2876 unsigned int mss = 0;
2880 len -= skb->data_len;
2882 tx_ring = adapter->tx_ring;
2884 if (unlikely(skb->len <= 0)) {
2885 dev_kfree_skb_any(skb);
2886 return NETDEV_TX_OK;
2890 mss = skb_shinfo(skb)->tso_size;
2891 /* The controller does a simple calculation to
2892 * make sure there is enough room in the FIFO before
2893 * initiating the DMA for each buffer. The calc is:
2894 * 4 = ceil(buffer len/mss). To make sure we don't
2895 * overrun the FIFO, adjust the max buffer len if mss
2899 max_per_txd = min(mss << 2, max_per_txd);
2900 max_txd_pwr = fls(max_per_txd) - 1;
2902 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2903 * points to just header, pull a few bytes of payload from
2904 * frags into skb->data */
2905 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2906 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2907 switch (adapter->hw.mac_type) {
2908 unsigned int pull_size;
2913 pull_size = min((unsigned int)4, skb->data_len);
2914 if (!__pskb_pull_tail(skb, pull_size)) {
2916 "__pskb_pull_tail failed.\n");
2917 dev_kfree_skb_any(skb);
2918 return NETDEV_TX_OK;
2920 len = skb->len - skb->data_len;
2929 /* reserve a descriptor for the offload context */
2930 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2934 if (skb->ip_summed == CHECKSUM_HW)
2939 /* Controller Erratum workaround */
2940 if (!skb->data_len && tx_ring->last_tx_tso &&
2941 !skb_shinfo(skb)->tso_size)
2945 count += TXD_USE_COUNT(len, max_txd_pwr);
2947 if (adapter->pcix_82544)
2950 /* work-around for errata 10 and it applies to all controllers
2951 * in PCI-X mode, so add one more descriptor to the count
2953 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2957 nr_frags = skb_shinfo(skb)->nr_frags;
2958 for (f = 0; f < nr_frags; f++)
2959 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2961 if (adapter->pcix_82544)
2965 if (adapter->hw.tx_pkt_filtering &&
2966 (adapter->hw.mac_type == e1000_82573))
2967 e1000_transfer_dhcp_info(adapter, skb);
2969 local_irq_save(flags);
2970 if (!spin_trylock(&tx_ring->tx_lock)) {
2971 /* Collision - tell upper layer to requeue */
2972 local_irq_restore(flags);
2973 return NETDEV_TX_LOCKED;
2976 /* need: count + 2 desc gap to keep tail from touching
2977 * head, otherwise try next time */
2978 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2979 netif_stop_queue(netdev);
2980 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2981 return NETDEV_TX_BUSY;
2984 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2985 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2986 netif_stop_queue(netdev);
2987 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2988 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2989 return NETDEV_TX_BUSY;
2993 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2994 tx_flags |= E1000_TX_FLAGS_VLAN;
2995 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2998 first = tx_ring->next_to_use;
3000 tso = e1000_tso(adapter, tx_ring, skb);
3002 dev_kfree_skb_any(skb);
3003 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3004 return NETDEV_TX_OK;
3008 tx_ring->last_tx_tso = 1;
3009 tx_flags |= E1000_TX_FLAGS_TSO;
3010 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3011 tx_flags |= E1000_TX_FLAGS_CSUM;
3013 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3014 * 82571 hardware supports TSO capabilities for IPv6 as well...
3015 * no longer assume, we must. */
3016 if (likely(skb->protocol == htons(ETH_P_IP)))
3017 tx_flags |= E1000_TX_FLAGS_IPV4;
3019 e1000_tx_queue(adapter, tx_ring, tx_flags,
3020 e1000_tx_map(adapter, tx_ring, skb, first,
3021 max_per_txd, nr_frags, mss));
3023 netdev->trans_start = jiffies;
3025 /* Make sure there is space in the ring for the next send. */
3026 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
3027 netif_stop_queue(netdev);
3029 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3030 return NETDEV_TX_OK;
3034 * e1000_tx_timeout - Respond to a Tx Hang
3035 * @netdev: network interface device structure
3039 e1000_tx_timeout(struct net_device *netdev)
3041 struct e1000_adapter *adapter = netdev_priv(netdev);
3043 /* Do the reset outside of interrupt context */
3044 adapter->tx_timeout_count++;
3045 schedule_work(&adapter->reset_task);
3049 e1000_reset_task(struct net_device *netdev)
3051 struct e1000_adapter *adapter = netdev_priv(netdev);
3053 e1000_reinit_locked(adapter);
3057 * e1000_get_stats - Get System Network Statistics
3058 * @netdev: network interface device structure
3060 * Returns the address of the device statistics structure.
3061 * The statistics are actually updated from the timer callback.
3064 static struct net_device_stats *
3065 e1000_get_stats(struct net_device *netdev)
3067 struct e1000_adapter *adapter = netdev_priv(netdev);
3069 /* only return the current stats */
3070 return &adapter->net_stats;
3074 * e1000_change_mtu - Change the Maximum Transfer Unit
3075 * @netdev: network interface device structure
3076 * @new_mtu: new value for maximum frame size
3078 * Returns 0 on success, negative on failure
3082 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3084 struct e1000_adapter *adapter = netdev_priv(netdev);
3085 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3086 uint16_t eeprom_data = 0;
3088 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3089 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3090 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3094 /* Adapter-specific max frame size limits. */
3095 switch (adapter->hw.mac_type) {
3096 case e1000_undefined ... e1000_82542_rev2_1:
3098 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3099 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3104 /* only enable jumbo frames if ASPM is disabled completely
3105 * this means both bits must be zero in 0x1A bits 3:2 */
3106 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3108 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
3109 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3111 "Jumbo Frames not supported.\n");
3116 /* fall through to get support */
3119 case e1000_80003es2lan:
3120 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3121 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3122 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3127 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3131 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3132 * means we reserve 2 more, this pushes us to allocate from the next
3134 * i.e. RXBUFFER_2048 --> size-4096 slab */
3136 if (max_frame <= E1000_RXBUFFER_256)
3137 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3138 else if (max_frame <= E1000_RXBUFFER_512)
3139 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3140 else if (max_frame <= E1000_RXBUFFER_1024)
3141 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3142 else if (max_frame <= E1000_RXBUFFER_2048)
3143 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3144 else if (max_frame <= E1000_RXBUFFER_4096)
3145 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3146 else if (max_frame <= E1000_RXBUFFER_8192)
3147 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3148 else if (max_frame <= E1000_RXBUFFER_16384)
3149 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3151 /* adjust allocation if LPE protects us, and we aren't using SBP */
3152 #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3153 if (!adapter->hw.tbi_compatibility_on &&
3154 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3155 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3156 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3158 netdev->mtu = new_mtu;
3160 if (netif_running(netdev))
3161 e1000_reinit_locked(adapter);
3163 adapter->hw.max_frame_size = max_frame;
3169 * e1000_update_stats - Update the board statistics counters
3170 * @adapter: board private structure
3174 e1000_update_stats(struct e1000_adapter *adapter)
3176 struct e1000_hw *hw = &adapter->hw;
3177 struct pci_dev *pdev = adapter->pdev;
3178 unsigned long flags;
3181 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3184 * Prevent stats update while adapter is being reset, or if the pci
3185 * connection is down.
3187 if (adapter->link_speed == 0)
3189 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3192 spin_lock_irqsave(&adapter->stats_lock, flags);
3194 /* these counters are modified from e1000_adjust_tbi_stats,
3195 * called from the interrupt context, so they must only
3196 * be written while holding adapter->stats_lock
3199 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3200 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3201 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3202 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3203 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3204 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3205 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3207 if (adapter->hw.mac_type != e1000_ich8lan) {
3208 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3209 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3210 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3211 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3212 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3213 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3216 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3217 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3218 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3219 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3220 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3221 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3222 adapter->stats.dc += E1000_READ_REG(hw, DC);
3223 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3224 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3225 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3226 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);