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 applied Anton's patch to resolve tx hang in hardware
34 * o Applied Andrew Mortons patch - e1000 stops working after resume
37 char e1000_driver_name[] = "e1000";
38 char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
39 #ifndef CONFIG_E1000_NAPI
42 #define DRIVERNAPI "-NAPI"
44 #define DRV_VERSION "6.0.54-k2"DRIVERNAPI
45 char e1000_driver_version[] = DRV_VERSION;
46 char e1000_copyright[] = "Copyright (c) 1999-2004 Intel Corporation.";
48 /* e1000_pci_tbl - PCI Device ID Table
50 * Last entry must be all 0s
53 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
55 static struct pci_device_id e1000_pci_tbl[] = {
56 INTEL_E1000_ETHERNET_DEVICE(0x1000),
57 INTEL_E1000_ETHERNET_DEVICE(0x1001),
58 INTEL_E1000_ETHERNET_DEVICE(0x1004),
59 INTEL_E1000_ETHERNET_DEVICE(0x1008),
60 INTEL_E1000_ETHERNET_DEVICE(0x1009),
61 INTEL_E1000_ETHERNET_DEVICE(0x100C),
62 INTEL_E1000_ETHERNET_DEVICE(0x100D),
63 INTEL_E1000_ETHERNET_DEVICE(0x100E),
64 INTEL_E1000_ETHERNET_DEVICE(0x100F),
65 INTEL_E1000_ETHERNET_DEVICE(0x1010),
66 INTEL_E1000_ETHERNET_DEVICE(0x1011),
67 INTEL_E1000_ETHERNET_DEVICE(0x1012),
68 INTEL_E1000_ETHERNET_DEVICE(0x1013),
69 INTEL_E1000_ETHERNET_DEVICE(0x1014),
70 INTEL_E1000_ETHERNET_DEVICE(0x1015),
71 INTEL_E1000_ETHERNET_DEVICE(0x1016),
72 INTEL_E1000_ETHERNET_DEVICE(0x1017),
73 INTEL_E1000_ETHERNET_DEVICE(0x1018),
74 INTEL_E1000_ETHERNET_DEVICE(0x1019),
75 INTEL_E1000_ETHERNET_DEVICE(0x101A),
76 INTEL_E1000_ETHERNET_DEVICE(0x101D),
77 INTEL_E1000_ETHERNET_DEVICE(0x101E),
78 INTEL_E1000_ETHERNET_DEVICE(0x1026),
79 INTEL_E1000_ETHERNET_DEVICE(0x1027),
80 INTEL_E1000_ETHERNET_DEVICE(0x1028),
81 INTEL_E1000_ETHERNET_DEVICE(0x1075),
82 INTEL_E1000_ETHERNET_DEVICE(0x1076),
83 INTEL_E1000_ETHERNET_DEVICE(0x1077),
84 INTEL_E1000_ETHERNET_DEVICE(0x1078),
85 INTEL_E1000_ETHERNET_DEVICE(0x1079),
86 INTEL_E1000_ETHERNET_DEVICE(0x107A),
87 INTEL_E1000_ETHERNET_DEVICE(0x107B),
88 INTEL_E1000_ETHERNET_DEVICE(0x107C),
89 INTEL_E1000_ETHERNET_DEVICE(0x108A),
90 INTEL_E1000_ETHERNET_DEVICE(0x108B),
91 INTEL_E1000_ETHERNET_DEVICE(0x108C),
92 INTEL_E1000_ETHERNET_DEVICE(0x1099),
93 /* required last entry */
97 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
99 int e1000_up(struct e1000_adapter *adapter);
100 void e1000_down(struct e1000_adapter *adapter);
101 void e1000_reset(struct e1000_adapter *adapter);
102 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
103 int e1000_setup_tx_resources(struct e1000_adapter *adapter);
104 int e1000_setup_rx_resources(struct e1000_adapter *adapter);
105 void e1000_free_tx_resources(struct e1000_adapter *adapter);
106 void e1000_free_rx_resources(struct e1000_adapter *adapter);
107 void e1000_update_stats(struct e1000_adapter *adapter);
109 /* Local Function Prototypes */
111 static int e1000_init_module(void);
112 static void e1000_exit_module(void);
113 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
114 static void __devexit e1000_remove(struct pci_dev *pdev);
115 static int e1000_sw_init(struct e1000_adapter *adapter);
116 static int e1000_open(struct net_device *netdev);
117 static int e1000_close(struct net_device *netdev);
118 static void e1000_configure_tx(struct e1000_adapter *adapter);
119 static void e1000_configure_rx(struct e1000_adapter *adapter);
120 static void e1000_setup_rctl(struct e1000_adapter *adapter);
121 static void e1000_clean_tx_ring(struct e1000_adapter *adapter);
122 static void e1000_clean_rx_ring(struct e1000_adapter *adapter);
123 static void e1000_set_multi(struct net_device *netdev);
124 static void e1000_update_phy_info(unsigned long data);
125 static void e1000_watchdog(unsigned long data);
126 static void e1000_watchdog_task(struct e1000_adapter *adapter);
127 static void e1000_82547_tx_fifo_stall(unsigned long data);
128 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
129 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
130 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
131 static int e1000_set_mac(struct net_device *netdev, void *p);
132 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
133 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter);
134 #ifdef CONFIG_E1000_NAPI
135 static int e1000_clean(struct net_device *netdev, int *budget);
136 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
137 int *work_done, int work_to_do);
138 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
139 int *work_done, int work_to_do);
141 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter);
142 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter);
144 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);
145 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter);
146 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
147 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
149 void e1000_set_ethtool_ops(struct net_device *netdev);
150 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
151 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
152 static void e1000_tx_timeout(struct net_device *dev);
153 static void e1000_tx_timeout_task(struct net_device *dev);
154 static void e1000_smartspeed(struct e1000_adapter *adapter);
155 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
156 struct sk_buff *skb);
158 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
159 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
160 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
161 static void e1000_restore_vlan(struct e1000_adapter *adapter);
163 static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
164 static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
166 static int e1000_resume(struct pci_dev *pdev);
169 #ifdef CONFIG_NET_POLL_CONTROLLER
170 /* for netdump / net console */
171 static void e1000_netpoll (struct net_device *netdev);
174 struct notifier_block e1000_notifier_reboot = {
175 .notifier_call = e1000_notify_reboot,
180 /* Exported from other modules */
182 extern void e1000_check_options(struct e1000_adapter *adapter);
184 static struct pci_driver e1000_driver = {
185 .name = e1000_driver_name,
186 .id_table = e1000_pci_tbl,
187 .probe = e1000_probe,
188 .remove = __devexit_p(e1000_remove),
189 /* Power Managment Hooks */
191 .suspend = e1000_suspend,
192 .resume = e1000_resume
196 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
197 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
198 MODULE_LICENSE("GPL");
199 MODULE_VERSION(DRV_VERSION);
201 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
202 module_param(debug, int, 0);
203 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
206 * e1000_init_module - Driver Registration Routine
208 * e1000_init_module is the first routine called when the driver is
209 * loaded. All it does is register with the PCI subsystem.
213 e1000_init_module(void)
216 printk(KERN_INFO "%s - version %s\n",
217 e1000_driver_string, e1000_driver_version);
219 printk(KERN_INFO "%s\n", e1000_copyright);
221 ret = pci_module_init(&e1000_driver);
223 register_reboot_notifier(&e1000_notifier_reboot);
228 module_init(e1000_init_module);
231 * e1000_exit_module - Driver Exit Cleanup Routine
233 * e1000_exit_module is called just before the driver is removed
238 e1000_exit_module(void)
240 unregister_reboot_notifier(&e1000_notifier_reboot);
241 pci_unregister_driver(&e1000_driver);
244 module_exit(e1000_exit_module);
247 * e1000_irq_disable - Mask off interrupt generation on the NIC
248 * @adapter: board private structure
252 e1000_irq_disable(struct e1000_adapter *adapter)
254 atomic_inc(&adapter->irq_sem);
255 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
256 E1000_WRITE_FLUSH(&adapter->hw);
257 synchronize_irq(adapter->pdev->irq);
261 * e1000_irq_enable - Enable default interrupt generation settings
262 * @adapter: board private structure
266 e1000_irq_enable(struct e1000_adapter *adapter)
268 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
269 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
270 E1000_WRITE_FLUSH(&adapter->hw);
274 e1000_update_mng_vlan(struct e1000_adapter *adapter)
276 struct net_device *netdev = adapter->netdev;
277 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
278 uint16_t old_vid = adapter->mng_vlan_id;
280 if(!adapter->vlgrp->vlan_devices[vid]) {
281 if(adapter->hw.mng_cookie.status &
282 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
283 e1000_vlan_rx_add_vid(netdev, vid);
284 adapter->mng_vlan_id = vid;
286 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
288 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
290 !adapter->vlgrp->vlan_devices[old_vid])
291 e1000_vlan_rx_kill_vid(netdev, old_vid);
297 e1000_up(struct e1000_adapter *adapter)
299 struct net_device *netdev = adapter->netdev;
302 /* hardware has been reset, we need to reload some things */
304 /* Reset the PHY if it was previously powered down */
305 if(adapter->hw.media_type == e1000_media_type_copper) {
307 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
308 if(mii_reg & MII_CR_POWER_DOWN)
309 e1000_phy_reset(&adapter->hw);
312 e1000_set_multi(netdev);
314 e1000_restore_vlan(adapter);
316 e1000_configure_tx(adapter);
317 e1000_setup_rctl(adapter);
318 e1000_configure_rx(adapter);
319 adapter->alloc_rx_buf(adapter);
321 #ifdef CONFIG_PCI_MSI
322 if(adapter->hw.mac_type > e1000_82547_rev_2) {
323 adapter->have_msi = TRUE;
324 if((err = pci_enable_msi(adapter->pdev))) {
326 "Unable to allocate MSI interrupt Error: %d\n", err);
327 adapter->have_msi = FALSE;
331 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
332 SA_SHIRQ | SA_SAMPLE_RANDOM,
333 netdev->name, netdev))) {
335 "Unable to allocate interrupt Error: %d\n", err);
339 mod_timer(&adapter->watchdog_timer, jiffies);
341 #ifdef CONFIG_E1000_NAPI
342 netif_poll_enable(netdev);
344 e1000_irq_enable(adapter);
350 e1000_down(struct e1000_adapter *adapter)
352 struct net_device *netdev = adapter->netdev;
354 e1000_irq_disable(adapter);
355 free_irq(adapter->pdev->irq, netdev);
356 #ifdef CONFIG_PCI_MSI
357 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
358 adapter->have_msi == TRUE)
359 pci_disable_msi(adapter->pdev);
361 del_timer_sync(&adapter->tx_fifo_stall_timer);
362 del_timer_sync(&adapter->watchdog_timer);
363 del_timer_sync(&adapter->phy_info_timer);
365 #ifdef CONFIG_E1000_NAPI
366 netif_poll_disable(netdev);
368 adapter->link_speed = 0;
369 adapter->link_duplex = 0;
370 netif_carrier_off(netdev);
371 netif_stop_queue(netdev);
373 e1000_reset(adapter);
374 e1000_clean_tx_ring(adapter);
375 e1000_clean_rx_ring(adapter);
377 /* If WoL is not enabled
378 * and management mode is not IAMT
379 * Power down the PHY so no link is implied when interface is down */
380 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
381 adapter->hw.media_type == e1000_media_type_copper &&
382 !e1000_check_mng_mode(&adapter->hw) &&
383 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
385 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
386 mii_reg |= MII_CR_POWER_DOWN;
387 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
393 e1000_reset(struct e1000_adapter *adapter)
395 struct net_device *netdev = adapter->netdev;
397 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
398 uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
400 /* Repartition Pba for greater than 9k mtu
401 * To take effect CTRL.RST is required.
404 switch (adapter->hw.mac_type) {
406 case e1000_82547_rev_2:
417 if((adapter->hw.mac_type != e1000_82573) &&
418 (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {
419 pba -= 8; /* allocate more FIFO for Tx */
420 /* send an XOFF when there is enough space in the
421 * Rx FIFO to hold one extra full size Rx packet
423 fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE +
424 ETHERNET_FCS_SIZE + 1;
425 fc_low_water_mark = fc_high_water_mark + 8;
429 if(adapter->hw.mac_type == e1000_82547) {
430 adapter->tx_fifo_head = 0;
431 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
432 adapter->tx_fifo_size =
433 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
434 atomic_set(&adapter->tx_fifo_stall, 0);
437 E1000_WRITE_REG(&adapter->hw, PBA, pba);
439 /* flow control settings */
440 adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
442 adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
444 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
445 adapter->hw.fc_send_xon = 1;
446 adapter->hw.fc = adapter->hw.original_fc;
448 /* Allow time for pending master requests to run */
449 e1000_reset_hw(&adapter->hw);
450 if(adapter->hw.mac_type >= e1000_82544)
451 E1000_WRITE_REG(&adapter->hw, WUC, 0);
452 if(e1000_init_hw(&adapter->hw))
453 DPRINTK(PROBE, ERR, "Hardware Error\n");
454 e1000_update_mng_vlan(adapter);
455 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
456 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
458 e1000_reset_adaptive(&adapter->hw);
459 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
460 if (adapter->en_mng_pt) {
461 manc = E1000_READ_REG(&adapter->hw, MANC);
462 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
463 E1000_WRITE_REG(&adapter->hw, MANC, manc);
468 * e1000_probe - Device Initialization Routine
469 * @pdev: PCI device information struct
470 * @ent: entry in e1000_pci_tbl
472 * Returns 0 on success, negative on failure
474 * e1000_probe initializes an adapter identified by a pci_dev structure.
475 * The OS initialization, configuring of the adapter private structure,
476 * and a hardware reset occur.
480 e1000_probe(struct pci_dev *pdev,
481 const struct pci_device_id *ent)
483 struct net_device *netdev;
484 struct e1000_adapter *adapter;
485 unsigned long mmio_start, mmio_len;
488 static int cards_found = 0;
489 int i, err, pci_using_dac;
490 uint16_t eeprom_data;
491 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
492 if((err = pci_enable_device(pdev)))
495 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
498 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
499 E1000_ERR("No usable DMA configuration, aborting\n");
505 if((err = pci_request_regions(pdev, e1000_driver_name)))
508 pci_set_master(pdev);
510 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
513 goto err_alloc_etherdev;
516 SET_MODULE_OWNER(netdev);
517 SET_NETDEV_DEV(netdev, &pdev->dev);
519 pci_set_drvdata(pdev, netdev);
520 adapter = netdev->priv;
521 adapter->netdev = netdev;
522 adapter->pdev = pdev;
523 adapter->hw.back = adapter;
524 adapter->msg_enable = (1 << debug) - 1;
526 mmio_start = pci_resource_start(pdev, BAR_0);
527 mmio_len = pci_resource_len(pdev, BAR_0);
529 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
530 if(!adapter->hw.hw_addr) {
535 for(i = BAR_1; i <= BAR_5; i++) {
536 if(pci_resource_len(pdev, i) == 0)
538 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
539 adapter->hw.io_base = pci_resource_start(pdev, i);
544 netdev->open = &e1000_open;
545 netdev->stop = &e1000_close;
546 netdev->hard_start_xmit = &e1000_xmit_frame;
547 netdev->get_stats = &e1000_get_stats;
548 netdev->set_multicast_list = &e1000_set_multi;
549 netdev->set_mac_address = &e1000_set_mac;
550 netdev->change_mtu = &e1000_change_mtu;
551 netdev->do_ioctl = &e1000_ioctl;
552 e1000_set_ethtool_ops(netdev);
553 netdev->tx_timeout = &e1000_tx_timeout;
554 netdev->watchdog_timeo = 5 * HZ;
555 #ifdef CONFIG_E1000_NAPI
556 netdev->poll = &e1000_clean;
559 netdev->vlan_rx_register = e1000_vlan_rx_register;
560 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
561 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
562 #ifdef CONFIG_NET_POLL_CONTROLLER
563 netdev->poll_controller = e1000_netpoll;
565 strcpy(netdev->name, pci_name(pdev));
567 netdev->mem_start = mmio_start;
568 netdev->mem_end = mmio_start + mmio_len;
569 netdev->base_addr = adapter->hw.io_base;
571 adapter->bd_number = cards_found;
573 /* setup the private structure */
575 if((err = e1000_sw_init(adapter)))
578 if((err = e1000_check_phy_reset_block(&adapter->hw)))
579 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
581 if(adapter->hw.mac_type >= e1000_82543) {
582 netdev->features = NETIF_F_SG |
586 NETIF_F_HW_VLAN_FILTER;
590 if((adapter->hw.mac_type >= e1000_82544) &&
591 (adapter->hw.mac_type != e1000_82547))
592 netdev->features |= NETIF_F_TSO;
594 #ifdef NETIF_F_TSO_IPV6
595 if(adapter->hw.mac_type > e1000_82547_rev_2)
596 netdev->features |= NETIF_F_TSO_IPV6;
600 netdev->features |= NETIF_F_HIGHDMA;
602 /* hard_start_xmit is safe against parallel locking */
603 netdev->features |= NETIF_F_LLTX;
605 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
607 /* before reading the EEPROM, reset the controller to
608 * put the device in a known good starting state */
610 e1000_reset_hw(&adapter->hw);
612 /* make sure the EEPROM is good */
614 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
615 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
620 /* copy the MAC address out of the EEPROM */
622 if(e1000_read_mac_addr(&adapter->hw))
623 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
624 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
626 if(!is_valid_ether_addr(netdev->dev_addr)) {
627 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
632 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
634 e1000_get_bus_info(&adapter->hw);
636 init_timer(&adapter->tx_fifo_stall_timer);
637 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
638 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
640 init_timer(&adapter->watchdog_timer);
641 adapter->watchdog_timer.function = &e1000_watchdog;
642 adapter->watchdog_timer.data = (unsigned long) adapter;
644 INIT_WORK(&adapter->watchdog_task,
645 (void (*)(void *))e1000_watchdog_task, adapter);
647 init_timer(&adapter->phy_info_timer);
648 adapter->phy_info_timer.function = &e1000_update_phy_info;
649 adapter->phy_info_timer.data = (unsigned long) adapter;
651 INIT_WORK(&adapter->tx_timeout_task,
652 (void (*)(void *))e1000_tx_timeout_task, netdev);
654 /* we're going to reset, so assume we have no link for now */
656 netif_carrier_off(netdev);
657 netif_stop_queue(netdev);
659 e1000_check_options(adapter);
661 /* Initial Wake on LAN setting
662 * If APM wake is enabled in the EEPROM,
663 * enable the ACPI Magic Packet filter
666 switch(adapter->hw.mac_type) {
667 case e1000_82542_rev2_0:
668 case e1000_82542_rev2_1:
672 e1000_read_eeprom(&adapter->hw,
673 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
674 eeprom_apme_mask = E1000_EEPROM_82544_APM;
677 case e1000_82546_rev_3:
678 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
679 && (adapter->hw.media_type == e1000_media_type_copper)) {
680 e1000_read_eeprom(&adapter->hw,
681 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
686 e1000_read_eeprom(&adapter->hw,
687 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
690 if(eeprom_data & eeprom_apme_mask)
691 adapter->wol |= E1000_WUFC_MAG;
693 /* reset the hardware with the new settings */
694 e1000_reset(adapter);
696 /* Let firmware know the driver has taken over */
697 switch(adapter->hw.mac_type) {
699 swsm = E1000_READ_REG(&adapter->hw, SWSM);
700 E1000_WRITE_REG(&adapter->hw, SWSM,
701 swsm | E1000_SWSM_DRV_LOAD);
707 strcpy(netdev->name, "eth%d");
708 if((err = register_netdev(netdev)))
711 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
719 iounmap(adapter->hw.hw_addr);
723 pci_release_regions(pdev);
728 * e1000_remove - Device Removal Routine
729 * @pdev: PCI device information struct
731 * e1000_remove is called by the PCI subsystem to alert the driver
732 * that it should release a PCI device. The could be caused by a
733 * Hot-Plug event, or because the driver is going to be removed from
737 static void __devexit
738 e1000_remove(struct pci_dev *pdev)
740 struct net_device *netdev = pci_get_drvdata(pdev);
741 struct e1000_adapter *adapter = netdev->priv;
744 flush_scheduled_work();
746 if(adapter->hw.mac_type >= e1000_82540 &&
747 adapter->hw.media_type == e1000_media_type_copper) {
748 manc = E1000_READ_REG(&adapter->hw, MANC);
749 if(manc & E1000_MANC_SMBUS_EN) {
750 manc |= E1000_MANC_ARP_EN;
751 E1000_WRITE_REG(&adapter->hw, MANC, manc);
755 switch(adapter->hw.mac_type) {
757 swsm = E1000_READ_REG(&adapter->hw, SWSM);
758 E1000_WRITE_REG(&adapter->hw, SWSM,
759 swsm & ~E1000_SWSM_DRV_LOAD);
766 unregister_netdev(netdev);
768 if(!e1000_check_phy_reset_block(&adapter->hw))
769 e1000_phy_hw_reset(&adapter->hw);
771 iounmap(adapter->hw.hw_addr);
772 pci_release_regions(pdev);
776 pci_disable_device(pdev);
780 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
781 * @adapter: board private structure to initialize
783 * e1000_sw_init initializes the Adapter private data structure.
784 * Fields are initialized based on PCI device information and
785 * OS network device settings (MTU size).
789 e1000_sw_init(struct e1000_adapter *adapter)
791 struct e1000_hw *hw = &adapter->hw;
792 struct net_device *netdev = adapter->netdev;
793 struct pci_dev *pdev = adapter->pdev;
795 /* PCI config space info */
797 hw->vendor_id = pdev->vendor;
798 hw->device_id = pdev->device;
799 hw->subsystem_vendor_id = pdev->subsystem_vendor;
800 hw->subsystem_id = pdev->subsystem_device;
802 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
804 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
806 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
807 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
808 hw->max_frame_size = netdev->mtu +
809 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
810 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
812 /* identify the MAC */
814 if(e1000_set_mac_type(hw)) {
815 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
819 /* initialize eeprom parameters */
821 if(e1000_init_eeprom_params(hw)) {
822 E1000_ERR("EEPROM initialization failed\n");
826 switch(hw->mac_type) {
831 case e1000_82541_rev_2:
832 case e1000_82547_rev_2:
833 hw->phy_init_script = 1;
837 e1000_set_media_type(hw);
839 hw->wait_autoneg_complete = FALSE;
840 hw->tbi_compatibility_en = TRUE;
841 hw->adaptive_ifs = TRUE;
845 if(hw->media_type == e1000_media_type_copper) {
846 hw->mdix = AUTO_ALL_MODES;
847 hw->disable_polarity_correction = FALSE;
848 hw->master_slave = E1000_MASTER_SLAVE;
851 atomic_set(&adapter->irq_sem, 1);
852 spin_lock_init(&adapter->stats_lock);
853 spin_lock_init(&adapter->tx_lock);
859 * e1000_open - Called when a network interface is made active
860 * @netdev: network interface device structure
862 * Returns 0 on success, negative value on failure
864 * The open entry point is called when a network interface is made
865 * active by the system (IFF_UP). At this point all resources needed
866 * for transmit and receive operations are allocated, the interrupt
867 * handler is registered with the OS, the watchdog timer is started,
868 * and the stack is notified that the interface is ready.
872 e1000_open(struct net_device *netdev)
874 struct e1000_adapter *adapter = netdev->priv;
877 /* allocate transmit descriptors */
879 if((err = e1000_setup_tx_resources(adapter)))
882 /* allocate receive descriptors */
884 if((err = e1000_setup_rx_resources(adapter)))
887 if((err = e1000_up(adapter)))
889 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
890 if((adapter->hw.mng_cookie.status &
891 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
892 e1000_update_mng_vlan(adapter);
895 return E1000_SUCCESS;
898 e1000_free_rx_resources(adapter);
900 e1000_free_tx_resources(adapter);
902 e1000_reset(adapter);
908 * e1000_close - Disables a network interface
909 * @netdev: network interface device structure
911 * Returns 0, this is not allowed to fail
913 * The close entry point is called when an interface is de-activated
914 * by the OS. The hardware is still under the drivers control, but
915 * needs to be disabled. A global MAC reset is issued to stop the
916 * hardware, and all transmit and receive resources are freed.
920 e1000_close(struct net_device *netdev)
922 struct e1000_adapter *adapter = netdev->priv;
926 e1000_free_tx_resources(adapter);
927 e1000_free_rx_resources(adapter);
929 if((adapter->hw.mng_cookie.status &
930 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
931 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
937 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
938 * @adapter: address of board private structure
939 * @start: address of beginning of memory
940 * @len: length of memory
942 static inline boolean_t
943 e1000_check_64k_bound(struct e1000_adapter *adapter,
944 void *start, unsigned long len)
946 unsigned long begin = (unsigned long) start;
947 unsigned long end = begin + len;
949 /* First rev 82545 and 82546 need to not allow any memory
950 * write location to cross 64k boundary due to errata 23 */
951 if (adapter->hw.mac_type == e1000_82545 ||
952 adapter->hw.mac_type == e1000_82546) {
953 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
960 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
961 * @adapter: board private structure
963 * Return 0 on success, negative on failure
967 e1000_setup_tx_resources(struct e1000_adapter *adapter)
969 struct e1000_desc_ring *txdr = &adapter->tx_ring;
970 struct pci_dev *pdev = adapter->pdev;
973 size = sizeof(struct e1000_buffer) * txdr->count;
974 txdr->buffer_info = vmalloc(size);
975 if(!txdr->buffer_info) {
977 "Unable to allocate memory for the transmit descriptor ring\n");
980 memset(txdr->buffer_info, 0, size);
982 /* round up to nearest 4K */
984 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
985 E1000_ROUNDUP(txdr->size, 4096);
987 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
990 vfree(txdr->buffer_info);
992 "Unable to allocate memory for the transmit descriptor ring\n");
996 /* Fix for errata 23, can't cross 64kB boundary */
997 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
998 void *olddesc = txdr->desc;
999 dma_addr_t olddma = txdr->dma;
1000 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1001 "at %p\n", txdr->size, txdr->desc);
1002 /* Try again, without freeing the previous */
1003 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1005 /* Failed allocation, critical failure */
1006 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1007 goto setup_tx_desc_die;
1010 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1012 pci_free_consistent(pdev, txdr->size, txdr->desc,
1014 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1016 "Unable to allocate aligned memory "
1017 "for the transmit descriptor ring\n");
1018 vfree(txdr->buffer_info);
1021 /* Free old allocation, new allocation was successful */
1022 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1025 memset(txdr->desc, 0, txdr->size);
1027 txdr->next_to_use = 0;
1028 txdr->next_to_clean = 0;
1034 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1035 * @adapter: board private structure
1037 * Configure the Tx unit of the MAC after a reset.
1041 e1000_configure_tx(struct e1000_adapter *adapter)
1043 uint64_t tdba = adapter->tx_ring.dma;
1044 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc);
1045 uint32_t tctl, tipg;
1047 E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1048 E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1050 E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
1052 /* Setup the HW Tx Head and Tail descriptor pointers */
1054 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1055 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1057 /* Set the default values for the Tx Inter Packet Gap timer */
1059 switch (adapter->hw.mac_type) {
1060 case e1000_82542_rev2_0:
1061 case e1000_82542_rev2_1:
1062 tipg = DEFAULT_82542_TIPG_IPGT;
1063 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1064 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1067 if(adapter->hw.media_type == e1000_media_type_fiber ||
1068 adapter->hw.media_type == e1000_media_type_internal_serdes)
1069 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1071 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1072 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1073 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1075 E1000_WRITE_REG(&adapter->hw, TIPG, tipg);
1077 /* Set the Tx Interrupt Delay register */
1079 E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
1080 if(adapter->hw.mac_type >= e1000_82540)
1081 E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay);
1083 /* Program the Transmit Control Register */
1085 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1087 tctl &= ~E1000_TCTL_CT;
1088 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
1089 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1091 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1093 e1000_config_collision_dist(&adapter->hw);
1095 /* Setup Transmit Descriptor Settings for eop descriptor */
1096 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1099 if(adapter->hw.mac_type < e1000_82543)
1100 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1102 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1104 /* Cache if we're 82544 running in PCI-X because we'll
1105 * need this to apply a workaround later in the send path. */
1106 if(adapter->hw.mac_type == e1000_82544 &&
1107 adapter->hw.bus_type == e1000_bus_type_pcix)
1108 adapter->pcix_82544 = 1;
1112 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1113 * @adapter: board private structure
1115 * Returns 0 on success, negative on failure
1119 e1000_setup_rx_resources(struct e1000_adapter *adapter)
1121 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
1122 struct pci_dev *pdev = adapter->pdev;
1125 size = sizeof(struct e1000_buffer) * rxdr->count;
1126 rxdr->buffer_info = vmalloc(size);
1127 if(!rxdr->buffer_info) {
1129 "Unable to allocate memory for the receive descriptor ring\n");
1132 memset(rxdr->buffer_info, 0, size);
1134 size = sizeof(struct e1000_ps_page) * rxdr->count;
1135 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1136 if(!rxdr->ps_page) {
1137 vfree(rxdr->buffer_info);
1139 "Unable to allocate memory for the receive descriptor ring\n");
1142 memset(rxdr->ps_page, 0, size);
1144 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1145 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1146 if(!rxdr->ps_page_dma) {
1147 vfree(rxdr->buffer_info);
1148 kfree(rxdr->ps_page);
1150 "Unable to allocate memory for the receive descriptor ring\n");
1153 memset(rxdr->ps_page_dma, 0, size);
1155 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1156 desc_len = sizeof(struct e1000_rx_desc);
1158 desc_len = sizeof(union e1000_rx_desc_packet_split);
1160 /* Round up to nearest 4K */
1162 rxdr->size = rxdr->count * desc_len;
1163 E1000_ROUNDUP(rxdr->size, 4096);
1165 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1169 vfree(rxdr->buffer_info);
1170 kfree(rxdr->ps_page);
1171 kfree(rxdr->ps_page_dma);
1173 "Unable to allocate memory for the receive descriptor ring\n");
1177 /* Fix for errata 23, can't cross 64kB boundary */
1178 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1179 void *olddesc = rxdr->desc;
1180 dma_addr_t olddma = rxdr->dma;
1181 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1182 "at %p\n", rxdr->size, rxdr->desc);
1183 /* Try again, without freeing the previous */
1184 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1186 /* Failed allocation, critical failure */
1187 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1188 goto setup_rx_desc_die;
1191 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1193 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1195 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1197 "Unable to allocate aligned memory "
1198 "for the receive descriptor ring\n");
1199 vfree(rxdr->buffer_info);
1200 kfree(rxdr->ps_page);
1201 kfree(rxdr->ps_page_dma);
1204 /* Free old allocation, new allocation was successful */
1205 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1208 memset(rxdr->desc, 0, rxdr->size);
1210 rxdr->next_to_clean = 0;
1211 rxdr->next_to_use = 0;
1217 * e1000_setup_rctl - configure the receive control registers
1218 * @adapter: Board private structure
1222 e1000_setup_rctl(struct e1000_adapter *adapter)
1224 uint32_t rctl, rfctl;
1225 uint32_t psrctl = 0;
1227 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1229 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1231 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1232 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1233 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1235 if(adapter->hw.tbi_compatibility_on == 1)
1236 rctl |= E1000_RCTL_SBP;
1238 rctl &= ~E1000_RCTL_SBP;
1240 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1241 rctl &= ~E1000_RCTL_LPE;
1243 rctl |= E1000_RCTL_LPE;
1245 /* Setup buffer sizes */
1246 if(adapter->hw.mac_type == e1000_82573) {
1247 /* We can now specify buffers in 1K increments.
1248 * BSIZE and BSEX are ignored in this case. */
1249 rctl |= adapter->rx_buffer_len << 0x11;
1251 rctl &= ~E1000_RCTL_SZ_4096;
1252 rctl |= E1000_RCTL_BSEX;
1253 switch (adapter->rx_buffer_len) {
1254 case E1000_RXBUFFER_2048:
1256 rctl |= E1000_RCTL_SZ_2048;
1257 rctl &= ~E1000_RCTL_BSEX;
1259 case E1000_RXBUFFER_4096:
1260 rctl |= E1000_RCTL_SZ_4096;
1262 case E1000_RXBUFFER_8192:
1263 rctl |= E1000_RCTL_SZ_8192;
1265 case E1000_RXBUFFER_16384:
1266 rctl |= E1000_RCTL_SZ_16384;
1271 #ifdef CONFIG_E1000_PACKET_SPLIT
1272 /* 82571 and greater support packet-split where the protocol
1273 * header is placed in skb->data and the packet data is
1274 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1275 * In the case of a non-split, skb->data is linearly filled,
1276 * followed by the page buffers. Therefore, skb->data is
1277 * sized to hold the largest protocol header.
1279 adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2)
1280 && (adapter->netdev->mtu
1281 < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0));
1283 if(adapter->rx_ps) {
1284 /* Configure extra packet-split registers */
1285 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1286 rfctl |= E1000_RFCTL_EXTEN;
1287 /* disable IPv6 packet split support */
1288 rfctl |= E1000_RFCTL_IPV6_DIS;
1289 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1291 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1293 psrctl |= adapter->rx_ps_bsize0 >>
1294 E1000_PSRCTL_BSIZE0_SHIFT;
1295 psrctl |= PAGE_SIZE >>
1296 E1000_PSRCTL_BSIZE1_SHIFT;
1297 psrctl |= PAGE_SIZE <<
1298 E1000_PSRCTL_BSIZE2_SHIFT;
1299 psrctl |= PAGE_SIZE <<
1300 E1000_PSRCTL_BSIZE3_SHIFT;
1302 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1305 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1309 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1310 * @adapter: board private structure
1312 * Configure the Rx unit of the MAC after a reset.
1316 e1000_configure_rx(struct e1000_adapter *adapter)
1318 uint64_t rdba = adapter->rx_ring.dma;
1319 uint32_t rdlen, rctl, rxcsum;
1321 if(adapter->rx_ps) {
1322 rdlen = adapter->rx_ring.count *
1323 sizeof(union e1000_rx_desc_packet_split);
1324 adapter->clean_rx = e1000_clean_rx_irq_ps;
1325 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1327 rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc);
1328 adapter->clean_rx = e1000_clean_rx_irq;
1329 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1332 /* disable receives while setting up the descriptors */
1333 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1334 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1336 /* set the Receive Delay Timer Register */
1337 E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay);
1339 if(adapter->hw.mac_type >= e1000_82540) {
1340 E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay);
1341 if(adapter->itr > 1)
1342 E1000_WRITE_REG(&adapter->hw, ITR,
1343 1000000000 / (adapter->itr * 256));
1346 /* Setup the Base and Length of the Rx Descriptor Ring */
1347 E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1348 E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
1350 E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen);
1352 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1353 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1354 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1356 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1357 if(adapter->hw.mac_type >= e1000_82543) {
1358 rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
1359 if(adapter->rx_csum == TRUE) {
1360 rxcsum |= E1000_RXCSUM_TUOFL;
1362 /* Enable 82573 IPv4 payload checksum for UDP fragments
1363 * Must be used in conjunction with packet-split. */
1364 if((adapter->hw.mac_type > e1000_82547_rev_2) &&
1366 rxcsum |= E1000_RXCSUM_IPPCSE;
1369 rxcsum &= ~E1000_RXCSUM_TUOFL;
1370 /* don't need to clear IPPCSE as it defaults to 0 */
1372 E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum);
1375 if (adapter->hw.mac_type == e1000_82573)
1376 E1000_WRITE_REG(&adapter->hw, ERT, 0x0100);
1378 /* Enable Receives */
1379 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1383 * e1000_free_tx_resources - Free Tx Resources
1384 * @adapter: board private structure
1386 * Free all transmit software resources
1390 e1000_free_tx_resources(struct e1000_adapter *adapter)
1392 struct pci_dev *pdev = adapter->pdev;
1394 e1000_clean_tx_ring(adapter);
1396 vfree(adapter->tx_ring.buffer_info);
1397 adapter->tx_ring.buffer_info = NULL;
1399 pci_free_consistent(pdev, adapter->tx_ring.size,
1400 adapter->tx_ring.desc, adapter->tx_ring.dma);
1402 adapter->tx_ring.desc = NULL;
1406 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1407 struct e1000_buffer *buffer_info)
1409 if(buffer_info->dma) {
1410 pci_unmap_page(adapter->pdev,
1412 buffer_info->length,
1414 buffer_info->dma = 0;
1416 if(buffer_info->skb) {
1417 dev_kfree_skb_any(buffer_info->skb);
1418 buffer_info->skb = NULL;
1423 * e1000_clean_tx_ring - Free Tx Buffers
1424 * @adapter: board private structure
1428 e1000_clean_tx_ring(struct e1000_adapter *adapter)
1430 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1431 struct e1000_buffer *buffer_info;
1435 /* Free all the Tx ring sk_buffs */
1437 if (likely(adapter->previous_buffer_info.skb != NULL)) {
1438 e1000_unmap_and_free_tx_resource(adapter,
1439 &adapter->previous_buffer_info);
1442 for(i = 0; i < tx_ring->count; i++) {
1443 buffer_info = &tx_ring->buffer_info[i];
1444 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1447 size = sizeof(struct e1000_buffer) * tx_ring->count;
1448 memset(tx_ring->buffer_info, 0, size);
1450 /* Zero out the descriptor ring */
1452 memset(tx_ring->desc, 0, tx_ring->size);
1454 tx_ring->next_to_use = 0;
1455 tx_ring->next_to_clean = 0;
1457 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1458 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1462 * e1000_free_rx_resources - Free Rx Resources
1463 * @adapter: board private structure
1465 * Free all receive software resources
1469 e1000_free_rx_resources(struct e1000_adapter *adapter)
1471 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1472 struct pci_dev *pdev = adapter->pdev;
1474 e1000_clean_rx_ring(adapter);
1476 vfree(rx_ring->buffer_info);
1477 rx_ring->buffer_info = NULL;
1478 kfree(rx_ring->ps_page);
1479 rx_ring->ps_page = NULL;
1480 kfree(rx_ring->ps_page_dma);
1481 rx_ring->ps_page_dma = NULL;
1483 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1485 rx_ring->desc = NULL;
1489 * e1000_clean_rx_ring - Free Rx Buffers
1490 * @adapter: board private structure
1494 e1000_clean_rx_ring(struct e1000_adapter *adapter)
1496 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1497 struct e1000_buffer *buffer_info;
1498 struct e1000_ps_page *ps_page;
1499 struct e1000_ps_page_dma *ps_page_dma;
1500 struct pci_dev *pdev = adapter->pdev;
1504 /* Free all the Rx ring sk_buffs */
1506 for(i = 0; i < rx_ring->count; i++) {
1507 buffer_info = &rx_ring->buffer_info[i];
1508 if(buffer_info->skb) {
1509 ps_page = &rx_ring->ps_page[i];
1510 ps_page_dma = &rx_ring->ps_page_dma[i];
1511 pci_unmap_single(pdev,
1513 buffer_info->length,
1514 PCI_DMA_FROMDEVICE);
1516 dev_kfree_skb(buffer_info->skb);
1517 buffer_info->skb = NULL;
1519 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
1520 if(!ps_page->ps_page[j]) break;
1521 pci_unmap_single(pdev,
1522 ps_page_dma->ps_page_dma[j],
1523 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1524 ps_page_dma->ps_page_dma[j] = 0;
1525 put_page(ps_page->ps_page[j]);
1526 ps_page->ps_page[j] = NULL;
1531 size = sizeof(struct e1000_buffer) * rx_ring->count;
1532 memset(rx_ring->buffer_info, 0, size);
1533 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1534 memset(rx_ring->ps_page, 0, size);
1535 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1536 memset(rx_ring->ps_page_dma, 0, size);
1538 /* Zero out the descriptor ring */
1540 memset(rx_ring->desc, 0, rx_ring->size);
1542 rx_ring->next_to_clean = 0;
1543 rx_ring->next_to_use = 0;
1545 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1546 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1549 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1550 * and memory write and invalidate disabled for certain operations
1553 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1555 struct net_device *netdev = adapter->netdev;
1558 e1000_pci_clear_mwi(&adapter->hw);
1560 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1561 rctl |= E1000_RCTL_RST;
1562 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1563 E1000_WRITE_FLUSH(&adapter->hw);
1566 if(netif_running(netdev))
1567 e1000_clean_rx_ring(adapter);
1571 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1573 struct net_device *netdev = adapter->netdev;
1576 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1577 rctl &= ~E1000_RCTL_RST;
1578 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1579 E1000_WRITE_FLUSH(&adapter->hw);
1582 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
1583 e1000_pci_set_mwi(&adapter->hw);
1585 if(netif_running(netdev)) {
1586 e1000_configure_rx(adapter);
1587 e1000_alloc_rx_buffers(adapter);
1592 * e1000_set_mac - Change the Ethernet Address of the NIC
1593 * @netdev: network interface device structure
1594 * @p: pointer to an address structure
1596 * Returns 0 on success, negative on failure
1600 e1000_set_mac(struct net_device *netdev, void *p)
1602 struct e1000_adapter *adapter = netdev->priv;
1603 struct sockaddr *addr = p;
1605 if(!is_valid_ether_addr(addr->sa_data))
1606 return -EADDRNOTAVAIL;
1608 /* 82542 2.0 needs to be in reset to write receive address registers */
1610 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1611 e1000_enter_82542_rst(adapter);
1613 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1614 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
1616 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
1618 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1619 e1000_leave_82542_rst(adapter);
1625 * e1000_set_multi - Multicast and Promiscuous mode set
1626 * @netdev: network interface device structure
1628 * The set_multi entry point is called whenever the multicast address
1629 * list or the network interface flags are updated. This routine is
1630 * responsible for configuring the hardware for proper multicast,
1631 * promiscuous mode, and all-multi behavior.
1635 e1000_set_multi(struct net_device *netdev)
1637 struct e1000_adapter *adapter = netdev->priv;
1638 struct e1000_hw *hw = &adapter->hw;
1639 struct dev_mc_list *mc_ptr;
1640 unsigned long flags;
1642 uint32_t hash_value;
1645 spin_lock_irqsave(&adapter->tx_lock, flags);
1647 /* Check for Promiscuous and All Multicast modes */
1649 rctl = E1000_READ_REG(hw, RCTL);
1651 if(netdev->flags & IFF_PROMISC) {
1652 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1653 } else if(netdev->flags & IFF_ALLMULTI) {
1654 rctl |= E1000_RCTL_MPE;
1655 rctl &= ~E1000_RCTL_UPE;
1657 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
1660 E1000_WRITE_REG(hw, RCTL, rctl);
1662 /* 82542 2.0 needs to be in reset to write receive address registers */
1664 if(hw->mac_type == e1000_82542_rev2_0)
1665 e1000_enter_82542_rst(adapter);
1667 /* load the first 14 multicast address into the exact filters 1-14
1668 * RAR 0 is used for the station MAC adddress
1669 * if there are not 14 addresses, go ahead and clear the filters
1671 mc_ptr = netdev->mc_list;
1673 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
1675 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
1676 mc_ptr = mc_ptr->next;
1678 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
1679 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
1683 /* clear the old settings from the multicast hash table */
1685 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
1686 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1688 /* load any remaining addresses into the hash table */
1690 for(; mc_ptr; mc_ptr = mc_ptr->next) {
1691 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
1692 e1000_mta_set(hw, hash_value);
1695 if(hw->mac_type == e1000_82542_rev2_0)
1696 e1000_leave_82542_rst(adapter);
1698 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1701 /* Need to wait a few seconds after link up to get diagnostic information from
1705 e1000_update_phy_info(unsigned long data)
1707 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1708 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
1712 * e1000_82547_tx_fifo_stall - Timer Call-back
1713 * @data: pointer to adapter cast into an unsigned long
1717 e1000_82547_tx_fifo_stall(unsigned long data)
1719 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1720 struct net_device *netdev = adapter->netdev;
1723 if(atomic_read(&adapter->tx_fifo_stall)) {
1724 if((E1000_READ_REG(&adapter->hw, TDT) ==
1725 E1000_READ_REG(&adapter->hw, TDH)) &&
1726 (E1000_READ_REG(&adapter->hw, TDFT) ==
1727 E1000_READ_REG(&adapter->hw, TDFH)) &&
1728 (E1000_READ_REG(&adapter->hw, TDFTS) ==
1729 E1000_READ_REG(&adapter->hw, TDFHS))) {
1730 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1731 E1000_WRITE_REG(&adapter->hw, TCTL,
1732 tctl & ~E1000_TCTL_EN);
1733 E1000_WRITE_REG(&adapter->hw, TDFT,
1734 adapter->tx_head_addr);
1735 E1000_WRITE_REG(&adapter->hw, TDFH,
1736 adapter->tx_head_addr);
1737 E1000_WRITE_REG(&adapter->hw, TDFTS,
1738 adapter->tx_head_addr);
1739 E1000_WRITE_REG(&adapter->hw, TDFHS,
1740 adapter->tx_head_addr);
1741 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1742 E1000_WRITE_FLUSH(&adapter->hw);
1744 adapter->tx_fifo_head = 0;
1745 atomic_set(&adapter->tx_fifo_stall, 0);
1746 netif_wake_queue(netdev);
1748 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
1754 * e1000_watchdog - Timer Call-back
1755 * @data: pointer to adapter cast into an unsigned long
1758 e1000_watchdog(unsigned long data)
1760 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1762 /* Do the rest outside of interrupt context */
1763 schedule_work(&adapter->watchdog_task);
1767 e1000_watchdog_task(struct e1000_adapter *adapter)
1769 struct net_device *netdev = adapter->netdev;
1770 struct e1000_desc_ring *txdr = &adapter->tx_ring;
1773 e1000_check_for_link(&adapter->hw);
1774 if (adapter->hw.mac_type == e1000_82573) {
1775 e1000_enable_tx_pkt_filtering(&adapter->hw);
1776 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
1777 e1000_update_mng_vlan(adapter);
1780 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
1781 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
1782 link = !adapter->hw.serdes_link_down;
1784 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
1787 if(!netif_carrier_ok(netdev)) {
1788 e1000_get_speed_and_duplex(&adapter->hw,
1789 &adapter->link_speed,
1790 &adapter->link_duplex);
1792 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
1793 adapter->link_speed,
1794 adapter->link_duplex == FULL_DUPLEX ?
1795 "Full Duplex" : "Half Duplex");
1797 netif_carrier_on(netdev);
1798 netif_wake_queue(netdev);
1799 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1800 adapter->smartspeed = 0;
1803 if(netif_carrier_ok(netdev)) {
1804 adapter->link_speed = 0;
1805 adapter->link_duplex = 0;
1806 DPRINTK(LINK, INFO, "NIC Link is Down\n");
1807 netif_carrier_off(netdev);
1808 netif_stop_queue(netdev);
1809 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1812 e1000_smartspeed(adapter);
1815 e1000_update_stats(adapter);
1817 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
1818 adapter->tpt_old = adapter->stats.tpt;
1819 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
1820 adapter->colc_old = adapter->stats.colc;
1822 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
1823 adapter->gorcl_old = adapter->stats.gorcl;
1824 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
1825 adapter->gotcl_old = adapter->stats.gotcl;
1827 e1000_update_adaptive(&adapter->hw);
1829 if(!netif_carrier_ok(netdev)) {
1830 if(E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
1831 /* We've lost link, so the controller stops DMA,
1832 * but we've got queued Tx work that's never going
1833 * to get done, so reset controller to flush Tx.
1834 * (Do the reset outside of interrupt context). */
1835 schedule_work(&adapter->tx_timeout_task);
1839 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
1840 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
1841 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
1842 * asymmetrical Tx or Rx gets ITR=8000; everyone
1843 * else is between 2000-8000. */
1844 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
1845 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
1846 adapter->gotcl - adapter->gorcl :
1847 adapter->gorcl - adapter->gotcl) / 10000;
1848 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
1849 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
1852 /* Cause software interrupt to ensure rx ring is cleaned */
1853 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
1855 /* Force detection of hung controller every watchdog period */
1856 adapter->detect_tx_hung = TRUE;
1858 /* Reset the timer */
1859 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1862 #define E1000_TX_FLAGS_CSUM 0x00000001
1863 #define E1000_TX_FLAGS_VLAN 0x00000002
1864 #define E1000_TX_FLAGS_TSO 0x00000004
1865 #define E1000_TX_FLAGS_IPV4 0x00000008
1866 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
1867 #define E1000_TX_FLAGS_VLAN_SHIFT 16
1870 e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1873 struct e1000_context_desc *context_desc;
1875 uint32_t cmd_length = 0;
1876 uint16_t ipcse = 0, tucse, mss;
1877 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1880 if(skb_shinfo(skb)->tso_size) {
1881 if (skb_header_cloned(skb)) {
1882 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1887 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1888 mss = skb_shinfo(skb)->tso_size;
1889 if(skb->protocol == ntohs(ETH_P_IP)) {
1890 skb->nh.iph->tot_len = 0;
1891 skb->nh.iph->check = 0;
1893 ~csum_tcpudp_magic(skb->nh.iph->saddr,
1898 cmd_length = E1000_TXD_CMD_IP;
1899 ipcse = skb->h.raw - skb->data - 1;
1900 #ifdef NETIF_F_TSO_IPV6
1901 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
1902 skb->nh.ipv6h->payload_len = 0;
1904 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
1905 &skb->nh.ipv6h->daddr,
1912 ipcss = skb->nh.raw - skb->data;
1913 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1914 tucss = skb->h.raw - skb->data;
1915 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1918 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
1919 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
1921 i = adapter->tx_ring.next_to_use;
1922 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1924 context_desc->lower_setup.ip_fields.ipcss = ipcss;
1925 context_desc->lower_setup.ip_fields.ipcso = ipcso;
1926 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
1927 context_desc->upper_setup.tcp_fields.tucss = tucss;
1928 context_desc->upper_setup.tcp_fields.tucso = tucso;
1929 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
1930 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
1931 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
1932 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
1934 if(++i == adapter->tx_ring.count) i = 0;
1935 adapter->tx_ring.next_to_use = i;
1944 static inline boolean_t
1945 e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1947 struct e1000_context_desc *context_desc;
1951 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1952 css = skb->h.raw - skb->data;
1954 i = adapter->tx_ring.next_to_use;
1955 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1957 context_desc->upper_setup.tcp_fields.tucss = css;
1958 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
1959 context_desc->upper_setup.tcp_fields.tucse = 0;
1960 context_desc->tcp_seg_setup.data = 0;
1961 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
1963 if(unlikely(++i == adapter->tx_ring.count)) i = 0;
1964 adapter->tx_ring.next_to_use = i;
1972 #define E1000_MAX_TXD_PWR 12
1973 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
1976 e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb,
1977 unsigned int first, unsigned int max_per_txd,
1978 unsigned int nr_frags, unsigned int mss)
1980 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1981 struct e1000_buffer *buffer_info;
1982 unsigned int len = skb->len;
1983 unsigned int offset = 0, size, count = 0, i;
1985 len -= skb->data_len;
1987 i = tx_ring->next_to_use;
1990 buffer_info = &tx_ring->buffer_info[i];
1991 size = min(len, max_per_txd);
1993 /* Workaround for premature desc write-backs
1994 * in TSO mode. Append 4-byte sentinel desc */
1995 if(unlikely(mss && !nr_frags && size == len && size > 8))
1998 /* work-around for errata 10 and it applies
1999 * to all controllers in PCI-X mode
2000 * The fix is to make sure that the first descriptor of a
2001 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2003 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2004 (size > 2015) && count == 0))
2007 /* Workaround for potential 82544 hang in PCI-X. Avoid
2008 * terminating buffers within evenly-aligned dwords. */
2009 if(unlikely(adapter->pcix_82544 &&
2010 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2014 buffer_info->length = size;
2016 pci_map_single(adapter->pdev,
2020 buffer_info->time_stamp = jiffies;
2025 if(unlikely(++i == tx_ring->count)) i = 0;
2028 for(f = 0; f < nr_frags; f++) {
2029 struct skb_frag_struct *frag;
2031 frag = &skb_shinfo(skb)->frags[f];
2033 offset = frag->page_offset;
2036 buffer_info = &tx_ring->buffer_info[i];
2037 size = min(len, max_per_txd);
2039 /* Workaround for premature desc write-backs
2040 * in TSO mode. Append 4-byte sentinel desc */
2041 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2044 /* Workaround for potential 82544 hang in PCI-X.
2045 * Avoid terminating buffers within evenly-aligned
2047 if(unlikely(adapter->pcix_82544 &&
2048 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2052 buffer_info->length = size;
2054 pci_map_page(adapter->pdev,
2059 buffer_info->time_stamp = jiffies;
2064 if(unlikely(++i == tx_ring->count)) i = 0;
2068 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2069 tx_ring->buffer_info[i].skb = skb;
2070 tx_ring->buffer_info[first].next_to_watch = i;
2076 e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
2078 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2079 struct e1000_tx_desc *tx_desc = NULL;
2080 struct e1000_buffer *buffer_info;
2081 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2084 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2085 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2087 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2089 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2090 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2093 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2094 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2095 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2098 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2099 txd_lower |= E1000_TXD_CMD_VLE;
2100 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2103 i = tx_ring->next_to_use;
2106 buffer_info = &tx_ring->buffer_info[i];
2107 tx_desc = E1000_TX_DESC(*tx_ring, i);
2108 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2109 tx_desc->lower.data =
2110 cpu_to_le32(txd_lower | buffer_info->length);
2111 tx_desc->upper.data = cpu_to_le32(txd_upper);
2112 if(unlikely(++i == tx_ring->count)) i = 0;
2115 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2117 /* Force memory writes to complete before letting h/w
2118 * know there are new descriptors to fetch. (Only
2119 * applicable for weak-ordered memory model archs,
2120 * such as IA-64). */
2123 tx_ring->next_to_use = i;
2124 E1000_WRITE_REG(&adapter->hw, TDT, i);
2128 * 82547 workaround to avoid controller hang in half-duplex environment.
2129 * The workaround is to avoid queuing a large packet that would span
2130 * the internal Tx FIFO ring boundary by notifying the stack to resend
2131 * the packet at a later time. This gives the Tx FIFO an opportunity to
2132 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2133 * to the beginning of the Tx FIFO.
2136 #define E1000_FIFO_HDR 0x10
2137 #define E1000_82547_PAD_LEN 0x3E0
2140 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2142 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2143 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2145 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2147 if(adapter->link_duplex != HALF_DUPLEX)
2148 goto no_fifo_stall_required;
2150 if(atomic_read(&adapter->tx_fifo_stall))
2153 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2154 atomic_set(&adapter->tx_fifo_stall, 1);
2158 no_fifo_stall_required:
2159 adapter->tx_fifo_head += skb_fifo_len;
2160 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2161 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2165 #define MINIMUM_DHCP_PACKET_SIZE 282
2167 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2169 struct e1000_hw *hw = &adapter->hw;
2170 uint16_t length, offset;
2171 if(vlan_tx_tag_present(skb)) {
2172 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2173 ( adapter->hw.mng_cookie.status &
2174 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2177 if(htons(ETH_P_IP) == skb->protocol) {
2178 const struct iphdr *ip = skb->nh.iph;
2179 if(IPPROTO_UDP == ip->protocol) {
2180 struct udphdr *udp = (struct udphdr *)(skb->h.uh);
2181 if(ntohs(udp->dest) == 67) {
2182 offset = (uint8_t *)udp + 8 - skb->data;
2183 length = skb->len - offset;
2185 return e1000_mng_write_dhcp_info(hw,
2186 (uint8_t *)udp + 8, length);
2189 } else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2190 struct ethhdr *eth = (struct ethhdr *) skb->data;
2191 if((htons(ETH_P_IP) == eth->h_proto)) {
2192 const struct iphdr *ip =
2193 (struct iphdr *)((uint8_t *)skb->data+14);
2194 if(IPPROTO_UDP == ip->protocol) {
2195 struct udphdr *udp =
2196 (struct udphdr *)((uint8_t *)ip +
2198 if(ntohs(udp->dest) == 67) {
2199 offset = (uint8_t *)udp + 8 - skb->data;
2200 length = skb->len - offset;
2202 return e1000_mng_write_dhcp_info(hw,
2212 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2214 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2216 struct e1000_adapter *adapter = netdev->priv;
2217 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2218 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2219 unsigned int tx_flags = 0;
2220 unsigned int len = skb->len;
2221 unsigned long flags;
2222 unsigned int nr_frags = 0;
2223 unsigned int mss = 0;
2227 len -= skb->data_len;
2229 if(unlikely(skb->len <= 0)) {
2230 dev_kfree_skb_any(skb);
2231 return NETDEV_TX_OK;
2235 mss = skb_shinfo(skb)->tso_size;
2236 /* The controller does a simple calculation to
2237 * make sure there is enough room in the FIFO before
2238 * initiating the DMA for each buffer. The calc is:
2239 * 4 = ceil(buffer len/mss). To make sure we don't
2240 * overrun the FIFO, adjust the max buffer len if mss
2243 max_per_txd = min(mss << 2, max_per_txd);
2244 max_txd_pwr = fls(max_per_txd) - 1;
2247 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2251 if(skb->ip_summed == CHECKSUM_HW)
2254 count += TXD_USE_COUNT(len, max_txd_pwr);
2256 if(adapter->pcix_82544)
2259 /* work-around for errata 10 and it applies to all controllers
2260 * in PCI-X mode, so add one more descriptor to the count
2262 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2266 nr_frags = skb_shinfo(skb)->nr_frags;
2267 for(f = 0; f < nr_frags; f++)
2268 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2270 if(adapter->pcix_82544)
2273 local_irq_save(flags);
2274 if (!spin_trylock(&adapter->tx_lock)) {
2275 /* Collision - tell upper layer to requeue */
2276 local_irq_restore(flags);
2277 return NETDEV_TX_LOCKED;
2279 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2280 e1000_transfer_dhcp_info(adapter, skb);
2283 /* need: count + 2 desc gap to keep tail from touching
2284 * head, otherwise try next time */
2285 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < count + 2)) {
2286 netif_stop_queue(netdev);
2287 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2288 return NETDEV_TX_BUSY;
2291 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2292 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2293 netif_stop_queue(netdev);
2294 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2295 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2296 return NETDEV_TX_BUSY;
2300 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2301 tx_flags |= E1000_TX_FLAGS_VLAN;
2302 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2305 first = adapter->tx_ring.next_to_use;
2307 tso = e1000_tso(adapter, skb);
2309 dev_kfree_skb_any(skb);
2310 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2311 return NETDEV_TX_OK;
2315 tx_flags |= E1000_TX_FLAGS_TSO;
2316 else if(likely(e1000_tx_csum(adapter, skb)))
2317 tx_flags |= E1000_TX_FLAGS_CSUM;
2319 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2320 * 82573 hardware supports TSO capabilities for IPv6 as well...
2321 * no longer assume, we must. */
2322 if(likely(skb->protocol == ntohs(ETH_P_IP)))
2323 tx_flags |= E1000_TX_FLAGS_IPV4;
2325 e1000_tx_queue(adapter,
2326 e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss),
2329 netdev->trans_start = jiffies;
2331 /* Make sure there is space in the ring for the next send. */
2332 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2))
2333 netif_stop_queue(netdev);
2335 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2336 return NETDEV_TX_OK;
2340 * e1000_tx_timeout - Respond to a Tx Hang
2341 * @netdev: network interface device structure
2345 e1000_tx_timeout(struct net_device *netdev)
2347 struct e1000_adapter *adapter = netdev->priv;
2349 /* Do the reset outside of interrupt context */
2350 schedule_work(&adapter->tx_timeout_task);
2354 e1000_tx_timeout_task(struct net_device *netdev)
2356 struct e1000_adapter *adapter = netdev->priv;
2358 e1000_down(adapter);
2363 * e1000_get_stats - Get System Network Statistics
2364 * @netdev: network interface device structure
2366 * Returns the address of the device statistics structure.
2367 * The statistics are actually updated from the timer callback.
2370 static struct net_device_stats *
2371 e1000_get_stats(struct net_device *netdev)
2373 struct e1000_adapter *adapter = netdev->priv;
2375 e1000_update_stats(adapter);
2376 return &adapter->net_stats;
2380 * e1000_change_mtu - Change the Maximum Transfer Unit
2381 * @netdev: network interface device structure
2382 * @new_mtu: new value for maximum frame size
2384 * Returns 0 on success, negative on failure
2388 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2390 struct e1000_adapter *adapter = netdev->priv;
2391 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2393 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2394 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2395 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2399 #define MAX_STD_JUMBO_FRAME_SIZE 9216
2400 /* might want this to be bigger enum check... */
2401 if (adapter->hw.mac_type == e1000_82573 &&
2402 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2403 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2408 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2409 adapter->rx_buffer_len = max_frame;
2410 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2412 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2413 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2414 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2419 if(max_frame <= E1000_RXBUFFER_2048) {
2420 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2421 } else if(max_frame <= E1000_RXBUFFER_4096) {
2422 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2423 } else if(max_frame <= E1000_RXBUFFER_8192) {
2424 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2425 } else if(max_frame <= E1000_RXBUFFER_16384) {
2426 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2431 netdev->mtu = new_mtu;
2433 if(netif_running(netdev)) {
2434 e1000_down(adapter);
2438 adapter->hw.max_frame_size = max_frame;
2444 * e1000_update_stats - Update the board statistics counters
2445 * @adapter: board private structure
2449 e1000_update_stats(struct e1000_adapter *adapter)
2451 struct e1000_hw *hw = &adapter->hw;
2452 unsigned long flags;
2455 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2457 spin_lock_irqsave(&adapter->stats_lock, flags);
2459 /* these counters are modified from e1000_adjust_tbi_stats,
2460 * called from the interrupt context, so they must only
2461 * be written while holding adapter->stats_lock
2464 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2465 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2466 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2467 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2468 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2469 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2470 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2471 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2472 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2473 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2474 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2475 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2476 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2478 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2479 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2480 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2481 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2482 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2483 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2484 adapter->stats.dc += E1000_READ_REG(hw, DC);
2485 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2486 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2487 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2488 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2489 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2490 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2491 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2492 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2493 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2494 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2495 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2496 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2497 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2498 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2499 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2500 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2501 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2502 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2503 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2504 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2505 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2506 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2507 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2508 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2509 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2510 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2511 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2513 /* used for adaptive IFS */
2515 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2516 adapter->stats.tpt += hw->tx_packet_delta;
2517 hw->collision_delta = E1000_READ_REG(hw, COLC);
2518 adapter->stats.colc += hw->collision_delta;
2520 if(hw->mac_type >= e1000_82543) {
2521 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2522 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
2523 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
2524 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
2525 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
2526 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
2528 if(hw->mac_type > e1000_82547_rev_2) {
2529 adapter->stats.iac += E1000_READ_REG(hw, IAC);
2530 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
2531 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
2532 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
2533 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
2534 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
2535 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
2536 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
2537 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
2540 /* Fill out the OS statistics structure */
2542 adapter->net_stats.rx_packets = adapter->stats.gprc;
2543 adapter->net_stats.tx_packets = adapter->stats.gptc;
2544 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2545 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2546 adapter->net_stats.multicast = adapter->stats.mprc;
2547 adapter->net_stats.collisions = adapter->stats.colc;
2551 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2552 adapter->stats.crcerrs + adapter->stats.algnerrc +
2553 adapter->stats.rlec + adapter->stats.mpc +
2554 adapter->stats.cexterr;
2555 adapter->net_stats.rx_dropped = adapter->stats.mpc;
2556 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2557 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2558 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2559 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
2560 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2564 adapter->net_stats.tx_errors = adapter->stats.ecol +
2565 adapter->stats.latecol;
2566 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2567 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2568 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2570 /* Tx Dropped needs to be maintained elsewhere */
2574 if(hw->media_type == e1000_media_type_copper) {
2575 if((adapter->link_speed == SPEED_1000) &&
2576 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
2577 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2578 adapter->phy_stats.idle_errors += phy_tmp;
2581 if((hw->mac_type <= e1000_82546) &&
2582 (hw->phy_type == e1000_phy_m88) &&
2583 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
2584 adapter->phy_stats.receive_errors += phy_tmp;
2587 spin_unlock_irqrestore(&adapter->stats_lock, flags);
2591 * e1000_intr - Interrupt Handler
2592 * @irq: interrupt number
2593 * @data: pointer to a network interface device structure
2594 * @pt_regs: CPU registers structure
2598 e1000_intr(int irq, void *data, struct pt_regs *regs)
2600 struct net_device *netdev = data;
2601 struct e1000_adapter *adapter = netdev->priv;
2602 struct e1000_hw *hw = &adapter->hw;
2603 uint32_t icr = E1000_READ_REG(hw, ICR);
2604 #ifndef CONFIG_E1000_NAPI
2609 return IRQ_NONE; /* Not our interrupt */
2611 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
2612 hw->get_link_status = 1;
2613 mod_timer(&adapter->watchdog_timer, jiffies);
2616 #ifdef CONFIG_E1000_NAPI
2617 if(likely(netif_rx_schedule_prep(netdev))) {
2619 /* Disable interrupts and register for poll. The flush
2620 of the posted write is intentionally left out.
2623 atomic_inc(&adapter->irq_sem);
2624 E1000_WRITE_REG(hw, IMC, ~0);
2625 __netif_rx_schedule(netdev);
2628 /* Writing IMC and IMS is needed for 82547.
2629 Due to Hub Link bus being occupied, an interrupt
2630 de-assertion message is not able to be sent.
2631 When an interrupt assertion message is generated later,
2632 two messages are re-ordered and sent out.
2633 That causes APIC to think 82547 is in de-assertion
2634 state, while 82547 is in assertion state, resulting
2635 in dead lock. Writing IMC forces 82547 into
2638 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
2639 atomic_inc(&adapter->irq_sem);
2640 E1000_WRITE_REG(hw, IMC, ~0);
2643 for(i = 0; i < E1000_MAX_INTR; i++)
2644 if(unlikely(!adapter->clean_rx(adapter) &
2645 !e1000_clean_tx_irq(adapter)))
2648 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
2649 e1000_irq_enable(adapter);
2655 #ifdef CONFIG_E1000_NAPI
2657 * e1000_clean - NAPI Rx polling callback
2658 * @adapter: board private structure
2662 e1000_clean(struct net_device *netdev, int *budget)
2664 struct e1000_adapter *adapter = netdev->priv;
2665 int work_to_do = min(*budget, netdev->quota);
2669 tx_cleaned = e1000_clean_tx_irq(adapter);
2670 adapter->clean_rx(adapter, &work_done, work_to_do);
2672 *budget -= work_done;
2673 netdev->quota -= work_done;
2675 /* If no Tx and no Rx work done, exit the polling mode */
2676 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2677 netif_rx_complete(netdev);
2678 e1000_irq_enable(adapter);
2687 * e1000_clean_tx_irq - Reclaim resources after transmit completes
2688 * @adapter: board private structure
2692 e1000_clean_tx_irq(struct e1000_adapter *adapter)
2694 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2695 struct net_device *netdev = adapter->netdev;
2696 struct e1000_tx_desc *tx_desc, *eop_desc;
2697 struct e1000_buffer *buffer_info;
2698 unsigned int i, eop;
2699 boolean_t cleaned = FALSE;
2701 i = tx_ring->next_to_clean;
2702 eop = tx_ring->buffer_info[i].next_to_watch;
2703 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2705 while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
2706 /* Premature writeback of Tx descriptors clear (free buffers
2707 * and unmap pci_mapping) previous_buffer_info */
2708 if (likely(adapter->previous_buffer_info.skb != NULL)) {
2709 e1000_unmap_and_free_tx_resource(adapter,
2710 &adapter->previous_buffer_info);
2713 for(cleaned = FALSE; !cleaned; ) {
2714 tx_desc = E1000_TX_DESC(*tx_ring, i);
2715 buffer_info = &tx_ring->buffer_info[i];
2716 cleaned = (i == eop);
2719 if (!(netdev->features & NETIF_F_TSO)) {
2721 e1000_unmap_and_free_tx_resource(adapter,
2726 memcpy(&adapter->previous_buffer_info,
2728 sizeof(struct e1000_buffer));
2729 memset(buffer_info, 0,
2730 sizeof(struct e1000_buffer));
2732 e1000_unmap_and_free_tx_resource(
2733 adapter, buffer_info);
2738 tx_desc->buffer_addr = 0;
2739 tx_desc->lower.data = 0;
2740 tx_desc->upper.data = 0;
2742 if(unlikely(++i == tx_ring->count)) i = 0;
2745 eop = tx_ring->buffer_info[i].next_to_watch;
2746 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2749 tx_ring->next_to_clean = i;
2751 spin_lock(&adapter->tx_lock);
2753 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
2754 netif_carrier_ok(netdev)))
2755 netif_wake_queue(netdev);
2757 spin_unlock(&adapter->tx_lock);
2758 if(adapter->detect_tx_hung) {
2760 /* Detect a transmit hang in hardware, this serializes the
2761 * check with the clearing of time_stamp and movement of i */
2762 adapter->detect_tx_hung = FALSE;
2763 if (tx_ring->buffer_info[i].dma &&
2764 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
2765 && !(E1000_READ_REG(&adapter->hw, STATUS) &
2766 E1000_STATUS_TXOFF)) {
2768 /* detected Tx unit hang */
2769 i = tx_ring->next_to_clean;
2770 eop = tx_ring->buffer_info[i].next_to_watch;
2771 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2772 DPRINTK(TX_ERR, ERR, "Detected Tx Unit Hang\n"
2775 " next_to_use <%x>\n"
2776 " next_to_clean <%x>\n"
2777 "buffer_info[next_to_clean]\n"
2779 " time_stamp <%lx>\n"
2780 " next_to_watch <%x>\n"
2782 " next_to_watch.status <%x>\n",
2783 E1000_READ_REG(&adapter->hw, TDH),
2784 E1000_READ_REG(&adapter->hw, TDT),
2785 tx_ring->next_to_use,
2787 tx_ring->buffer_info[i].dma,
2788 tx_ring->buffer_info[i].time_stamp,
2791 eop_desc->upper.fields.status);
2792 netif_stop_queue(netdev);
2797 if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
2798 time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
2799 e1000_unmap_and_free_tx_resource(
2800 adapter, &adapter->previous_buffer_info);
2807 * e1000_rx_checksum - Receive Checksum Offload for 82543
2808 * @adapter: board private structure
2809 * @status_err: receive descriptor status and error fields
2810 * @csum: receive descriptor csum field
2811 * @sk_buff: socket buffer with received data
2815 e1000_rx_checksum(struct e1000_adapter *adapter,
2816 uint32_t status_err, uint32_t csum,
2817 struct sk_buff *skb)
2819 uint16_t status = (uint16_t)status_err;
2820 uint8_t errors = (uint8_t)(status_err >> 24);
2821 skb->ip_summed = CHECKSUM_NONE;
2823 /* 82543 or newer only */
2824 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
2825 /* Ignore Checksum bit is set */
2826 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
2827 /* TCP/UDP checksum error bit is set */
2828 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
2829 /* let the stack verify checksum errors */
2830 adapter->hw_csum_err++;
2833 /* TCP/UDP Checksum has not been calculated */
2834 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
2835 if(!(status & E1000_RXD_STAT_TCPCS))
2838 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
2841 /* It must be a TCP or UDP packet with a valid checksum */
2842 if (likely(status & E1000_RXD_STAT_TCPCS)) {
2843 /* TCP checksum is good */
2844 skb->ip_summed = CHECKSUM_UNNECESSARY;
2845 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
2846 /* IP fragment with UDP payload */
2847 /* Hardware complements the payload checksum, so we undo it
2848 * and then put the value in host order for further stack use.
2850 csum = ntohl(csum ^ 0xFFFF);
2852 skb->ip_summed = CHECKSUM_HW;
2854 adapter->hw_csum_good++;
2858 * e1000_clean_rx_irq - Send received data up the network stack; legacy
2859 * @adapter: board private structure
2863 #ifdef CONFIG_E1000_NAPI
2864 e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done,
2867 e1000_clean_rx_irq(struct e1000_adapter *adapter)
2870 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2871 struct net_device *netdev = adapter->netdev;
2872 struct pci_dev *pdev = adapter->pdev;
2873 struct e1000_rx_desc *rx_desc;
2874 struct e1000_buffer *buffer_info;
2875 struct sk_buff *skb;
2876 unsigned long flags;
2880 boolean_t cleaned = FALSE;
2882 i = rx_ring->next_to_clean;
2883 rx_desc = E1000_RX_DESC(*rx_ring, i);
2885 while(rx_desc->status & E1000_RXD_STAT_DD) {
2886 buffer_info = &rx_ring->buffer_info[i];
2887 #ifdef CONFIG_E1000_NAPI
2888 if(*work_done >= work_to_do)
2894 pci_unmap_single(pdev,
2896 buffer_info->length,
2897 PCI_DMA_FROMDEVICE);
2899 skb = buffer_info->skb;
2900 length = le16_to_cpu(rx_desc->length);
2902 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
2903 /* All receives must fit into a single buffer */
2904 E1000_DBG("%s: Receive packet consumed multiple"
2905 " buffers\n", netdev->name);
2906 dev_kfree_skb_irq(skb);
2910 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
2911 last_byte = *(skb->data + length - 1);
2912 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
2913 rx_desc->errors, length, last_byte)) {
2914 spin_lock_irqsave(&adapter->stats_lock, flags);
2915 e1000_tbi_adjust_stats(&adapter->hw,
2918 spin_unlock_irqrestore(&adapter->stats_lock,
2922 dev_kfree_skb_irq(skb);
2928 skb_put(skb, length - ETHERNET_FCS_SIZE);
2930 /* Receive Checksum Offload */
2931 e1000_rx_checksum(adapter,
2932 (uint32_t)(rx_desc->status) |
2933 ((uint32_t)(rx_desc->errors) << 24),
2934 rx_desc->csum, skb);
2935 skb->protocol = eth_type_trans(skb, netdev);
2936 #ifdef CONFIG_E1000_NAPI
2937 if(unlikely(adapter->vlgrp &&
2938 (rx_desc->status & E1000_RXD_STAT_VP))) {
2939 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
2940 le16_to_cpu(rx_desc->special) &
2941 E1000_RXD_SPC_VLAN_MASK);
2943 netif_receive_skb(skb);
2945 #else /* CONFIG_E1000_NAPI */
2946 if(unlikely(adapter->vlgrp &&
2947 (rx_desc->status & E1000_RXD_STAT_VP))) {
2948 vlan_hwaccel_rx(skb, adapter->vlgrp,
2949 le16_to_cpu(rx_desc->special) &
2950 E1000_RXD_SPC_VLAN_MASK);
2954 #endif /* CONFIG_E1000_NAPI */
2955 netdev->last_rx = jiffies;
2958 rx_desc->status = 0;
2959 buffer_info->skb = NULL;
2960 if(unlikely(++i == rx_ring->count)) i = 0;
2962 rx_desc = E1000_RX_DESC(*rx_ring, i);
2964 rx_ring->next_to_clean = i;
2965 adapter->alloc_rx_buf(adapter);
2971 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
2972 * @adapter: board private structure
2976 #ifdef CONFIG_E1000_NAPI
2977 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done,
2980 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
2983 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2984 union e1000_rx_desc_packet_split *rx_desc;
2985 struct net_device *netdev = adapter->netdev;
2986 struct pci_dev *pdev = adapter->pdev;
2987 struct e1000_buffer *buffer_info;
2988 struct e1000_ps_page *ps_page;
2989 struct e1000_ps_page_dma *ps_page_dma;
2990 struct sk_buff *skb;
2992 uint32_t length, staterr;
2993 boolean_t cleaned = FALSE;
2995 i = rx_ring->next_to_clean;
2996 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
2997 staterr = rx_desc->wb.middle.status_error;
2999 while(staterr & E1000_RXD_STAT_DD) {
3000 buffer_info = &rx_ring->buffer_info[i];
3001 ps_page = &rx_ring->ps_page[i];
3002 ps_page_dma = &rx_ring->ps_page_dma[i];
3003 #ifdef CONFIG_E1000_NAPI
3004 if(unlikely(*work_done >= work_to_do))
3009 pci_unmap_single(pdev, buffer_info->dma,
3010 buffer_info->length,
3011 PCI_DMA_FROMDEVICE);
3013 skb = buffer_info->skb;
3015 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3016 E1000_DBG("%s: Packet Split buffers didn't pick up"
3017 " the full packet\n", netdev->name);
3018 dev_kfree_skb_irq(skb);
3022 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3023 dev_kfree_skb_irq(skb);
3027 length = le16_to_cpu(rx_desc->wb.middle.length0);
3029 if(unlikely(!length)) {
3030 E1000_DBG("%s: Last part of the packet spanning"
3031 " multiple descriptors\n", netdev->name);
3032 dev_kfree_skb_irq(skb);
3037 skb_put(skb, length);
3039 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3040 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3043 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3044 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3045 ps_page_dma->ps_page_dma[j] = 0;
3046 skb_shinfo(skb)->frags[j].page =
3047 ps_page->ps_page[j];
3048 ps_page->ps_page[j] = NULL;
3049 skb_shinfo(skb)->frags[j].page_offset = 0;
3050 skb_shinfo(skb)->frags[j].size = length;
3051 skb_shinfo(skb)->nr_frags++;
3053 skb->data_len += length;
3056 e1000_rx_checksum(adapter, staterr,
3057 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3058 skb->protocol = eth_type_trans(skb, netdev);
3060 #ifdef HAVE_RX_ZERO_COPY
3061 if(likely(rx_desc->wb.upper.header_status &
3062 E1000_RXDPS_HDRSTAT_HDRSP))
3063 skb_shinfo(skb)->zero_copy = TRUE;
3065 #ifdef CONFIG_E1000_NAPI
3066 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3067 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3068 le16_to_cpu(rx_desc->wb.middle.vlan &
3069 E1000_RXD_SPC_VLAN_MASK));
3071 netif_receive_skb(skb);
3073 #else /* CONFIG_E1000_NAPI */
3074 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3075 vlan_hwaccel_rx(skb, adapter->vlgrp,
3076 le16_to_cpu(rx_desc->wb.middle.vlan &
3077 E1000_RXD_SPC_VLAN_MASK));
3081 #endif /* CONFIG_E1000_NAPI */
3082 netdev->last_rx = jiffies;
3085 rx_desc->wb.middle.status_error &= ~0xFF;
3086 buffer_info->skb = NULL;
3087 if(unlikely(++i == rx_ring->count)) i = 0;
3089 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3090 staterr = rx_desc->wb.middle.status_error;
3092 rx_ring->next_to_clean = i;
3093 adapter->alloc_rx_buf(adapter);
3099 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3100 * @adapter: address of board private structure
3104 e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3106 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3107 struct net_device *netdev = adapter->netdev;
3108 struct pci_dev *pdev = adapter->pdev;
3109 struct e1000_rx_desc *rx_desc;
3110 struct e1000_buffer *buffer_info;
3111 struct sk_buff *skb;
3113 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3115 i = rx_ring->next_to_use;
3116 buffer_info = &rx_ring->buffer_info[i];
3118 while(!buffer_info->skb) {
3119 skb = dev_alloc_skb(bufsz);
3121 if(unlikely(!skb)) {
3122 /* Better luck next round */
3126 /* Fix for errata 23, can't cross 64kB boundary */
3127 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3128 struct sk_buff *oldskb = skb;
3129 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3130 "at %p\n", bufsz, skb->data);
3131 /* Try again, without freeing the previous */
3132 skb = dev_alloc_skb(bufsz);
3133 /* Failed allocation, critical failure */
3135 dev_kfree_skb(oldskb);
3139 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3142 dev_kfree_skb(oldskb);
3143 break; /* while !buffer_info->skb */
3145 /* Use new allocation */
3146 dev_kfree_skb(oldskb);
3149 /* Make buffer alignment 2 beyond a 16 byte boundary
3150 * this will result in a 16 byte aligned IP header after
3151 * the 14 byte MAC header is removed
3153 skb_reserve(skb, NET_IP_ALIGN);
3157 buffer_info->skb = skb;
3158 buffer_info->length = adapter->rx_buffer_len;
3159 buffer_info->dma = pci_map_single(pdev,
3161 adapter->rx_buffer_len,
3162 PCI_DMA_FROMDEVICE);
3164 /* Fix for errata 23, can't cross 64kB boundary */
3165 if (!e1000_check_64k_bound(adapter,
3166 (void *)(unsigned long)buffer_info->dma,
3167 adapter->rx_buffer_len)) {
3168 DPRINTK(RX_ERR, ERR,
3169 "dma align check failed: %u bytes at %p\n",
3170 adapter->rx_buffer_len,
3171 (void *)(unsigned long)buffer_info->dma);
3173 buffer_info->skb = NULL;
3175 pci_unmap_single(pdev, buffer_info->dma,
3176 adapter->rx_buffer_len,
3177 PCI_DMA_FROMDEVICE);
3179 break; /* while !buffer_info->skb */
3181 rx_desc = E1000_RX_DESC(*rx_ring, i);
3182 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3184 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3185 /* Force memory writes to complete before letting h/w
3186 * know there are new descriptors to fetch. (Only
3187 * applicable for weak-ordered memory model archs,
3188 * such as IA-64). */
3190 E1000_WRITE_REG(&adapter->hw, RDT, i);
3193 if(unlikely(++i == rx_ring->count)) i = 0;
3194 buffer_info = &rx_ring->buffer_info[i];
3197 rx_ring->next_to_use = i;
3201 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3202 * @adapter: address of board private structure
3206 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3208 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3209 struct net_device *netdev = adapter->netdev;
3210 struct pci_dev *pdev = adapter->pdev;
3211 union e1000_rx_desc_packet_split *rx_desc;
3212 struct e1000_buffer *buffer_info;
3213 struct e1000_ps_page *ps_page;
3214 struct e1000_ps_page_dma *ps_page_dma;
3215 struct sk_buff *skb;
3218 i = rx_ring->next_to_use;
3219 buffer_info = &rx_ring->buffer_info[i];
3220 ps_page = &rx_ring->ps_page[i];
3221 ps_page_dma = &rx_ring->ps_page_dma[i];
3223 while(!buffer_info->skb) {
3224 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3226 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3227 if(unlikely(!ps_page->ps_page[j])) {
3228 ps_page->ps_page[j] =
3229 alloc_page(GFP_ATOMIC);
3230 if(unlikely(!ps_page->ps_page[j]))
3232 ps_page_dma->ps_page_dma[j] =
3234 ps_page->ps_page[j],
3236 PCI_DMA_FROMDEVICE);
3238 /* Refresh the desc even if buffer_addrs didn't
3239 * change because each write-back erases this info.
3241 rx_desc->read.buffer_addr[j+1] =
3242 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3245 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3250 /* Make buffer alignment 2 beyond a 16 byte boundary
3251 * this will result in a 16 byte aligned IP header after
3252 * the 14 byte MAC header is removed
3254 skb_reserve(skb, NET_IP_ALIGN);
3258 buffer_info->skb = skb;
3259 buffer_info->length = adapter->rx_ps_bsize0;
3260 buffer_info->dma = pci_map_single(pdev, skb->data,
3261 adapter->rx_ps_bsize0,
3262 PCI_DMA_FROMDEVICE);
3264 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3266 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3267 /* Force memory writes to complete before letting h/w
3268 * know there are new descriptors to fetch. (Only
3269 * applicable for weak-ordered memory model archs,
3270 * such as IA-64). */
3272 /* Hardware increments by 16 bytes, but packet split
3273 * descriptors are 32 bytes...so we increment tail
3276 E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
3279 if(unlikely(++i == rx_ring->count)) i = 0;
3280 buffer_info = &rx_ring->buffer_info[i];
3281 ps_page = &rx_ring->ps_page[i];
3282 ps_page_dma = &rx_ring->ps_page_dma[i];
3286 rx_ring->next_to_use = i;
3290 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3295 e1000_smartspeed(struct e1000_adapter *adapter)
3297 uint16_t phy_status;
3300 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3301 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3304 if(adapter->smartspeed == 0) {
3305 /* If Master/Slave config fault is asserted twice,
3306 * we assume back-to-back */
3307 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3308 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3309 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3310 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3311 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3312 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3313 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3314 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3316 adapter->smartspeed++;
3317 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3318 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3320 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3321 MII_CR_RESTART_AUTO_NEG);
3322 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3327 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3328 /* If still no link, perhaps using 2/3 pair cable */
3329 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3330 phy_ctrl |= CR_1000T_MS_ENABLE;
3331 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3332 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3333 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3334 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3335 MII_CR_RESTART_AUTO_NEG);
3336 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3339 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3340 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3341 adapter->smartspeed = 0;
3352 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3358 return e1000_mii_ioctl(netdev, ifr, cmd);
3372 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3374 struct e1000_adapter *adapter = netdev->priv;
3375 struct mii_ioctl_data *data = if_mii(ifr);
3380 if(adapter->hw.media_type != e1000_media_type_copper)
3385 data->phy_id = adapter->hw.phy_addr;
3388 if (!capable(CAP_NET_ADMIN))
3390 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3395 if (!capable(CAP_NET_ADMIN))
3397 if (data->reg_num & ~(0x1F))
3399 mii_reg = data->val_in;
3400 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
3403 if (adapter->hw.phy_type == e1000_phy_m88) {
3404 switch (data->reg_num) {
3406 if(mii_reg & MII_CR_POWER_DOWN)
3408 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3409 adapter->hw.autoneg = 1;
3410 adapter->hw.autoneg_advertised = 0x2F;
3413 spddplx = SPEED_1000;
3414 else if (mii_reg & 0x2000)
3415 spddplx = SPEED_100;
3418 spddplx += (mii_reg & 0x100)
3421 retval = e1000_set_spd_dplx(adapter,
3426 if(netif_running(adapter->netdev)) {
3427 e1000_down(adapter);
3430 e1000_reset(adapter);
3432 case M88E1000_PHY_SPEC_CTRL:
3433 case M88E1000_EXT_PHY_SPEC_CTRL:
3434 if (e1000_phy_reset(&adapter->hw))
3439 switch (data->reg_num) {
3441 if(mii_reg & MII_CR_POWER_DOWN)
3443 if(netif_running(adapter->netdev)) {
3444 e1000_down(adapter);
3447 e1000_reset(adapter);
3455 return E1000_SUCCESS;
3459 e1000_pci_set_mwi(struct e1000_hw *hw)
3461 struct e1000_adapter *adapter = hw->back;
3462 int ret_val = pci_set_mwi(adapter->pdev);
3465 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
3469 e1000_pci_clear_mwi(struct e1000_hw *hw)
3471 struct e1000_adapter *adapter = hw->back;
3473 pci_clear_mwi(adapter->pdev);
3477 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3479 struct e1000_adapter *adapter = hw->back;
3481 pci_read_config_word(adapter->pdev, reg, value);
3485 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3487 struct e1000_adapter *adapter = hw->back;
3489 pci_write_config_word(adapter->pdev, reg, *value);
3493 e1000_io_read(struct e1000_hw *hw, unsigned long port)
3499 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3505 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3507 struct e1000_adapter *adapter = netdev->priv;
3508 uint32_t ctrl, rctl;
3510 e1000_irq_disable(adapter);
3511 adapter->vlgrp = grp;
3514 /* enable VLAN tag insert/strip */
3515 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3516 ctrl |= E1000_CTRL_VME;
3517 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3519 /* enable VLAN receive filtering */
3520 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3521 rctl |= E1000_RCTL_VFE;
3522 rctl &= ~E1000_RCTL_CFIEN;
3523 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3524 e1000_update_mng_vlan(adapter);
3526 /* disable VLAN tag insert/strip */
3527 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3528 ctrl &= ~E1000_CTRL_VME;
3529 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3531 /* disable VLAN filtering */
3532 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3533 rctl &= ~E1000_RCTL_VFE;
3534 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3535 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
3536 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3537 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3541 e1000_irq_enable(adapter);
3545 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3547 struct e1000_adapter *adapter = netdev->priv;
3548 uint32_t vfta, index;
3549 if((adapter->hw.mng_cookie.status &
3550 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3551 (vid == adapter->mng_vlan_id))
3553 /* add VID to filter table */
3554 index = (vid >> 5) & 0x7F;
3555 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3556 vfta |= (1 << (vid & 0x1F));
3557 e1000_write_vfta(&adapter->hw, index, vfta);
3561 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3563 struct e1000_adapter *adapter = netdev->priv;
3564 uint32_t vfta, index;
3566 e1000_irq_disable(adapter);
3569 adapter->vlgrp->vlan_devices[vid] = NULL;
3571 e1000_irq_enable(adapter);
3573 if((adapter->hw.mng_cookie.status &
3574 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3575 (vid == adapter->mng_vlan_id))
3577 /* remove VID from filter table */
3578 index = (vid >> 5) & 0x7F;
3579 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3580 vfta &= ~(1 << (vid & 0x1F));
3581 e1000_write_vfta(&adapter->hw, index, vfta);
3585 e1000_restore_vlan(struct e1000_adapter *adapter)
3587 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
3589 if(adapter->vlgrp) {
3591 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
3592 if(!adapter->vlgrp->vlan_devices[vid])
3594 e1000_vlan_rx_add_vid(adapter->netdev, vid);
3600 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3602 adapter->hw.autoneg = 0;
3605 case SPEED_10 + DUPLEX_HALF:
3606 adapter->hw.forced_speed_duplex = e1000_10_half;
3608 case SPEED_10 + DUPLEX_FULL:
3609 adapter->hw.forced_speed_duplex = e1000_10_full;
3611 case SPEED_100 + DUPLEX_HALF:
3612 adapter->hw.forced_speed_duplex = e1000_100_half;
3614 case SPEED_100 + DUPLEX_FULL:
3615 adapter->hw.forced_speed_duplex = e1000_100_full;
3617 case SPEED_1000 + DUPLEX_FULL:
3618 adapter->hw.autoneg = 1;
3619 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
3621 case SPEED_1000 + DUPLEX_HALF: /* not supported */
3623 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3630 e1000_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3632 struct pci_dev *pdev = NULL;
3638 while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
3639 if(pci_dev_driver(pdev) == &e1000_driver)
3640 e1000_suspend(pdev, 3);
3647 e1000_suspend(struct pci_dev *pdev, uint32_t state)
3649 struct net_device *netdev = pci_get_drvdata(pdev);
3650 struct e1000_adapter *adapter = netdev->priv;
3651 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
3652 uint32_t wufc = adapter->wol;
3654 netif_device_detach(netdev);
3656 if(netif_running(netdev))
3657 e1000_down(adapter);
3659 status = E1000_READ_REG(&adapter->hw, STATUS);
3660 if(status & E1000_STATUS_LU)
3661 wufc &= ~E1000_WUFC_LNKC;
3664 e1000_setup_rctl(adapter);
3665 e1000_set_multi(netdev);
3667 /* turn on all-multi mode if wake on multicast is enabled */
3668 if(adapter->wol & E1000_WUFC_MC) {
3669 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3670 rctl |= E1000_RCTL_MPE;
3671 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3674 if(adapter->hw.mac_type >= e1000_82540) {
3675 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3676 /* advertise wake from D3Cold */
3677 #define E1000_CTRL_ADVD3WUC 0x00100000
3678 /* phy power management enable */
3679 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3680 ctrl |= E1000_CTRL_ADVD3WUC |
3681 E1000_CTRL_EN_PHY_PWR_MGMT;
3682 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3685 if(adapter->hw.media_type == e1000_media_type_fiber ||
3686 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3687 /* keep the laser running in D3 */
3688 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
3689 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3690 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
3693 /* Allow time for pending master requests to run */
3694 e1000_disable_pciex_master(&adapter->hw);
3696 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
3697 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
3698 pci_enable_wake(pdev, 3, 1);
3699 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3701 E1000_WRITE_REG(&adapter->hw, WUC, 0);
3702 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
3703 pci_enable_wake(pdev, 3, 0);
3704 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3707 pci_save_state(pdev);
3709 if(adapter->hw.mac_type >= e1000_82540 &&
3710 adapter->hw.media_type == e1000_media_type_copper) {
3711 manc = E1000_READ_REG(&adapter->hw, MANC);
3712 if(manc & E1000_MANC_SMBUS_EN) {
3713 manc |= E1000_MANC_ARP_EN;
3714 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3715 pci_enable_wake(pdev, 3, 1);
3716 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3720 switch(adapter->hw.mac_type) {
3722 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3723 E1000_WRITE_REG(&adapter->hw, SWSM,
3724 swsm & ~E1000_SWSM_DRV_LOAD);
3730 pci_disable_device(pdev);
3732 state = (state > 0) ? 3 : 0;
3733 pci_set_power_state(pdev, state);
3740 e1000_resume(struct pci_dev *pdev)
3742 struct net_device *netdev = pci_get_drvdata(pdev);
3743 struct e1000_adapter *adapter = netdev->priv;
3744 uint32_t manc, ret, swsm;
3746 pci_set_power_state(pdev, 0);
3747 pci_restore_state(pdev);
3748 ret = pci_enable_device(pdev);
3749 pci_set_master(pdev);
3751 pci_enable_wake(pdev, 3, 0);
3752 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3754 e1000_reset(adapter);
3755 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
3757 if(netif_running(netdev))
3760 netif_device_attach(netdev);
3762 if(adapter->hw.mac_type >= e1000_82540 &&
3763 adapter->hw.media_type == e1000_media_type_copper) {
3764 manc = E1000_READ_REG(&adapter->hw, MANC);
3765 manc &= ~(E1000_MANC_ARP_EN);
3766 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3769 switch(adapter->hw.mac_type) {
3771 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3772 E1000_WRITE_REG(&adapter->hw, SWSM,
3773 swsm | E1000_SWSM_DRV_LOAD);
3782 #ifdef CONFIG_NET_POLL_CONTROLLER
3784 * Polling 'interrupt' - used by things like netconsole to send skbs
3785 * without having to re-enable interrupts. It's not called while
3786 * the interrupt routine is executing.
3789 e1000_netpoll(struct net_device *netdev)
3791 struct e1000_adapter *adapter = netdev->priv;
3792 disable_irq(adapter->pdev->irq);
3793 e1000_intr(adapter->pdev->irq, netdev, NULL);
3794 enable_irq(adapter->pdev->irq);