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.0.38-k4"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(0x105E),
77 INTEL_E1000_ETHERNET_DEVICE(0x105F),
78 INTEL_E1000_ETHERNET_DEVICE(0x1060),
79 INTEL_E1000_ETHERNET_DEVICE(0x1075),
80 INTEL_E1000_ETHERNET_DEVICE(0x1076),
81 INTEL_E1000_ETHERNET_DEVICE(0x1077),
82 INTEL_E1000_ETHERNET_DEVICE(0x1078),
83 INTEL_E1000_ETHERNET_DEVICE(0x1079),
84 INTEL_E1000_ETHERNET_DEVICE(0x107A),
85 INTEL_E1000_ETHERNET_DEVICE(0x107B),
86 INTEL_E1000_ETHERNET_DEVICE(0x107C),
87 INTEL_E1000_ETHERNET_DEVICE(0x107D),
88 INTEL_E1000_ETHERNET_DEVICE(0x107E),
89 INTEL_E1000_ETHERNET_DEVICE(0x107F),
90 INTEL_E1000_ETHERNET_DEVICE(0x108A),
91 INTEL_E1000_ETHERNET_DEVICE(0x108B),
92 INTEL_E1000_ETHERNET_DEVICE(0x108C),
93 INTEL_E1000_ETHERNET_DEVICE(0x1096),
94 INTEL_E1000_ETHERNET_DEVICE(0x1098),
95 INTEL_E1000_ETHERNET_DEVICE(0x1099),
96 INTEL_E1000_ETHERNET_DEVICE(0x109A),
97 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
98 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
99 /* required last entry */
103 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
105 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
106 struct e1000_tx_ring *txdr);
107 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
108 struct e1000_rx_ring *rxdr);
109 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
110 struct e1000_tx_ring *tx_ring);
111 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
112 struct e1000_rx_ring *rx_ring);
114 /* Local Function Prototypes */
116 static int e1000_init_module(void);
117 static void e1000_exit_module(void);
118 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
119 static void __devexit e1000_remove(struct pci_dev *pdev);
120 static int e1000_alloc_queues(struct e1000_adapter *adapter);
121 static int e1000_sw_init(struct e1000_adapter *adapter);
122 static int e1000_open(struct net_device *netdev);
123 static int e1000_close(struct net_device *netdev);
124 static void e1000_configure_tx(struct e1000_adapter *adapter);
125 static void e1000_configure_rx(struct e1000_adapter *adapter);
126 static void e1000_setup_rctl(struct e1000_adapter *adapter);
127 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
128 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
129 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
130 struct e1000_tx_ring *tx_ring);
131 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
132 struct e1000_rx_ring *rx_ring);
133 static void e1000_set_multi(struct net_device *netdev);
134 static void e1000_update_phy_info(unsigned long data);
135 static void e1000_watchdog(unsigned long data);
136 static void e1000_82547_tx_fifo_stall(unsigned long data);
137 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
138 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
139 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
140 static int e1000_set_mac(struct net_device *netdev, void *p);
141 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
142 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
143 struct e1000_tx_ring *tx_ring);
144 #ifdef CONFIG_E1000_NAPI
145 static int e1000_clean(struct net_device *poll_dev, int *budget);
146 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int *work_done, int work_to_do);
149 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
150 struct e1000_rx_ring *rx_ring,
151 int *work_done, int work_to_do);
153 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
154 struct e1000_rx_ring *rx_ring);
155 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
156 struct e1000_rx_ring *rx_ring);
158 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
159 struct e1000_rx_ring *rx_ring,
161 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
162 struct e1000_rx_ring *rx_ring,
164 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
165 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
167 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
168 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
169 static void e1000_tx_timeout(struct net_device *dev);
170 static void e1000_reset_task(struct net_device *dev);
171 static void e1000_smartspeed(struct e1000_adapter *adapter);
172 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
173 struct sk_buff *skb);
175 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
176 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
177 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
178 static void e1000_restore_vlan(struct e1000_adapter *adapter);
180 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
182 static int e1000_resume(struct pci_dev *pdev);
184 static void e1000_shutdown(struct pci_dev *pdev);
186 #ifdef CONFIG_NET_POLL_CONTROLLER
187 /* for netdump / net console */
188 static void e1000_netpoll (struct net_device *netdev);
191 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
192 pci_channel_state_t state);
193 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
194 static void e1000_io_resume(struct pci_dev *pdev);
196 static struct pci_error_handlers e1000_err_handler = {
197 .error_detected = e1000_io_error_detected,
198 .slot_reset = e1000_io_slot_reset,
199 .resume = e1000_io_resume,
202 static struct pci_driver e1000_driver = {
203 .name = e1000_driver_name,
204 .id_table = e1000_pci_tbl,
205 .probe = e1000_probe,
206 .remove = __devexit_p(e1000_remove),
207 /* Power Managment Hooks */
208 .suspend = e1000_suspend,
210 .resume = e1000_resume,
212 .shutdown = e1000_shutdown,
213 .err_handler = &e1000_err_handler
216 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
217 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
218 MODULE_LICENSE("GPL");
219 MODULE_VERSION(DRV_VERSION);
221 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
222 module_param(debug, int, 0);
223 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
226 * e1000_init_module - Driver Registration Routine
228 * e1000_init_module is the first routine called when the driver is
229 * loaded. All it does is register with the PCI subsystem.
233 e1000_init_module(void)
236 printk(KERN_INFO "%s - version %s\n",
237 e1000_driver_string, e1000_driver_version);
239 printk(KERN_INFO "%s\n", e1000_copyright);
241 ret = pci_module_init(&e1000_driver);
246 module_init(e1000_init_module);
249 * e1000_exit_module - Driver Exit Cleanup Routine
251 * e1000_exit_module is called just before the driver is removed
256 e1000_exit_module(void)
258 pci_unregister_driver(&e1000_driver);
261 module_exit(e1000_exit_module);
263 static int e1000_request_irq(struct e1000_adapter *adapter)
265 struct net_device *netdev = adapter->netdev;
268 flags = SA_SHIRQ | SA_SAMPLE_RANDOM;
269 #ifdef CONFIG_PCI_MSI
270 if (adapter->hw.mac_type > e1000_82547_rev_2) {
271 adapter->have_msi = TRUE;
272 if ((err = pci_enable_msi(adapter->pdev))) {
274 "Unable to allocate MSI interrupt Error: %d\n", err);
275 adapter->have_msi = FALSE;
278 if (adapter->have_msi)
281 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
282 netdev->name, netdev)))
284 "Unable to allocate interrupt Error: %d\n", err);
289 static void e1000_free_irq(struct e1000_adapter *adapter)
291 struct net_device *netdev = adapter->netdev;
293 free_irq(adapter->pdev->irq, netdev);
295 #ifdef CONFIG_PCI_MSI
296 if (adapter->have_msi)
297 pci_disable_msi(adapter->pdev);
302 * e1000_irq_disable - Mask off interrupt generation on the NIC
303 * @adapter: board private structure
307 e1000_irq_disable(struct e1000_adapter *adapter)
309 atomic_inc(&adapter->irq_sem);
310 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
311 E1000_WRITE_FLUSH(&adapter->hw);
312 synchronize_irq(adapter->pdev->irq);
316 * e1000_irq_enable - Enable default interrupt generation settings
317 * @adapter: board private structure
321 e1000_irq_enable(struct e1000_adapter *adapter)
323 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
324 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
325 E1000_WRITE_FLUSH(&adapter->hw);
330 e1000_update_mng_vlan(struct e1000_adapter *adapter)
332 struct net_device *netdev = adapter->netdev;
333 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
334 uint16_t old_vid = adapter->mng_vlan_id;
335 if (adapter->vlgrp) {
336 if (!adapter->vlgrp->vlan_devices[vid]) {
337 if (adapter->hw.mng_cookie.status &
338 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
339 e1000_vlan_rx_add_vid(netdev, vid);
340 adapter->mng_vlan_id = vid;
342 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
344 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
346 !adapter->vlgrp->vlan_devices[old_vid])
347 e1000_vlan_rx_kill_vid(netdev, old_vid);
349 adapter->mng_vlan_id = vid;
354 * e1000_release_hw_control - release control of the h/w to f/w
355 * @adapter: address of board private structure
357 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
358 * For ASF and Pass Through versions of f/w this means that the
359 * driver is no longer loaded. For AMT version (only with 82573) i
360 * of the f/w this means that the netowrk i/f is closed.
365 e1000_release_hw_control(struct e1000_adapter *adapter)
370 /* Let firmware taken over control of h/w */
371 switch (adapter->hw.mac_type) {
374 case e1000_80003es2lan:
375 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
376 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
377 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
380 swsm = E1000_READ_REG(&adapter->hw, SWSM);
381 E1000_WRITE_REG(&adapter->hw, SWSM,
382 swsm & ~E1000_SWSM_DRV_LOAD);
389 * e1000_get_hw_control - get control of the h/w from f/w
390 * @adapter: address of board private structure
392 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
393 * For ASF and Pass Through versions of f/w this means that
394 * the driver is loaded. For AMT version (only with 82573)
395 * of the f/w this means that the netowrk i/f is open.
400 e1000_get_hw_control(struct e1000_adapter *adapter)
404 /* Let firmware know the driver has taken over */
405 switch (adapter->hw.mac_type) {
408 case e1000_80003es2lan:
409 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
410 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
411 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
414 swsm = E1000_READ_REG(&adapter->hw, SWSM);
415 E1000_WRITE_REG(&adapter->hw, SWSM,
416 swsm | E1000_SWSM_DRV_LOAD);
424 e1000_up(struct e1000_adapter *adapter)
426 struct net_device *netdev = adapter->netdev;
429 /* hardware has been reset, we need to reload some things */
431 e1000_set_multi(netdev);
433 e1000_restore_vlan(adapter);
435 e1000_configure_tx(adapter);
436 e1000_setup_rctl(adapter);
437 e1000_configure_rx(adapter);
438 /* call E1000_DESC_UNUSED which always leaves
439 * at least 1 descriptor unused to make sure
440 * next_to_use != next_to_clean */
441 for (i = 0; i < adapter->num_rx_queues; i++) {
442 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
443 adapter->alloc_rx_buf(adapter, ring,
444 E1000_DESC_UNUSED(ring));
447 adapter->tx_queue_len = netdev->tx_queue_len;
449 mod_timer(&adapter->watchdog_timer, jiffies);
451 #ifdef CONFIG_E1000_NAPI
452 netif_poll_enable(netdev);
454 e1000_irq_enable(adapter);
460 * e1000_power_up_phy - restore link in case the phy was powered down
461 * @adapter: address of board private structure
463 * The phy may be powered down to save power and turn off link when the
464 * driver is unloaded and wake on lan is not enabled (among others)
465 * *** this routine MUST be followed by a call to e1000_reset ***
469 static void e1000_power_up_phy(struct e1000_adapter *adapter)
471 uint16_t mii_reg = 0;
473 /* Just clear the power down bit to wake the phy back up */
474 if (adapter->hw.media_type == e1000_media_type_copper) {
475 /* according to the manual, the phy will retain its
476 * settings across a power-down/up cycle */
477 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
478 mii_reg &= ~MII_CR_POWER_DOWN;
479 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
483 static void e1000_power_down_phy(struct e1000_adapter *adapter)
485 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
486 e1000_check_mng_mode(&adapter->hw);
487 /* Power down the PHY so no link is implied when interface is down
488 * The PHY cannot be powered down if any of the following is TRUE
491 * (c) SoL/IDER session is active */
492 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
493 adapter->hw.media_type == e1000_media_type_copper &&
494 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
496 !e1000_check_phy_reset_block(&adapter->hw)) {
497 uint16_t mii_reg = 0;
498 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
499 mii_reg |= MII_CR_POWER_DOWN;
500 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
506 e1000_down(struct e1000_adapter *adapter)
508 struct net_device *netdev = adapter->netdev;
510 e1000_irq_disable(adapter);
512 del_timer_sync(&adapter->tx_fifo_stall_timer);
513 del_timer_sync(&adapter->watchdog_timer);
514 del_timer_sync(&adapter->phy_info_timer);
516 #ifdef CONFIG_E1000_NAPI
517 netif_poll_disable(netdev);
519 netdev->tx_queue_len = adapter->tx_queue_len;
520 adapter->link_speed = 0;
521 adapter->link_duplex = 0;
522 netif_carrier_off(netdev);
523 netif_stop_queue(netdev);
525 e1000_reset(adapter);
526 e1000_clean_all_tx_rings(adapter);
527 e1000_clean_all_rx_rings(adapter);
531 e1000_reinit_locked(struct e1000_adapter *adapter)
533 WARN_ON(in_interrupt());
534 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
538 clear_bit(__E1000_RESETTING, &adapter->flags);
542 e1000_reset(struct e1000_adapter *adapter)
545 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
547 /* Repartition Pba for greater than 9k mtu
548 * To take effect CTRL.RST is required.
551 switch (adapter->hw.mac_type) {
553 case e1000_82547_rev_2:
558 case e1000_80003es2lan:
569 if ((adapter->hw.mac_type != e1000_82573) &&
570 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
571 pba -= 8; /* allocate more FIFO for Tx */
574 if (adapter->hw.mac_type == e1000_82547) {
575 adapter->tx_fifo_head = 0;
576 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
577 adapter->tx_fifo_size =
578 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
579 atomic_set(&adapter->tx_fifo_stall, 0);
582 E1000_WRITE_REG(&adapter->hw, PBA, pba);
584 /* flow control settings */
585 /* Set the FC high water mark to 90% of the FIFO size.
586 * Required to clear last 3 LSB */
587 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
589 adapter->hw.fc_high_water = fc_high_water_mark;
590 adapter->hw.fc_low_water = fc_high_water_mark - 8;
591 if (adapter->hw.mac_type == e1000_80003es2lan)
592 adapter->hw.fc_pause_time = 0xFFFF;
594 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
595 adapter->hw.fc_send_xon = 1;
596 adapter->hw.fc = adapter->hw.original_fc;
598 /* Allow time for pending master requests to run */
599 e1000_reset_hw(&adapter->hw);
600 if (adapter->hw.mac_type >= e1000_82544)
601 E1000_WRITE_REG(&adapter->hw, WUC, 0);
602 if (e1000_init_hw(&adapter->hw))
603 DPRINTK(PROBE, ERR, "Hardware Error\n");
604 e1000_update_mng_vlan(adapter);
605 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
606 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
608 e1000_reset_adaptive(&adapter->hw);
609 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
611 if (!adapter->smart_power_down &&
612 (adapter->hw.mac_type == e1000_82571 ||
613 adapter->hw.mac_type == e1000_82572)) {
614 uint16_t phy_data = 0;
615 /* speed up time to link by disabling smart power down, ignore
616 * the return value of this function because there is nothing
617 * different we would do if it failed */
618 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
620 phy_data &= ~IGP02E1000_PM_SPD;
621 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
625 if (adapter->en_mng_pt) {
626 manc = E1000_READ_REG(&adapter->hw, MANC);
627 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
628 E1000_WRITE_REG(&adapter->hw, MANC, manc);
633 * e1000_probe - Device Initialization Routine
634 * @pdev: PCI device information struct
635 * @ent: entry in e1000_pci_tbl
637 * Returns 0 on success, negative on failure
639 * e1000_probe initializes an adapter identified by a pci_dev structure.
640 * The OS initialization, configuring of the adapter private structure,
641 * and a hardware reset occur.
645 e1000_probe(struct pci_dev *pdev,
646 const struct pci_device_id *ent)
648 struct net_device *netdev;
649 struct e1000_adapter *adapter;
650 unsigned long mmio_start, mmio_len;
652 static int cards_found = 0;
653 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
654 int i, err, pci_using_dac;
655 uint16_t eeprom_data;
656 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
657 if ((err = pci_enable_device(pdev)))
660 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
663 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
664 E1000_ERR("No usable DMA configuration, aborting\n");
670 if ((err = pci_request_regions(pdev, e1000_driver_name)))
673 pci_set_master(pdev);
675 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
678 goto err_alloc_etherdev;
681 SET_MODULE_OWNER(netdev);
682 SET_NETDEV_DEV(netdev, &pdev->dev);
684 pci_set_drvdata(pdev, netdev);
685 adapter = netdev_priv(netdev);
686 adapter->netdev = netdev;
687 adapter->pdev = pdev;
688 adapter->hw.back = adapter;
689 adapter->msg_enable = (1 << debug) - 1;
691 mmio_start = pci_resource_start(pdev, BAR_0);
692 mmio_len = pci_resource_len(pdev, BAR_0);
694 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
695 if (!adapter->hw.hw_addr) {
700 for (i = BAR_1; i <= BAR_5; i++) {
701 if (pci_resource_len(pdev, i) == 0)
703 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
704 adapter->hw.io_base = pci_resource_start(pdev, i);
709 netdev->open = &e1000_open;
710 netdev->stop = &e1000_close;
711 netdev->hard_start_xmit = &e1000_xmit_frame;
712 netdev->get_stats = &e1000_get_stats;
713 netdev->set_multicast_list = &e1000_set_multi;
714 netdev->set_mac_address = &e1000_set_mac;
715 netdev->change_mtu = &e1000_change_mtu;
716 netdev->do_ioctl = &e1000_ioctl;
717 e1000_set_ethtool_ops(netdev);
718 netdev->tx_timeout = &e1000_tx_timeout;
719 netdev->watchdog_timeo = 5 * HZ;
720 #ifdef CONFIG_E1000_NAPI
721 netdev->poll = &e1000_clean;
724 netdev->vlan_rx_register = e1000_vlan_rx_register;
725 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
726 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
727 #ifdef CONFIG_NET_POLL_CONTROLLER
728 netdev->poll_controller = e1000_netpoll;
730 strcpy(netdev->name, pci_name(pdev));
732 netdev->mem_start = mmio_start;
733 netdev->mem_end = mmio_start + mmio_len;
734 netdev->base_addr = adapter->hw.io_base;
736 adapter->bd_number = cards_found;
738 /* setup the private structure */
740 if ((err = e1000_sw_init(adapter)))
743 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
744 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
746 /* if ksp3, indicate if it's port a being setup */
747 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
748 e1000_ksp3_port_a == 0)
749 adapter->ksp3_port_a = 1;
751 /* Reset for multiple KP3 adapters */
752 if (e1000_ksp3_port_a == 4)
753 e1000_ksp3_port_a = 0;
755 if (adapter->hw.mac_type >= e1000_82543) {
756 netdev->features = NETIF_F_SG |
760 NETIF_F_HW_VLAN_FILTER;
764 if ((adapter->hw.mac_type >= e1000_82544) &&
765 (adapter->hw.mac_type != e1000_82547))
766 netdev->features |= NETIF_F_TSO;
768 #ifdef NETIF_F_TSO_IPV6
769 if (adapter->hw.mac_type > e1000_82547_rev_2)
770 netdev->features |= NETIF_F_TSO_IPV6;
774 netdev->features |= NETIF_F_HIGHDMA;
776 /* hard_start_xmit is safe against parallel locking */
777 netdev->features |= NETIF_F_LLTX;
779 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
781 /* before reading the EEPROM, reset the controller to
782 * put the device in a known good starting state */
784 e1000_reset_hw(&adapter->hw);
786 /* make sure the EEPROM is good */
788 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
789 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
794 /* copy the MAC address out of the EEPROM */
796 if (e1000_read_mac_addr(&adapter->hw))
797 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
798 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
799 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
801 if (!is_valid_ether_addr(netdev->perm_addr)) {
802 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
807 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
809 e1000_get_bus_info(&adapter->hw);
811 init_timer(&adapter->tx_fifo_stall_timer);
812 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
813 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
815 init_timer(&adapter->watchdog_timer);
816 adapter->watchdog_timer.function = &e1000_watchdog;
817 adapter->watchdog_timer.data = (unsigned long) adapter;
819 init_timer(&adapter->phy_info_timer);
820 adapter->phy_info_timer.function = &e1000_update_phy_info;
821 adapter->phy_info_timer.data = (unsigned long) adapter;
823 INIT_WORK(&adapter->reset_task,
824 (void (*)(void *))e1000_reset_task, netdev);
826 /* we're going to reset, so assume we have no link for now */
828 netif_carrier_off(netdev);
829 netif_stop_queue(netdev);
831 e1000_check_options(adapter);
833 /* Initial Wake on LAN setting
834 * If APM wake is enabled in the EEPROM,
835 * enable the ACPI Magic Packet filter
838 switch (adapter->hw.mac_type) {
839 case e1000_82542_rev2_0:
840 case e1000_82542_rev2_1:
844 e1000_read_eeprom(&adapter->hw,
845 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
846 eeprom_apme_mask = E1000_EEPROM_82544_APM;
849 case e1000_82546_rev_3:
851 case e1000_80003es2lan:
852 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
853 e1000_read_eeprom(&adapter->hw,
854 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
859 e1000_read_eeprom(&adapter->hw,
860 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
863 if (eeprom_data & eeprom_apme_mask)
864 adapter->wol |= E1000_WUFC_MAG;
866 /* print bus type/speed/width info */
868 struct e1000_hw *hw = &adapter->hw;
869 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
870 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
871 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
872 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
873 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
874 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
875 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
876 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
877 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
878 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
879 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
883 for (i = 0; i < 6; i++)
884 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
886 /* reset the hardware with the new settings */
887 e1000_reset(adapter);
889 /* If the controller is 82573 and f/w is AMT, do not set
890 * DRV_LOAD until the interface is up. For all other cases,
891 * let the f/w know that the h/w is now under the control
893 if (adapter->hw.mac_type != e1000_82573 ||
894 !e1000_check_mng_mode(&adapter->hw))
895 e1000_get_hw_control(adapter);
897 strcpy(netdev->name, "eth%d");
898 if ((err = register_netdev(netdev)))
901 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
909 iounmap(adapter->hw.hw_addr);
913 pci_release_regions(pdev);
918 * e1000_remove - Device Removal Routine
919 * @pdev: PCI device information struct
921 * e1000_remove is called by the PCI subsystem to alert the driver
922 * that it should release a PCI device. The could be caused by a
923 * Hot-Plug event, or because the driver is going to be removed from
927 static void __devexit
928 e1000_remove(struct pci_dev *pdev)
930 struct net_device *netdev = pci_get_drvdata(pdev);
931 struct e1000_adapter *adapter = netdev_priv(netdev);
933 #ifdef CONFIG_E1000_NAPI
937 flush_scheduled_work();
939 if (adapter->hw.mac_type >= e1000_82540 &&
940 adapter->hw.media_type == e1000_media_type_copper) {
941 manc = E1000_READ_REG(&adapter->hw, MANC);
942 if (manc & E1000_MANC_SMBUS_EN) {
943 manc |= E1000_MANC_ARP_EN;
944 E1000_WRITE_REG(&adapter->hw, MANC, manc);
948 /* Release control of h/w to f/w. If f/w is AMT enabled, this
949 * would have already happened in close and is redundant. */
950 e1000_release_hw_control(adapter);
952 unregister_netdev(netdev);
953 #ifdef CONFIG_E1000_NAPI
954 for (i = 0; i < adapter->num_rx_queues; i++)
955 dev_put(&adapter->polling_netdev[i]);
958 if (!e1000_check_phy_reset_block(&adapter->hw))
959 e1000_phy_hw_reset(&adapter->hw);
961 kfree(adapter->tx_ring);
962 kfree(adapter->rx_ring);
963 #ifdef CONFIG_E1000_NAPI
964 kfree(adapter->polling_netdev);
967 iounmap(adapter->hw.hw_addr);
968 pci_release_regions(pdev);
972 pci_disable_device(pdev);
976 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
977 * @adapter: board private structure to initialize
979 * e1000_sw_init initializes the Adapter private data structure.
980 * Fields are initialized based on PCI device information and
981 * OS network device settings (MTU size).
985 e1000_sw_init(struct e1000_adapter *adapter)
987 struct e1000_hw *hw = &adapter->hw;
988 struct net_device *netdev = adapter->netdev;
989 struct pci_dev *pdev = adapter->pdev;
990 #ifdef CONFIG_E1000_NAPI
994 /* PCI config space info */
996 hw->vendor_id = pdev->vendor;
997 hw->device_id = pdev->device;
998 hw->subsystem_vendor_id = pdev->subsystem_vendor;
999 hw->subsystem_id = pdev->subsystem_device;
1001 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1003 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1005 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE;
1006 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
1007 hw->max_frame_size = netdev->mtu +
1008 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1009 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1011 /* identify the MAC */
1013 if (e1000_set_mac_type(hw)) {
1014 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1018 /* initialize eeprom parameters */
1020 if (e1000_init_eeprom_params(hw)) {
1021 E1000_ERR("EEPROM initialization failed\n");
1025 switch (hw->mac_type) {
1030 case e1000_82541_rev_2:
1031 case e1000_82547_rev_2:
1032 hw->phy_init_script = 1;
1036 e1000_set_media_type(hw);
1038 hw->wait_autoneg_complete = FALSE;
1039 hw->tbi_compatibility_en = TRUE;
1040 hw->adaptive_ifs = TRUE;
1042 /* Copper options */
1044 if (hw->media_type == e1000_media_type_copper) {
1045 hw->mdix = AUTO_ALL_MODES;
1046 hw->disable_polarity_correction = FALSE;
1047 hw->master_slave = E1000_MASTER_SLAVE;
1050 adapter->num_tx_queues = 1;
1051 adapter->num_rx_queues = 1;
1053 if (e1000_alloc_queues(adapter)) {
1054 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1058 #ifdef CONFIG_E1000_NAPI
1059 for (i = 0; i < adapter->num_rx_queues; i++) {
1060 adapter->polling_netdev[i].priv = adapter;
1061 adapter->polling_netdev[i].poll = &e1000_clean;
1062 adapter->polling_netdev[i].weight = 64;
1063 dev_hold(&adapter->polling_netdev[i]);
1064 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1066 spin_lock_init(&adapter->tx_queue_lock);
1069 atomic_set(&adapter->irq_sem, 1);
1070 spin_lock_init(&adapter->stats_lock);
1076 * e1000_alloc_queues - Allocate memory for all rings
1077 * @adapter: board private structure to initialize
1079 * We allocate one ring per queue at run-time since we don't know the
1080 * number of queues at compile-time. The polling_netdev array is
1081 * intended for Multiqueue, but should work fine with a single queue.
1084 static int __devinit
1085 e1000_alloc_queues(struct e1000_adapter *adapter)
1089 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1090 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1091 if (!adapter->tx_ring)
1093 memset(adapter->tx_ring, 0, size);
1095 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1096 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1097 if (!adapter->rx_ring) {
1098 kfree(adapter->tx_ring);
1101 memset(adapter->rx_ring, 0, size);
1103 #ifdef CONFIG_E1000_NAPI
1104 size = sizeof(struct net_device) * adapter->num_rx_queues;
1105 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1106 if (!adapter->polling_netdev) {
1107 kfree(adapter->tx_ring);
1108 kfree(adapter->rx_ring);
1111 memset(adapter->polling_netdev, 0, size);
1114 return E1000_SUCCESS;
1118 * e1000_open - Called when a network interface is made active
1119 * @netdev: network interface device structure
1121 * Returns 0 on success, negative value on failure
1123 * The open entry point is called when a network interface is made
1124 * active by the system (IFF_UP). At this point all resources needed
1125 * for transmit and receive operations are allocated, the interrupt
1126 * handler is registered with the OS, the watchdog timer is started,
1127 * and the stack is notified that the interface is ready.
1131 e1000_open(struct net_device *netdev)
1133 struct e1000_adapter *adapter = netdev_priv(netdev);
1136 /* disallow open during test */
1137 if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
1140 /* allocate transmit descriptors */
1142 if ((err = e1000_setup_all_tx_resources(adapter)))
1145 /* allocate receive descriptors */
1147 if ((err = e1000_setup_all_rx_resources(adapter)))
1150 err = e1000_request_irq(adapter);
1154 e1000_power_up_phy(adapter);
1156 if ((err = e1000_up(adapter)))
1158 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1159 if ((adapter->hw.mng_cookie.status &
1160 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1161 e1000_update_mng_vlan(adapter);
1164 /* If AMT is enabled, let the firmware know that the network
1165 * interface is now open */
1166 if (adapter->hw.mac_type == e1000_82573 &&
1167 e1000_check_mng_mode(&adapter->hw))
1168 e1000_get_hw_control(adapter);
1170 return E1000_SUCCESS;
1173 e1000_free_all_rx_resources(adapter);
1175 e1000_free_all_tx_resources(adapter);
1177 e1000_reset(adapter);
1183 * e1000_close - Disables a network interface
1184 * @netdev: network interface device structure
1186 * Returns 0, this is not allowed to fail
1188 * The close entry point is called when an interface is de-activated
1189 * by the OS. The hardware is still under the drivers control, but
1190 * needs to be disabled. A global MAC reset is issued to stop the
1191 * hardware, and all transmit and receive resources are freed.
1195 e1000_close(struct net_device *netdev)
1197 struct e1000_adapter *adapter = netdev_priv(netdev);
1199 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1200 e1000_down(adapter);
1201 e1000_power_down_phy(adapter);
1202 e1000_free_irq(adapter);
1204 e1000_free_all_tx_resources(adapter);
1205 e1000_free_all_rx_resources(adapter);
1207 if ((adapter->hw.mng_cookie.status &
1208 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1209 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1212 /* If AMT is enabled, let the firmware know that the network
1213 * interface is now closed */
1214 if (adapter->hw.mac_type == e1000_82573 &&
1215 e1000_check_mng_mode(&adapter->hw))
1216 e1000_release_hw_control(adapter);
1222 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1223 * @adapter: address of board private structure
1224 * @start: address of beginning of memory
1225 * @len: length of memory
1228 e1000_check_64k_bound(struct e1000_adapter *adapter,
1229 void *start, unsigned long len)
1231 unsigned long begin = (unsigned long) start;
1232 unsigned long end = begin + len;
1234 /* First rev 82545 and 82546 need to not allow any memory
1235 * write location to cross 64k boundary due to errata 23 */
1236 if (adapter->hw.mac_type == e1000_82545 ||
1237 adapter->hw.mac_type == e1000_82546) {
1238 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1245 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1246 * @adapter: board private structure
1247 * @txdr: tx descriptor ring (for a specific queue) to setup
1249 * Return 0 on success, negative on failure
1253 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1254 struct e1000_tx_ring *txdr)
1256 struct pci_dev *pdev = adapter->pdev;
1259 size = sizeof(struct e1000_buffer) * txdr->count;
1261 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1262 if (!txdr->buffer_info) {
1264 "Unable to allocate memory for the transmit descriptor ring\n");
1267 memset(txdr->buffer_info, 0, size);
1269 /* round up to nearest 4K */
1271 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1272 E1000_ROUNDUP(txdr->size, 4096);
1274 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1277 vfree(txdr->buffer_info);
1279 "Unable to allocate memory for the transmit descriptor ring\n");
1283 /* Fix for errata 23, can't cross 64kB boundary */
1284 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1285 void *olddesc = txdr->desc;
1286 dma_addr_t olddma = txdr->dma;
1287 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1288 "at %p\n", txdr->size, txdr->desc);
1289 /* Try again, without freeing the previous */
1290 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1291 /* Failed allocation, critical failure */
1293 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1294 goto setup_tx_desc_die;
1297 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1299 pci_free_consistent(pdev, txdr->size, txdr->desc,
1301 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1303 "Unable to allocate aligned memory "
1304 "for the transmit descriptor ring\n");
1305 vfree(txdr->buffer_info);
1308 /* Free old allocation, new allocation was successful */
1309 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1312 memset(txdr->desc, 0, txdr->size);
1314 txdr->next_to_use = 0;
1315 txdr->next_to_clean = 0;
1316 spin_lock_init(&txdr->tx_lock);
1322 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1323 * (Descriptors) for all queues
1324 * @adapter: board private structure
1326 * If this function returns with an error, then it's possible one or
1327 * more of the rings is populated (while the rest are not). It is the
1328 * callers duty to clean those orphaned rings.
1330 * Return 0 on success, negative on failure
1334 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1338 for (i = 0; i < adapter->num_tx_queues; i++) {
1339 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1342 "Allocation for Tx Queue %u failed\n", i);
1351 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1352 * @adapter: board private structure
1354 * Configure the Tx unit of the MAC after a reset.
1358 e1000_configure_tx(struct e1000_adapter *adapter)
1361 struct e1000_hw *hw = &adapter->hw;
1362 uint32_t tdlen, tctl, tipg, tarc;
1363 uint32_t ipgr1, ipgr2;
1365 /* Setup the HW Tx Head and Tail descriptor pointers */
1367 switch (adapter->num_tx_queues) {
1370 tdba = adapter->tx_ring[0].dma;
1371 tdlen = adapter->tx_ring[0].count *
1372 sizeof(struct e1000_tx_desc);
1373 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1374 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1375 E1000_WRITE_REG(hw, TDLEN, tdlen);
1376 E1000_WRITE_REG(hw, TDH, 0);
1377 E1000_WRITE_REG(hw, TDT, 0);
1378 adapter->tx_ring[0].tdh = E1000_TDH;
1379 adapter->tx_ring[0].tdt = E1000_TDT;
1383 /* Set the default values for the Tx Inter Packet Gap timer */
1385 if (hw->media_type == e1000_media_type_fiber ||
1386 hw->media_type == e1000_media_type_internal_serdes)
1387 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1389 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1391 switch (hw->mac_type) {
1392 case e1000_82542_rev2_0:
1393 case e1000_82542_rev2_1:
1394 tipg = DEFAULT_82542_TIPG_IPGT;
1395 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1396 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1398 case e1000_80003es2lan:
1399 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1400 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1403 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1404 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1407 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1408 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1409 E1000_WRITE_REG(hw, TIPG, tipg);
1411 /* Set the Tx Interrupt Delay register */
1413 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1414 if (hw->mac_type >= e1000_82540)
1415 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1417 /* Program the Transmit Control Register */
1419 tctl = E1000_READ_REG(hw, TCTL);
1421 tctl &= ~E1000_TCTL_CT;
1422 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1423 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1426 /* disable Multiple Reads for debugging */
1427 tctl &= ~E1000_TCTL_MULR;
1430 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1431 tarc = E1000_READ_REG(hw, TARC0);
1432 tarc |= ((1 << 25) | (1 << 21));
1433 E1000_WRITE_REG(hw, TARC0, tarc);
1434 tarc = E1000_READ_REG(hw, TARC1);
1436 if (tctl & E1000_TCTL_MULR)
1440 E1000_WRITE_REG(hw, TARC1, tarc);
1441 } else if (hw->mac_type == e1000_80003es2lan) {
1442 tarc = E1000_READ_REG(hw, TARC0);
1444 if (hw->media_type == e1000_media_type_internal_serdes)
1446 E1000_WRITE_REG(hw, TARC0, tarc);
1447 tarc = E1000_READ_REG(hw, TARC1);
1449 E1000_WRITE_REG(hw, TARC1, tarc);
1452 e1000_config_collision_dist(hw);
1454 /* Setup Transmit Descriptor Settings for eop descriptor */
1455 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1458 if (hw->mac_type < e1000_82543)
1459 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1461 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1463 /* Cache if we're 82544 running in PCI-X because we'll
1464 * need this to apply a workaround later in the send path. */
1465 if (hw->mac_type == e1000_82544 &&
1466 hw->bus_type == e1000_bus_type_pcix)
1467 adapter->pcix_82544 = 1;
1469 E1000_WRITE_REG(hw, TCTL, tctl);
1474 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1475 * @adapter: board private structure
1476 * @rxdr: rx descriptor ring (for a specific queue) to setup
1478 * Returns 0 on success, negative on failure
1482 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1483 struct e1000_rx_ring *rxdr)
1485 struct pci_dev *pdev = adapter->pdev;
1488 size = sizeof(struct e1000_buffer) * rxdr->count;
1489 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1490 if (!rxdr->buffer_info) {
1492 "Unable to allocate memory for the receive descriptor ring\n");
1495 memset(rxdr->buffer_info, 0, size);
1497 size = sizeof(struct e1000_ps_page) * rxdr->count;
1498 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1499 if (!rxdr->ps_page) {
1500 vfree(rxdr->buffer_info);
1502 "Unable to allocate memory for the receive descriptor ring\n");
1505 memset(rxdr->ps_page, 0, size);
1507 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1508 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1509 if (!rxdr->ps_page_dma) {
1510 vfree(rxdr->buffer_info);
1511 kfree(rxdr->ps_page);
1513 "Unable to allocate memory for the receive descriptor ring\n");
1516 memset(rxdr->ps_page_dma, 0, size);
1518 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1519 desc_len = sizeof(struct e1000_rx_desc);
1521 desc_len = sizeof(union e1000_rx_desc_packet_split);
1523 /* Round up to nearest 4K */
1525 rxdr->size = rxdr->count * desc_len;
1526 E1000_ROUNDUP(rxdr->size, 4096);
1528 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1532 "Unable to allocate memory for the receive descriptor ring\n");
1534 vfree(rxdr->buffer_info);
1535 kfree(rxdr->ps_page);
1536 kfree(rxdr->ps_page_dma);
1540 /* Fix for errata 23, can't cross 64kB boundary */
1541 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1542 void *olddesc = rxdr->desc;
1543 dma_addr_t olddma = rxdr->dma;
1544 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1545 "at %p\n", rxdr->size, rxdr->desc);
1546 /* Try again, without freeing the previous */
1547 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1548 /* Failed allocation, critical failure */
1550 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1552 "Unable to allocate memory "
1553 "for the receive descriptor ring\n");
1554 goto setup_rx_desc_die;
1557 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1559 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1561 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1563 "Unable to allocate aligned memory "
1564 "for the receive descriptor ring\n");
1565 goto setup_rx_desc_die;
1567 /* Free old allocation, new allocation was successful */
1568 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1571 memset(rxdr->desc, 0, rxdr->size);
1573 rxdr->next_to_clean = 0;
1574 rxdr->next_to_use = 0;
1580 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1581 * (Descriptors) for all queues
1582 * @adapter: board private structure
1584 * If this function returns with an error, then it's possible one or
1585 * more of the rings is populated (while the rest are not). It is the
1586 * callers duty to clean those orphaned rings.
1588 * Return 0 on success, negative on failure
1592 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1596 for (i = 0; i < adapter->num_rx_queues; i++) {
1597 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1600 "Allocation for Rx Queue %u failed\n", i);
1609 * e1000_setup_rctl - configure the receive control registers
1610 * @adapter: Board private structure
1612 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1613 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1615 e1000_setup_rctl(struct e1000_adapter *adapter)
1617 uint32_t rctl, rfctl;
1618 uint32_t psrctl = 0;
1619 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1623 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1625 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1627 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1628 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1629 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1631 if (adapter->hw.mac_type > e1000_82543)
1632 rctl |= E1000_RCTL_SECRC;
1634 if (adapter->hw.tbi_compatibility_on == 1)
1635 rctl |= E1000_RCTL_SBP;
1637 rctl &= ~E1000_RCTL_SBP;
1639 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1640 rctl &= ~E1000_RCTL_LPE;
1642 rctl |= E1000_RCTL_LPE;
1644 /* Setup buffer sizes */
1645 rctl &= ~E1000_RCTL_SZ_4096;
1646 rctl |= E1000_RCTL_BSEX;
1647 switch (adapter->rx_buffer_len) {
1648 case E1000_RXBUFFER_256:
1649 rctl |= E1000_RCTL_SZ_256;
1650 rctl &= ~E1000_RCTL_BSEX;
1652 case E1000_RXBUFFER_512:
1653 rctl |= E1000_RCTL_SZ_512;
1654 rctl &= ~E1000_RCTL_BSEX;
1656 case E1000_RXBUFFER_1024:
1657 rctl |= E1000_RCTL_SZ_1024;
1658 rctl &= ~E1000_RCTL_BSEX;
1660 case E1000_RXBUFFER_2048:
1662 rctl |= E1000_RCTL_SZ_2048;
1663 rctl &= ~E1000_RCTL_BSEX;
1665 case E1000_RXBUFFER_4096:
1666 rctl |= E1000_RCTL_SZ_4096;
1668 case E1000_RXBUFFER_8192:
1669 rctl |= E1000_RCTL_SZ_8192;
1671 case E1000_RXBUFFER_16384:
1672 rctl |= E1000_RCTL_SZ_16384;
1676 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1677 /* 82571 and greater support packet-split where the protocol
1678 * header is placed in skb->data and the packet data is
1679 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1680 * In the case of a non-split, skb->data is linearly filled,
1681 * followed by the page buffers. Therefore, skb->data is
1682 * sized to hold the largest protocol header.
1684 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1685 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1687 adapter->rx_ps_pages = pages;
1689 adapter->rx_ps_pages = 0;
1691 if (adapter->rx_ps_pages) {
1692 /* Configure extra packet-split registers */
1693 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1694 rfctl |= E1000_RFCTL_EXTEN;
1695 /* disable IPv6 packet split support */
1696 rfctl |= E1000_RFCTL_IPV6_DIS;
1697 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1699 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1701 psrctl |= adapter->rx_ps_bsize0 >>
1702 E1000_PSRCTL_BSIZE0_SHIFT;
1704 switch (adapter->rx_ps_pages) {
1706 psrctl |= PAGE_SIZE <<
1707 E1000_PSRCTL_BSIZE3_SHIFT;
1709 psrctl |= PAGE_SIZE <<
1710 E1000_PSRCTL_BSIZE2_SHIFT;
1712 psrctl |= PAGE_SIZE >>
1713 E1000_PSRCTL_BSIZE1_SHIFT;
1717 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1720 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1724 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1725 * @adapter: board private structure
1727 * Configure the Rx unit of the MAC after a reset.
1731 e1000_configure_rx(struct e1000_adapter *adapter)
1734 struct e1000_hw *hw = &adapter->hw;
1735 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1737 if (adapter->rx_ps_pages) {
1738 /* this is a 32 byte descriptor */
1739 rdlen = adapter->rx_ring[0].count *
1740 sizeof(union e1000_rx_desc_packet_split);
1741 adapter->clean_rx = e1000_clean_rx_irq_ps;
1742 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1744 rdlen = adapter->rx_ring[0].count *
1745 sizeof(struct e1000_rx_desc);
1746 adapter->clean_rx = e1000_clean_rx_irq;
1747 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1750 /* disable receives while setting up the descriptors */
1751 rctl = E1000_READ_REG(hw, RCTL);
1752 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1754 /* set the Receive Delay Timer Register */
1755 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1757 if (hw->mac_type >= e1000_82540) {
1758 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1759 if (adapter->itr > 1)
1760 E1000_WRITE_REG(hw, ITR,
1761 1000000000 / (adapter->itr * 256));
1764 if (hw->mac_type >= e1000_82571) {
1765 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1766 /* Reset delay timers after every interrupt */
1767 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
1768 #ifdef CONFIG_E1000_NAPI
1769 /* Auto-Mask interrupts upon ICR read. */
1770 ctrl_ext |= E1000_CTRL_EXT_IAME;
1772 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1773 E1000_WRITE_REG(hw, IAM, ~0);
1774 E1000_WRITE_FLUSH(hw);
1777 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1778 * the Base and Length of the Rx Descriptor Ring */
1779 switch (adapter->num_rx_queues) {
1782 rdba = adapter->rx_ring[0].dma;
1783 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1784 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1785 E1000_WRITE_REG(hw, RDLEN, rdlen);
1786 E1000_WRITE_REG(hw, RDH, 0);
1787 E1000_WRITE_REG(hw, RDT, 0);
1788 adapter->rx_ring[0].rdh = E1000_RDH;
1789 adapter->rx_ring[0].rdt = E1000_RDT;
1793 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1794 if (hw->mac_type >= e1000_82543) {
1795 rxcsum = E1000_READ_REG(hw, RXCSUM);
1796 if (adapter->rx_csum == TRUE) {
1797 rxcsum |= E1000_RXCSUM_TUOFL;
1799 /* Enable 82571 IPv4 payload checksum for UDP fragments
1800 * Must be used in conjunction with packet-split. */
1801 if ((hw->mac_type >= e1000_82571) &&
1802 (adapter->rx_ps_pages)) {
1803 rxcsum |= E1000_RXCSUM_IPPCSE;
1806 rxcsum &= ~E1000_RXCSUM_TUOFL;
1807 /* don't need to clear IPPCSE as it defaults to 0 */
1809 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1812 if (hw->mac_type == e1000_82573)
1813 E1000_WRITE_REG(hw, ERT, 0x0100);
1815 /* Enable Receives */
1816 E1000_WRITE_REG(hw, RCTL, rctl);
1820 * e1000_free_tx_resources - Free Tx Resources per Queue
1821 * @adapter: board private structure
1822 * @tx_ring: Tx descriptor ring for a specific queue
1824 * Free all transmit software resources
1828 e1000_free_tx_resources(struct e1000_adapter *adapter,
1829 struct e1000_tx_ring *tx_ring)
1831 struct pci_dev *pdev = adapter->pdev;
1833 e1000_clean_tx_ring(adapter, tx_ring);
1835 vfree(tx_ring->buffer_info);
1836 tx_ring->buffer_info = NULL;
1838 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1840 tx_ring->desc = NULL;
1844 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1845 * @adapter: board private structure
1847 * Free all transmit software resources
1851 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1855 for (i = 0; i < adapter->num_tx_queues; i++)
1856 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1860 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1861 struct e1000_buffer *buffer_info)
1863 if (buffer_info->dma) {
1864 pci_unmap_page(adapter->pdev,
1866 buffer_info->length,
1869 if (buffer_info->skb)
1870 dev_kfree_skb_any(buffer_info->skb);
1871 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1875 * e1000_clean_tx_ring - Free Tx Buffers
1876 * @adapter: board private structure
1877 * @tx_ring: ring to be cleaned
1881 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1882 struct e1000_tx_ring *tx_ring)
1884 struct e1000_buffer *buffer_info;
1888 /* Free all the Tx ring sk_buffs */
1890 for (i = 0; i < tx_ring->count; i++) {
1891 buffer_info = &tx_ring->buffer_info[i];
1892 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1895 size = sizeof(struct e1000_buffer) * tx_ring->count;
1896 memset(tx_ring->buffer_info, 0, size);
1898 /* Zero out the descriptor ring */
1900 memset(tx_ring->desc, 0, tx_ring->size);
1902 tx_ring->next_to_use = 0;
1903 tx_ring->next_to_clean = 0;
1904 tx_ring->last_tx_tso = 0;
1906 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1907 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1911 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1912 * @adapter: board private structure
1916 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1920 for (i = 0; i < adapter->num_tx_queues; i++)
1921 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1925 * e1000_free_rx_resources - Free Rx Resources
1926 * @adapter: board private structure
1927 * @rx_ring: ring to clean the resources from
1929 * Free all receive software resources
1933 e1000_free_rx_resources(struct e1000_adapter *adapter,
1934 struct e1000_rx_ring *rx_ring)
1936 struct pci_dev *pdev = adapter->pdev;
1938 e1000_clean_rx_ring(adapter, rx_ring);
1940 vfree(rx_ring->buffer_info);
1941 rx_ring->buffer_info = NULL;
1942 kfree(rx_ring->ps_page);
1943 rx_ring->ps_page = NULL;
1944 kfree(rx_ring->ps_page_dma);
1945 rx_ring->ps_page_dma = NULL;
1947 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1949 rx_ring->desc = NULL;
1953 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1954 * @adapter: board private structure
1956 * Free all receive software resources
1960 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1964 for (i = 0; i < adapter->num_rx_queues; i++)
1965 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1969 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1970 * @adapter: board private structure
1971 * @rx_ring: ring to free buffers from
1975 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1976 struct e1000_rx_ring *rx_ring)
1978 struct e1000_buffer *buffer_info;
1979 struct e1000_ps_page *ps_page;
1980 struct e1000_ps_page_dma *ps_page_dma;
1981 struct pci_dev *pdev = adapter->pdev;
1985 /* Free all the Rx ring sk_buffs */
1986 for (i = 0; i < rx_ring->count; i++) {
1987 buffer_info = &rx_ring->buffer_info[i];
1988 if (buffer_info->skb) {
1989 pci_unmap_single(pdev,
1991 buffer_info->length,
1992 PCI_DMA_FROMDEVICE);
1994 dev_kfree_skb(buffer_info->skb);
1995 buffer_info->skb = NULL;
1997 ps_page = &rx_ring->ps_page[i];
1998 ps_page_dma = &rx_ring->ps_page_dma[i];
1999 for (j = 0; j < adapter->rx_ps_pages; j++) {
2000 if (!ps_page->ps_page[j]) break;
2001 pci_unmap_page(pdev,
2002 ps_page_dma->ps_page_dma[j],
2003 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2004 ps_page_dma->ps_page_dma[j] = 0;
2005 put_page(ps_page->ps_page[j]);
2006 ps_page->ps_page[j] = NULL;
2010 size = sizeof(struct e1000_buffer) * rx_ring->count;
2011 memset(rx_ring->buffer_info, 0, size);
2012 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2013 memset(rx_ring->ps_page, 0, size);
2014 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2015 memset(rx_ring->ps_page_dma, 0, size);
2017 /* Zero out the descriptor ring */
2019 memset(rx_ring->desc, 0, rx_ring->size);
2021 rx_ring->next_to_clean = 0;
2022 rx_ring->next_to_use = 0;
2024 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2025 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2029 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2030 * @adapter: board private structure
2034 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2038 for (i = 0; i < adapter->num_rx_queues; i++)
2039 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2042 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2043 * and memory write and invalidate disabled for certain operations
2046 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2048 struct net_device *netdev = adapter->netdev;
2051 e1000_pci_clear_mwi(&adapter->hw);
2053 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2054 rctl |= E1000_RCTL_RST;
2055 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2056 E1000_WRITE_FLUSH(&adapter->hw);
2059 if (netif_running(netdev))
2060 e1000_clean_all_rx_rings(adapter);
2064 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2066 struct net_device *netdev = adapter->netdev;
2069 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2070 rctl &= ~E1000_RCTL_RST;
2071 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2072 E1000_WRITE_FLUSH(&adapter->hw);
2075 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2076 e1000_pci_set_mwi(&adapter->hw);
2078 if (netif_running(netdev)) {
2079 /* No need to loop, because 82542 supports only 1 queue */
2080 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2081 e1000_configure_rx(adapter);
2082 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2087 * e1000_set_mac - Change the Ethernet Address of the NIC
2088 * @netdev: network interface device structure
2089 * @p: pointer to an address structure
2091 * Returns 0 on success, negative on failure
2095 e1000_set_mac(struct net_device *netdev, void *p)
2097 struct e1000_adapter *adapter = netdev_priv(netdev);
2098 struct sockaddr *addr = p;
2100 if (!is_valid_ether_addr(addr->sa_data))
2101 return -EADDRNOTAVAIL;
2103 /* 82542 2.0 needs to be in reset to write receive address registers */
2105 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2106 e1000_enter_82542_rst(adapter);
2108 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2109 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2111 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2113 /* With 82571 controllers, LAA may be overwritten (with the default)
2114 * due to controller reset from the other port. */
2115 if (adapter->hw.mac_type == e1000_82571) {
2116 /* activate the work around */
2117 adapter->hw.laa_is_present = 1;
2119 /* Hold a copy of the LAA in RAR[14] This is done so that
2120 * between the time RAR[0] gets clobbered and the time it
2121 * gets fixed (in e1000_watchdog), the actual LAA is in one
2122 * of the RARs and no incoming packets directed to this port
2123 * are dropped. Eventaully the LAA will be in RAR[0] and
2125 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2126 E1000_RAR_ENTRIES - 1);
2129 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2130 e1000_leave_82542_rst(adapter);
2136 * e1000_set_multi - Multicast and Promiscuous mode set
2137 * @netdev: network interface device structure
2139 * The set_multi entry point is called whenever the multicast address
2140 * list or the network interface flags are updated. This routine is
2141 * responsible for configuring the hardware for proper multicast,
2142 * promiscuous mode, and all-multi behavior.
2146 e1000_set_multi(struct net_device *netdev)
2148 struct e1000_adapter *adapter = netdev_priv(netdev);
2149 struct e1000_hw *hw = &adapter->hw;
2150 struct dev_mc_list *mc_ptr;
2152 uint32_t hash_value;
2153 int i, rar_entries = E1000_RAR_ENTRIES;
2155 /* reserve RAR[14] for LAA over-write work-around */
2156 if (adapter->hw.mac_type == e1000_82571)
2159 /* Check for Promiscuous and All Multicast modes */
2161 rctl = E1000_READ_REG(hw, RCTL);
2163 if (netdev->flags & IFF_PROMISC) {
2164 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2165 } else if (netdev->flags & IFF_ALLMULTI) {
2166 rctl |= E1000_RCTL_MPE;
2167 rctl &= ~E1000_RCTL_UPE;
2169 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2172 E1000_WRITE_REG(hw, RCTL, rctl);
2174 /* 82542 2.0 needs to be in reset to write receive address registers */
2176 if (hw->mac_type == e1000_82542_rev2_0)
2177 e1000_enter_82542_rst(adapter);
2179 /* load the first 14 multicast address into the exact filters 1-14
2180 * RAR 0 is used for the station MAC adddress
2181 * if there are not 14 addresses, go ahead and clear the filters
2182 * -- with 82571 controllers only 0-13 entries are filled here
2184 mc_ptr = netdev->mc_list;
2186 for (i = 1; i < rar_entries; i++) {
2188 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2189 mc_ptr = mc_ptr->next;
2191 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2192 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2196 /* clear the old settings from the multicast hash table */
2198 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2199 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2201 /* load any remaining addresses into the hash table */
2203 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2204 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2205 e1000_mta_set(hw, hash_value);
2208 if (hw->mac_type == e1000_82542_rev2_0)
2209 e1000_leave_82542_rst(adapter);
2212 /* Need to wait a few seconds after link up to get diagnostic information from
2216 e1000_update_phy_info(unsigned long data)
2218 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2219 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2223 * e1000_82547_tx_fifo_stall - Timer Call-back
2224 * @data: pointer to adapter cast into an unsigned long
2228 e1000_82547_tx_fifo_stall(unsigned long data)
2230 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2231 struct net_device *netdev = adapter->netdev;
2234 if (atomic_read(&adapter->tx_fifo_stall)) {
2235 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2236 E1000_READ_REG(&adapter->hw, TDH)) &&
2237 (E1000_READ_REG(&adapter->hw, TDFT) ==
2238 E1000_READ_REG(&adapter->hw, TDFH)) &&
2239 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2240 E1000_READ_REG(&adapter->hw, TDFHS))) {
2241 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2242 E1000_WRITE_REG(&adapter->hw, TCTL,
2243 tctl & ~E1000_TCTL_EN);
2244 E1000_WRITE_REG(&adapter->hw, TDFT,
2245 adapter->tx_head_addr);
2246 E1000_WRITE_REG(&adapter->hw, TDFH,
2247 adapter->tx_head_addr);
2248 E1000_WRITE_REG(&adapter->hw, TDFTS,
2249 adapter->tx_head_addr);
2250 E1000_WRITE_REG(&adapter->hw, TDFHS,
2251 adapter->tx_head_addr);
2252 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2253 E1000_WRITE_FLUSH(&adapter->hw);
2255 adapter->tx_fifo_head = 0;
2256 atomic_set(&adapter->tx_fifo_stall, 0);
2257 netif_wake_queue(netdev);
2259 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2265 * e1000_watchdog - Timer Call-back
2266 * @data: pointer to adapter cast into an unsigned long
2269 e1000_watchdog(unsigned long data)
2271 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2272 struct net_device *netdev = adapter->netdev;
2273 struct e1000_tx_ring *txdr = adapter->tx_ring;
2274 uint32_t link, tctl;
2276 e1000_check_for_link(&adapter->hw);
2277 if (adapter->hw.mac_type == e1000_82573) {
2278 e1000_enable_tx_pkt_filtering(&adapter->hw);
2279 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2280 e1000_update_mng_vlan(adapter);
2283 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2284 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2285 link = !adapter->hw.serdes_link_down;
2287 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2290 if (!netif_carrier_ok(netdev)) {
2291 boolean_t txb2b = 1;
2292 e1000_get_speed_and_duplex(&adapter->hw,
2293 &adapter->link_speed,
2294 &adapter->link_duplex);
2296 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2297 adapter->link_speed,
2298 adapter->link_duplex == FULL_DUPLEX ?
2299 "Full Duplex" : "Half Duplex");
2301 /* tweak tx_queue_len according to speed/duplex
2302 * and adjust the timeout factor */
2303 netdev->tx_queue_len = adapter->tx_queue_len;
2304 adapter->tx_timeout_factor = 1;
2305 switch (adapter->link_speed) {
2308 netdev->tx_queue_len = 10;
2309 adapter->tx_timeout_factor = 8;
2313 netdev->tx_queue_len = 100;
2314 /* maybe add some timeout factor ? */
2318 if ((adapter->hw.mac_type == e1000_82571 ||
2319 adapter->hw.mac_type == e1000_82572) &&
2321 #define SPEED_MODE_BIT (1 << 21)
2323 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2324 tarc0 &= ~SPEED_MODE_BIT;
2325 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2329 /* disable TSO for pcie and 10/100 speeds, to avoid
2330 * some hardware issues */
2331 if (!adapter->tso_force &&
2332 adapter->hw.bus_type == e1000_bus_type_pci_express){
2333 switch (adapter->link_speed) {
2337 "10/100 speed: disabling TSO\n");
2338 netdev->features &= ~NETIF_F_TSO;
2341 netdev->features |= NETIF_F_TSO;
2350 /* enable transmits in the hardware, need to do this
2351 * after setting TARC0 */
2352 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2353 tctl |= E1000_TCTL_EN;
2354 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2356 netif_carrier_on(netdev);
2357 netif_wake_queue(netdev);
2358 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2359 adapter->smartspeed = 0;
2362 if (netif_carrier_ok(netdev)) {
2363 adapter->link_speed = 0;
2364 adapter->link_duplex = 0;
2365 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2366 netif_carrier_off(netdev);
2367 netif_stop_queue(netdev);
2368 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2370 /* 80003ES2LAN workaround--
2371 * For packet buffer work-around on link down event;
2372 * disable receives in the ISR and
2373 * reset device here in the watchdog
2375 if (adapter->hw.mac_type == e1000_80003es2lan) {
2377 schedule_work(&adapter->reset_task);
2381 e1000_smartspeed(adapter);
2384 e1000_update_stats(adapter);
2386 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2387 adapter->tpt_old = adapter->stats.tpt;
2388 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2389 adapter->colc_old = adapter->stats.colc;
2391 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2392 adapter->gorcl_old = adapter->stats.gorcl;
2393 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2394 adapter->gotcl_old = adapter->stats.gotcl;
2396 e1000_update_adaptive(&adapter->hw);
2398 if (!netif_carrier_ok(netdev)) {
2399 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2400 /* We've lost link, so the controller stops DMA,
2401 * but we've got queued Tx work that's never going
2402 * to get done, so reset controller to flush Tx.
2403 * (Do the reset outside of interrupt context). */
2404 adapter->tx_timeout_count++;
2405 schedule_work(&adapter->reset_task);
2409 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2410 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2411 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2412 * asymmetrical Tx or Rx gets ITR=8000; everyone
2413 * else is between 2000-8000. */
2414 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2415 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2416 adapter->gotcl - adapter->gorcl :
2417 adapter->gorcl - adapter->gotcl) / 10000;
2418 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2419 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2422 /* Cause software interrupt to ensure rx ring is cleaned */
2423 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2425 /* Force detection of hung controller every watchdog period */
2426 adapter->detect_tx_hung = TRUE;
2428 /* With 82571 controllers, LAA may be overwritten due to controller
2429 * reset from the other port. Set the appropriate LAA in RAR[0] */
2430 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2431 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2433 /* Reset the timer */
2434 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2437 #define E1000_TX_FLAGS_CSUM 0x00000001
2438 #define E1000_TX_FLAGS_VLAN 0x00000002
2439 #define E1000_TX_FLAGS_TSO 0x00000004
2440 #define E1000_TX_FLAGS_IPV4 0x00000008
2441 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2442 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2445 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2446 struct sk_buff *skb)
2449 struct e1000_context_desc *context_desc;
2450 struct e1000_buffer *buffer_info;
2452 uint32_t cmd_length = 0;
2453 uint16_t ipcse = 0, tucse, mss;
2454 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2457 if (skb_shinfo(skb)->tso_size) {
2458 if (skb_header_cloned(skb)) {
2459 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2464 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2465 mss = skb_shinfo(skb)->tso_size;
2466 if (skb->protocol == htons(ETH_P_IP)) {
2467 skb->nh.iph->tot_len = 0;
2468 skb->nh.iph->check = 0;
2470 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2475 cmd_length = E1000_TXD_CMD_IP;
2476 ipcse = skb->h.raw - skb->data - 1;
2477 #ifdef NETIF_F_TSO_IPV6
2478 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2479 skb->nh.ipv6h->payload_len = 0;
2481 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2482 &skb->nh.ipv6h->daddr,
2489 ipcss = skb->nh.raw - skb->data;
2490 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2491 tucss = skb->h.raw - skb->data;
2492 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2495 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2496 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2498 i = tx_ring->next_to_use;
2499 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2500 buffer_info = &tx_ring->buffer_info[i];
2502 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2503 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2504 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2505 context_desc->upper_setup.tcp_fields.tucss = tucss;
2506 context_desc->upper_setup.tcp_fields.tucso = tucso;
2507 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2508 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2509 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2510 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2512 buffer_info->time_stamp = jiffies;
2514 if (++i == tx_ring->count) i = 0;
2515 tx_ring->next_to_use = i;
2525 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2526 struct sk_buff *skb)
2528 struct e1000_context_desc *context_desc;
2529 struct e1000_buffer *buffer_info;
2533 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2534 css = skb->h.raw - skb->data;
2536 i = tx_ring->next_to_use;
2537 buffer_info = &tx_ring->buffer_info[i];
2538 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2540 context_desc->upper_setup.tcp_fields.tucss = css;
2541 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2542 context_desc->upper_setup.tcp_fields.tucse = 0;
2543 context_desc->tcp_seg_setup.data = 0;
2544 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2546 buffer_info->time_stamp = jiffies;
2548 if (unlikely(++i == tx_ring->count)) i = 0;
2549 tx_ring->next_to_use = i;
2557 #define E1000_MAX_TXD_PWR 12
2558 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2561 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2562 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2563 unsigned int nr_frags, unsigned int mss)
2565 struct e1000_buffer *buffer_info;
2566 unsigned int len = skb->len;
2567 unsigned int offset = 0, size, count = 0, i;
2569 len -= skb->data_len;
2571 i = tx_ring->next_to_use;
2574 buffer_info = &tx_ring->buffer_info[i];
2575 size = min(len, max_per_txd);
2577 /* Workaround for Controller erratum --
2578 * descriptor for non-tso packet in a linear SKB that follows a
2579 * tso gets written back prematurely before the data is fully
2580 * DMA'd to the controller */
2581 if (!skb->data_len && tx_ring->last_tx_tso &&
2582 !skb_shinfo(skb)->tso_size) {
2583 tx_ring->last_tx_tso = 0;
2587 /* Workaround for premature desc write-backs
2588 * in TSO mode. Append 4-byte sentinel desc */
2589 if (unlikely(mss && !nr_frags && size == len && size > 8))
2592 /* work-around for errata 10 and it applies
2593 * to all controllers in PCI-X mode
2594 * The fix is to make sure that the first descriptor of a
2595 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2597 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2598 (size > 2015) && count == 0))
2601 /* Workaround for potential 82544 hang in PCI-X. Avoid
2602 * terminating buffers within evenly-aligned dwords. */
2603 if (unlikely(adapter->pcix_82544 &&
2604 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2608 buffer_info->length = size;
2610 pci_map_single(adapter->pdev,
2614 buffer_info->time_stamp = jiffies;
2619 if (unlikely(++i == tx_ring->count)) i = 0;
2622 for (f = 0; f < nr_frags; f++) {
2623 struct skb_frag_struct *frag;
2625 frag = &skb_shinfo(skb)->frags[f];
2627 offset = frag->page_offset;
2630 buffer_info = &tx_ring->buffer_info[i];
2631 size = min(len, max_per_txd);
2633 /* Workaround for premature desc write-backs
2634 * in TSO mode. Append 4-byte sentinel desc */
2635 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2638 /* Workaround for potential 82544 hang in PCI-X.
2639 * Avoid terminating buffers within evenly-aligned
2641 if (unlikely(adapter->pcix_82544 &&
2642 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2646 buffer_info->length = size;
2648 pci_map_page(adapter->pdev,
2653 buffer_info->time_stamp = jiffies;
2658 if (unlikely(++i == tx_ring->count)) i = 0;
2662 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2663 tx_ring->buffer_info[i].skb = skb;
2664 tx_ring->buffer_info[first].next_to_watch = i;
2670 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2671 int tx_flags, int count)
2673 struct e1000_tx_desc *tx_desc = NULL;
2674 struct e1000_buffer *buffer_info;
2675 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2678 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2679 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2681 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2683 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2684 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2687 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2688 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2689 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2692 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2693 txd_lower |= E1000_TXD_CMD_VLE;
2694 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2697 i = tx_ring->next_to_use;
2700 buffer_info = &tx_ring->buffer_info[i];
2701 tx_desc = E1000_TX_DESC(*tx_ring, i);
2702 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2703 tx_desc->lower.data =
2704 cpu_to_le32(txd_lower | buffer_info->length);
2705 tx_desc->upper.data = cpu_to_le32(txd_upper);
2706 if (unlikely(++i == tx_ring->count)) i = 0;
2709 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2711 /* Force memory writes to complete before letting h/w
2712 * know there are new descriptors to fetch. (Only
2713 * applicable for weak-ordered memory model archs,
2714 * such as IA-64). */
2717 tx_ring->next_to_use = i;
2718 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2722 * 82547 workaround to avoid controller hang in half-duplex environment.
2723 * The workaround is to avoid queuing a large packet that would span
2724 * the internal Tx FIFO ring boundary by notifying the stack to resend
2725 * the packet at a later time. This gives the Tx FIFO an opportunity to
2726 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2727 * to the beginning of the Tx FIFO.
2730 #define E1000_FIFO_HDR 0x10
2731 #define E1000_82547_PAD_LEN 0x3E0
2734 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2736 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2737 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2739 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2741 if (adapter->link_duplex != HALF_DUPLEX)
2742 goto no_fifo_stall_required;
2744 if (atomic_read(&adapter->tx_fifo_stall))
2747 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2748 atomic_set(&adapter->tx_fifo_stall, 1);
2752 no_fifo_stall_required:
2753 adapter->tx_fifo_head += skb_fifo_len;
2754 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2755 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2759 #define MINIMUM_DHCP_PACKET_SIZE 282
2761 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2763 struct e1000_hw *hw = &adapter->hw;
2764 uint16_t length, offset;
2765 if (vlan_tx_tag_present(skb)) {
2766 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2767 ( adapter->hw.mng_cookie.status &
2768 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2771 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
2772 struct ethhdr *eth = (struct ethhdr *) skb->data;
2773 if ((htons(ETH_P_IP) == eth->h_proto)) {
2774 const struct iphdr *ip =
2775 (struct iphdr *)((uint8_t *)skb->data+14);
2776 if (IPPROTO_UDP == ip->protocol) {
2777 struct udphdr *udp =
2778 (struct udphdr *)((uint8_t *)ip +
2780 if (ntohs(udp->dest) == 67) {
2781 offset = (uint8_t *)udp + 8 - skb->data;
2782 length = skb->len - offset;
2784 return e1000_mng_write_dhcp_info(hw,
2794 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2796 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2798 struct e1000_adapter *adapter = netdev_priv(netdev);
2799 struct e1000_tx_ring *tx_ring;
2800 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2801 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2802 unsigned int tx_flags = 0;
2803 unsigned int len = skb->len;
2804 unsigned long flags;
2805 unsigned int nr_frags = 0;
2806 unsigned int mss = 0;
2810 len -= skb->data_len;
2812 tx_ring = adapter->tx_ring;
2814 if (unlikely(skb->len <= 0)) {
2815 dev_kfree_skb_any(skb);
2816 return NETDEV_TX_OK;
2820 mss = skb_shinfo(skb)->tso_size;
2821 /* The controller does a simple calculation to
2822 * make sure there is enough room in the FIFO before
2823 * initiating the DMA for each buffer. The calc is:
2824 * 4 = ceil(buffer len/mss). To make sure we don't
2825 * overrun the FIFO, adjust the max buffer len if mss
2829 max_per_txd = min(mss << 2, max_per_txd);
2830 max_txd_pwr = fls(max_per_txd) - 1;
2832 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2833 * points to just header, pull a few bytes of payload from
2834 * frags into skb->data */
2835 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2836 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2837 switch (adapter->hw.mac_type) {
2838 unsigned int pull_size;
2842 pull_size = min((unsigned int)4, skb->data_len);
2843 if (!__pskb_pull_tail(skb, pull_size)) {
2845 "__pskb_pull_tail failed.\n");
2846 dev_kfree_skb_any(skb);
2847 return NETDEV_TX_OK;
2849 len = skb->len - skb->data_len;
2858 /* reserve a descriptor for the offload context */
2859 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2863 if (skb->ip_summed == CHECKSUM_HW)
2868 /* Controller Erratum workaround */
2869 if (!skb->data_len && tx_ring->last_tx_tso &&
2870 !skb_shinfo(skb)->tso_size)
2874 count += TXD_USE_COUNT(len, max_txd_pwr);
2876 if (adapter->pcix_82544)
2879 /* work-around for errata 10 and it applies to all controllers
2880 * in PCI-X mode, so add one more descriptor to the count
2882 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2886 nr_frags = skb_shinfo(skb)->nr_frags;
2887 for (f = 0; f < nr_frags; f++)
2888 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2890 if (adapter->pcix_82544)
2894 if (adapter->hw.tx_pkt_filtering &&
2895 (adapter->hw.mac_type == e1000_82573))
2896 e1000_transfer_dhcp_info(adapter, skb);
2898 local_irq_save(flags);
2899 if (!spin_trylock(&tx_ring->tx_lock)) {
2900 /* Collision - tell upper layer to requeue */
2901 local_irq_restore(flags);
2902 return NETDEV_TX_LOCKED;
2905 /* need: count + 2 desc gap to keep tail from touching
2906 * head, otherwise try next time */
2907 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2908 netif_stop_queue(netdev);
2909 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2910 return NETDEV_TX_BUSY;
2913 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2914 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2915 netif_stop_queue(netdev);
2916 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2917 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2918 return NETDEV_TX_BUSY;
2922 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2923 tx_flags |= E1000_TX_FLAGS_VLAN;
2924 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2927 first = tx_ring->next_to_use;
2929 tso = e1000_tso(adapter, tx_ring, skb);
2931 dev_kfree_skb_any(skb);
2932 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2933 return NETDEV_TX_OK;
2937 tx_ring->last_tx_tso = 1;
2938 tx_flags |= E1000_TX_FLAGS_TSO;
2939 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2940 tx_flags |= E1000_TX_FLAGS_CSUM;
2942 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2943 * 82571 hardware supports TSO capabilities for IPv6 as well...
2944 * no longer assume, we must. */
2945 if (likely(skb->protocol == htons(ETH_P_IP)))
2946 tx_flags |= E1000_TX_FLAGS_IPV4;
2948 e1000_tx_queue(adapter, tx_ring, tx_flags,
2949 e1000_tx_map(adapter, tx_ring, skb, first,
2950 max_per_txd, nr_frags, mss));
2952 netdev->trans_start = jiffies;
2954 /* Make sure there is space in the ring for the next send. */
2955 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2956 netif_stop_queue(netdev);
2958 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2959 return NETDEV_TX_OK;
2963 * e1000_tx_timeout - Respond to a Tx Hang
2964 * @netdev: network interface device structure
2968 e1000_tx_timeout(struct net_device *netdev)
2970 struct e1000_adapter *adapter = netdev_priv(netdev);
2972 /* Do the reset outside of interrupt context */
2973 adapter->tx_timeout_count++;
2974 schedule_work(&adapter->reset_task);
2978 e1000_reset_task(struct net_device *netdev)
2980 struct e1000_adapter *adapter = netdev_priv(netdev);
2982 e1000_reinit_locked(adapter);
2986 * e1000_get_stats - Get System Network Statistics
2987 * @netdev: network interface device structure
2989 * Returns the address of the device statistics structure.
2990 * The statistics are actually updated from the timer callback.
2993 static struct net_device_stats *
2994 e1000_get_stats(struct net_device *netdev)
2996 struct e1000_adapter *adapter = netdev_priv(netdev);
2998 /* only return the current stats */
2999 return &adapter->net_stats;
3003 * e1000_change_mtu - Change the Maximum Transfer Unit
3004 * @netdev: network interface device structure
3005 * @new_mtu: new value for maximum frame size
3007 * Returns 0 on success, negative on failure
3011 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3013 struct e1000_adapter *adapter = netdev_priv(netdev);
3014 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3015 uint16_t eeprom_data = 0;
3017 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3018 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3019 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3023 /* Adapter-specific max frame size limits. */
3024 switch (adapter->hw.mac_type) {
3025 case e1000_undefined ... e1000_82542_rev2_1:
3026 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3027 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3032 /* only enable jumbo frames if ASPM is disabled completely
3033 * this means both bits must be zero in 0x1A bits 3:2 */
3034 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3036 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
3037 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3039 "Jumbo Frames not supported.\n");
3044 /* fall through to get support */
3047 case e1000_80003es2lan:
3048 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3049 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3050 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3055 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3059 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3060 * means we reserve 2 more, this pushes us to allocate from the next
3062 * i.e. RXBUFFER_2048 --> size-4096 slab */
3064 if (max_frame <= E1000_RXBUFFER_256)
3065 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3066 else if (max_frame <= E1000_RXBUFFER_512)
3067 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3068 else if (max_frame <= E1000_RXBUFFER_1024)
3069 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3070 else if (max_frame <= E1000_RXBUFFER_2048)
3071 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3072 else if (max_frame <= E1000_RXBUFFER_4096)
3073 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3074 else if (max_frame <= E1000_RXBUFFER_8192)
3075 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3076 else if (max_frame <= E1000_RXBUFFER_16384)
3077 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3079 /* adjust allocation if LPE protects us, and we aren't using SBP */
3080 #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3081 if (!adapter->hw.tbi_compatibility_on &&
3082 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3083 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3084 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3086 netdev->mtu = new_mtu;
3088 if (netif_running(netdev))
3089 e1000_reinit_locked(adapter);
3091 adapter->hw.max_frame_size = max_frame;
3097 * e1000_update_stats - Update the board statistics counters
3098 * @adapter: board private structure
3102 e1000_update_stats(struct e1000_adapter *adapter)
3104 struct e1000_hw *hw = &adapter->hw;
3105 struct pci_dev *pdev = adapter->pdev;
3106 unsigned long flags;
3109 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3112 * Prevent stats update while adapter is being reset, or if the pci
3113 * connection is down.
3115 if (adapter->link_speed == 0)
3117 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3120 spin_lock_irqsave(&adapter->stats_lock, flags);
3122 /* these counters are modified from e1000_adjust_tbi_stats,
3123 * called from the interrupt context, so they must only
3124 * be written while holding adapter->stats_lock
3127 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3128 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3129 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3130 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3131 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3132 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3133 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3134 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3135 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3136 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3137 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3138 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3139 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3141 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3142 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3143 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3144 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3145 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3146 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3147 adapter->stats.dc += E1000_READ_REG(hw, DC);
3148 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3149 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3150 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3151 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3152 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3153 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3154 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3155 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3156 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3157 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3158 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3159 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3160 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3161 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3162 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3163 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3164 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3165 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3166 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3167 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3168 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3169 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3170 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3171 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3172 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3173 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3174 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3176 /* used for adaptive IFS */
3178 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3179 adapter->stats.tpt += hw->tx_packet_delta;
3180 hw->collision_delta = E1000_READ_REG(hw, COLC);
3181 adapter->stats.colc += hw->collision_delta;
3183 if (hw->mac_type >= e1000_82543) {
3184 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3185 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3186 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3187 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3188 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3189 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3191 if (hw->mac_type > e1000_82547_rev_2) {
3192 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3193 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3194 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3195 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3196 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3197 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3198 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3199 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3200 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3203 /* Fill out the OS statistics structure */
3205 adapter->net_stats.rx_packets = adapter->stats.gprc;
3206 adapter->net_stats.tx_packets = adapter->stats.gptc;
3207 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3208 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3209 adapter->net_stats.multicast = adapter->stats.mprc;
3210 adapter->net_stats.collisions = adapter->stats.colc;
3214 /* RLEC on some newer hardware can be incorrect so build
3215 * our own version based on RUC and ROC */
3216 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3217 adapter->stats.crcerrs + adapter->stats.algnerrc +
3218 adapter->stats.ruc + adapter->stats.roc +
3219 adapter->stats.cexterr;
3220 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3222 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3223 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3224 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3228 adapter->net_stats.tx_errors = adapter->stats.ecol +
3229 adapter->stats.latecol;
3230 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3231 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3232 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3234 /* Tx Dropped needs to be maintained elsewhere */
3238 if (hw->media_type == e1000_media_type_copper) {
3239 if ((adapter->link_speed == SPEED_1000) &&
3240 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3241 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3242 adapter->phy_stats.idle_errors += phy_tmp;
3245 if ((hw->mac_type <= e1000_82546) &&
3246 (hw->phy_type == e1000_phy_m88) &&
3247 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3248 adapter->phy_stats.receive_errors += phy_tmp;
3251 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3255 * e1000_intr - Interrupt Handler
3256 * @irq: interrupt number
3257 * @data: pointer to a network interface device structure
3258 * @pt_regs: CPU registers structure
3262 e1000_intr(int irq, void *data, struct pt_regs *regs)
3264 struct net_device *netdev = data;
3265 struct e1000_adapter *adapter = netdev_priv(netdev);
3266 struct e1000_hw *hw = &adapter->hw;
3267 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
3268 #ifndef CONFIG_E1000_NAPI
3271 /* Interrupt Auto-Mask...upon reading ICR,
3272 * interrupts are masked. No need for the
3273 * IMC write, but it does mean we should
3274 * account for it ASAP. */
3275 if (likely(hw->mac_type >= e1000_82571))
3276 atomic_inc(&adapter->irq_sem);
3279 if (unlikely(!icr)) {
3280 #ifdef CONFIG_E1000_NAPI
3281 if (hw->mac_type >= e1000_82571)
3282 e1000_irq_enable(adapter);
3284 return IRQ_NONE; /* Not our interrupt */
3287 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3288 hw->get_link_status = 1;
3289 /* 80003ES2LAN workaround--
3290 * For packet buffer work-around on link down event;
3291 * disable receives here in the ISR and
3292 * reset adapter in watchdog
3294 if (netif_carrier_ok(netdev) &&
3295 (adapter->hw.mac_type == e1000_80003es2lan)) {
3296 /* disable receives */
3297 rctl = E1000_READ_REG(hw, RCTL);
3298 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3300 mod_timer(&adapter->watchdog_timer, jiffies);
3303 #ifdef CONFIG_E1000_NAPI
3304 if (unlikely(hw->mac_type < e1000_82571)) {
3305 atomic_inc(&adapter->irq_sem);
3306 E1000_WRITE_REG(hw, IMC, ~0);
3307 E1000_WRITE_FLUSH(hw);
3309 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3310 __netif_rx_schedule(&adapter->polling_netdev[0]);
3312 e1000_irq_enable(adapter);
3314 /* Writing IMC and IMS is needed for 82547.
3315 * Due to Hub Link bus being occupied, an interrupt
3316 * de-assertion message is not able to be sent.
3317 * When an interrupt assertion message is generated later,
3318 * two messages are re-ordered and sent out.
3319 * That causes APIC to think 82547 is in de-assertion
3320 * state, while 82547 is in assertion state, resulting
3321 * in dead lock. Writing IMC forces 82547 into
3322 * de-assertion state.
3324 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3325 atomic_inc(&adapter->irq_sem);
3326 E1000_WRITE_REG(hw, IMC, ~0);
3329 for (i = 0; i < E1000_MAX_INTR; i++)
3330 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3331 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3334 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3335 e1000_irq_enable(adapter);
3342 #ifdef CONFIG_E1000_NAPI
3344 * e1000_clean - NAPI Rx polling callback
3345 * @adapter: board private structure
3349 e1000_clean(struct net_device *poll_dev, int *budget)
3351 struct e1000_adapter *adapter;
3352 int work_to_do = min(*budget, poll_dev->quota);
3353 int tx_cleaned = 0, i = 0, work_done = 0;
3355 /* Must NOT use netdev_priv macro here. */
3356 adapter = poll_dev->priv;
3358 /* Keep link state information with original netdev */
3359 if (!netif_carrier_ok(adapter->netdev))
3362 while (poll_dev != &adapter->polling_netdev[i]) {
3364 BUG_ON(i == adapter->num_rx_queues);
3367 if (likely(adapter->num_tx_queues == 1)) {
3368 /* e1000_clean is called per-cpu. This lock protects
3369 * tx_ring[0] from being cleaned by multiple cpus
3370 * simultaneously. A failure obtaining the lock means
3371 * tx_ring[0] is currently being cleaned anyway. */
3372 if (spin_trylock(&adapter->tx_queue_lock)) {
3373 tx_cleaned = e1000_clean_tx_irq(adapter,
3374 &adapter->tx_ring[0]);
3375 spin_unlock(&adapter->tx_queue_lock);
3378 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3380 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3381 &work_done, work_to_do);
3383 *budget -= work_done;
3384 poll_dev->quota -= work_done;
3386 /* If no Tx and not enough Rx work done, exit the polling mode */
3387 if ((!tx_cleaned && (work_done == 0)) ||
3388 !netif_running(adapter->netdev)) {
3390 netif_rx_complete(poll_dev);
3391 e1000_irq_enable(adapter);
3400 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3401 * @adapter: board private structure
3405 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3406 struct e1000_tx_ring *tx_ring)
3408 struct net_device *netdev = adapter->netdev;
3409 struct e1000_tx_desc *tx_desc, *eop_desc;
3410 struct e1000_buffer *buffer_info;
3411 unsigned int i, eop;
3412 #ifdef CONFIG_E1000_NAPI
3413 unsigned int count = 0;
3415 boolean_t cleaned = FALSE;
3417 i = tx_ring->next_to_clean;
3418 eop = tx_ring->buffer_info[i].next_to_watch;
3419 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3421 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3422 for (cleaned = FALSE; !cleaned; ) {
3423 tx_desc = E1000_TX_DESC(*tx_ring, i);
3424 buffer_info = &tx_ring->buffer_info[i];
3425 cleaned = (i == eop);
3427 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3428 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3430 if (unlikely(++i == tx_ring->count)) i = 0;
3434 eop = tx_ring->buffer_info[i].next_to_watch;
3435 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3436 #ifdef CONFIG_E1000_NAPI
3437 #define E1000_TX_WEIGHT 64
3438 /* weight of a sort for tx, to avoid endless transmit cleanup */
3439 if (count++ == E1000_TX_WEIGHT) break;
3443 tx_ring->next_to_clean = i;
3445 #define TX_WAKE_THRESHOLD 32
3446 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3447 netif_carrier_ok(netdev))) {
3448 spin_lock(&tx_ring->tx_lock);
3449 if (netif_queue_stopped(netdev) &&
3450 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
3451 netif_wake_queue(netdev);
3452 spin_unlock(&tx_ring->tx_lock);
3455 if (adapter->detect_tx_hung) {
3456 /* Detect a transmit hang in hardware, this serializes the
3457 * check with the clearing of time_stamp and movement of i */
3458 adapter->detect_tx_hung = FALSE;
3459 if (tx_ring->buffer_info[eop].dma &&
3460 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3461 (adapter->tx_timeout_factor * HZ))
3462 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3463 E1000_STATUS_TXOFF)) {
3465 /* detected Tx unit hang */
3466 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3470 " next_to_use <%x>\n"
3471 " next_to_clean <%x>\n"
3472 "buffer_info[next_to_clean]\n"
3473 " time_stamp <%lx>\n"
3474 " next_to_watch <%x>\n"
3476 " next_to_watch.status <%x>\n",
3477 (unsigned long)((tx_ring - adapter->tx_ring) /
3478 sizeof(struct e1000_tx_ring)),
3479 readl(adapter->hw.hw_addr + tx_ring->tdh),
3480 readl(adapter->hw.hw_addr + tx_ring->tdt),
3481 tx_ring->next_to_use,
3482 tx_ring->next_to_clean,
3483 tx_ring->buffer_info[eop].time_stamp,
3486 eop_desc->upper.fields.status);
3487 netif_stop_queue(netdev);
3494 * e1000_rx_checksum - Receive Checksum Offload for 82543
3495 * @adapter: board private structure
3496 * @status_err: receive descriptor status and error fields
3497 * @csum: receive descriptor csum field
3498 * @sk_buff: socket buffer with received data
3502 e1000_rx_checksum(struct e1000_adapter *adapter,
3503 uint32_t status_err, uint32_t csum,
3504 struct sk_buff *skb)
3506 uint16_t status = (uint16_t)status_err;
3507 uint8_t errors = (uint8_t)(status_err >> 24);
3508 skb->ip_summed = CHECKSUM_NONE;
3510 /* 82543 or newer only */
3511 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3512 /* Ignore Checksum bit is set */
3513 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3514 /* TCP/UDP checksum error bit is set */
3515 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3516 /* let the stack verify checksum errors */
3517 adapter->hw_csum_err++;
3520 /* TCP/UDP Checksum has not been calculated */
3521 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3522 if (!(status & E1000_RXD_STAT_TCPCS))
3525 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3528 /* It must be a TCP or UDP packet with a valid checksum */
3529 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3530 /* TCP checksum is good */
3531 skb->ip_summed = CHECKSUM_UNNECESSARY;
3532 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3533 /* IP fragment with UDP payload */
3534 /* Hardware complements the payload checksum, so we undo it
3535 * and then put the value in host order for further stack use.
3537 csum = ntohl(csum ^ 0xFFFF);
3539 skb->ip_summed = CHECKSUM_HW;
3541 adapter->hw_csum_good++;
3545 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3546 * @adapter: board private structure
3550 #ifdef CONFIG_E1000_NAPI
3551 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3552 struct e1000_rx_ring *rx_ring,
3553 int *work_done, int work_to_do)
3555 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3556 struct e1000_rx_ring *rx_ring)
3559 struct net_device *netdev = adapter->netdev;
3560 struct pci_dev *pdev = adapter->pdev;
3561 struct e1000_rx_desc *rx_desc, *next_rxd;
3562 struct e1000_buffer *buffer_info, *next_buffer;
3563 unsigned long flags;
3567 int cleaned_count = 0;
3568 boolean_t cleaned = FALSE;
3570 i = rx_ring->next_to_clean;
3571 rx_desc = E1000_RX_DESC(*rx_ring, i);
3572 buffer_info = &rx_ring->buffer_info[i];
3574 while (rx_desc->status & E1000_RXD_STAT_DD) {
3575 struct sk_buff *skb;
3577 #ifdef CONFIG_E1000_NAPI
3578 if (*work_done >= work_to_do)
3582 status = rx_desc->status;
3583 skb = buffer_info->skb;
3584 buffer_info->skb = NULL;
3586 prefetch(skb->data - NET_IP_ALIGN);
3588 if (++i == rx_ring->count) i = 0;
3589 next_rxd = E1000_RX_DESC(*rx_ring, i);
3592 next_buffer = &rx_ring->buffer_info[i];
3596 pci_unmap_single(pdev,
3598 buffer_info->length,
3599 PCI_DMA_FROMDEVICE);
3601 length = le16_to_cpu(rx_desc->length);
3603 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3604 /* All receives must fit into a single buffer */
3605 E1000_DBG("%s: Receive packet consumed multiple"
3606 " buffers\n", netdev->name);
3607 dev_kfree_skb_irq(skb);
3611 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3612 last_byte = *(skb->data + length - 1);
3613 if (TBI_ACCEPT(&adapter->hw, status,
3614 rx_desc->errors, length, last_byte)) {
3615 spin_lock_irqsave(&adapter->stats_lock, flags);
3616 e1000_tbi_adjust_stats(&adapter->hw,
3619 spin_unlock_irqrestore(&adapter->stats_lock,
3624 buffer_info->skb = skb;
3629 /* code added for copybreak, this should improve
3630 * performance for small packets with large amounts
3631 * of reassembly being done in the stack */
3632 #define E1000_CB_LENGTH 256
3633 if (length < E1000_CB_LENGTH) {
3634 struct sk_buff *new_skb =
3635 dev_alloc_skb(length + NET_IP_ALIGN);
3637 skb_reserve(new_skb, NET_IP_ALIGN);
3638 new_skb->dev = netdev;
3639 memcpy(new_skb->data - NET_IP_ALIGN,
3640 skb->data - NET_IP_ALIGN,
3641 length + NET_IP_ALIGN);
3642 /* save the skb in buffer_info as good */
3643 buffer_info->skb = skb;
3645 skb_put(skb, length);
3648 skb_put(skb, length);
3650 /* end copybreak code */
3652 /* Receive Checksum Offload */
3653 e1000_rx_checksum(adapter,
3654 (uint32_t)(status) |
3655 ((uint32_t)(rx_desc->errors) << 24),
3656 le16_to_cpu(rx_desc->csum), skb);
3658 skb->protocol = eth_type_trans(skb, netdev);
3659 #ifdef CONFIG_E1000_NAPI
3660 if (unlikely(adapter->vlgrp &&
3661 (status & E1000_RXD_STAT_VP))) {
3662 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3663 le16_to_cpu(rx_desc->special) &
3664 E1000_RXD_SPC_VLAN_MASK);
3666 netif_receive_skb(skb);
3668 #else /* CONFIG_E1000_NAPI */
3669 if (unlikely(adapter->vlgrp &&
3670 (status & E1000_RXD_STAT_VP))) {
3671 vlan_hwaccel_rx(skb, adapter->vlgrp,
3672 le16_to_cpu(rx_desc->special) &
3673 E1000_RXD_SPC_VLAN_MASK);
3677 #endif /* CONFIG_E1000_NAPI */
3678 netdev->last_rx = jiffies;
3681 rx_desc->status = 0;
3683 /* return some buffers to hardware, one at a time is too slow */
3684 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3685 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3689 /* use prefetched values */
3691 buffer_info = next_buffer;
3693 rx_ring->next_to_clean = i;
3695 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3697 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3703 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3704 * @adapter: board private structure
3708 #ifdef CONFIG_E1000_NAPI
3709 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3710 struct e1000_rx_ring *rx_ring,
3711 int *work_done, int work_to_do)
3713 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3714 struct e1000_rx_ring *rx_ring)
3717 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
3718 struct net_device *netdev = adapter->netdev;
3719 struct pci_dev *pdev = adapter->pdev;
3720 struct e1000_buffer *buffer_info, *next_buffer;
3721 struct e1000_ps_page *ps_page;
3722 struct e1000_ps_page_dma *ps_page_dma;
3723 struct sk_buff *skb;
3725 uint32_t length, staterr;
3726 int cleaned_count = 0;
3727 boolean_t cleaned = FALSE;
3729 i = rx_ring->next_to_clean;
3730 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3731 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3732 buffer_info = &rx_ring->buffer_info[i];
3734 while (staterr & E1000_RXD_STAT_DD) {
3735 ps_page = &rx_ring->ps_page[i];
3736 ps_page_dma = &rx_ring->ps_page_dma[i];
3737 #ifdef CONFIG_E1000_NAPI
3738 if (unlikely(*work_done >= work_to_do))
3742 skb = buffer_info->skb;
3744 /* in the packet split case this is header only */
3745 prefetch(skb->data - NET_IP_ALIGN);
3747 if (++i == rx_ring->count) i = 0;
3748 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
3751 next_buffer = &rx_ring->buffer_info[i];
3755 pci_unmap_single(pdev, buffer_info->dma,
3756 buffer_info->length,
3757 PCI_DMA_FROMDEVICE);
3759 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3760 E1000_DBG("%s: Packet Split buffers didn't pick up"
3761 " the full packet\n", netdev->name);
3762 dev_kfree_skb_irq(skb);
3766 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3767 dev_kfree_skb_irq(skb);
3771 length = le16_to_cpu(rx_desc->wb.middle.length0);
3773 if (unlikely(!length)) {
3774 E1000_DBG("%s: Last part of the packet spanning"
3775 " multiple descriptors\n", netdev->name);
3776 dev_kfree_skb_irq(skb);
3781 skb_put(skb, length);
3784 /* this looks ugly, but it seems compiler issues make it
3785 more efficient than reusing j */
3786 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3788 /* page alloc/put takes too long and effects small packet
3789 * throughput, so unsplit small packets and save the alloc/put*/
3790 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
3792 /* there is no documentation about how to call
3793 * kmap_atomic, so we can't hold the mapping
3795 pci_dma_sync_single_for_cpu(pdev,
3796 ps_page_dma->ps_page_dma[0],
3798 PCI_DMA_FROMDEVICE);
3799 vaddr = kmap_atomic(ps_page->ps_page[0],
3800 KM_SKB_DATA_SOFTIRQ);
3801 memcpy(skb->tail, vaddr, l1);
3802 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3803 pci_dma_sync_single_for_device(pdev,
3804 ps_page_dma->ps_page_dma[0],
3805 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3812 for (j = 0; j < adapter->rx_ps_pages; j++) {
3813 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
3815 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3816 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3817 ps_page_dma->ps_page_dma[j] = 0;
3818 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3820 ps_page->ps_page[j] = NULL;
3822 skb->data_len += length;
3823 skb->truesize += length;
3827 e1000_rx_checksum(adapter, staterr,
3828 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
3829 skb->protocol = eth_type_trans(skb, netdev);
3831 if (likely(rx_desc->wb.upper.header_status &
3832 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
3833 adapter->rx_hdr_split++;
3834 #ifdef CONFIG_E1000_NAPI
3835 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3836 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3837 le16_to_cpu(rx_desc->wb.middle.vlan) &
3838 E1000_RXD_SPC_VLAN_MASK);
3840 netif_receive_skb(skb);
3842 #else /* CONFIG_E1000_NAPI */
3843 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3844 vlan_hwaccel_rx(skb, adapter->vlgrp,
3845 le16_to_cpu(rx_desc->wb.middle.vlan) &
3846 E1000_RXD_SPC_VLAN_MASK);
3850 #endif /* CONFIG_E1000_NAPI */
3851 netdev->last_rx = jiffies;
3854 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
3855 buffer_info->skb = NULL;
3857 /* return some buffers to hardware, one at a time is too slow */
3858 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3859 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3863 /* use prefetched values */
3865 buffer_info = next_buffer;
3867 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3869 rx_ring->next_to_clean = i;
3871 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3873 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3879 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3880 * @adapter: address of board private structure
3884 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3885 struct e1000_rx_ring *rx_ring,
3888 struct net_device *netdev = adapter->netdev;
3889 struct pci_dev *pdev = adapter->pdev;
3890 struct e1000_rx_desc *rx_desc;
3891 struct e1000_buffer *buffer_info;
3892 struct sk_buff *skb;
3894 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3896 i = rx_ring->next_to_use;
3897 buffer_info = &rx_ring->buffer_info[i];
3899 while (cleaned_count--) {
3900 if (!(skb = buffer_info->skb))
3901 skb = dev_alloc_skb(bufsz);
3907 if (unlikely(!skb)) {
3908 /* Better luck next round */
3909 adapter->alloc_rx_buff_failed++;
3913 /* Fix for errata 23, can't cross 64kB boundary */
3914 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3915 struct sk_buff *oldskb = skb;
3916 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3917 "at %p\n", bufsz, skb->data);
3918 /* Try again, without freeing the previous */
3919 skb = dev_alloc_skb(bufsz);
3920 /* Failed allocation, critical failure */
3922 dev_kfree_skb(oldskb);
3926 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3929 dev_kfree_skb(oldskb);
3930 break; /* while !buffer_info->skb */
3932 /* Use new allocation */
3933 dev_kfree_skb(oldskb);
3936 /* Make buffer alignment 2 beyond a 16 byte boundary
3937 * this will result in a 16 byte aligned IP header after
3938 * the 14 byte MAC header is removed
3940 skb_reserve(skb, NET_IP_ALIGN);
3944 buffer_info->skb = skb;
3945 buffer_info->length = adapter->rx_buffer_len;
3947 buffer_info->dma = pci_map_single(pdev,
3949 adapter->rx_buffer_len,
3950 PCI_DMA_FROMDEVICE);
3952 /* Fix for errata 23, can't cross 64kB boundary */
3953 if (!e1000_check_64k_bound(adapter,
3954 (void *)(unsigned long)buffer_info->dma,
3955 adapter->rx_buffer_len)) {
3956 DPRINTK(RX_ERR, ERR,
3957 "dma align check failed: %u bytes at %p\n",
3958 adapter->rx_buffer_len,
3959 (void *)(unsigned long)buffer_info->dma);
3961 buffer_info->skb = NULL;
3963 pci_unmap_single(pdev, buffer_info->dma,
3964 adapter->rx_buffer_len,
3965 PCI_DMA_FROMDEVICE);
3967 break; /* while !buffer_info->skb */
3969 rx_desc = E1000_RX_DESC(*rx_ring, i);
3970 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3972 if (unlikely(++i == rx_ring->count))
3974 buffer_info = &rx_ring->buffer_info[i];
3977 if (likely(rx_ring->next_to_use != i)) {
3978 rx_ring->next_to_use = i;
3979 if (unlikely(i-- == 0))
3980 i = (rx_ring->count - 1);
3982 /* Force memory writes to complete before letting h/w
3983 * know there are new descriptors to fetch. (Only
3984 * applicable for weak-ordered memory model archs,
3985 * such as IA-64). */
3987 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3992 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3993 * @adapter: address of board private structure
3997 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3998 struct e1000_rx_ring *rx_ring,
4001 struct net_device *netdev = adapter->netdev;
4002 struct pci_dev *pdev = adapter->pdev;
4003 union e1000_rx_desc_packet_split *rx_desc;
4004 struct e1000_buffer *buffer_info;
4005 struct e1000_ps_page *ps_page;
4006 struct e1000_ps_page_dma *ps_page_dma;
4007 struct sk_buff *skb;
4010 i = rx_ring->next_to_use;
4011 buffer_info = &rx_ring->buffer_info[i];
4012 ps_page = &rx_ring->ps_page[i];
4013 ps_page_dma = &rx_ring->ps_page_dma[i];
4015 while (cleaned_count--) {
4016 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4018 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4019 if (j < adapter->rx_ps_pages) {
4020 if (likely(!ps_page->ps_page[j])) {
4021 ps_page->ps_page[j] =
4022 alloc_page(GFP_ATOMIC);
4023 if (unlikely(!ps_page->ps_page[j])) {
4024 adapter->alloc_rx_buff_failed++;
4027 ps_page_dma->ps_page_dma[j] =
4029 ps_page->ps_page[j],
4031 PCI_DMA_FROMDEVICE);
4033 /* Refresh the desc even if buffer_addrs didn't
4034 * change because each write-back erases
4037 rx_desc->read.buffer_addr[j+1] =
4038 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4040 rx_desc->read.buffer_addr[j+1] = ~0;
4043 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4045 if (unlikely(!skb)) {
4046 adapter->alloc_rx_buff_failed++;
4050 /* Make buffer alignment 2 beyond a 16 byte boundary
4051 * this will result in a 16 byte aligned IP header after
4052 * the 14 byte MAC header is removed
4054 skb_reserve(skb, NET_IP_ALIGN);
4058 buffer_info->skb = skb;
4059 buffer_info->length = adapter->rx_ps_bsize0;
4060 buffer_info->dma = pci_map_single(pdev, skb->data,
4061 adapter->rx_ps_bsize0,
4062 PCI_DMA_FROMDEVICE);
4064 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4066 if (unlikely(++i == rx_ring->count)) i = 0;
4067 buffer_info = &rx_ring->buffer_info[i];
4068 ps_page = &rx_ring->ps_page[i];
4069 ps_page_dma = &rx_ring->ps_page_dma[i];
4073 if (likely(rx_ring->next_to_use != i)) {
4074 rx_ring->next_to_use = i;
4075 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4077 /* Force memory writes to complete before letting h/w
4078 * know there are new descriptors to fetch. (Only
4079 * applicable for weak-ordered memory model archs,
4080 * such as IA-64). */
4082 /* Hardware increments by 16 bytes, but packet split
4083 * descriptors are 32 bytes...so we increment tail
4086 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4091 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4096 e1000_smartspeed(struct e1000_adapter *adapter)
4098 uint16_t phy_status;
4101 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4102 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4105 if (adapter->smartspeed == 0) {
4106 /* If Master/Slave config fault is asserted twice,
4107 * we assume back-to-back */
4108 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4109 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4110 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4111 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4112 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4113 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4114 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4115 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4117 adapter->smartspeed++;
4118 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4119 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4121 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4122 MII_CR_RESTART_AUTO_NEG);
4123 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4128 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4129 /* If still no link, perhaps using 2/3 pair cable */
4130 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4131 phy_ctrl |= CR_1000T_MS_ENABLE;
4132 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4133 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4134 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4135 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4136 MII_CR_RESTART_AUTO_NEG);
4137 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4140 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4141 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4142 adapter->smartspeed = 0;
4153 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4159 return e1000_mii_ioctl(netdev, ifr, cmd);
4173 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4175 struct e1000_adapter *adapter = netdev_priv(netdev);
4176 struct mii_ioctl_data *data = if_mii(ifr);
4180 unsigned long flags;
4182 if (adapter->hw.media_type != e1000_media_type_copper)
4187 data->phy_id = adapter->hw.phy_addr;
4190 if (!capable(CAP_NET_ADMIN))
4192 spin_lock_irqsave(&adapter->stats_lock, flags);
4193 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4195 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4198 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4201 if (!capable(CAP_NET_ADMIN))
4203 if (data->reg_num & ~(0x1F))
4205 mii_reg = data->val_in;
4206 spin_lock_irqsave(&adapter->stats_lock, flags);
4207 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4209 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4212 if (adapter->hw.media_type == e1000_media_type_copper) {
4213 switch (data->reg_num) {
4215 if (mii_reg & MII_CR_POWER_DOWN)
4217 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4218 adapter->hw.autoneg = 1;
4219 adapter->hw.autoneg_advertised = 0x2F;
4222 spddplx = SPEED_1000;
4223 else if (mii_reg & 0x2000)
4224 spddplx = SPEED_100;
4227 spddplx += (mii_reg & 0x100)
4230 retval = e1000_set_spd_dplx(adapter,
4233 spin_unlock_irqrestore(
4234 &adapter->stats_lock,
4239 if (netif_running(adapter->netdev))
4240 e1000_reinit_locked(adapter);
4242 e1000_reset(adapter);
4244 case M88E1000_PHY_SPEC_CTRL:
4245 case M88E1000_EXT_PHY_SPEC_CTRL:
4246 if (e1000_phy_reset(&adapter->hw)) {
4247 spin_unlock_irqrestore(
4248 &adapter->stats_lock, flags);
4254 switch (data->reg_num) {
4256 if (mii_reg & MII_CR_POWER_DOWN)
4258 if (netif_running(adapter->netdev))
4259 e1000_reinit_locked(adapter);
4261 e1000_reset(adapter);
4265 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4270 return E1000_SUCCESS;
4274 e1000_pci_set_mwi(struct e1000_hw *hw)
4276 struct e1000_adapter *adapter = hw->back;
4277 int ret_val = pci_set_mwi(adapter->pdev);
4280 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4284 e1000_pci_clear_mwi(struct e1000_hw *hw)
4286 struct e1000_adapter *adapter = hw->back;
4288 pci_clear_mwi(adapter->pdev);
4292 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4294 struct e1000_adapter *adapter = hw->back;
4296 pci_read_config_word(adapter->pdev, reg, value);
4300 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4302 struct e1000_adapter *adapter = hw->back;
4304 pci_write_config_word(adapter->pdev, reg, *value);
4308 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4314 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4320 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4322 struct e1000_adapter *adapter = netdev_priv(netdev);
4323 uint32_t ctrl, rctl;
4325 e1000_irq_disable(adapter);
4326 adapter->vlgrp = grp;
4329 /* enable VLAN tag insert/strip */
4330 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4331 ctrl |= E1000_CTRL_VME;
4332 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4334 /* enable VLAN receive filtering */
4335 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4336 rctl |= E1000_RCTL_VFE;
4337 rctl &= ~E1000_RCTL_CFIEN;
4338 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4339 e1000_update_mng_vlan(adapter);
4341 /* disable VLAN tag insert/strip */
4342 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4343 ctrl &= ~E1000_CTRL_VME;
4344 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4346 /* disable VLAN filtering */
4347 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4348 rctl &= ~E1000_RCTL_VFE;
4349 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4350 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4351 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4352 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4356 e1000_irq_enable(adapter);
4360 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4362 struct e1000_adapter *adapter = netdev_priv(netdev);
4363 uint32_t vfta, index;
4365 if ((adapter->hw.mng_cookie.status &
4366 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4367 (vid == adapter->mng_vlan_id))
4369 /* add VID to filter table */
4370 index = (vid >> 5) & 0x7F;
4371 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4372 vfta |= (1 << (vid & 0x1F));
4373 e1000_write_vfta(&adapter->hw, index, vfta);
4377 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4379 struct e1000_adapter *adapter = netdev_priv(netdev);
4380 uint32_t vfta, index;
4382 e1000_irq_disable(adapter);
4385 adapter->vlgrp->vlan_devices[vid] = NULL;
4387 e1000_irq_enable(adapter);
4389 if ((adapter->hw.mng_cookie.status &
4390 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4391 (vid == adapter->mng_vlan_id)) {
4392 /* release control to f/w */
4393 e1000_release_hw_control(adapter);
4397 /* remove VID from filter table */
4398 index = (vid >> 5) & 0x7F;
4399 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4400 vfta &= ~(1 << (vid & 0x1F));
4401 e1000_write_vfta(&adapter->hw, index, vfta);
4405 e1000_restore_vlan(struct e1000_adapter *adapter)
4407 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4409 if (adapter->vlgrp) {
4411 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4412 if (!adapter->vlgrp->vlan_devices[vid])
4414 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4420 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4422 adapter->hw.autoneg = 0;
4424 /* Fiber NICs only allow 1000 gbps Full duplex */
4425 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4426 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4427 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4432 case SPEED_10 + DUPLEX_HALF:
4433 adapter->hw.forced_speed_duplex = e1000_10_half;
4435 case SPEED_10 + DUPLEX_FULL:
4436 adapter->hw.forced_speed_duplex = e1000_10_full;
4438 case SPEED_100 + DUPLEX_HALF:
4439 adapter->hw.forced_speed_duplex = e1000_100_half;
4441 case SPEED_100 + DUPLEX_FULL:
4442 adapter->hw.forced_speed_duplex = e1000_100_full;
4444 case SPEED_1000 + DUPLEX_FULL:
4445 adapter->hw.autoneg = 1;
4446 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4448 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4450 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4457 /* Save/restore 16 or 64 dwords of PCI config space depending on which
4458 * bus we're on (PCI(X) vs. PCI-E)
4460 #define PCIE_CONFIG_SPACE_LEN 256
4461 #define PCI_CONFIG_SPACE_LEN 64
4463 e1000_pci_save_state(struct e1000_adapter *adapter)
4465 struct pci_dev *dev = adapter->pdev;
4469 if (adapter->hw.mac_type >= e1000_82571)
4470 size = PCIE_CONFIG_SPACE_LEN;
4472 size = PCI_CONFIG_SPACE_LEN;
4474 WARN_ON(adapter->config_space != NULL);
4476 adapter->config_space = kmalloc(size, GFP_KERNEL);
4477 if (!adapter->config_space) {
4478 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4481 for (i = 0; i < (size / 4); i++)
4482 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4487 e1000_pci_restore_state(struct e1000_adapter *adapter)
4489 struct pci_dev *dev = adapter->pdev;
4493 if (adapter->config_space == NULL)
4496 if (adapter->hw.mac_type >= e1000_82571)
4497 size = PCIE_CONFIG_SPACE_LEN;
4499 size = PCI_CONFIG_SPACE_LEN;
4500 for (i = 0; i < (size / 4); i++)
4501 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4502 kfree(adapter->config_space);
4503 adapter->config_space = NULL;
4506 #endif /* CONFIG_PM */
4509 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4511 struct net_device *netdev = pci_get_drvdata(pdev);
4512 struct e1000_adapter *adapter = netdev_priv(netdev);
4513 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4514 uint32_t wufc = adapter->wol;
4519 netif_device_detach(netdev);
4521 if (netif_running(netdev)) {
4522 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4523 e1000_down(adapter);
4527 /* Implement our own version of pci_save_state(pdev) because pci-
4528 * express adapters have 256-byte config spaces. */
4529 retval = e1000_pci_save_state(adapter);
4534 status = E1000_READ_REG(&adapter->hw, STATUS);
4535 if (status & E1000_STATUS_LU)
4536 wufc &= ~E1000_WUFC_LNKC;
4539 e1000_setup_rctl(adapter);
4540 e1000_set_multi(netdev);
4542 /* turn on all-multi mode if wake on multicast is enabled */
4543 if (adapter->wol & E1000_WUFC_MC) {
4544 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4545 rctl |= E1000_RCTL_MPE;
4546 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4549 if (adapter->hw.mac_type >= e1000_82540) {
4550 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4551 /* advertise wake from D3Cold */
4552 #define E1000_CTRL_ADVD3WUC 0x00100000
4553 /* phy power management enable */
4554 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4555 ctrl |= E1000_CTRL_ADVD3WUC |
4556 E1000_CTRL_EN_PHY_PWR_MGMT;
4557 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4560 if (adapter->hw.media_type == e1000_media_type_fiber ||
4561 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4562 /* keep the laser running in D3 */
4563 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4564 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4565 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4568 /* Allow time for pending master requests to run */
4569 e1000_disable_pciex_master(&adapter->hw);
4571 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4572 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4573 pci_enable_wake(pdev, PCI_D3hot, 1);
4574 pci_enable_wake(pdev, PCI_D3cold, 1);
4576 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4577 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4578 pci_enable_wake(pdev, PCI_D3hot, 0);
4579 pci_enable_wake(pdev, PCI_D3cold, 0);
4582 if (adapter->hw.mac_type >= e1000_82540 &&
4583 adapter->hw.media_type == e1000_media_type_copper) {
4584 manc = E1000_READ_REG(&adapter->hw, MANC);
4585 if (manc & E1000_MANC_SMBUS_EN) {
4586 manc |= E1000_MANC_ARP_EN;
4587 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4588 pci_enable_wake(pdev, PCI_D3hot, 1);
4589 pci_enable_wake(pdev, PCI_D3cold, 1);
4593 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4594 * would have already happened in close and is redundant. */
4595 e1000_release_hw_control(adapter);
4597 pci_disable_device(pdev);
4599 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4606 e1000_resume(struct pci_dev *pdev)
4608 struct net_device *netdev = pci_get_drvdata(pdev);
4609 struct e1000_adapter *adapter = netdev_priv(netdev);
4610 uint32_t manc, ret_val;
4612 pci_set_power_state(pdev, PCI_D0);
4613 e1000_pci_restore_state(adapter);
4614 ret_val = pci_enable_device(pdev);
4615 pci_set_master(pdev);
4617 pci_enable_wake(pdev, PCI_D3hot, 0);
4618 pci_enable_wake(pdev, PCI_D3cold, 0);
4620 e1000_reset(adapter);
4621 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4623 if (netif_running(netdev))
4626 netif_device_attach(netdev);
4628 if (adapter->hw.mac_type >= e1000_82540 &&
4629 adapter->hw.media_type == e1000_media_type_copper) {
4630 manc = E1000_READ_REG(&adapter->hw, MANC);
4631 manc &= ~(E1000_MANC_ARP_EN);
4632 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4635 /* If the controller is 82573 and f/w is AMT, do not set
4636 * DRV_LOAD until the interface is up. For all other cases,
4637 * let the f/w know that the h/w is now under the control
4639 if (adapter->hw.mac_type != e1000_82573 ||
4640 !e1000_check_mng_mode(&adapter->hw))
4641 e1000_get_hw_control(adapter);
4647 static void e1000_shutdown(struct pci_dev *pdev)
4649 e1000_suspend(pdev, PMSG_SUSPEND);
4652 #ifdef CONFIG_NET_POLL_CONTROLLER
4654 * Polling 'interrupt' - used by things like netconsole to send skbs
4655 * without having to re-enable interrupts. It's not called while
4656 * the interrupt routine is executing.
4659 e1000_netpoll(struct net_device *netdev)
4661 struct e1000_adapter *adapter = netdev_priv(netdev);
4662 disable_irq(adapter->pdev->irq);
4663 e1000_intr(adapter->pdev->irq, netdev, NULL);
4664 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4665 #ifndef CONFIG_E1000_NAPI
4666 adapter->clean_rx(adapter, adapter->rx_ring);
4668 enable_irq(adapter->pdev->irq);
4673 * e1000_io_error_detected - called when PCI error is detected
4674 * @pdev: Pointer to PCI device
4675 * @state: The current pci conneection state
4677 * This function is called after a PCI bus error affecting
4678 * this device has been detected.
4680 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4682 struct net_device *netdev = pci_get_drvdata(pdev);
4683 struct e1000_adapter *adapter = netdev->priv;
4685 netif_device_detach(netdev);
4687 if (netif_running(netdev))
4688 e1000_down(adapter);
4690 /* Request a slot slot reset. */
4691 return PCI_ERS_RESULT_NEED_RESET;
4695 * e1000_io_slot_reset - called after the pci bus has been reset.
4696 * @pdev: Pointer to PCI device
4698 * Restart the card from scratch, as if from a cold-boot. Implementation
4699 * resembles the first-half of the e1000_resume routine.
4701 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4703 struct net_device *netdev = pci_get_drvdata(pdev);
4704 struct e1000_adapter *adapter = netdev->priv;
4706 if (pci_enable_device(pdev)) {
4707 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4708 return PCI_ERS_RESULT_DISCONNECT;
4710 pci_set_master(pdev);
4712 pci_enable_wake(pdev, 3, 0);
4713 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4715 /* Perform card reset only on one instance of the card */
4716 if (PCI_FUNC (pdev->devfn) != 0)
4717 return PCI_ERS_RESULT_RECOVERED;
4719 e1000_reset(adapter);
4720 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4722 return PCI_ERS_RESULT_RECOVERED;
4726 * e1000_io_resume - called when traffic can start flowing again.
4727 * @pdev: Pointer to PCI device
4729 * This callback is called when the error recovery driver tells us that
4730 * its OK to resume normal operation. Implementation resembles the
4731 * second-half of the e1000_resume routine.
4733 static void e1000_io_resume(struct pci_dev *pdev)
4735 struct net_device *netdev = pci_get_drvdata(pdev);
4736 struct e1000_adapter *adapter = netdev->priv;
4737 uint32_t manc, swsm;
4739 if (netif_running(netdev)) {
4740 if (e1000_up(adapter)) {
4741 printk("e1000: can't bring device back up after reset\n");
4746 netif_device_attach(netdev);
4748 if (adapter->hw.mac_type >= e1000_82540 &&
4749 adapter->hw.media_type == e1000_media_type_copper) {
4750 manc = E1000_READ_REG(&adapter->hw, MANC);
4751 manc &= ~(E1000_MANC_ARP_EN);
4752 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4755 switch (adapter->hw.mac_type) {
4757 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4758 E1000_WRITE_REG(&adapter->hw, SWSM,
4759 swsm | E1000_SWSM_DRV_LOAD);
4765 if (netif_running(netdev))
4766 mod_timer(&adapter->watchdog_timer, jiffies);