1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 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 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o Added another fix for the pass false carrier bit
35 * o Need to rebuild with noew version number for the pass false carrier
38 * o fixup for tso workaround to disable it for pci-x
39 * o fix mem leak on 82542
40 * o fixes for 10 Mb/s connections and incorrect stats
42 * o hardware workaround to only set "speed mode" bit for 1G link.
44 * o wake on lan support modified for device ID 10B5
45 * o fix dhcp + vlan issue not making it to the iAMT firmware
47 * o New hardware support for the Gigabit NIC embedded in the south bridge
48 * o Fixes to the recycling logic (skb->tail) from IBM LTC
50 * o incorporate fix for recycled skbs from IBM LTC
52 * o Honor eeprom setting for enabling/disabling Wake On Lan
54 * o Fix memory leak in rx ring handling for PCI Express adapters
56 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
58 * o Render logic that sets/resets DRV_LOAD as inline functions to
59 * avoid code replication. If f/w is AMT then set DRV_LOAD only when
60 * network interface is open.
61 * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
62 * o Adjust PBA partioning for Jumbo frames using MTU size and not
65 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
66 * (e1000_clean_tx_irq)
67 * o Support for 8086:10B5 device (Quad Port)
70 char e1000_driver_name[] = "e1000";
71 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
72 #ifndef CONFIG_E1000_NAPI
75 #define DRIVERNAPI "-NAPI"
77 #define DRV_VERSION "7.0.33-k2"DRIVERNAPI
78 char e1000_driver_version[] = DRV_VERSION;
79 static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
81 /* e1000_pci_tbl - PCI Device ID Table
83 * Last entry must be all 0s
86 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
88 static struct pci_device_id e1000_pci_tbl[] = {
89 INTEL_E1000_ETHERNET_DEVICE(0x1000),
90 INTEL_E1000_ETHERNET_DEVICE(0x1001),
91 INTEL_E1000_ETHERNET_DEVICE(0x1004),
92 INTEL_E1000_ETHERNET_DEVICE(0x1008),
93 INTEL_E1000_ETHERNET_DEVICE(0x1009),
94 INTEL_E1000_ETHERNET_DEVICE(0x100C),
95 INTEL_E1000_ETHERNET_DEVICE(0x100D),
96 INTEL_E1000_ETHERNET_DEVICE(0x100E),
97 INTEL_E1000_ETHERNET_DEVICE(0x100F),
98 INTEL_E1000_ETHERNET_DEVICE(0x1010),
99 INTEL_E1000_ETHERNET_DEVICE(0x1011),
100 INTEL_E1000_ETHERNET_DEVICE(0x1012),
101 INTEL_E1000_ETHERNET_DEVICE(0x1013),
102 INTEL_E1000_ETHERNET_DEVICE(0x1014),
103 INTEL_E1000_ETHERNET_DEVICE(0x1015),
104 INTEL_E1000_ETHERNET_DEVICE(0x1016),
105 INTEL_E1000_ETHERNET_DEVICE(0x1017),
106 INTEL_E1000_ETHERNET_DEVICE(0x1018),
107 INTEL_E1000_ETHERNET_DEVICE(0x1019),
108 INTEL_E1000_ETHERNET_DEVICE(0x101A),
109 INTEL_E1000_ETHERNET_DEVICE(0x101D),
110 INTEL_E1000_ETHERNET_DEVICE(0x101E),
111 INTEL_E1000_ETHERNET_DEVICE(0x1026),
112 INTEL_E1000_ETHERNET_DEVICE(0x1027),
113 INTEL_E1000_ETHERNET_DEVICE(0x1028),
114 INTEL_E1000_ETHERNET_DEVICE(0x105E),
115 INTEL_E1000_ETHERNET_DEVICE(0x105F),
116 INTEL_E1000_ETHERNET_DEVICE(0x1060),
117 INTEL_E1000_ETHERNET_DEVICE(0x1075),
118 INTEL_E1000_ETHERNET_DEVICE(0x1076),
119 INTEL_E1000_ETHERNET_DEVICE(0x1077),
120 INTEL_E1000_ETHERNET_DEVICE(0x1078),
121 INTEL_E1000_ETHERNET_DEVICE(0x1079),
122 INTEL_E1000_ETHERNET_DEVICE(0x107A),
123 INTEL_E1000_ETHERNET_DEVICE(0x107B),
124 INTEL_E1000_ETHERNET_DEVICE(0x107C),
125 INTEL_E1000_ETHERNET_DEVICE(0x107D),
126 INTEL_E1000_ETHERNET_DEVICE(0x107E),
127 INTEL_E1000_ETHERNET_DEVICE(0x107F),
128 INTEL_E1000_ETHERNET_DEVICE(0x108A),
129 INTEL_E1000_ETHERNET_DEVICE(0x108B),
130 INTEL_E1000_ETHERNET_DEVICE(0x108C),
131 INTEL_E1000_ETHERNET_DEVICE(0x1096),
132 INTEL_E1000_ETHERNET_DEVICE(0x1098),
133 INTEL_E1000_ETHERNET_DEVICE(0x1099),
134 INTEL_E1000_ETHERNET_DEVICE(0x109A),
135 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
136 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
137 /* required last entry */
141 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
143 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *txdr);
145 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
146 struct e1000_rx_ring *rxdr);
147 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
148 struct e1000_tx_ring *tx_ring);
149 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
150 struct e1000_rx_ring *rx_ring);
152 /* Local Function Prototypes */
154 static int e1000_init_module(void);
155 static void e1000_exit_module(void);
156 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
157 static void __devexit e1000_remove(struct pci_dev *pdev);
158 static int e1000_alloc_queues(struct e1000_adapter *adapter);
159 static int e1000_sw_init(struct e1000_adapter *adapter);
160 static int e1000_open(struct net_device *netdev);
161 static int e1000_close(struct net_device *netdev);
162 static void e1000_configure_tx(struct e1000_adapter *adapter);
163 static void e1000_configure_rx(struct e1000_adapter *adapter);
164 static void e1000_setup_rctl(struct e1000_adapter *adapter);
165 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
166 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
167 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
168 struct e1000_tx_ring *tx_ring);
169 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
170 struct e1000_rx_ring *rx_ring);
171 static void e1000_set_multi(struct net_device *netdev);
172 static void e1000_update_phy_info(unsigned long data);
173 static void e1000_watchdog(unsigned long data);
174 static void e1000_watchdog_task(struct e1000_adapter *adapter);
175 static void e1000_82547_tx_fifo_stall(unsigned long data);
176 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
177 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
178 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
179 static int e1000_set_mac(struct net_device *netdev, void *p);
180 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
181 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
182 struct e1000_tx_ring *tx_ring);
183 #ifdef CONFIG_E1000_NAPI
184 static int e1000_clean(struct net_device *poll_dev, int *budget);
185 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
186 struct e1000_rx_ring *rx_ring,
187 int *work_done, int work_to_do);
188 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
189 struct e1000_rx_ring *rx_ring,
190 int *work_done, int work_to_do);
192 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
193 struct e1000_rx_ring *rx_ring);
194 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
195 struct e1000_rx_ring *rx_ring);
197 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
198 struct e1000_rx_ring *rx_ring,
200 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
201 struct e1000_rx_ring *rx_ring,
203 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
204 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
206 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
207 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
208 static void e1000_tx_timeout(struct net_device *dev);
209 static void e1000_reset_task(struct net_device *dev);
210 static void e1000_smartspeed(struct e1000_adapter *adapter);
211 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
212 struct sk_buff *skb);
214 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
215 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
216 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
217 static void e1000_restore_vlan(struct e1000_adapter *adapter);
220 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
221 static int e1000_resume(struct pci_dev *pdev);
223 static void e1000_shutdown(struct pci_dev *pdev);
225 #ifdef CONFIG_NET_POLL_CONTROLLER
226 /* for netdump / net console */
227 static void e1000_netpoll (struct net_device *netdev);
231 static struct pci_driver e1000_driver = {
232 .name = e1000_driver_name,
233 .id_table = e1000_pci_tbl,
234 .probe = e1000_probe,
235 .remove = __devexit_p(e1000_remove),
236 /* Power Managment Hooks */
238 .suspend = e1000_suspend,
239 .resume = e1000_resume,
241 .shutdown = e1000_shutdown
244 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
245 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
246 MODULE_LICENSE("GPL");
247 MODULE_VERSION(DRV_VERSION);
249 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
250 module_param(debug, int, 0);
251 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
254 * e1000_init_module - Driver Registration Routine
256 * e1000_init_module is the first routine called when the driver is
257 * loaded. All it does is register with the PCI subsystem.
261 e1000_init_module(void)
264 printk(KERN_INFO "%s - version %s\n",
265 e1000_driver_string, e1000_driver_version);
267 printk(KERN_INFO "%s\n", e1000_copyright);
269 ret = pci_module_init(&e1000_driver);
274 module_init(e1000_init_module);
277 * e1000_exit_module - Driver Exit Cleanup Routine
279 * e1000_exit_module is called just before the driver is removed
284 e1000_exit_module(void)
286 pci_unregister_driver(&e1000_driver);
289 module_exit(e1000_exit_module);
292 * e1000_irq_disable - Mask off interrupt generation on the NIC
293 * @adapter: board private structure
297 e1000_irq_disable(struct e1000_adapter *adapter)
299 atomic_inc(&adapter->irq_sem);
300 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
301 E1000_WRITE_FLUSH(&adapter->hw);
302 synchronize_irq(adapter->pdev->irq);
306 * e1000_irq_enable - Enable default interrupt generation settings
307 * @adapter: board private structure
311 e1000_irq_enable(struct e1000_adapter *adapter)
313 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
314 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
315 E1000_WRITE_FLUSH(&adapter->hw);
320 e1000_update_mng_vlan(struct e1000_adapter *adapter)
322 struct net_device *netdev = adapter->netdev;
323 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
324 uint16_t old_vid = adapter->mng_vlan_id;
325 if (adapter->vlgrp) {
326 if (!adapter->vlgrp->vlan_devices[vid]) {
327 if (adapter->hw.mng_cookie.status &
328 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
329 e1000_vlan_rx_add_vid(netdev, vid);
330 adapter->mng_vlan_id = vid;
332 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
334 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
336 !adapter->vlgrp->vlan_devices[old_vid])
337 e1000_vlan_rx_kill_vid(netdev, old_vid);
339 adapter->mng_vlan_id = vid;
344 * e1000_release_hw_control - release control of the h/w to f/w
345 * @adapter: address of board private structure
347 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
348 * For ASF and Pass Through versions of f/w this means that the
349 * driver is no longer loaded. For AMT version (only with 82573) i
350 * of the f/w this means that the netowrk i/f is closed.
355 e1000_release_hw_control(struct e1000_adapter *adapter)
360 /* Let firmware taken over control of h/w */
361 switch (adapter->hw.mac_type) {
364 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
365 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
366 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
369 swsm = E1000_READ_REG(&adapter->hw, SWSM);
370 E1000_WRITE_REG(&adapter->hw, SWSM,
371 swsm & ~E1000_SWSM_DRV_LOAD);
378 * e1000_get_hw_control - get control of the h/w from f/w
379 * @adapter: address of board private structure
381 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
382 * For ASF and Pass Through versions of f/w this means that
383 * the driver is loaded. For AMT version (only with 82573)
384 * of the f/w this means that the netowrk i/f is open.
389 e1000_get_hw_control(struct e1000_adapter *adapter)
393 /* Let firmware know the driver has taken over */
394 switch (adapter->hw.mac_type) {
397 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
398 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
399 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
402 swsm = E1000_READ_REG(&adapter->hw, SWSM);
403 E1000_WRITE_REG(&adapter->hw, SWSM,
404 swsm | E1000_SWSM_DRV_LOAD);
412 e1000_up(struct e1000_adapter *adapter)
414 struct net_device *netdev = adapter->netdev;
417 /* hardware has been reset, we need to reload some things */
419 /* Reset the PHY if it was previously powered down */
420 if (adapter->hw.media_type == e1000_media_type_copper) {
422 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
423 if (mii_reg & MII_CR_POWER_DOWN)
424 e1000_phy_reset(&adapter->hw);
427 e1000_set_multi(netdev);
429 e1000_restore_vlan(adapter);
431 e1000_configure_tx(adapter);
432 e1000_setup_rctl(adapter);
433 e1000_configure_rx(adapter);
434 /* call E1000_DESC_UNUSED which always leaves
435 * at least 1 descriptor unused to make sure
436 * next_to_use != next_to_clean */
437 for (i = 0; i < adapter->num_rx_queues; i++) {
438 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
439 adapter->alloc_rx_buf(adapter, ring,
440 E1000_DESC_UNUSED(ring));
443 #ifdef CONFIG_PCI_MSI
444 if (adapter->hw.mac_type > e1000_82547_rev_2) {
445 adapter->have_msi = TRUE;
446 if ((err = pci_enable_msi(adapter->pdev))) {
448 "Unable to allocate MSI interrupt Error: %d\n", err);
449 adapter->have_msi = FALSE;
453 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
454 SA_SHIRQ | SA_SAMPLE_RANDOM,
455 netdev->name, netdev))) {
457 "Unable to allocate interrupt Error: %d\n", err);
461 adapter->tx_queue_len = netdev->tx_queue_len;
463 mod_timer(&adapter->watchdog_timer, jiffies);
465 #ifdef CONFIG_E1000_NAPI
466 netif_poll_enable(netdev);
468 e1000_irq_enable(adapter);
474 e1000_down(struct e1000_adapter *adapter)
476 struct net_device *netdev = adapter->netdev;
477 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
478 e1000_check_mng_mode(&adapter->hw);
480 e1000_irq_disable(adapter);
482 free_irq(adapter->pdev->irq, netdev);
483 #ifdef CONFIG_PCI_MSI
484 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
485 adapter->have_msi == TRUE)
486 pci_disable_msi(adapter->pdev);
488 del_timer_sync(&adapter->tx_fifo_stall_timer);
489 del_timer_sync(&adapter->watchdog_timer);
490 del_timer_sync(&adapter->phy_info_timer);
492 #ifdef CONFIG_E1000_NAPI
493 netif_poll_disable(netdev);
495 netdev->tx_queue_len = adapter->tx_queue_len;
496 adapter->link_speed = 0;
497 adapter->link_duplex = 0;
498 netif_carrier_off(netdev);
499 netif_stop_queue(netdev);
501 e1000_reset(adapter);
502 e1000_clean_all_tx_rings(adapter);
503 e1000_clean_all_rx_rings(adapter);
505 /* Power down the PHY so no link is implied when interface is down *
506 * The PHY cannot be powered down if any of the following is TRUE *
509 * (c) SoL/IDER session is active */
510 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
511 adapter->hw.media_type == e1000_media_type_copper &&
512 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
514 !e1000_check_phy_reset_block(&adapter->hw)) {
516 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
517 mii_reg |= MII_CR_POWER_DOWN;
518 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
524 e1000_reset(struct e1000_adapter *adapter)
527 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
529 /* Repartition Pba for greater than 9k mtu
530 * To take effect CTRL.RST is required.
533 switch (adapter->hw.mac_type) {
535 case e1000_82547_rev_2:
540 case e1000_80003es2lan:
551 if ((adapter->hw.mac_type != e1000_82573) &&
552 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
553 pba -= 8; /* allocate more FIFO for Tx */
556 if (adapter->hw.mac_type == e1000_82547) {
557 adapter->tx_fifo_head = 0;
558 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
559 adapter->tx_fifo_size =
560 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
561 atomic_set(&adapter->tx_fifo_stall, 0);
564 E1000_WRITE_REG(&adapter->hw, PBA, pba);
566 /* flow control settings */
567 /* Set the FC high water mark to 90% of the FIFO size.
568 * Required to clear last 3 LSB */
569 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
571 adapter->hw.fc_high_water = fc_high_water_mark;
572 adapter->hw.fc_low_water = fc_high_water_mark - 8;
573 if (adapter->hw.mac_type == e1000_80003es2lan)
574 adapter->hw.fc_pause_time = 0xFFFF;
576 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
577 adapter->hw.fc_send_xon = 1;
578 adapter->hw.fc = adapter->hw.original_fc;
580 /* Allow time for pending master requests to run */
581 e1000_reset_hw(&adapter->hw);
582 if (adapter->hw.mac_type >= e1000_82544)
583 E1000_WRITE_REG(&adapter->hw, WUC, 0);
584 if (e1000_init_hw(&adapter->hw))
585 DPRINTK(PROBE, ERR, "Hardware Error\n");
586 e1000_update_mng_vlan(adapter);
587 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
588 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
590 e1000_reset_adaptive(&adapter->hw);
591 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
592 if (adapter->en_mng_pt) {
593 manc = E1000_READ_REG(&adapter->hw, MANC);
594 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
595 E1000_WRITE_REG(&adapter->hw, MANC, manc);
600 * e1000_probe - Device Initialization Routine
601 * @pdev: PCI device information struct
602 * @ent: entry in e1000_pci_tbl
604 * Returns 0 on success, negative on failure
606 * e1000_probe initializes an adapter identified by a pci_dev structure.
607 * The OS initialization, configuring of the adapter private structure,
608 * and a hardware reset occur.
612 e1000_probe(struct pci_dev *pdev,
613 const struct pci_device_id *ent)
615 struct net_device *netdev;
616 struct e1000_adapter *adapter;
617 unsigned long mmio_start, mmio_len;
619 static int cards_found = 0;
620 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
621 int i, err, pci_using_dac;
622 uint16_t eeprom_data;
623 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
624 if ((err = pci_enable_device(pdev)))
627 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
630 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
631 E1000_ERR("No usable DMA configuration, aborting\n");
637 if ((err = pci_request_regions(pdev, e1000_driver_name)))
640 pci_set_master(pdev);
642 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
645 goto err_alloc_etherdev;
648 SET_MODULE_OWNER(netdev);
649 SET_NETDEV_DEV(netdev, &pdev->dev);
651 pci_set_drvdata(pdev, netdev);
652 adapter = netdev_priv(netdev);
653 adapter->netdev = netdev;
654 adapter->pdev = pdev;
655 adapter->hw.back = adapter;
656 adapter->msg_enable = (1 << debug) - 1;
658 mmio_start = pci_resource_start(pdev, BAR_0);
659 mmio_len = pci_resource_len(pdev, BAR_0);
661 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
662 if (!adapter->hw.hw_addr) {
667 for (i = BAR_1; i <= BAR_5; i++) {
668 if (pci_resource_len(pdev, i) == 0)
670 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
671 adapter->hw.io_base = pci_resource_start(pdev, i);
676 netdev->open = &e1000_open;
677 netdev->stop = &e1000_close;
678 netdev->hard_start_xmit = &e1000_xmit_frame;
679 netdev->get_stats = &e1000_get_stats;
680 netdev->set_multicast_list = &e1000_set_multi;
681 netdev->set_mac_address = &e1000_set_mac;
682 netdev->change_mtu = &e1000_change_mtu;
683 netdev->do_ioctl = &e1000_ioctl;
684 e1000_set_ethtool_ops(netdev);
685 netdev->tx_timeout = &e1000_tx_timeout;
686 netdev->watchdog_timeo = 5 * HZ;
687 #ifdef CONFIG_E1000_NAPI
688 netdev->poll = &e1000_clean;
691 netdev->vlan_rx_register = e1000_vlan_rx_register;
692 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
693 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
694 #ifdef CONFIG_NET_POLL_CONTROLLER
695 netdev->poll_controller = e1000_netpoll;
697 strcpy(netdev->name, pci_name(pdev));
699 netdev->mem_start = mmio_start;
700 netdev->mem_end = mmio_start + mmio_len;
701 netdev->base_addr = adapter->hw.io_base;
703 adapter->bd_number = cards_found;
705 /* setup the private structure */
707 if ((err = e1000_sw_init(adapter)))
710 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
711 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
713 /* if ksp3, indicate if it's port a being setup */
714 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
715 e1000_ksp3_port_a == 0)
716 adapter->ksp3_port_a = 1;
718 /* Reset for multiple KP3 adapters */
719 if (e1000_ksp3_port_a == 4)
720 e1000_ksp3_port_a = 0;
722 if (adapter->hw.mac_type >= e1000_82543) {
723 netdev->features = NETIF_F_SG |
727 NETIF_F_HW_VLAN_FILTER;
731 if ((adapter->hw.mac_type >= e1000_82544) &&
732 (adapter->hw.mac_type != e1000_82547))
733 netdev->features |= NETIF_F_TSO;
735 #ifdef NETIF_F_TSO_IPV6
736 if (adapter->hw.mac_type > e1000_82547_rev_2)
737 netdev->features |= NETIF_F_TSO_IPV6;
741 netdev->features |= NETIF_F_HIGHDMA;
743 /* hard_start_xmit is safe against parallel locking */
744 netdev->features |= NETIF_F_LLTX;
746 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
748 /* before reading the EEPROM, reset the controller to
749 * put the device in a known good starting state */
751 e1000_reset_hw(&adapter->hw);
753 /* make sure the EEPROM is good */
755 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
756 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
761 /* copy the MAC address out of the EEPROM */
763 if (e1000_read_mac_addr(&adapter->hw))
764 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
765 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
766 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
768 if (!is_valid_ether_addr(netdev->perm_addr)) {
769 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
774 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
776 e1000_get_bus_info(&adapter->hw);
778 init_timer(&adapter->tx_fifo_stall_timer);
779 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
780 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
782 init_timer(&adapter->watchdog_timer);
783 adapter->watchdog_timer.function = &e1000_watchdog;
784 adapter->watchdog_timer.data = (unsigned long) adapter;
786 INIT_WORK(&adapter->watchdog_task,
787 (void (*)(void *))e1000_watchdog_task, adapter);
789 init_timer(&adapter->phy_info_timer);
790 adapter->phy_info_timer.function = &e1000_update_phy_info;
791 adapter->phy_info_timer.data = (unsigned long) adapter;
793 INIT_WORK(&adapter->reset_task,
794 (void (*)(void *))e1000_reset_task, netdev);
796 /* we're going to reset, so assume we have no link for now */
798 netif_carrier_off(netdev);
799 netif_stop_queue(netdev);
801 e1000_check_options(adapter);
803 /* Initial Wake on LAN setting
804 * If APM wake is enabled in the EEPROM,
805 * enable the ACPI Magic Packet filter
808 switch (adapter->hw.mac_type) {
809 case e1000_82542_rev2_0:
810 case e1000_82542_rev2_1:
814 e1000_read_eeprom(&adapter->hw,
815 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
816 eeprom_apme_mask = E1000_EEPROM_82544_APM;
819 case e1000_82546_rev_3:
821 case e1000_80003es2lan:
822 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
823 e1000_read_eeprom(&adapter->hw,
824 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
829 e1000_read_eeprom(&adapter->hw,
830 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
833 if (eeprom_data & eeprom_apme_mask)
834 adapter->wol |= E1000_WUFC_MAG;
836 /* print bus type/speed/width info */
838 struct e1000_hw *hw = &adapter->hw;
839 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
840 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
841 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
842 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
843 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
844 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
845 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
846 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
847 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
848 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
849 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
853 for (i = 0; i < 6; i++)
854 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
856 /* reset the hardware with the new settings */
857 e1000_reset(adapter);
859 /* If the controller is 82573 and f/w is AMT, do not set
860 * DRV_LOAD until the interface is up. For all other cases,
861 * let the f/w know that the h/w is now under the control
863 if (adapter->hw.mac_type != e1000_82573 ||
864 !e1000_check_mng_mode(&adapter->hw))
865 e1000_get_hw_control(adapter);
867 strcpy(netdev->name, "eth%d");
868 if ((err = register_netdev(netdev)))
871 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
879 iounmap(adapter->hw.hw_addr);
883 pci_release_regions(pdev);
888 * e1000_remove - Device Removal Routine
889 * @pdev: PCI device information struct
891 * e1000_remove is called by the PCI subsystem to alert the driver
892 * that it should release a PCI device. The could be caused by a
893 * Hot-Plug event, or because the driver is going to be removed from
897 static void __devexit
898 e1000_remove(struct pci_dev *pdev)
900 struct net_device *netdev = pci_get_drvdata(pdev);
901 struct e1000_adapter *adapter = netdev_priv(netdev);
903 #ifdef CONFIG_E1000_NAPI
907 flush_scheduled_work();
909 if (adapter->hw.mac_type >= e1000_82540 &&
910 adapter->hw.media_type == e1000_media_type_copper) {
911 manc = E1000_READ_REG(&adapter->hw, MANC);
912 if (manc & E1000_MANC_SMBUS_EN) {
913 manc |= E1000_MANC_ARP_EN;
914 E1000_WRITE_REG(&adapter->hw, MANC, manc);
918 /* Release control of h/w to f/w. If f/w is AMT enabled, this
919 * would have already happened in close and is redundant. */
920 e1000_release_hw_control(adapter);
922 unregister_netdev(netdev);
923 #ifdef CONFIG_E1000_NAPI
924 for (i = 0; i < adapter->num_rx_queues; i++)
925 dev_put(&adapter->polling_netdev[i]);
928 if (!e1000_check_phy_reset_block(&adapter->hw))
929 e1000_phy_hw_reset(&adapter->hw);
931 kfree(adapter->tx_ring);
932 kfree(adapter->rx_ring);
933 #ifdef CONFIG_E1000_NAPI
934 kfree(adapter->polling_netdev);
937 iounmap(adapter->hw.hw_addr);
938 pci_release_regions(pdev);
942 pci_disable_device(pdev);
946 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
947 * @adapter: board private structure to initialize
949 * e1000_sw_init initializes the Adapter private data structure.
950 * Fields are initialized based on PCI device information and
951 * OS network device settings (MTU size).
955 e1000_sw_init(struct e1000_adapter *adapter)
957 struct e1000_hw *hw = &adapter->hw;
958 struct net_device *netdev = adapter->netdev;
959 struct pci_dev *pdev = adapter->pdev;
960 #ifdef CONFIG_E1000_NAPI
964 /* PCI config space info */
966 hw->vendor_id = pdev->vendor;
967 hw->device_id = pdev->device;
968 hw->subsystem_vendor_id = pdev->subsystem_vendor;
969 hw->subsystem_id = pdev->subsystem_device;
971 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
973 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
975 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
976 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
977 hw->max_frame_size = netdev->mtu +
978 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
979 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
981 /* identify the MAC */
983 if (e1000_set_mac_type(hw)) {
984 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
988 /* initialize eeprom parameters */
990 if (e1000_init_eeprom_params(hw)) {
991 E1000_ERR("EEPROM initialization failed\n");
995 switch (hw->mac_type) {
1000 case e1000_82541_rev_2:
1001 case e1000_82547_rev_2:
1002 hw->phy_init_script = 1;
1006 e1000_set_media_type(hw);
1008 hw->wait_autoneg_complete = FALSE;
1009 hw->tbi_compatibility_en = TRUE;
1010 hw->adaptive_ifs = TRUE;
1012 /* Copper options */
1014 if (hw->media_type == e1000_media_type_copper) {
1015 hw->mdix = AUTO_ALL_MODES;
1016 hw->disable_polarity_correction = FALSE;
1017 hw->master_slave = E1000_MASTER_SLAVE;
1020 adapter->num_tx_queues = 1;
1021 adapter->num_rx_queues = 1;
1023 if (e1000_alloc_queues(adapter)) {
1024 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1028 #ifdef CONFIG_E1000_NAPI
1029 for (i = 0; i < adapter->num_rx_queues; i++) {
1030 adapter->polling_netdev[i].priv = adapter;
1031 adapter->polling_netdev[i].poll = &e1000_clean;
1032 adapter->polling_netdev[i].weight = 64;
1033 dev_hold(&adapter->polling_netdev[i]);
1034 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1036 spin_lock_init(&adapter->tx_queue_lock);
1039 atomic_set(&adapter->irq_sem, 1);
1040 spin_lock_init(&adapter->stats_lock);
1046 * e1000_alloc_queues - Allocate memory for all rings
1047 * @adapter: board private structure to initialize
1049 * We allocate one ring per queue at run-time since we don't know the
1050 * number of queues at compile-time. The polling_netdev array is
1051 * intended for Multiqueue, but should work fine with a single queue.
1054 static int __devinit
1055 e1000_alloc_queues(struct e1000_adapter *adapter)
1059 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1060 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1061 if (!adapter->tx_ring)
1063 memset(adapter->tx_ring, 0, size);
1065 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1066 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1067 if (!adapter->rx_ring) {
1068 kfree(adapter->tx_ring);
1071 memset(adapter->rx_ring, 0, size);
1073 #ifdef CONFIG_E1000_NAPI
1074 size = sizeof(struct net_device) * adapter->num_rx_queues;
1075 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1076 if (!adapter->polling_netdev) {
1077 kfree(adapter->tx_ring);
1078 kfree(adapter->rx_ring);
1081 memset(adapter->polling_netdev, 0, size);
1084 return E1000_SUCCESS;
1088 * e1000_open - Called when a network interface is made active
1089 * @netdev: network interface device structure
1091 * Returns 0 on success, negative value on failure
1093 * The open entry point is called when a network interface is made
1094 * active by the system (IFF_UP). At this point all resources needed
1095 * for transmit and receive operations are allocated, the interrupt
1096 * handler is registered with the OS, the watchdog timer is started,
1097 * and the stack is notified that the interface is ready.
1101 e1000_open(struct net_device *netdev)
1103 struct e1000_adapter *adapter = netdev_priv(netdev);
1106 /* allocate transmit descriptors */
1108 if ((err = e1000_setup_all_tx_resources(adapter)))
1111 /* allocate receive descriptors */
1113 if ((err = e1000_setup_all_rx_resources(adapter)))
1116 if ((err = e1000_up(adapter)))
1118 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1119 if ((adapter->hw.mng_cookie.status &
1120 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1121 e1000_update_mng_vlan(adapter);
1124 /* If AMT is enabled, let the firmware know that the network
1125 * interface is now open */
1126 if (adapter->hw.mac_type == e1000_82573 &&
1127 e1000_check_mng_mode(&adapter->hw))
1128 e1000_get_hw_control(adapter);
1130 return E1000_SUCCESS;
1133 e1000_free_all_rx_resources(adapter);
1135 e1000_free_all_tx_resources(adapter);
1137 e1000_reset(adapter);
1143 * e1000_close - Disables a network interface
1144 * @netdev: network interface device structure
1146 * Returns 0, this is not allowed to fail
1148 * The close entry point is called when an interface is de-activated
1149 * by the OS. The hardware is still under the drivers control, but
1150 * needs to be disabled. A global MAC reset is issued to stop the
1151 * hardware, and all transmit and receive resources are freed.
1155 e1000_close(struct net_device *netdev)
1157 struct e1000_adapter *adapter = netdev_priv(netdev);
1159 e1000_down(adapter);
1161 e1000_free_all_tx_resources(adapter);
1162 e1000_free_all_rx_resources(adapter);
1164 if ((adapter->hw.mng_cookie.status &
1165 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1166 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1169 /* If AMT is enabled, let the firmware know that the network
1170 * interface is now closed */
1171 if (adapter->hw.mac_type == e1000_82573 &&
1172 e1000_check_mng_mode(&adapter->hw))
1173 e1000_release_hw_control(adapter);
1179 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1180 * @adapter: address of board private structure
1181 * @start: address of beginning of memory
1182 * @len: length of memory
1184 static inline boolean_t
1185 e1000_check_64k_bound(struct e1000_adapter *adapter,
1186 void *start, unsigned long len)
1188 unsigned long begin = (unsigned long) start;
1189 unsigned long end = begin + len;
1191 /* First rev 82545 and 82546 need to not allow any memory
1192 * write location to cross 64k boundary due to errata 23 */
1193 if (adapter->hw.mac_type == e1000_82545 ||
1194 adapter->hw.mac_type == e1000_82546) {
1195 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1202 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1203 * @adapter: board private structure
1204 * @txdr: tx descriptor ring (for a specific queue) to setup
1206 * Return 0 on success, negative on failure
1210 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1211 struct e1000_tx_ring *txdr)
1213 struct pci_dev *pdev = adapter->pdev;
1216 size = sizeof(struct e1000_buffer) * txdr->count;
1218 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1219 if (!txdr->buffer_info) {
1221 "Unable to allocate memory for the transmit descriptor ring\n");
1224 memset(txdr->buffer_info, 0, size);
1226 /* round up to nearest 4K */
1228 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1229 E1000_ROUNDUP(txdr->size, 4096);
1231 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1234 vfree(txdr->buffer_info);
1236 "Unable to allocate memory for the transmit descriptor ring\n");
1240 /* Fix for errata 23, can't cross 64kB boundary */
1241 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1242 void *olddesc = txdr->desc;
1243 dma_addr_t olddma = txdr->dma;
1244 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1245 "at %p\n", txdr->size, txdr->desc);
1246 /* Try again, without freeing the previous */
1247 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1248 /* Failed allocation, critical failure */
1250 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1251 goto setup_tx_desc_die;
1254 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1256 pci_free_consistent(pdev, txdr->size, txdr->desc,
1258 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1260 "Unable to allocate aligned memory "
1261 "for the transmit descriptor ring\n");
1262 vfree(txdr->buffer_info);
1265 /* Free old allocation, new allocation was successful */
1266 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1269 memset(txdr->desc, 0, txdr->size);
1271 txdr->next_to_use = 0;
1272 txdr->next_to_clean = 0;
1273 spin_lock_init(&txdr->tx_lock);
1279 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1280 * (Descriptors) for all queues
1281 * @adapter: board private structure
1283 * If this function returns with an error, then it's possible one or
1284 * more of the rings is populated (while the rest are not). It is the
1285 * callers duty to clean those orphaned rings.
1287 * Return 0 on success, negative on failure
1291 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1295 for (i = 0; i < adapter->num_tx_queues; i++) {
1296 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1299 "Allocation for Tx Queue %u failed\n", i);
1308 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1309 * @adapter: board private structure
1311 * Configure the Tx unit of the MAC after a reset.
1315 e1000_configure_tx(struct e1000_adapter *adapter)
1318 struct e1000_hw *hw = &adapter->hw;
1319 uint32_t tdlen, tctl, tipg, tarc;
1320 uint32_t ipgr1, ipgr2;
1322 /* Setup the HW Tx Head and Tail descriptor pointers */
1324 switch (adapter->num_tx_queues) {
1327 tdba = adapter->tx_ring[0].dma;
1328 tdlen = adapter->tx_ring[0].count *
1329 sizeof(struct e1000_tx_desc);
1330 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1331 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1332 E1000_WRITE_REG(hw, TDLEN, tdlen);
1333 E1000_WRITE_REG(hw, TDH, 0);
1334 E1000_WRITE_REG(hw, TDT, 0);
1335 adapter->tx_ring[0].tdh = E1000_TDH;
1336 adapter->tx_ring[0].tdt = E1000_TDT;
1340 /* Set the default values for the Tx Inter Packet Gap timer */
1342 if (hw->media_type == e1000_media_type_fiber ||
1343 hw->media_type == e1000_media_type_internal_serdes)
1344 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1346 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1348 switch (hw->mac_type) {
1349 case e1000_82542_rev2_0:
1350 case e1000_82542_rev2_1:
1351 tipg = DEFAULT_82542_TIPG_IPGT;
1352 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1353 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1355 case e1000_80003es2lan:
1356 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1357 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1360 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1361 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1364 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1365 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1366 E1000_WRITE_REG(hw, TIPG, tipg);
1368 /* Set the Tx Interrupt Delay register */
1370 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1371 if (hw->mac_type >= e1000_82540)
1372 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1374 /* Program the Transmit Control Register */
1376 tctl = E1000_READ_REG(hw, TCTL);
1378 tctl &= ~E1000_TCTL_CT;
1379 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1380 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1383 /* disable Multiple Reads for debugging */
1384 tctl &= ~E1000_TCTL_MULR;
1387 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1388 tarc = E1000_READ_REG(hw, TARC0);
1389 tarc |= ((1 << 25) | (1 << 21));
1390 E1000_WRITE_REG(hw, TARC0, tarc);
1391 tarc = E1000_READ_REG(hw, TARC1);
1393 if (tctl & E1000_TCTL_MULR)
1397 E1000_WRITE_REG(hw, TARC1, tarc);
1398 } else if (hw->mac_type == e1000_80003es2lan) {
1399 tarc = E1000_READ_REG(hw, TARC0);
1401 if (hw->media_type == e1000_media_type_internal_serdes)
1403 E1000_WRITE_REG(hw, TARC0, tarc);
1404 tarc = E1000_READ_REG(hw, TARC1);
1406 E1000_WRITE_REG(hw, TARC1, tarc);
1409 e1000_config_collision_dist(hw);
1411 /* Setup Transmit Descriptor Settings for eop descriptor */
1412 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1415 if (hw->mac_type < e1000_82543)
1416 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1418 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1420 /* Cache if we're 82544 running in PCI-X because we'll
1421 * need this to apply a workaround later in the send path. */
1422 if (hw->mac_type == e1000_82544 &&
1423 hw->bus_type == e1000_bus_type_pcix)
1424 adapter->pcix_82544 = 1;
1426 E1000_WRITE_REG(hw, TCTL, tctl);
1431 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1432 * @adapter: board private structure
1433 * @rxdr: rx descriptor ring (for a specific queue) to setup
1435 * Returns 0 on success, negative on failure
1439 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1440 struct e1000_rx_ring *rxdr)
1442 struct pci_dev *pdev = adapter->pdev;
1445 size = sizeof(struct e1000_buffer) * rxdr->count;
1446 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1447 if (!rxdr->buffer_info) {
1449 "Unable to allocate memory for the receive descriptor ring\n");
1452 memset(rxdr->buffer_info, 0, size);
1454 size = sizeof(struct e1000_ps_page) * rxdr->count;
1455 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1456 if (!rxdr->ps_page) {
1457 vfree(rxdr->buffer_info);
1459 "Unable to allocate memory for the receive descriptor ring\n");
1462 memset(rxdr->ps_page, 0, size);
1464 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1465 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1466 if (!rxdr->ps_page_dma) {
1467 vfree(rxdr->buffer_info);
1468 kfree(rxdr->ps_page);
1470 "Unable to allocate memory for the receive descriptor ring\n");
1473 memset(rxdr->ps_page_dma, 0, size);
1475 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1476 desc_len = sizeof(struct e1000_rx_desc);
1478 desc_len = sizeof(union e1000_rx_desc_packet_split);
1480 /* Round up to nearest 4K */
1482 rxdr->size = rxdr->count * desc_len;
1483 E1000_ROUNDUP(rxdr->size, 4096);
1485 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1489 "Unable to allocate memory for the receive descriptor ring\n");
1491 vfree(rxdr->buffer_info);
1492 kfree(rxdr->ps_page);
1493 kfree(rxdr->ps_page_dma);
1497 /* Fix for errata 23, can't cross 64kB boundary */
1498 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1499 void *olddesc = rxdr->desc;
1500 dma_addr_t olddma = rxdr->dma;
1501 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1502 "at %p\n", rxdr->size, rxdr->desc);
1503 /* Try again, without freeing the previous */
1504 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1505 /* Failed allocation, critical failure */
1507 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1509 "Unable to allocate memory "
1510 "for the receive descriptor ring\n");
1511 goto setup_rx_desc_die;
1514 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1516 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1518 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1520 "Unable to allocate aligned memory "
1521 "for the receive descriptor ring\n");
1522 goto setup_rx_desc_die;
1524 /* Free old allocation, new allocation was successful */
1525 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1528 memset(rxdr->desc, 0, rxdr->size);
1530 rxdr->next_to_clean = 0;
1531 rxdr->next_to_use = 0;
1537 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1538 * (Descriptors) for all queues
1539 * @adapter: board private structure
1541 * If this function returns with an error, then it's possible one or
1542 * more of the rings is populated (while the rest are not). It is the
1543 * callers duty to clean those orphaned rings.
1545 * Return 0 on success, negative on failure
1549 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1553 for (i = 0; i < adapter->num_rx_queues; i++) {
1554 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1557 "Allocation for Rx Queue %u failed\n", i);
1566 * e1000_setup_rctl - configure the receive control registers
1567 * @adapter: Board private structure
1569 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1570 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1572 e1000_setup_rctl(struct e1000_adapter *adapter)
1574 uint32_t rctl, rfctl;
1575 uint32_t psrctl = 0;
1576 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1580 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1582 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1584 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1585 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1586 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1588 if (adapter->hw.mac_type > e1000_82543)
1589 rctl |= E1000_RCTL_SECRC;
1591 if (adapter->hw.tbi_compatibility_on == 1)
1592 rctl |= E1000_RCTL_SBP;
1594 rctl &= ~E1000_RCTL_SBP;
1596 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1597 rctl &= ~E1000_RCTL_LPE;
1599 rctl |= E1000_RCTL_LPE;
1601 /* Setup buffer sizes */
1602 if (adapter->hw.mac_type >= e1000_82571) {
1603 /* We can now specify buffers in 1K increments.
1604 * BSIZE and BSEX are ignored in this case. */
1605 rctl |= adapter->rx_buffer_len << 0x11;
1607 rctl &= ~E1000_RCTL_SZ_4096;
1608 rctl |= E1000_RCTL_BSEX;
1609 switch (adapter->rx_buffer_len) {
1610 case E1000_RXBUFFER_2048:
1612 rctl |= E1000_RCTL_SZ_2048;
1613 rctl &= ~E1000_RCTL_BSEX;
1615 case E1000_RXBUFFER_4096:
1616 rctl |= E1000_RCTL_SZ_4096;
1618 case E1000_RXBUFFER_8192:
1619 rctl |= E1000_RCTL_SZ_8192;
1621 case E1000_RXBUFFER_16384:
1622 rctl |= E1000_RCTL_SZ_16384;
1627 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1628 /* 82571 and greater support packet-split where the protocol
1629 * header is placed in skb->data and the packet data is
1630 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1631 * In the case of a non-split, skb->data is linearly filled,
1632 * followed by the page buffers. Therefore, skb->data is
1633 * sized to hold the largest protocol header.
1635 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1636 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1638 adapter->rx_ps_pages = pages;
1640 adapter->rx_ps_pages = 0;
1642 if (adapter->rx_ps_pages) {
1643 /* Configure extra packet-split registers */
1644 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1645 rfctl |= E1000_RFCTL_EXTEN;
1646 /* disable IPv6 packet split support */
1647 rfctl |= E1000_RFCTL_IPV6_DIS;
1648 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1650 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1652 psrctl |= adapter->rx_ps_bsize0 >>
1653 E1000_PSRCTL_BSIZE0_SHIFT;
1655 switch (adapter->rx_ps_pages) {
1657 psrctl |= PAGE_SIZE <<
1658 E1000_PSRCTL_BSIZE3_SHIFT;
1660 psrctl |= PAGE_SIZE <<
1661 E1000_PSRCTL_BSIZE2_SHIFT;
1663 psrctl |= PAGE_SIZE >>
1664 E1000_PSRCTL_BSIZE1_SHIFT;
1668 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1671 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1675 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1676 * @adapter: board private structure
1678 * Configure the Rx unit of the MAC after a reset.
1682 e1000_configure_rx(struct e1000_adapter *adapter)
1685 struct e1000_hw *hw = &adapter->hw;
1686 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1688 if (adapter->rx_ps_pages) {
1689 /* this is a 32 byte descriptor */
1690 rdlen = adapter->rx_ring[0].count *
1691 sizeof(union e1000_rx_desc_packet_split);
1692 adapter->clean_rx = e1000_clean_rx_irq_ps;
1693 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1695 rdlen = adapter->rx_ring[0].count *
1696 sizeof(struct e1000_rx_desc);
1697 adapter->clean_rx = e1000_clean_rx_irq;
1698 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1701 /* disable receives while setting up the descriptors */
1702 rctl = E1000_READ_REG(hw, RCTL);
1703 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1705 /* set the Receive Delay Timer Register */
1706 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1708 if (hw->mac_type >= e1000_82540) {
1709 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1710 if (adapter->itr > 1)
1711 E1000_WRITE_REG(hw, ITR,
1712 1000000000 / (adapter->itr * 256));
1715 if (hw->mac_type >= e1000_82571) {
1716 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1717 /* Reset delay timers after every interrupt */
1718 ctrl_ext |= E1000_CTRL_EXT_CANC;
1719 #ifdef CONFIG_E1000_NAPI
1720 /* Auto-Mask interrupts upon ICR read. */
1721 ctrl_ext |= E1000_CTRL_EXT_IAME;
1723 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1724 E1000_WRITE_REG(hw, IAM, ~0);
1725 E1000_WRITE_FLUSH(hw);
1728 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1729 * the Base and Length of the Rx Descriptor Ring */
1730 switch (adapter->num_rx_queues) {
1733 rdba = adapter->rx_ring[0].dma;
1734 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1735 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1736 E1000_WRITE_REG(hw, RDLEN, rdlen);
1737 E1000_WRITE_REG(hw, RDH, 0);
1738 E1000_WRITE_REG(hw, RDT, 0);
1739 adapter->rx_ring[0].rdh = E1000_RDH;
1740 adapter->rx_ring[0].rdt = E1000_RDT;
1744 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1745 if (hw->mac_type >= e1000_82543) {
1746 rxcsum = E1000_READ_REG(hw, RXCSUM);
1747 if (adapter->rx_csum == TRUE) {
1748 rxcsum |= E1000_RXCSUM_TUOFL;
1750 /* Enable 82571 IPv4 payload checksum for UDP fragments
1751 * Must be used in conjunction with packet-split. */
1752 if ((hw->mac_type >= e1000_82571) &&
1753 (adapter->rx_ps_pages)) {
1754 rxcsum |= E1000_RXCSUM_IPPCSE;
1757 rxcsum &= ~E1000_RXCSUM_TUOFL;
1758 /* don't need to clear IPPCSE as it defaults to 0 */
1760 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1763 if (hw->mac_type == e1000_82573)
1764 E1000_WRITE_REG(hw, ERT, 0x0100);
1766 /* Enable Receives */
1767 E1000_WRITE_REG(hw, RCTL, rctl);
1771 * e1000_free_tx_resources - Free Tx Resources per Queue
1772 * @adapter: board private structure
1773 * @tx_ring: Tx descriptor ring for a specific queue
1775 * Free all transmit software resources
1779 e1000_free_tx_resources(struct e1000_adapter *adapter,
1780 struct e1000_tx_ring *tx_ring)
1782 struct pci_dev *pdev = adapter->pdev;
1784 e1000_clean_tx_ring(adapter, tx_ring);
1786 vfree(tx_ring->buffer_info);
1787 tx_ring->buffer_info = NULL;
1789 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1791 tx_ring->desc = NULL;
1795 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1796 * @adapter: board private structure
1798 * Free all transmit software resources
1802 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1806 for (i = 0; i < adapter->num_tx_queues; i++)
1807 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1811 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1812 struct e1000_buffer *buffer_info)
1814 if (buffer_info->dma) {
1815 pci_unmap_page(adapter->pdev,
1817 buffer_info->length,
1820 if (buffer_info->skb)
1821 dev_kfree_skb_any(buffer_info->skb);
1822 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1826 * e1000_clean_tx_ring - Free Tx Buffers
1827 * @adapter: board private structure
1828 * @tx_ring: ring to be cleaned
1832 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1833 struct e1000_tx_ring *tx_ring)
1835 struct e1000_buffer *buffer_info;
1839 /* Free all the Tx ring sk_buffs */
1841 for (i = 0; i < tx_ring->count; i++) {
1842 buffer_info = &tx_ring->buffer_info[i];
1843 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1846 size = sizeof(struct e1000_buffer) * tx_ring->count;
1847 memset(tx_ring->buffer_info, 0, size);
1849 /* Zero out the descriptor ring */
1851 memset(tx_ring->desc, 0, tx_ring->size);
1853 tx_ring->next_to_use = 0;
1854 tx_ring->next_to_clean = 0;
1855 tx_ring->last_tx_tso = 0;
1857 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1858 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1862 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1863 * @adapter: board private structure
1867 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1871 for (i = 0; i < adapter->num_tx_queues; i++)
1872 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1876 * e1000_free_rx_resources - Free Rx Resources
1877 * @adapter: board private structure
1878 * @rx_ring: ring to clean the resources from
1880 * Free all receive software resources
1884 e1000_free_rx_resources(struct e1000_adapter *adapter,
1885 struct e1000_rx_ring *rx_ring)
1887 struct pci_dev *pdev = adapter->pdev;
1889 e1000_clean_rx_ring(adapter, rx_ring);
1891 vfree(rx_ring->buffer_info);
1892 rx_ring->buffer_info = NULL;
1893 kfree(rx_ring->ps_page);
1894 rx_ring->ps_page = NULL;
1895 kfree(rx_ring->ps_page_dma);
1896 rx_ring->ps_page_dma = NULL;
1898 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1900 rx_ring->desc = NULL;
1904 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1905 * @adapter: board private structure
1907 * Free all receive software resources
1911 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1915 for (i = 0; i < adapter->num_rx_queues; i++)
1916 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1920 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1921 * @adapter: board private structure
1922 * @rx_ring: ring to free buffers from
1926 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1927 struct e1000_rx_ring *rx_ring)
1929 struct e1000_buffer *buffer_info;
1930 struct e1000_ps_page *ps_page;
1931 struct e1000_ps_page_dma *ps_page_dma;
1932 struct pci_dev *pdev = adapter->pdev;
1936 /* Free all the Rx ring sk_buffs */
1937 for (i = 0; i < rx_ring->count; i++) {
1938 buffer_info = &rx_ring->buffer_info[i];
1939 if (buffer_info->skb) {
1940 pci_unmap_single(pdev,
1942 buffer_info->length,
1943 PCI_DMA_FROMDEVICE);
1945 dev_kfree_skb(buffer_info->skb);
1946 buffer_info->skb = NULL;
1948 ps_page = &rx_ring->ps_page[i];
1949 ps_page_dma = &rx_ring->ps_page_dma[i];
1950 for (j = 0; j < adapter->rx_ps_pages; j++) {
1951 if (!ps_page->ps_page[j]) break;
1952 pci_unmap_page(pdev,
1953 ps_page_dma->ps_page_dma[j],
1954 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1955 ps_page_dma->ps_page_dma[j] = 0;
1956 put_page(ps_page->ps_page[j]);
1957 ps_page->ps_page[j] = NULL;
1961 size = sizeof(struct e1000_buffer) * rx_ring->count;
1962 memset(rx_ring->buffer_info, 0, size);
1963 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1964 memset(rx_ring->ps_page, 0, size);
1965 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1966 memset(rx_ring->ps_page_dma, 0, size);
1968 /* Zero out the descriptor ring */
1970 memset(rx_ring->desc, 0, rx_ring->size);
1972 rx_ring->next_to_clean = 0;
1973 rx_ring->next_to_use = 0;
1975 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1976 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1980 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1981 * @adapter: board private structure
1985 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1989 for (i = 0; i < adapter->num_rx_queues; i++)
1990 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1993 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1994 * and memory write and invalidate disabled for certain operations
1997 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1999 struct net_device *netdev = adapter->netdev;
2002 e1000_pci_clear_mwi(&adapter->hw);
2004 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2005 rctl |= E1000_RCTL_RST;
2006 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2007 E1000_WRITE_FLUSH(&adapter->hw);
2010 if (netif_running(netdev))
2011 e1000_clean_all_rx_rings(adapter);
2015 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2017 struct net_device *netdev = adapter->netdev;
2020 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2021 rctl &= ~E1000_RCTL_RST;
2022 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2023 E1000_WRITE_FLUSH(&adapter->hw);
2026 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2027 e1000_pci_set_mwi(&adapter->hw);
2029 if (netif_running(netdev)) {
2030 /* No need to loop, because 82542 supports only 1 queue */
2031 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2032 e1000_configure_rx(adapter);
2033 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2038 * e1000_set_mac - Change the Ethernet Address of the NIC
2039 * @netdev: network interface device structure
2040 * @p: pointer to an address structure
2042 * Returns 0 on success, negative on failure
2046 e1000_set_mac(struct net_device *netdev, void *p)
2048 struct e1000_adapter *adapter = netdev_priv(netdev);
2049 struct sockaddr *addr = p;
2051 if (!is_valid_ether_addr(addr->sa_data))
2052 return -EADDRNOTAVAIL;
2054 /* 82542 2.0 needs to be in reset to write receive address registers */
2056 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2057 e1000_enter_82542_rst(adapter);
2059 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2060 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2062 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2064 /* With 82571 controllers, LAA may be overwritten (with the default)
2065 * due to controller reset from the other port. */
2066 if (adapter->hw.mac_type == e1000_82571) {
2067 /* activate the work around */
2068 adapter->hw.laa_is_present = 1;
2070 /* Hold a copy of the LAA in RAR[14] This is done so that
2071 * between the time RAR[0] gets clobbered and the time it
2072 * gets fixed (in e1000_watchdog), the actual LAA is in one
2073 * of the RARs and no incoming packets directed to this port
2074 * are dropped. Eventaully the LAA will be in RAR[0] and
2076 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2077 E1000_RAR_ENTRIES - 1);
2080 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2081 e1000_leave_82542_rst(adapter);
2087 * e1000_set_multi - Multicast and Promiscuous mode set
2088 * @netdev: network interface device structure
2090 * The set_multi entry point is called whenever the multicast address
2091 * list or the network interface flags are updated. This routine is
2092 * responsible for configuring the hardware for proper multicast,
2093 * promiscuous mode, and all-multi behavior.
2097 e1000_set_multi(struct net_device *netdev)
2099 struct e1000_adapter *adapter = netdev_priv(netdev);
2100 struct e1000_hw *hw = &adapter->hw;
2101 struct dev_mc_list *mc_ptr;
2103 uint32_t hash_value;
2104 int i, rar_entries = E1000_RAR_ENTRIES;
2106 /* reserve RAR[14] for LAA over-write work-around */
2107 if (adapter->hw.mac_type == e1000_82571)
2110 /* Check for Promiscuous and All Multicast modes */
2112 rctl = E1000_READ_REG(hw, RCTL);
2114 if (netdev->flags & IFF_PROMISC) {
2115 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2116 } else if (netdev->flags & IFF_ALLMULTI) {
2117 rctl |= E1000_RCTL_MPE;
2118 rctl &= ~E1000_RCTL_UPE;
2120 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2123 E1000_WRITE_REG(hw, RCTL, rctl);
2125 /* 82542 2.0 needs to be in reset to write receive address registers */
2127 if (hw->mac_type == e1000_82542_rev2_0)
2128 e1000_enter_82542_rst(adapter);
2130 /* load the first 14 multicast address into the exact filters 1-14
2131 * RAR 0 is used for the station MAC adddress
2132 * if there are not 14 addresses, go ahead and clear the filters
2133 * -- with 82571 controllers only 0-13 entries are filled here
2135 mc_ptr = netdev->mc_list;
2137 for (i = 1; i < rar_entries; i++) {
2139 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2140 mc_ptr = mc_ptr->next;
2142 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2143 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2147 /* clear the old settings from the multicast hash table */
2149 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2150 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2152 /* load any remaining addresses into the hash table */
2154 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2155 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2156 e1000_mta_set(hw, hash_value);
2159 if (hw->mac_type == e1000_82542_rev2_0)
2160 e1000_leave_82542_rst(adapter);
2163 /* Need to wait a few seconds after link up to get diagnostic information from
2167 e1000_update_phy_info(unsigned long data)
2169 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2170 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2174 * e1000_82547_tx_fifo_stall - Timer Call-back
2175 * @data: pointer to adapter cast into an unsigned long
2179 e1000_82547_tx_fifo_stall(unsigned long data)
2181 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2182 struct net_device *netdev = adapter->netdev;
2185 if (atomic_read(&adapter->tx_fifo_stall)) {
2186 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2187 E1000_READ_REG(&adapter->hw, TDH)) &&
2188 (E1000_READ_REG(&adapter->hw, TDFT) ==
2189 E1000_READ_REG(&adapter->hw, TDFH)) &&
2190 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2191 E1000_READ_REG(&adapter->hw, TDFHS))) {
2192 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2193 E1000_WRITE_REG(&adapter->hw, TCTL,
2194 tctl & ~E1000_TCTL_EN);
2195 E1000_WRITE_REG(&adapter->hw, TDFT,
2196 adapter->tx_head_addr);
2197 E1000_WRITE_REG(&adapter->hw, TDFH,
2198 adapter->tx_head_addr);
2199 E1000_WRITE_REG(&adapter->hw, TDFTS,
2200 adapter->tx_head_addr);
2201 E1000_WRITE_REG(&adapter->hw, TDFHS,
2202 adapter->tx_head_addr);
2203 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2204 E1000_WRITE_FLUSH(&adapter->hw);
2206 adapter->tx_fifo_head = 0;
2207 atomic_set(&adapter->tx_fifo_stall, 0);
2208 netif_wake_queue(netdev);
2210 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2216 * e1000_watchdog - Timer Call-back
2217 * @data: pointer to adapter cast into an unsigned long
2220 e1000_watchdog(unsigned long data)
2222 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2224 /* Do the rest outside of interrupt context */
2225 schedule_work(&adapter->watchdog_task);
2229 e1000_watchdog_task(struct e1000_adapter *adapter)
2231 struct net_device *netdev = adapter->netdev;
2232 struct e1000_tx_ring *txdr = adapter->tx_ring;
2233 uint32_t link, tctl;
2235 e1000_check_for_link(&adapter->hw);
2236 if (adapter->hw.mac_type == e1000_82573) {
2237 e1000_enable_tx_pkt_filtering(&adapter->hw);
2238 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2239 e1000_update_mng_vlan(adapter);
2242 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2243 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2244 link = !adapter->hw.serdes_link_down;
2246 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2249 if (!netif_carrier_ok(netdev)) {
2250 e1000_get_speed_and_duplex(&adapter->hw,
2251 &adapter->link_speed,
2252 &adapter->link_duplex);
2254 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2255 adapter->link_speed,
2256 adapter->link_duplex == FULL_DUPLEX ?
2257 "Full Duplex" : "Half Duplex");
2259 /* tweak tx_queue_len according to speed/duplex
2260 * and adjust the timeout factor */
2261 netdev->tx_queue_len = adapter->tx_queue_len;
2262 adapter->tx_timeout_factor = 1;
2264 switch (adapter->link_speed) {
2267 netdev->tx_queue_len = 10;
2268 adapter->tx_timeout_factor = 8;
2272 netdev->tx_queue_len = 100;
2273 /* maybe add some timeout factor ? */
2277 if ((adapter->hw.mac_type == e1000_82571 ||
2278 adapter->hw.mac_type == e1000_82572) &&
2279 adapter->txb2b == 0) {
2280 #define SPEED_MODE_BIT (1 << 21)
2282 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2283 tarc0 &= ~SPEED_MODE_BIT;
2284 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2288 /* disable TSO for pcie and 10/100 speeds, to avoid
2289 * some hardware issues */
2290 if (!adapter->tso_force &&
2291 adapter->hw.bus_type == e1000_bus_type_pci_express){
2292 switch (adapter->link_speed) {
2296 "10/100 speed: disabling TSO\n");
2297 netdev->features &= ~NETIF_F_TSO;
2300 netdev->features |= NETIF_F_TSO;
2309 /* enable transmits in the hardware, need to do this
2310 * after setting TARC0 */
2311 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2312 tctl |= E1000_TCTL_EN;
2313 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2315 netif_carrier_on(netdev);
2316 netif_wake_queue(netdev);
2317 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2318 adapter->smartspeed = 0;
2321 if (netif_carrier_ok(netdev)) {
2322 adapter->link_speed = 0;
2323 adapter->link_duplex = 0;
2324 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2325 netif_carrier_off(netdev);
2326 netif_stop_queue(netdev);
2327 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2329 /* 80003ES2LAN workaround--
2330 * For packet buffer work-around on link down event;
2331 * disable receives in the ISR and
2332 * reset device here in the watchdog
2334 if (adapter->hw.mac_type == e1000_80003es2lan) {
2336 schedule_work(&adapter->reset_task);
2340 e1000_smartspeed(adapter);
2343 e1000_update_stats(adapter);
2345 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2346 adapter->tpt_old = adapter->stats.tpt;
2347 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2348 adapter->colc_old = adapter->stats.colc;
2350 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2351 adapter->gorcl_old = adapter->stats.gorcl;
2352 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2353 adapter->gotcl_old = adapter->stats.gotcl;
2355 e1000_update_adaptive(&adapter->hw);
2357 if (!netif_carrier_ok(netdev)) {
2358 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2359 /* We've lost link, so the controller stops DMA,
2360 * but we've got queued Tx work that's never going
2361 * to get done, so reset controller to flush Tx.
2362 * (Do the reset outside of interrupt context). */
2363 adapter->tx_timeout_count++;
2364 schedule_work(&adapter->reset_task);
2368 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2369 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2370 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2371 * asymmetrical Tx or Rx gets ITR=8000; everyone
2372 * else is between 2000-8000. */
2373 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2374 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2375 adapter->gotcl - adapter->gorcl :
2376 adapter->gorcl - adapter->gotcl) / 10000;
2377 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2378 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2381 /* Cause software interrupt to ensure rx ring is cleaned */
2382 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2384 /* Force detection of hung controller every watchdog period */
2385 adapter->detect_tx_hung = TRUE;
2387 /* With 82571 controllers, LAA may be overwritten due to controller
2388 * reset from the other port. Set the appropriate LAA in RAR[0] */
2389 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2390 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2392 /* Reset the timer */
2393 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2396 #define E1000_TX_FLAGS_CSUM 0x00000001
2397 #define E1000_TX_FLAGS_VLAN 0x00000002
2398 #define E1000_TX_FLAGS_TSO 0x00000004
2399 #define E1000_TX_FLAGS_IPV4 0x00000008
2400 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2401 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2404 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2405 struct sk_buff *skb)
2408 struct e1000_context_desc *context_desc;
2409 struct e1000_buffer *buffer_info;
2411 uint32_t cmd_length = 0;
2412 uint16_t ipcse = 0, tucse, mss;
2413 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2416 if (skb_shinfo(skb)->tso_size) {
2417 if (skb_header_cloned(skb)) {
2418 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2423 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2424 mss = skb_shinfo(skb)->tso_size;
2425 if (skb->protocol == ntohs(ETH_P_IP)) {
2426 skb->nh.iph->tot_len = 0;
2427 skb->nh.iph->check = 0;
2429 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2434 cmd_length = E1000_TXD_CMD_IP;
2435 ipcse = skb->h.raw - skb->data - 1;
2436 #ifdef NETIF_F_TSO_IPV6
2437 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2438 skb->nh.ipv6h->payload_len = 0;
2440 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2441 &skb->nh.ipv6h->daddr,
2448 ipcss = skb->nh.raw - skb->data;
2449 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2450 tucss = skb->h.raw - skb->data;
2451 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2454 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2455 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2457 i = tx_ring->next_to_use;
2458 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2459 buffer_info = &tx_ring->buffer_info[i];
2461 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2462 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2463 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2464 context_desc->upper_setup.tcp_fields.tucss = tucss;
2465 context_desc->upper_setup.tcp_fields.tucso = tucso;
2466 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2467 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2468 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2469 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2471 buffer_info->time_stamp = jiffies;
2473 if (++i == tx_ring->count) i = 0;
2474 tx_ring->next_to_use = i;
2483 static inline boolean_t
2484 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2485 struct sk_buff *skb)
2487 struct e1000_context_desc *context_desc;
2488 struct e1000_buffer *buffer_info;
2492 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2493 css = skb->h.raw - skb->data;
2495 i = tx_ring->next_to_use;
2496 buffer_info = &tx_ring->buffer_info[i];
2497 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2499 context_desc->upper_setup.tcp_fields.tucss = css;
2500 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2501 context_desc->upper_setup.tcp_fields.tucse = 0;
2502 context_desc->tcp_seg_setup.data = 0;
2503 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2505 buffer_info->time_stamp = jiffies;
2507 if (unlikely(++i == tx_ring->count)) i = 0;
2508 tx_ring->next_to_use = i;
2516 #define E1000_MAX_TXD_PWR 12
2517 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2520 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2521 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2522 unsigned int nr_frags, unsigned int mss)
2524 struct e1000_buffer *buffer_info;
2525 unsigned int len = skb->len;
2526 unsigned int offset = 0, size, count = 0, i;
2528 len -= skb->data_len;
2530 i = tx_ring->next_to_use;
2533 buffer_info = &tx_ring->buffer_info[i];
2534 size = min(len, max_per_txd);
2536 /* Workaround for Controller erratum --
2537 * descriptor for non-tso packet in a linear SKB that follows a
2538 * tso gets written back prematurely before the data is fully
2539 * DMA'd to the controller */
2540 if (!skb->data_len && tx_ring->last_tx_tso &&
2541 !skb_shinfo(skb)->tso_size) {
2542 tx_ring->last_tx_tso = 0;
2546 /* Workaround for premature desc write-backs
2547 * in TSO mode. Append 4-byte sentinel desc */
2548 if (unlikely(mss && !nr_frags && size == len && size > 8))
2551 /* work-around for errata 10 and it applies
2552 * to all controllers in PCI-X mode
2553 * The fix is to make sure that the first descriptor of a
2554 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2556 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2557 (size > 2015) && count == 0))
2560 /* Workaround for potential 82544 hang in PCI-X. Avoid
2561 * terminating buffers within evenly-aligned dwords. */
2562 if (unlikely(adapter->pcix_82544 &&
2563 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2567 buffer_info->length = size;
2569 pci_map_single(adapter->pdev,
2573 buffer_info->time_stamp = jiffies;
2578 if (unlikely(++i == tx_ring->count)) i = 0;
2581 for (f = 0; f < nr_frags; f++) {
2582 struct skb_frag_struct *frag;
2584 frag = &skb_shinfo(skb)->frags[f];
2586 offset = frag->page_offset;
2589 buffer_info = &tx_ring->buffer_info[i];
2590 size = min(len, max_per_txd);
2592 /* Workaround for premature desc write-backs
2593 * in TSO mode. Append 4-byte sentinel desc */
2594 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2597 /* Workaround for potential 82544 hang in PCI-X.
2598 * Avoid terminating buffers within evenly-aligned
2600 if (unlikely(adapter->pcix_82544 &&
2601 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2605 buffer_info->length = size;
2607 pci_map_page(adapter->pdev,
2612 buffer_info->time_stamp = jiffies;
2617 if (unlikely(++i == tx_ring->count)) i = 0;
2621 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2622 tx_ring->buffer_info[i].skb = skb;
2623 tx_ring->buffer_info[first].next_to_watch = i;
2629 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2630 int tx_flags, int count)
2632 struct e1000_tx_desc *tx_desc = NULL;
2633 struct e1000_buffer *buffer_info;
2634 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2637 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2638 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2640 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2642 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2643 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2646 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2647 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2648 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2651 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2652 txd_lower |= E1000_TXD_CMD_VLE;
2653 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2656 i = tx_ring->next_to_use;
2659 buffer_info = &tx_ring->buffer_info[i];
2660 tx_desc = E1000_TX_DESC(*tx_ring, i);
2661 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2662 tx_desc->lower.data =
2663 cpu_to_le32(txd_lower | buffer_info->length);
2664 tx_desc->upper.data = cpu_to_le32(txd_upper);
2665 if (unlikely(++i == tx_ring->count)) i = 0;
2668 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2670 /* Force memory writes to complete before letting h/w
2671 * know there are new descriptors to fetch. (Only
2672 * applicable for weak-ordered memory model archs,
2673 * such as IA-64). */
2676 tx_ring->next_to_use = i;
2677 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2681 * 82547 workaround to avoid controller hang in half-duplex environment.
2682 * The workaround is to avoid queuing a large packet that would span
2683 * the internal Tx FIFO ring boundary by notifying the stack to resend
2684 * the packet at a later time. This gives the Tx FIFO an opportunity to
2685 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2686 * to the beginning of the Tx FIFO.
2689 #define E1000_FIFO_HDR 0x10
2690 #define E1000_82547_PAD_LEN 0x3E0
2693 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2695 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2696 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2698 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2700 if (adapter->link_duplex != HALF_DUPLEX)
2701 goto no_fifo_stall_required;
2703 if (atomic_read(&adapter->tx_fifo_stall))
2706 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2707 atomic_set(&adapter->tx_fifo_stall, 1);
2711 no_fifo_stall_required:
2712 adapter->tx_fifo_head += skb_fifo_len;
2713 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2714 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2718 #define MINIMUM_DHCP_PACKET_SIZE 282
2720 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2722 struct e1000_hw *hw = &adapter->hw;
2723 uint16_t length, offset;
2724 if (vlan_tx_tag_present(skb)) {
2725 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2726 ( adapter->hw.mng_cookie.status &
2727 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2730 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
2731 struct ethhdr *eth = (struct ethhdr *) skb->data;
2732 if ((htons(ETH_P_IP) == eth->h_proto)) {
2733 const struct iphdr *ip =
2734 (struct iphdr *)((uint8_t *)skb->data+14);
2735 if (IPPROTO_UDP == ip->protocol) {
2736 struct udphdr *udp =
2737 (struct udphdr *)((uint8_t *)ip +
2739 if (ntohs(udp->dest) == 67) {
2740 offset = (uint8_t *)udp + 8 - skb->data;
2741 length = skb->len - offset;
2743 return e1000_mng_write_dhcp_info(hw,
2753 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2755 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2757 struct e1000_adapter *adapter = netdev_priv(netdev);
2758 struct e1000_tx_ring *tx_ring;
2759 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2760 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2761 unsigned int tx_flags = 0;
2762 unsigned int len = skb->len;
2763 unsigned long flags;
2764 unsigned int nr_frags = 0;
2765 unsigned int mss = 0;
2769 len -= skb->data_len;
2771 tx_ring = adapter->tx_ring;
2773 if (unlikely(skb->len <= 0)) {
2774 dev_kfree_skb_any(skb);
2775 return NETDEV_TX_OK;
2779 mss = skb_shinfo(skb)->tso_size;
2780 /* The controller does a simple calculation to
2781 * make sure there is enough room in the FIFO before
2782 * initiating the DMA for each buffer. The calc is:
2783 * 4 = ceil(buffer len/mss). To make sure we don't
2784 * overrun the FIFO, adjust the max buffer len if mss
2788 max_per_txd = min(mss << 2, max_per_txd);
2789 max_txd_pwr = fls(max_per_txd) - 1;
2791 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2792 * points to just header, pull a few bytes of payload from
2793 * frags into skb->data */
2794 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2795 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2796 switch (adapter->hw.mac_type) {
2797 unsigned int pull_size;
2801 pull_size = min((unsigned int)4, skb->data_len);
2802 if (!__pskb_pull_tail(skb, pull_size)) {
2804 "__pskb_pull_tail failed.\n");
2805 dev_kfree_skb_any(skb);
2806 return NETDEV_TX_OK;
2808 len = skb->len - skb->data_len;
2817 /* reserve a descriptor for the offload context */
2818 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2822 if (skb->ip_summed == CHECKSUM_HW)
2827 /* Controller Erratum workaround */
2828 if (!skb->data_len && tx_ring->last_tx_tso &&
2829 !skb_shinfo(skb)->tso_size)
2833 count += TXD_USE_COUNT(len, max_txd_pwr);
2835 if (adapter->pcix_82544)
2838 /* work-around for errata 10 and it applies to all controllers
2839 * in PCI-X mode, so add one more descriptor to the count
2841 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2845 nr_frags = skb_shinfo(skb)->nr_frags;
2846 for (f = 0; f < nr_frags; f++)
2847 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2849 if (adapter->pcix_82544)
2853 if (adapter->hw.tx_pkt_filtering &&
2854 (adapter->hw.mac_type == e1000_82573))
2855 e1000_transfer_dhcp_info(adapter, skb);
2857 local_irq_save(flags);
2858 if (!spin_trylock(&tx_ring->tx_lock)) {
2859 /* Collision - tell upper layer to requeue */
2860 local_irq_restore(flags);
2861 return NETDEV_TX_LOCKED;
2864 /* need: count + 2 desc gap to keep tail from touching
2865 * head, otherwise try next time */
2866 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2867 netif_stop_queue(netdev);
2868 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2869 return NETDEV_TX_BUSY;
2872 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2873 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2874 netif_stop_queue(netdev);
2875 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2876 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2877 return NETDEV_TX_BUSY;
2881 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2882 tx_flags |= E1000_TX_FLAGS_VLAN;
2883 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2886 first = tx_ring->next_to_use;
2888 tso = e1000_tso(adapter, tx_ring, skb);
2890 dev_kfree_skb_any(skb);
2891 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2892 return NETDEV_TX_OK;
2896 tx_ring->last_tx_tso = 1;
2897 tx_flags |= E1000_TX_FLAGS_TSO;
2898 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2899 tx_flags |= E1000_TX_FLAGS_CSUM;
2901 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2902 * 82571 hardware supports TSO capabilities for IPv6 as well...
2903 * no longer assume, we must. */
2904 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2905 tx_flags |= E1000_TX_FLAGS_IPV4;
2907 e1000_tx_queue(adapter, tx_ring, tx_flags,
2908 e1000_tx_map(adapter, tx_ring, skb, first,
2909 max_per_txd, nr_frags, mss));
2911 netdev->trans_start = jiffies;
2913 /* Make sure there is space in the ring for the next send. */
2914 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2915 netif_stop_queue(netdev);
2917 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2918 return NETDEV_TX_OK;
2922 * e1000_tx_timeout - Respond to a Tx Hang
2923 * @netdev: network interface device structure
2927 e1000_tx_timeout(struct net_device *netdev)
2929 struct e1000_adapter *adapter = netdev_priv(netdev);
2931 /* Do the reset outside of interrupt context */
2932 adapter->tx_timeout_count++;
2933 schedule_work(&adapter->reset_task);
2937 e1000_reset_task(struct net_device *netdev)
2939 struct e1000_adapter *adapter = netdev_priv(netdev);
2941 e1000_down(adapter);
2946 * e1000_get_stats - Get System Network Statistics
2947 * @netdev: network interface device structure
2949 * Returns the address of the device statistics structure.
2950 * The statistics are actually updated from the timer callback.
2953 static struct net_device_stats *
2954 e1000_get_stats(struct net_device *netdev)
2956 struct e1000_adapter *adapter = netdev_priv(netdev);
2958 /* only return the current stats */
2959 return &adapter->net_stats;
2963 * e1000_change_mtu - Change the Maximum Transfer Unit
2964 * @netdev: network interface device structure
2965 * @new_mtu: new value for maximum frame size
2967 * Returns 0 on success, negative on failure
2971 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2973 struct e1000_adapter *adapter = netdev_priv(netdev);
2974 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2975 uint16_t eeprom_data = 0;
2977 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2978 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2979 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2983 /* Adapter-specific max frame size limits. */
2984 switch (adapter->hw.mac_type) {
2985 case e1000_82542_rev2_0:
2986 case e1000_82542_rev2_1:
2987 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2988 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
2993 /* only enable jumbo frames if ASPM is disabled completely
2994 * this means both bits must be zero in 0x1A bits 3:2 */
2995 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
2997 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
2998 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3000 "Jumbo Frames not supported.\n");
3005 /* fall through to get support */
3008 case e1000_80003es2lan:
3009 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3010 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3011 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3016 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3021 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3022 adapter->rx_buffer_len = max_frame;
3023 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3025 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
3026 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
3027 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
3031 if(max_frame <= E1000_RXBUFFER_2048)
3032 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3033 else if(max_frame <= E1000_RXBUFFER_4096)
3034 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3035 else if(max_frame <= E1000_RXBUFFER_8192)
3036 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3037 else if(max_frame <= E1000_RXBUFFER_16384)
3038 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3042 netdev->mtu = new_mtu;
3044 if (netif_running(netdev)) {
3045 e1000_down(adapter);
3049 adapter->hw.max_frame_size = max_frame;
3055 * e1000_update_stats - Update the board statistics counters
3056 * @adapter: board private structure
3060 e1000_update_stats(struct e1000_adapter *adapter)
3062 struct e1000_hw *hw = &adapter->hw;
3063 unsigned long flags;
3066 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3068 spin_lock_irqsave(&adapter->stats_lock, flags);
3070 /* these counters are modified from e1000_adjust_tbi_stats,
3071 * called from the interrupt context, so they must only
3072 * be written while holding adapter->stats_lock
3075 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3076 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3077 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3078 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3079 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3080 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3081 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3082 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3083 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3084 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3085 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3086 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3087 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3089 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3090 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3091 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3092 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3093 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3094 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3095 adapter->stats.dc += E1000_READ_REG(hw, DC);
3096 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3097 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3098 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3099 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3100 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3101 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3102 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3103 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3104 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3105 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3106 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3107 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3108 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3109 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3110 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3111 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3112 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3113 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3114 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3115 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3116 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3117 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3118 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3119 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3120 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3121 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3122 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3124 /* used for adaptive IFS */
3126 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3127 adapter->stats.tpt += hw->tx_packet_delta;
3128 hw->collision_delta = E1000_READ_REG(hw, COLC);
3129 adapter->stats.colc += hw->collision_delta;
3131 if (hw->mac_type >= e1000_82543) {
3132 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3133 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3134 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3135 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3136 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3137 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3139 if (hw->mac_type > e1000_82547_rev_2) {
3140 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3141 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3142 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3143 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3144 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3145 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3146 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3147 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3148 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3151 /* Fill out the OS statistics structure */
3153 adapter->net_stats.rx_packets = adapter->stats.gprc;
3154 adapter->net_stats.tx_packets = adapter->stats.gptc;
3155 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3156 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3157 adapter->net_stats.multicast = adapter->stats.mprc;
3158 adapter->net_stats.collisions = adapter->stats.colc;
3162 /* RLEC on some newer hardware can be incorrect so build
3163 * our own version based on RUC and ROC */
3164 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3165 adapter->stats.crcerrs + adapter->stats.algnerrc +
3166 adapter->stats.ruc + adapter->stats.roc +
3167 adapter->stats.cexterr;
3168 adapter->net_stats.rx_dropped = 0;
3169 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3171 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3172 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3173 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3177 adapter->net_stats.tx_errors = adapter->stats.ecol +
3178 adapter->stats.latecol;
3179 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3180 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3181 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3183 /* Tx Dropped needs to be maintained elsewhere */
3187 if (hw->media_type == e1000_media_type_copper) {
3188 if ((adapter->link_speed == SPEED_1000) &&
3189 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3190 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3191 adapter->phy_stats.idle_errors += phy_tmp;
3194 if ((hw->mac_type <= e1000_82546) &&
3195 (hw->phy_type == e1000_phy_m88) &&
3196 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3197 adapter->phy_stats.receive_errors += phy_tmp;
3200 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3204 * e1000_intr - Interrupt Handler
3205 * @irq: interrupt number
3206 * @data: pointer to a network interface device structure
3207 * @pt_regs: CPU registers structure
3211 e1000_intr(int irq, void *data, struct pt_regs *regs)
3213 struct net_device *netdev = data;
3214 struct e1000_adapter *adapter = netdev_priv(netdev);
3215 struct e1000_hw *hw = &adapter->hw;
3216 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
3217 #ifndef CONFIG_E1000_NAPI
3220 /* Interrupt Auto-Mask...upon reading ICR,
3221 * interrupts are masked. No need for the
3222 * IMC write, but it does mean we should
3223 * account for it ASAP. */
3224 if (likely(hw->mac_type >= e1000_82571))
3225 atomic_inc(&adapter->irq_sem);
3228 if (unlikely(!icr)) {
3229 #ifdef CONFIG_E1000_NAPI
3230 if (hw->mac_type >= e1000_82571)
3231 e1000_irq_enable(adapter);
3233 return IRQ_NONE; /* Not our interrupt */
3236 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3237 hw->get_link_status = 1;
3238 /* 80003ES2LAN workaround--
3239 * For packet buffer work-around on link down event;
3240 * disable receives here in the ISR and
3241 * reset adapter in watchdog
3243 if (netif_carrier_ok(netdev) &&
3244 (adapter->hw.mac_type == e1000_80003es2lan)) {
3245 /* disable receives */
3246 rctl = E1000_READ_REG(hw, RCTL);
3247 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3249 mod_timer(&adapter->watchdog_timer, jiffies);
3252 #ifdef CONFIG_E1000_NAPI
3253 if (unlikely(hw->mac_type < e1000_82571)) {
3254 atomic_inc(&adapter->irq_sem);
3255 E1000_WRITE_REG(hw, IMC, ~0);
3256 E1000_WRITE_FLUSH(hw);
3258 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3259 __netif_rx_schedule(&adapter->polling_netdev[0]);
3261 e1000_irq_enable(adapter);
3263 /* Writing IMC and IMS is needed for 82547.
3264 * Due to Hub Link bus being occupied, an interrupt
3265 * de-assertion message is not able to be sent.
3266 * When an interrupt assertion message is generated later,
3267 * two messages are re-ordered and sent out.
3268 * That causes APIC to think 82547 is in de-assertion
3269 * state, while 82547 is in assertion state, resulting
3270 * in dead lock. Writing IMC forces 82547 into
3271 * de-assertion state.
3273 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3274 atomic_inc(&adapter->irq_sem);
3275 E1000_WRITE_REG(hw, IMC, ~0);
3278 for (i = 0; i < E1000_MAX_INTR; i++)
3279 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3280 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3283 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3284 e1000_irq_enable(adapter);
3291 #ifdef CONFIG_E1000_NAPI
3293 * e1000_clean - NAPI Rx polling callback
3294 * @adapter: board private structure
3298 e1000_clean(struct net_device *poll_dev, int *budget)
3300 struct e1000_adapter *adapter;
3301 int work_to_do = min(*budget, poll_dev->quota);
3302 int tx_cleaned = 0, i = 0, work_done = 0;
3304 /* Must NOT use netdev_priv macro here. */
3305 adapter = poll_dev->priv;
3307 /* Keep link state information with original netdev */
3308 if (!netif_carrier_ok(adapter->netdev))
3311 while (poll_dev != &adapter->polling_netdev[i]) {
3313 BUG_ON(i == adapter->num_rx_queues);
3316 if (likely(adapter->num_tx_queues == 1)) {
3317 /* e1000_clean is called per-cpu. This lock protects
3318 * tx_ring[0] from being cleaned by multiple cpus
3319 * simultaneously. A failure obtaining the lock means
3320 * tx_ring[0] is currently being cleaned anyway. */
3321 if (spin_trylock(&adapter->tx_queue_lock)) {
3322 tx_cleaned = e1000_clean_tx_irq(adapter,
3323 &adapter->tx_ring[0]);
3324 spin_unlock(&adapter->tx_queue_lock);
3327 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3329 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3330 &work_done, work_to_do);
3332 *budget -= work_done;
3333 poll_dev->quota -= work_done;
3335 /* If no Tx and not enough Rx work done, exit the polling mode */
3336 if ((!tx_cleaned && (work_done == 0)) ||
3337 !netif_running(adapter->netdev)) {
3339 netif_rx_complete(poll_dev);
3340 e1000_irq_enable(adapter);
3349 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3350 * @adapter: board private structure
3354 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3355 struct e1000_tx_ring *tx_ring)
3357 struct net_device *netdev = adapter->netdev;
3358 struct e1000_tx_desc *tx_desc, *eop_desc;
3359 struct e1000_buffer *buffer_info;
3360 unsigned int i, eop;
3361 #ifdef CONFIG_E1000_NAPI
3362 unsigned int count = 0;
3364 boolean_t cleaned = FALSE;
3366 i = tx_ring->next_to_clean;
3367 eop = tx_ring->buffer_info[i].next_to_watch;
3368 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3370 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3371 for (cleaned = FALSE; !cleaned; ) {
3372 tx_desc = E1000_TX_DESC(*tx_ring, i);
3373 buffer_info = &tx_ring->buffer_info[i];
3374 cleaned = (i == eop);
3376 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3377 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3379 if (unlikely(++i == tx_ring->count)) i = 0;
3383 eop = tx_ring->buffer_info[i].next_to_watch;
3384 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3385 #ifdef CONFIG_E1000_NAPI
3386 #define E1000_TX_WEIGHT 64
3387 /* weight of a sort for tx, to avoid endless transmit cleanup */
3388 if (count++ == E1000_TX_WEIGHT) break;
3392 tx_ring->next_to_clean = i;
3394 spin_lock(&tx_ring->tx_lock);
3396 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3397 netif_carrier_ok(netdev)))
3398 netif_wake_queue(netdev);
3400 spin_unlock(&tx_ring->tx_lock);
3402 if (adapter->detect_tx_hung) {
3403 /* Detect a transmit hang in hardware, this serializes the
3404 * check with the clearing of time_stamp and movement of i */
3405 adapter->detect_tx_hung = FALSE;
3406 if (tx_ring->buffer_info[eop].dma &&
3407 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3408 (adapter->tx_timeout_factor * HZ))
3409 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3410 E1000_STATUS_TXOFF)) {
3412 /* detected Tx unit hang */
3413 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3417 " next_to_use <%x>\n"
3418 " next_to_clean <%x>\n"
3419 "buffer_info[next_to_clean]\n"
3420 " time_stamp <%lx>\n"
3421 " next_to_watch <%x>\n"
3423 " next_to_watch.status <%x>\n",
3424 (unsigned long)((tx_ring - adapter->tx_ring) /
3425 sizeof(struct e1000_tx_ring)),
3426 readl(adapter->hw.hw_addr + tx_ring->tdh),
3427 readl(adapter->hw.hw_addr + tx_ring->tdt),
3428 tx_ring->next_to_use,
3429 tx_ring->next_to_clean,
3430 tx_ring->buffer_info[eop].time_stamp,
3433 eop_desc->upper.fields.status);
3434 netif_stop_queue(netdev);
3441 * e1000_rx_checksum - Receive Checksum Offload for 82543
3442 * @adapter: board private structure
3443 * @status_err: receive descriptor status and error fields
3444 * @csum: receive descriptor csum field
3445 * @sk_buff: socket buffer with received data
3449 e1000_rx_checksum(struct e1000_adapter *adapter,
3450 uint32_t status_err, uint32_t csum,
3451 struct sk_buff *skb)
3453 uint16_t status = (uint16_t)status_err;
3454 uint8_t errors = (uint8_t)(status_err >> 24);
3455 skb->ip_summed = CHECKSUM_NONE;
3457 /* 82543 or newer only */
3458 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3459 /* Ignore Checksum bit is set */
3460 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3461 /* TCP/UDP checksum error bit is set */
3462 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3463 /* let the stack verify checksum errors */
3464 adapter->hw_csum_err++;
3467 /* TCP/UDP Checksum has not been calculated */
3468 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3469 if (!(status & E1000_RXD_STAT_TCPCS))
3472 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3475 /* It must be a TCP or UDP packet with a valid checksum */
3476 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3477 /* TCP checksum is good */
3478 skb->ip_summed = CHECKSUM_UNNECESSARY;
3479 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3480 /* IP fragment with UDP payload */
3481 /* Hardware complements the payload checksum, so we undo it
3482 * and then put the value in host order for further stack use.
3484 csum = ntohl(csum ^ 0xFFFF);
3486 skb->ip_summed = CHECKSUM_HW;
3488 adapter->hw_csum_good++;
3492 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3493 * @adapter: board private structure
3497 #ifdef CONFIG_E1000_NAPI
3498 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3499 struct e1000_rx_ring *rx_ring,
3500 int *work_done, int work_to_do)
3502 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3503 struct e1000_rx_ring *rx_ring)
3506 struct net_device *netdev = adapter->netdev;
3507 struct pci_dev *pdev = adapter->pdev;
3508 struct e1000_rx_desc *rx_desc, *next_rxd;
3509 struct e1000_buffer *buffer_info, *next_buffer;
3510 unsigned long flags;
3514 int cleaned_count = 0;
3515 boolean_t cleaned = FALSE;
3517 i = rx_ring->next_to_clean;
3518 rx_desc = E1000_RX_DESC(*rx_ring, i);
3519 buffer_info = &rx_ring->buffer_info[i];
3521 while (rx_desc->status & E1000_RXD_STAT_DD) {
3522 struct sk_buff *skb;
3524 #ifdef CONFIG_E1000_NAPI
3525 if (*work_done >= work_to_do)
3529 status = rx_desc->status;
3530 skb = buffer_info->skb;
3531 buffer_info->skb = NULL;
3533 prefetch(skb->data - NET_IP_ALIGN);
3535 if (++i == rx_ring->count) i = 0;
3536 next_rxd = E1000_RX_DESC(*rx_ring, i);
3539 next_buffer = &rx_ring->buffer_info[i];
3543 pci_unmap_single(pdev,
3545 buffer_info->length,
3546 PCI_DMA_FROMDEVICE);
3548 length = le16_to_cpu(rx_desc->length);
3550 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3551 /* All receives must fit into a single buffer */
3552 E1000_DBG("%s: Receive packet consumed multiple"
3553 " buffers\n", netdev->name);
3554 dev_kfree_skb_irq(skb);
3558 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3559 last_byte = *(skb->data + length - 1);
3560 if (TBI_ACCEPT(&adapter->hw, status,
3561 rx_desc->errors, length, last_byte)) {
3562 spin_lock_irqsave(&adapter->stats_lock, flags);
3563 e1000_tbi_adjust_stats(&adapter->hw,
3566 spin_unlock_irqrestore(&adapter->stats_lock,
3570 dev_kfree_skb_irq(skb);
3575 /* code added for copybreak, this should improve
3576 * performance for small packets with large amounts
3577 * of reassembly being done in the stack */
3578 #define E1000_CB_LENGTH 256
3579 if (length < E1000_CB_LENGTH) {
3580 struct sk_buff *new_skb =
3581 dev_alloc_skb(length + NET_IP_ALIGN);
3583 skb_reserve(new_skb, NET_IP_ALIGN);
3584 new_skb->dev = netdev;
3585 memcpy(new_skb->data - NET_IP_ALIGN,
3586 skb->data - NET_IP_ALIGN,
3587 length + NET_IP_ALIGN);
3588 /* save the skb in buffer_info as good */
3589 buffer_info->skb = skb;
3591 skb_put(skb, length);
3594 skb_put(skb, length);
3596 /* end copybreak code */
3598 /* Receive Checksum Offload */
3599 e1000_rx_checksum(adapter,
3600 (uint32_t)(status) |
3601 ((uint32_t)(rx_desc->errors) << 24),
3602 le16_to_cpu(rx_desc->csum), skb);
3604 skb->protocol = eth_type_trans(skb, netdev);
3605 #ifdef CONFIG_E1000_NAPI
3606 if (unlikely(adapter->vlgrp &&
3607 (status & E1000_RXD_STAT_VP))) {
3608 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3609 le16_to_cpu(rx_desc->special) &
3610 E1000_RXD_SPC_VLAN_MASK);
3612 netif_receive_skb(skb);
3614 #else /* CONFIG_E1000_NAPI */
3615 if (unlikely(adapter->vlgrp &&
3616 (status & E1000_RXD_STAT_VP))) {
3617 vlan_hwaccel_rx(skb, adapter->vlgrp,
3618 le16_to_cpu(rx_desc->special) &
3619 E1000_RXD_SPC_VLAN_MASK);
3623 #endif /* CONFIG_E1000_NAPI */
3624 netdev->last_rx = jiffies;
3627 rx_desc->status = 0;
3629 /* return some buffers to hardware, one at a time is too slow */
3630 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3631 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3635 /* use prefetched values */
3637 buffer_info = next_buffer;
3639 rx_ring->next_to_clean = i;
3641 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3643 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3649 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3650 * @adapter: board private structure
3654 #ifdef CONFIG_E1000_NAPI
3655 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3656 struct e1000_rx_ring *rx_ring,
3657 int *work_done, int work_to_do)
3659 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3660 struct e1000_rx_ring *rx_ring)
3663 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
3664 struct net_device *netdev = adapter->netdev;
3665 struct pci_dev *pdev = adapter->pdev;
3666 struct e1000_buffer *buffer_info, *next_buffer;
3667 struct e1000_ps_page *ps_page;
3668 struct e1000_ps_page_dma *ps_page_dma;
3669 struct sk_buff *skb;
3671 uint32_t length, staterr;
3672 int cleaned_count = 0;
3673 boolean_t cleaned = FALSE;
3675 i = rx_ring->next_to_clean;
3676 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3677 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3679 while (staterr & E1000_RXD_STAT_DD) {
3680 buffer_info = &rx_ring->buffer_info[i];
3681 ps_page = &rx_ring->ps_page[i];
3682 ps_page_dma = &rx_ring->ps_page_dma[i];
3683 #ifdef CONFIG_E1000_NAPI
3684 if (unlikely(*work_done >= work_to_do))
3688 skb = buffer_info->skb;
3690 /* in the packet split case this is header only */
3691 prefetch(skb->data - NET_IP_ALIGN);
3693 if (++i == rx_ring->count) i = 0;
3694 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
3697 next_buffer = &rx_ring->buffer_info[i];
3701 pci_unmap_single(pdev, buffer_info->dma,
3702 buffer_info->length,
3703 PCI_DMA_FROMDEVICE);
3705 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3706 E1000_DBG("%s: Packet Split buffers didn't pick up"
3707 " the full packet\n", netdev->name);
3708 dev_kfree_skb_irq(skb);
3712 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3713 dev_kfree_skb_irq(skb);
3717 length = le16_to_cpu(rx_desc->wb.middle.length0);
3719 if (unlikely(!length)) {
3720 E1000_DBG("%s: Last part of the packet spanning"
3721 " multiple descriptors\n", netdev->name);
3722 dev_kfree_skb_irq(skb);
3727 skb_put(skb, length);
3730 /* this looks ugly, but it seems compiler issues make it
3731 more efficient than reusing j */
3732 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3734 /* page alloc/put takes too long and effects small packet
3735 * throughput, so unsplit small packets and save the alloc/put*/
3736 if (l1 && ((length + l1) < E1000_CB_LENGTH)) {
3738 /* there is no documentation about how to call
3739 * kmap_atomic, so we can't hold the mapping
3741 pci_dma_sync_single_for_cpu(pdev,
3742 ps_page_dma->ps_page_dma[0],
3744 PCI_DMA_FROMDEVICE);
3745 vaddr = kmap_atomic(ps_page->ps_page[0],
3746 KM_SKB_DATA_SOFTIRQ);
3747 memcpy(skb->tail, vaddr, l1);
3748 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3749 pci_dma_sync_single_for_device(pdev,
3750 ps_page_dma->ps_page_dma[0],
3751 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3758 for (j = 0; j < adapter->rx_ps_pages; j++) {
3759 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
3761 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3762 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3763 ps_page_dma->ps_page_dma[j] = 0;
3764 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3766 ps_page->ps_page[j] = NULL;
3768 skb->data_len += length;
3769 skb->truesize += length;
3773 e1000_rx_checksum(adapter, staterr,
3774 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
3775 skb->protocol = eth_type_trans(skb, netdev);
3777 if (likely(rx_desc->wb.upper.header_status &
3778 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
3779 adapter->rx_hdr_split++;
3780 #ifdef CONFIG_E1000_NAPI
3781 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3782 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3783 le16_to_cpu(rx_desc->wb.middle.vlan) &
3784 E1000_RXD_SPC_VLAN_MASK);
3786 netif_receive_skb(skb);
3788 #else /* CONFIG_E1000_NAPI */
3789 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3790 vlan_hwaccel_rx(skb, adapter->vlgrp,
3791 le16_to_cpu(rx_desc->wb.middle.vlan) &
3792 E1000_RXD_SPC_VLAN_MASK);
3796 #endif /* CONFIG_E1000_NAPI */
3797 netdev->last_rx = jiffies;
3800 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
3801 buffer_info->skb = NULL;
3803 /* return some buffers to hardware, one at a time is too slow */
3804 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3805 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3809 /* use prefetched values */
3811 buffer_info = next_buffer;
3813 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3815 rx_ring->next_to_clean = i;
3817 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3819 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3825 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3826 * @adapter: address of board private structure
3830 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3831 struct e1000_rx_ring *rx_ring,
3834 struct net_device *netdev = adapter->netdev;
3835 struct pci_dev *pdev = adapter->pdev;
3836 struct e1000_rx_desc *rx_desc;
3837 struct e1000_buffer *buffer_info;
3838 struct sk_buff *skb;
3840 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3842 i = rx_ring->next_to_use;
3843 buffer_info = &rx_ring->buffer_info[i];
3845 while (cleaned_count--) {
3846 if (!(skb = buffer_info->skb))
3847 skb = dev_alloc_skb(bufsz);
3853 if (unlikely(!skb)) {
3854 /* Better luck next round */
3855 adapter->alloc_rx_buff_failed++;
3859 /* Fix for errata 23, can't cross 64kB boundary */
3860 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3861 struct sk_buff *oldskb = skb;
3862 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3863 "at %p\n", bufsz, skb->data);
3864 /* Try again, without freeing the previous */
3865 skb = dev_alloc_skb(bufsz);
3866 /* Failed allocation, critical failure */
3868 dev_kfree_skb(oldskb);
3872 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3875 dev_kfree_skb(oldskb);
3876 break; /* while !buffer_info->skb */
3878 /* Use new allocation */
3879 dev_kfree_skb(oldskb);
3882 /* Make buffer alignment 2 beyond a 16 byte boundary
3883 * this will result in a 16 byte aligned IP header after
3884 * the 14 byte MAC header is removed
3886 skb_reserve(skb, NET_IP_ALIGN);
3890 buffer_info->skb = skb;
3891 buffer_info->length = adapter->rx_buffer_len;
3893 buffer_info->dma = pci_map_single(pdev,
3895 adapter->rx_buffer_len,
3896 PCI_DMA_FROMDEVICE);
3898 /* Fix for errata 23, can't cross 64kB boundary */
3899 if (!e1000_check_64k_bound(adapter,
3900 (void *)(unsigned long)buffer_info->dma,
3901 adapter->rx_buffer_len)) {
3902 DPRINTK(RX_ERR, ERR,
3903 "dma align check failed: %u bytes at %p\n",
3904 adapter->rx_buffer_len,
3905 (void *)(unsigned long)buffer_info->dma);
3907 buffer_info->skb = NULL;
3909 pci_unmap_single(pdev, buffer_info->dma,
3910 adapter->rx_buffer_len,
3911 PCI_DMA_FROMDEVICE);
3913 break; /* while !buffer_info->skb */
3915 rx_desc = E1000_RX_DESC(*rx_ring, i);
3916 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3918 if (unlikely(++i == rx_ring->count))
3920 buffer_info = &rx_ring->buffer_info[i];
3923 if (likely(rx_ring->next_to_use != i)) {
3924 rx_ring->next_to_use = i;
3925 if (unlikely(i-- == 0))
3926 i = (rx_ring->count - 1);
3928 /* Force memory writes to complete before letting h/w
3929 * know there are new descriptors to fetch. (Only
3930 * applicable for weak-ordered memory model archs,
3931 * such as IA-64). */
3933 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3938 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3939 * @adapter: address of board private structure
3943 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3944 struct e1000_rx_ring *rx_ring,
3947 struct net_device *netdev = adapter->netdev;
3948 struct pci_dev *pdev = adapter->pdev;
3949 union e1000_rx_desc_packet_split *rx_desc;
3950 struct e1000_buffer *buffer_info;
3951 struct e1000_ps_page *ps_page;
3952 struct e1000_ps_page_dma *ps_page_dma;
3953 struct sk_buff *skb;
3956 i = rx_ring->next_to_use;
3957 buffer_info = &rx_ring->buffer_info[i];
3958 ps_page = &rx_ring->ps_page[i];
3959 ps_page_dma = &rx_ring->ps_page_dma[i];
3961 while (cleaned_count--) {
3962 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3964 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
3965 if (j < adapter->rx_ps_pages) {
3966 if (likely(!ps_page->ps_page[j])) {
3967 ps_page->ps_page[j] =
3968 alloc_page(GFP_ATOMIC);
3969 if (unlikely(!ps_page->ps_page[j])) {
3970 adapter->alloc_rx_buff_failed++;
3973 ps_page_dma->ps_page_dma[j] =
3975 ps_page->ps_page[j],
3977 PCI_DMA_FROMDEVICE);
3979 /* Refresh the desc even if buffer_addrs didn't
3980 * change because each write-back erases
3983 rx_desc->read.buffer_addr[j+1] =
3984 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3986 rx_desc->read.buffer_addr[j+1] = ~0;
3989 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3991 if (unlikely(!skb)) {
3992 adapter->alloc_rx_buff_failed++;
3996 /* Make buffer alignment 2 beyond a 16 byte boundary
3997 * this will result in a 16 byte aligned IP header after
3998 * the 14 byte MAC header is removed
4000 skb_reserve(skb, NET_IP_ALIGN);
4004 buffer_info->skb = skb;
4005 buffer_info->length = adapter->rx_ps_bsize0;
4006 buffer_info->dma = pci_map_single(pdev, skb->data,
4007 adapter->rx_ps_bsize0,
4008 PCI_DMA_FROMDEVICE);
4010 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4012 if (unlikely(++i == rx_ring->count)) i = 0;
4013 buffer_info = &rx_ring->buffer_info[i];
4014 ps_page = &rx_ring->ps_page[i];
4015 ps_page_dma = &rx_ring->ps_page_dma[i];
4019 if (likely(rx_ring->next_to_use != i)) {
4020 rx_ring->next_to_use = i;
4021 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4023 /* Force memory writes to complete before letting h/w
4024 * know there are new descriptors to fetch. (Only
4025 * applicable for weak-ordered memory model archs,
4026 * such as IA-64). */
4028 /* Hardware increments by 16 bytes, but packet split
4029 * descriptors are 32 bytes...so we increment tail
4032 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4037 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4042 e1000_smartspeed(struct e1000_adapter *adapter)
4044 uint16_t phy_status;
4047 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4048 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4051 if (adapter->smartspeed == 0) {
4052 /* If Master/Slave config fault is asserted twice,
4053 * we assume back-to-back */
4054 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4055 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4056 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4057 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4058 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4059 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4060 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4061 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4063 adapter->smartspeed++;
4064 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4065 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4067 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4068 MII_CR_RESTART_AUTO_NEG);
4069 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4074 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4075 /* If still no link, perhaps using 2/3 pair cable */
4076 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4077 phy_ctrl |= CR_1000T_MS_ENABLE;
4078 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4079 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4080 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4081 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4082 MII_CR_RESTART_AUTO_NEG);
4083 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4086 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4087 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4088 adapter->smartspeed = 0;
4099 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4105 return e1000_mii_ioctl(netdev, ifr, cmd);
4119 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4121 struct e1000_adapter *adapter = netdev_priv(netdev);
4122 struct mii_ioctl_data *data = if_mii(ifr);
4126 unsigned long flags;
4128 if (adapter->hw.media_type != e1000_media_type_copper)
4133 data->phy_id = adapter->hw.phy_addr;
4136 if (!capable(CAP_NET_ADMIN))
4138 spin_lock_irqsave(&adapter->stats_lock, flags);
4139 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4141 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4144 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4147 if (!capable(CAP_NET_ADMIN))
4149 if (data->reg_num & ~(0x1F))
4151 mii_reg = data->val_in;
4152 spin_lock_irqsave(&adapter->stats_lock, flags);
4153 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4155 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4158 if (adapter->hw.phy_type == e1000_media_type_copper) {
4159 switch (data->reg_num) {
4161 if (mii_reg & MII_CR_POWER_DOWN)
4163 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4164 adapter->hw.autoneg = 1;
4165 adapter->hw.autoneg_advertised = 0x2F;
4168 spddplx = SPEED_1000;
4169 else if (mii_reg & 0x2000)
4170 spddplx = SPEED_100;
4173 spddplx += (mii_reg & 0x100)
4176 retval = e1000_set_spd_dplx(adapter,
4179 spin_unlock_irqrestore(
4180 &adapter->stats_lock,
4185 if (netif_running(adapter->netdev)) {
4186 e1000_down(adapter);
4189 e1000_reset(adapter);
4191 case M88E1000_PHY_SPEC_CTRL:
4192 case M88E1000_EXT_PHY_SPEC_CTRL:
4193 if (e1000_phy_reset(&adapter->hw)) {
4194 spin_unlock_irqrestore(
4195 &adapter->stats_lock, flags);
4201 switch (data->reg_num) {
4203 if (mii_reg & MII_CR_POWER_DOWN)
4205 if (netif_running(adapter->netdev)) {
4206 e1000_down(adapter);
4209 e1000_reset(adapter);
4213 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4218 return E1000_SUCCESS;
4222 e1000_pci_set_mwi(struct e1000_hw *hw)
4224 struct e1000_adapter *adapter = hw->back;
4225 int ret_val = pci_set_mwi(adapter->pdev);
4228 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4232 e1000_pci_clear_mwi(struct e1000_hw *hw)
4234 struct e1000_adapter *adapter = hw->back;
4236 pci_clear_mwi(adapter->pdev);
4240 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4242 struct e1000_adapter *adapter = hw->back;
4244 pci_read_config_word(adapter->pdev, reg, value);
4248 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4250 struct e1000_adapter *adapter = hw->back;
4252 pci_write_config_word(adapter->pdev, reg, *value);
4256 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4262 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4268 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4270 struct e1000_adapter *adapter = netdev_priv(netdev);
4271 uint32_t ctrl, rctl;
4273 e1000_irq_disable(adapter);
4274 adapter->vlgrp = grp;
4277 /* enable VLAN tag insert/strip */
4278 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4279 ctrl |= E1000_CTRL_VME;
4280 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4282 /* enable VLAN receive filtering */
4283 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4284 rctl |= E1000_RCTL_VFE;
4285 rctl &= ~E1000_RCTL_CFIEN;
4286 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4287 e1000_update_mng_vlan(adapter);
4289 /* disable VLAN tag insert/strip */
4290 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4291 ctrl &= ~E1000_CTRL_VME;
4292 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4294 /* disable VLAN filtering */
4295 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4296 rctl &= ~E1000_RCTL_VFE;
4297 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4298 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4299 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4300 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4304 e1000_irq_enable(adapter);
4308 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4310 struct e1000_adapter *adapter = netdev_priv(netdev);
4311 uint32_t vfta, index;
4313 if ((adapter->hw.mng_cookie.status &
4314 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4315 (vid == adapter->mng_vlan_id))
4317 /* add VID to filter table */
4318 index = (vid >> 5) & 0x7F;
4319 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4320 vfta |= (1 << (vid & 0x1F));
4321 e1000_write_vfta(&adapter->hw, index, vfta);
4325 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4327 struct e1000_adapter *adapter = netdev_priv(netdev);
4328 uint32_t vfta, index;
4330 e1000_irq_disable(adapter);
4333 adapter->vlgrp->vlan_devices[vid] = NULL;
4335 e1000_irq_enable(adapter);
4337 if ((adapter->hw.mng_cookie.status &
4338 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4339 (vid == adapter->mng_vlan_id)) {
4340 /* release control to f/w */
4341 e1000_release_hw_control(adapter);
4345 /* remove VID from filter table */
4346 index = (vid >> 5) & 0x7F;
4347 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4348 vfta &= ~(1 << (vid & 0x1F));
4349 e1000_write_vfta(&adapter->hw, index, vfta);
4353 e1000_restore_vlan(struct e1000_adapter *adapter)
4355 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4357 if (adapter->vlgrp) {
4359 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4360 if (!adapter->vlgrp->vlan_devices[vid])
4362 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4368 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4370 adapter->hw.autoneg = 0;
4372 /* Fiber NICs only allow 1000 gbps Full duplex */
4373 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4374 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4375 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4380 case SPEED_10 + DUPLEX_HALF:
4381 adapter->hw.forced_speed_duplex = e1000_10_half;
4383 case SPEED_10 + DUPLEX_FULL:
4384 adapter->hw.forced_speed_duplex = e1000_10_full;
4386 case SPEED_100 + DUPLEX_HALF:
4387 adapter->hw.forced_speed_duplex = e1000_100_half;
4389 case SPEED_100 + DUPLEX_FULL:
4390 adapter->hw.forced_speed_duplex = e1000_100_full;
4392 case SPEED_1000 + DUPLEX_FULL:
4393 adapter->hw.autoneg = 1;
4394 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4396 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4398 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4405 /* Save/restore 16 or 64 dwords of PCI config space depending on which
4406 * bus we're on (PCI(X) vs. PCI-E)
4408 #define PCIE_CONFIG_SPACE_LEN 256
4409 #define PCI_CONFIG_SPACE_LEN 64
4411 e1000_pci_save_state(struct e1000_adapter *adapter)
4413 struct pci_dev *dev = adapter->pdev;
4417 if (adapter->hw.mac_type >= e1000_82571)
4418 size = PCIE_CONFIG_SPACE_LEN;
4420 size = PCI_CONFIG_SPACE_LEN;
4422 WARN_ON(adapter->config_space != NULL);
4424 adapter->config_space = kmalloc(size, GFP_KERNEL);
4425 if (!adapter->config_space) {
4426 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4429 for (i = 0; i < (size / 4); i++)
4430 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4435 e1000_pci_restore_state(struct e1000_adapter *adapter)
4437 struct pci_dev *dev = adapter->pdev;
4441 if (adapter->config_space == NULL)
4444 if (adapter->hw.mac_type >= e1000_82571)
4445 size = PCIE_CONFIG_SPACE_LEN;
4447 size = PCI_CONFIG_SPACE_LEN;
4448 for (i = 0; i < (size / 4); i++)
4449 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4450 kfree(adapter->config_space);
4451 adapter->config_space = NULL;
4454 #endif /* CONFIG_PM */
4457 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4459 struct net_device *netdev = pci_get_drvdata(pdev);
4460 struct e1000_adapter *adapter = netdev_priv(netdev);
4461 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4462 uint32_t wufc = adapter->wol;
4465 netif_device_detach(netdev);
4467 if (netif_running(netdev))
4468 e1000_down(adapter);
4471 /* Implement our own version of pci_save_state(pdev) because pci-
4472 * express adapters have 256-byte config spaces. */
4473 retval = e1000_pci_save_state(adapter);
4478 status = E1000_READ_REG(&adapter->hw, STATUS);
4479 if (status & E1000_STATUS_LU)
4480 wufc &= ~E1000_WUFC_LNKC;
4483 e1000_setup_rctl(adapter);
4484 e1000_set_multi(netdev);
4486 /* turn on all-multi mode if wake on multicast is enabled */
4487 if (adapter->wol & E1000_WUFC_MC) {
4488 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4489 rctl |= E1000_RCTL_MPE;
4490 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4493 if (adapter->hw.mac_type >= e1000_82540) {
4494 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4495 /* advertise wake from D3Cold */
4496 #define E1000_CTRL_ADVD3WUC 0x00100000
4497 /* phy power management enable */
4498 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4499 ctrl |= E1000_CTRL_ADVD3WUC |
4500 E1000_CTRL_EN_PHY_PWR_MGMT;
4501 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4504 if (adapter->hw.media_type == e1000_media_type_fiber ||
4505 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4506 /* keep the laser running in D3 */
4507 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4508 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4509 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4512 /* Allow time for pending master requests to run */
4513 e1000_disable_pciex_master(&adapter->hw);
4515 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4516 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4517 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4519 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4520 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4522 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4524 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4525 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4526 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4528 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4529 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4531 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4534 if (adapter->hw.mac_type >= e1000_82540 &&
4535 adapter->hw.media_type == e1000_media_type_copper) {
4536 manc = E1000_READ_REG(&adapter->hw, MANC);
4537 if (manc & E1000_MANC_SMBUS_EN) {
4538 manc |= E1000_MANC_ARP_EN;
4539 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4540 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4542 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4543 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4546 "Error enabling D3 cold wake\n");
4550 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4551 * would have already happened in close and is redundant. */
4552 e1000_release_hw_control(adapter);
4554 pci_disable_device(pdev);
4556 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4558 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4565 e1000_resume(struct pci_dev *pdev)
4567 struct net_device *netdev = pci_get_drvdata(pdev);
4568 struct e1000_adapter *adapter = netdev_priv(netdev);
4570 uint32_t manc, ret_val;
4572 retval = pci_set_power_state(pdev, PCI_D0);
4574 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4575 e1000_pci_restore_state(adapter);
4576 ret_val = pci_enable_device(pdev);
4577 pci_set_master(pdev);
4579 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4581 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4582 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4584 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4586 e1000_reset(adapter);
4587 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4589 if (netif_running(netdev))
4592 netif_device_attach(netdev);
4594 if (adapter->hw.mac_type >= e1000_82540 &&
4595 adapter->hw.media_type == e1000_media_type_copper) {
4596 manc = E1000_READ_REG(&adapter->hw, MANC);
4597 manc &= ~(E1000_MANC_ARP_EN);
4598 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4601 /* If the controller is 82573 and f/w is AMT, do not set
4602 * DRV_LOAD until the interface is up. For all other cases,
4603 * let the f/w know that the h/w is now under the control
4605 if (adapter->hw.mac_type != e1000_82573 ||
4606 !e1000_check_mng_mode(&adapter->hw))
4607 e1000_get_hw_control(adapter);
4613 static void e1000_shutdown(struct pci_dev *pdev)
4615 e1000_suspend(pdev, PMSG_SUSPEND);
4618 #ifdef CONFIG_NET_POLL_CONTROLLER
4620 * Polling 'interrupt' - used by things like netconsole to send skbs
4621 * without having to re-enable interrupts. It's not called while
4622 * the interrupt routine is executing.
4625 e1000_netpoll(struct net_device *netdev)
4627 struct e1000_adapter *adapter = netdev_priv(netdev);
4628 disable_irq(adapter->pdev->irq);
4629 e1000_intr(adapter->pdev->irq, netdev, NULL);
4630 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4631 #ifndef CONFIG_E1000_NAPI
4632 adapter->clean_rx(adapter, adapter->rx_ring);
4634 enable_irq(adapter->pdev->irq);