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 return NETDEV_TX_OK;
2314 tx_flags |= E1000_TX_FLAGS_TSO;
2315 else if(likely(e1000_tx_csum(adapter, skb)))
2316 tx_flags |= E1000_TX_FLAGS_CSUM;
2318 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2319 * 82573 hardware supports TSO capabilities for IPv6 as well...
2320 * no longer assume, we must. */
2321 if(likely(skb->protocol == ntohs(ETH_P_IP)))
2322 tx_flags |= E1000_TX_FLAGS_IPV4;
2324 e1000_tx_queue(adapter,
2325 e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss),
2328 netdev->trans_start = jiffies;
2330 /* Make sure there is space in the ring for the next send. */
2331 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2))
2332 netif_stop_queue(netdev);
2334 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2335 return NETDEV_TX_OK;
2339 * e1000_tx_timeout - Respond to a Tx Hang
2340 * @netdev: network interface device structure
2344 e1000_tx_timeout(struct net_device *netdev)
2346 struct e1000_adapter *adapter = netdev->priv;
2348 /* Do the reset outside of interrupt context */
2349 schedule_work(&adapter->tx_timeout_task);
2353 e1000_tx_timeout_task(struct net_device *netdev)
2355 struct e1000_adapter *adapter = netdev->priv;
2357 e1000_down(adapter);
2362 * e1000_get_stats - Get System Network Statistics
2363 * @netdev: network interface device structure
2365 * Returns the address of the device statistics structure.
2366 * The statistics are actually updated from the timer callback.
2369 static struct net_device_stats *
2370 e1000_get_stats(struct net_device *netdev)
2372 struct e1000_adapter *adapter = netdev->priv;
2374 e1000_update_stats(adapter);
2375 return &adapter->net_stats;
2379 * e1000_change_mtu - Change the Maximum Transfer Unit
2380 * @netdev: network interface device structure
2381 * @new_mtu: new value for maximum frame size
2383 * Returns 0 on success, negative on failure
2387 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2389 struct e1000_adapter *adapter = netdev->priv;
2390 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2392 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2393 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2394 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2398 #define MAX_STD_JUMBO_FRAME_SIZE 9216
2399 /* might want this to be bigger enum check... */
2400 if (adapter->hw.mac_type == e1000_82573 &&
2401 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2402 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2407 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2408 adapter->rx_buffer_len = max_frame;
2409 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2411 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2412 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2413 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2418 if(max_frame <= E1000_RXBUFFER_2048) {
2419 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2420 } else if(max_frame <= E1000_RXBUFFER_4096) {
2421 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2422 } else if(max_frame <= E1000_RXBUFFER_8192) {
2423 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2424 } else if(max_frame <= E1000_RXBUFFER_16384) {
2425 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2430 netdev->mtu = new_mtu;
2432 if(netif_running(netdev)) {
2433 e1000_down(adapter);
2437 adapter->hw.max_frame_size = max_frame;
2443 * e1000_update_stats - Update the board statistics counters
2444 * @adapter: board private structure
2448 e1000_update_stats(struct e1000_adapter *adapter)
2450 struct e1000_hw *hw = &adapter->hw;
2451 unsigned long flags;
2454 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2456 spin_lock_irqsave(&adapter->stats_lock, flags);
2458 /* these counters are modified from e1000_adjust_tbi_stats,
2459 * called from the interrupt context, so they must only
2460 * be written while holding adapter->stats_lock
2463 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2464 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2465 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2466 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2467 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2468 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2469 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2470 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2471 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2472 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2473 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2474 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2475 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2477 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2478 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2479 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2480 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2481 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2482 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2483 adapter->stats.dc += E1000_READ_REG(hw, DC);
2484 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2485 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2486 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2487 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2488 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2489 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2490 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2491 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2492 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2493 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2494 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2495 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2496 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2497 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2498 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2499 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2500 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2501 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2502 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2503 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2504 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2505 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2506 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2507 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2508 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2509 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2510 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2512 /* used for adaptive IFS */
2514 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2515 adapter->stats.tpt += hw->tx_packet_delta;
2516 hw->collision_delta = E1000_READ_REG(hw, COLC);
2517 adapter->stats.colc += hw->collision_delta;
2519 if(hw->mac_type >= e1000_82543) {
2520 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2521 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
2522 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
2523 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
2524 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
2525 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
2527 if(hw->mac_type > e1000_82547_rev_2) {
2528 adapter->stats.iac += E1000_READ_REG(hw, IAC);
2529 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
2530 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
2531 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
2532 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
2533 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
2534 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
2535 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
2536 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
2539 /* Fill out the OS statistics structure */
2541 adapter->net_stats.rx_packets = adapter->stats.gprc;
2542 adapter->net_stats.tx_packets = adapter->stats.gptc;
2543 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2544 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2545 adapter->net_stats.multicast = adapter->stats.mprc;
2546 adapter->net_stats.collisions = adapter->stats.colc;
2550 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2551 adapter->stats.crcerrs + adapter->stats.algnerrc +
2552 adapter->stats.rlec + adapter->stats.mpc +
2553 adapter->stats.cexterr;
2554 adapter->net_stats.rx_dropped = adapter->stats.mpc;
2555 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2556 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2557 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2558 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
2559 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2563 adapter->net_stats.tx_errors = adapter->stats.ecol +
2564 adapter->stats.latecol;
2565 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2566 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2567 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2569 /* Tx Dropped needs to be maintained elsewhere */
2573 if(hw->media_type == e1000_media_type_copper) {
2574 if((adapter->link_speed == SPEED_1000) &&
2575 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
2576 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2577 adapter->phy_stats.idle_errors += phy_tmp;
2580 if((hw->mac_type <= e1000_82546) &&
2581 (hw->phy_type == e1000_phy_m88) &&
2582 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
2583 adapter->phy_stats.receive_errors += phy_tmp;
2586 spin_unlock_irqrestore(&adapter->stats_lock, flags);
2590 * e1000_intr - Interrupt Handler
2591 * @irq: interrupt number
2592 * @data: pointer to a network interface device structure
2593 * @pt_regs: CPU registers structure
2597 e1000_intr(int irq, void *data, struct pt_regs *regs)
2599 struct net_device *netdev = data;
2600 struct e1000_adapter *adapter = netdev->priv;
2601 struct e1000_hw *hw = &adapter->hw;
2602 uint32_t icr = E1000_READ_REG(hw, ICR);
2603 #ifndef CONFIG_E1000_NAPI
2608 return IRQ_NONE; /* Not our interrupt */
2610 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
2611 hw->get_link_status = 1;
2612 mod_timer(&adapter->watchdog_timer, jiffies);
2615 #ifdef CONFIG_E1000_NAPI
2616 if(likely(netif_rx_schedule_prep(netdev))) {
2618 /* Disable interrupts and register for poll. The flush
2619 of the posted write is intentionally left out.
2622 atomic_inc(&adapter->irq_sem);
2623 E1000_WRITE_REG(hw, IMC, ~0);
2624 __netif_rx_schedule(netdev);
2627 /* Writing IMC and IMS is needed for 82547.
2628 Due to Hub Link bus being occupied, an interrupt
2629 de-assertion message is not able to be sent.
2630 When an interrupt assertion message is generated later,
2631 two messages are re-ordered and sent out.
2632 That causes APIC to think 82547 is in de-assertion
2633 state, while 82547 is in assertion state, resulting
2634 in dead lock. Writing IMC forces 82547 into
2637 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
2638 atomic_inc(&adapter->irq_sem);
2639 E1000_WRITE_REG(hw, IMC, ~0);
2642 for(i = 0; i < E1000_MAX_INTR; i++)
2643 if(unlikely(!adapter->clean_rx(adapter) &
2644 !e1000_clean_tx_irq(adapter)))
2647 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
2648 e1000_irq_enable(adapter);
2654 #ifdef CONFIG_E1000_NAPI
2656 * e1000_clean - NAPI Rx polling callback
2657 * @adapter: board private structure
2661 e1000_clean(struct net_device *netdev, int *budget)
2663 struct e1000_adapter *adapter = netdev->priv;
2664 int work_to_do = min(*budget, netdev->quota);
2668 tx_cleaned = e1000_clean_tx_irq(adapter);
2669 adapter->clean_rx(adapter, &work_done, work_to_do);
2671 *budget -= work_done;
2672 netdev->quota -= work_done;
2674 /* If no Tx and no Rx work done, exit the polling mode */
2675 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2676 netif_rx_complete(netdev);
2677 e1000_irq_enable(adapter);
2686 * e1000_clean_tx_irq - Reclaim resources after transmit completes
2687 * @adapter: board private structure
2691 e1000_clean_tx_irq(struct e1000_adapter *adapter)
2693 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2694 struct net_device *netdev = adapter->netdev;
2695 struct e1000_tx_desc *tx_desc, *eop_desc;
2696 struct e1000_buffer *buffer_info;
2697 unsigned int i, eop;
2698 boolean_t cleaned = FALSE;
2700 i = tx_ring->next_to_clean;
2701 eop = tx_ring->buffer_info[i].next_to_watch;
2702 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2704 while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
2705 /* Premature writeback of Tx descriptors clear (free buffers
2706 * and unmap pci_mapping) previous_buffer_info */
2707 if (likely(adapter->previous_buffer_info.skb != NULL)) {
2708 e1000_unmap_and_free_tx_resource(adapter,
2709 &adapter->previous_buffer_info);
2712 for(cleaned = FALSE; !cleaned; ) {
2713 tx_desc = E1000_TX_DESC(*tx_ring, i);
2714 buffer_info = &tx_ring->buffer_info[i];
2715 cleaned = (i == eop);
2718 if (!(netdev->features & NETIF_F_TSO)) {
2720 e1000_unmap_and_free_tx_resource(adapter,
2725 memcpy(&adapter->previous_buffer_info,
2727 sizeof(struct e1000_buffer));
2728 memset(buffer_info, 0,
2729 sizeof(struct e1000_buffer));
2731 e1000_unmap_and_free_tx_resource(
2732 adapter, buffer_info);
2737 tx_desc->buffer_addr = 0;
2738 tx_desc->lower.data = 0;
2739 tx_desc->upper.data = 0;
2741 if(unlikely(++i == tx_ring->count)) i = 0;
2744 eop = tx_ring->buffer_info[i].next_to_watch;
2745 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2748 tx_ring->next_to_clean = i;
2750 spin_lock(&adapter->tx_lock);
2752 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
2753 netif_carrier_ok(netdev)))
2754 netif_wake_queue(netdev);
2756 spin_unlock(&adapter->tx_lock);
2757 if(adapter->detect_tx_hung) {
2759 /* Detect a transmit hang in hardware, this serializes the
2760 * check with the clearing of time_stamp and movement of i */
2761 adapter->detect_tx_hung = FALSE;
2762 if (tx_ring->buffer_info[i].dma &&
2763 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
2764 && !(E1000_READ_REG(&adapter->hw, STATUS) &
2765 E1000_STATUS_TXOFF)) {
2767 /* detected Tx unit hang */
2768 i = tx_ring->next_to_clean;
2769 eop = tx_ring->buffer_info[i].next_to_watch;
2770 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2771 DPRINTK(TX_ERR, ERR, "Detected Tx Unit Hang\n"
2774 " next_to_use <%x>\n"
2775 " next_to_clean <%x>\n"
2776 "buffer_info[next_to_clean]\n"
2778 " time_stamp <%lx>\n"
2779 " next_to_watch <%x>\n"
2781 " next_to_watch.status <%x>\n",
2782 E1000_READ_REG(&adapter->hw, TDH),
2783 E1000_READ_REG(&adapter->hw, TDT),
2784 tx_ring->next_to_use,
2786 tx_ring->buffer_info[i].dma,
2787 tx_ring->buffer_info[i].time_stamp,
2790 eop_desc->upper.fields.status);
2791 netif_stop_queue(netdev);
2796 if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
2797 time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
2798 e1000_unmap_and_free_tx_resource(
2799 adapter, &adapter->previous_buffer_info);
2806 * e1000_rx_checksum - Receive Checksum Offload for 82543
2807 * @adapter: board private structure
2808 * @status_err: receive descriptor status and error fields
2809 * @csum: receive descriptor csum field
2810 * @sk_buff: socket buffer with received data
2814 e1000_rx_checksum(struct e1000_adapter *adapter,
2815 uint32_t status_err, uint32_t csum,
2816 struct sk_buff *skb)
2818 uint16_t status = (uint16_t)status_err;
2819 uint8_t errors = (uint8_t)(status_err >> 24);
2820 skb->ip_summed = CHECKSUM_NONE;
2822 /* 82543 or newer only */
2823 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
2824 /* Ignore Checksum bit is set */
2825 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
2826 /* TCP/UDP checksum error bit is set */
2827 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
2828 /* let the stack verify checksum errors */
2829 adapter->hw_csum_err++;
2832 /* TCP/UDP Checksum has not been calculated */
2833 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
2834 if(!(status & E1000_RXD_STAT_TCPCS))
2837 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
2840 /* It must be a TCP or UDP packet with a valid checksum */
2841 if (likely(status & E1000_RXD_STAT_TCPCS)) {
2842 /* TCP checksum is good */
2843 skb->ip_summed = CHECKSUM_UNNECESSARY;
2844 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
2845 /* IP fragment with UDP payload */
2846 /* Hardware complements the payload checksum, so we undo it
2847 * and then put the value in host order for further stack use.
2849 csum = ntohl(csum ^ 0xFFFF);
2851 skb->ip_summed = CHECKSUM_HW;
2853 adapter->hw_csum_good++;
2857 * e1000_clean_rx_irq - Send received data up the network stack; legacy
2858 * @adapter: board private structure
2862 #ifdef CONFIG_E1000_NAPI
2863 e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done,
2866 e1000_clean_rx_irq(struct e1000_adapter *adapter)
2869 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2870 struct net_device *netdev = adapter->netdev;
2871 struct pci_dev *pdev = adapter->pdev;
2872 struct e1000_rx_desc *rx_desc;
2873 struct e1000_buffer *buffer_info;
2874 struct sk_buff *skb;
2875 unsigned long flags;
2879 boolean_t cleaned = FALSE;
2881 i = rx_ring->next_to_clean;
2882 rx_desc = E1000_RX_DESC(*rx_ring, i);
2884 while(rx_desc->status & E1000_RXD_STAT_DD) {
2885 buffer_info = &rx_ring->buffer_info[i];
2886 #ifdef CONFIG_E1000_NAPI
2887 if(*work_done >= work_to_do)
2893 pci_unmap_single(pdev,
2895 buffer_info->length,
2896 PCI_DMA_FROMDEVICE);
2898 skb = buffer_info->skb;
2899 length = le16_to_cpu(rx_desc->length);
2901 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
2902 /* All receives must fit into a single buffer */
2903 E1000_DBG("%s: Receive packet consumed multiple"
2904 " buffers\n", netdev->name);
2905 dev_kfree_skb_irq(skb);
2909 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
2910 last_byte = *(skb->data + length - 1);
2911 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
2912 rx_desc->errors, length, last_byte)) {
2913 spin_lock_irqsave(&adapter->stats_lock, flags);
2914 e1000_tbi_adjust_stats(&adapter->hw,
2917 spin_unlock_irqrestore(&adapter->stats_lock,
2921 dev_kfree_skb_irq(skb);
2927 skb_put(skb, length - ETHERNET_FCS_SIZE);
2929 /* Receive Checksum Offload */
2930 e1000_rx_checksum(adapter,
2931 (uint32_t)(rx_desc->status) |
2932 ((uint32_t)(rx_desc->errors) << 24),
2933 rx_desc->csum, skb);
2934 skb->protocol = eth_type_trans(skb, netdev);
2935 #ifdef CONFIG_E1000_NAPI
2936 if(unlikely(adapter->vlgrp &&
2937 (rx_desc->status & E1000_RXD_STAT_VP))) {
2938 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
2939 le16_to_cpu(rx_desc->special) &
2940 E1000_RXD_SPC_VLAN_MASK);
2942 netif_receive_skb(skb);
2944 #else /* CONFIG_E1000_NAPI */
2945 if(unlikely(adapter->vlgrp &&
2946 (rx_desc->status & E1000_RXD_STAT_VP))) {
2947 vlan_hwaccel_rx(skb, adapter->vlgrp,
2948 le16_to_cpu(rx_desc->special) &
2949 E1000_RXD_SPC_VLAN_MASK);
2953 #endif /* CONFIG_E1000_NAPI */
2954 netdev->last_rx = jiffies;
2957 rx_desc->status = 0;
2958 buffer_info->skb = NULL;
2959 if(unlikely(++i == rx_ring->count)) i = 0;
2961 rx_desc = E1000_RX_DESC(*rx_ring, i);
2963 rx_ring->next_to_clean = i;
2964 adapter->alloc_rx_buf(adapter);
2970 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
2971 * @adapter: board private structure
2975 #ifdef CONFIG_E1000_NAPI
2976 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done,
2979 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
2982 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2983 union e1000_rx_desc_packet_split *rx_desc;
2984 struct net_device *netdev = adapter->netdev;
2985 struct pci_dev *pdev = adapter->pdev;
2986 struct e1000_buffer *buffer_info;
2987 struct e1000_ps_page *ps_page;
2988 struct e1000_ps_page_dma *ps_page_dma;
2989 struct sk_buff *skb;
2991 uint32_t length, staterr;
2992 boolean_t cleaned = FALSE;
2994 i = rx_ring->next_to_clean;
2995 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
2996 staterr = rx_desc->wb.middle.status_error;
2998 while(staterr & E1000_RXD_STAT_DD) {
2999 buffer_info = &rx_ring->buffer_info[i];
3000 ps_page = &rx_ring->ps_page[i];
3001 ps_page_dma = &rx_ring->ps_page_dma[i];
3002 #ifdef CONFIG_E1000_NAPI
3003 if(unlikely(*work_done >= work_to_do))
3008 pci_unmap_single(pdev, buffer_info->dma,
3009 buffer_info->length,
3010 PCI_DMA_FROMDEVICE);
3012 skb = buffer_info->skb;
3014 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3015 E1000_DBG("%s: Packet Split buffers didn't pick up"
3016 " the full packet\n", netdev->name);
3017 dev_kfree_skb_irq(skb);
3021 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3022 dev_kfree_skb_irq(skb);
3026 length = le16_to_cpu(rx_desc->wb.middle.length0);
3028 if(unlikely(!length)) {
3029 E1000_DBG("%s: Last part of the packet spanning"
3030 " multiple descriptors\n", netdev->name);
3031 dev_kfree_skb_irq(skb);
3036 skb_put(skb, length);
3038 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3039 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3042 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3043 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3044 ps_page_dma->ps_page_dma[j] = 0;
3045 skb_shinfo(skb)->frags[j].page =
3046 ps_page->ps_page[j];
3047 ps_page->ps_page[j] = NULL;
3048 skb_shinfo(skb)->frags[j].page_offset = 0;
3049 skb_shinfo(skb)->frags[j].size = length;
3050 skb_shinfo(skb)->nr_frags++;
3052 skb->data_len += length;
3055 e1000_rx_checksum(adapter, staterr,
3056 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3057 skb->protocol = eth_type_trans(skb, netdev);
3059 #ifdef HAVE_RX_ZERO_COPY
3060 if(likely(rx_desc->wb.upper.header_status &
3061 E1000_RXDPS_HDRSTAT_HDRSP))
3062 skb_shinfo(skb)->zero_copy = TRUE;
3064 #ifdef CONFIG_E1000_NAPI
3065 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3066 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3067 le16_to_cpu(rx_desc->wb.middle.vlan &
3068 E1000_RXD_SPC_VLAN_MASK));
3070 netif_receive_skb(skb);
3072 #else /* CONFIG_E1000_NAPI */
3073 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3074 vlan_hwaccel_rx(skb, adapter->vlgrp,
3075 le16_to_cpu(rx_desc->wb.middle.vlan &
3076 E1000_RXD_SPC_VLAN_MASK));
3080 #endif /* CONFIG_E1000_NAPI */
3081 netdev->last_rx = jiffies;
3084 rx_desc->wb.middle.status_error &= ~0xFF;
3085 buffer_info->skb = NULL;
3086 if(unlikely(++i == rx_ring->count)) i = 0;
3088 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3089 staterr = rx_desc->wb.middle.status_error;
3091 rx_ring->next_to_clean = i;
3092 adapter->alloc_rx_buf(adapter);
3098 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3099 * @adapter: address of board private structure
3103 e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3105 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3106 struct net_device *netdev = adapter->netdev;
3107 struct pci_dev *pdev = adapter->pdev;
3108 struct e1000_rx_desc *rx_desc;
3109 struct e1000_buffer *buffer_info;
3110 struct sk_buff *skb;
3112 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3114 i = rx_ring->next_to_use;
3115 buffer_info = &rx_ring->buffer_info[i];
3117 while(!buffer_info->skb) {
3118 skb = dev_alloc_skb(bufsz);
3120 if(unlikely(!skb)) {
3121 /* Better luck next round */
3125 /* Fix for errata 23, can't cross 64kB boundary */
3126 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3127 struct sk_buff *oldskb = skb;
3128 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3129 "at %p\n", bufsz, skb->data);
3130 /* Try again, without freeing the previous */
3131 skb = dev_alloc_skb(bufsz);
3132 /* Failed allocation, critical failure */
3134 dev_kfree_skb(oldskb);
3138 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3141 dev_kfree_skb(oldskb);
3142 break; /* while !buffer_info->skb */
3144 /* Use new allocation */
3145 dev_kfree_skb(oldskb);
3148 /* Make buffer alignment 2 beyond a 16 byte boundary
3149 * this will result in a 16 byte aligned IP header after
3150 * the 14 byte MAC header is removed
3152 skb_reserve(skb, NET_IP_ALIGN);
3156 buffer_info->skb = skb;
3157 buffer_info->length = adapter->rx_buffer_len;
3158 buffer_info->dma = pci_map_single(pdev,
3160 adapter->rx_buffer_len,
3161 PCI_DMA_FROMDEVICE);
3163 /* Fix for errata 23, can't cross 64kB boundary */
3164 if (!e1000_check_64k_bound(adapter,
3165 (void *)(unsigned long)buffer_info->dma,
3166 adapter->rx_buffer_len)) {
3167 DPRINTK(RX_ERR, ERR,
3168 "dma align check failed: %u bytes at %p\n",
3169 adapter->rx_buffer_len,
3170 (void *)(unsigned long)buffer_info->dma);
3172 buffer_info->skb = NULL;
3174 pci_unmap_single(pdev, buffer_info->dma,
3175 adapter->rx_buffer_len,
3176 PCI_DMA_FROMDEVICE);
3178 break; /* while !buffer_info->skb */
3180 rx_desc = E1000_RX_DESC(*rx_ring, i);
3181 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3183 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3184 /* Force memory writes to complete before letting h/w
3185 * know there are new descriptors to fetch. (Only
3186 * applicable for weak-ordered memory model archs,
3187 * such as IA-64). */
3189 E1000_WRITE_REG(&adapter->hw, RDT, i);
3192 if(unlikely(++i == rx_ring->count)) i = 0;
3193 buffer_info = &rx_ring->buffer_info[i];
3196 rx_ring->next_to_use = i;
3200 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3201 * @adapter: address of board private structure
3205 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3207 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3208 struct net_device *netdev = adapter->netdev;
3209 struct pci_dev *pdev = adapter->pdev;
3210 union e1000_rx_desc_packet_split *rx_desc;
3211 struct e1000_buffer *buffer_info;
3212 struct e1000_ps_page *ps_page;
3213 struct e1000_ps_page_dma *ps_page_dma;
3214 struct sk_buff *skb;
3217 i = rx_ring->next_to_use;
3218 buffer_info = &rx_ring->buffer_info[i];
3219 ps_page = &rx_ring->ps_page[i];
3220 ps_page_dma = &rx_ring->ps_page_dma[i];
3222 while(!buffer_info->skb) {
3223 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3225 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3226 if(unlikely(!ps_page->ps_page[j])) {
3227 ps_page->ps_page[j] =
3228 alloc_page(GFP_ATOMIC);
3229 if(unlikely(!ps_page->ps_page[j]))
3231 ps_page_dma->ps_page_dma[j] =
3233 ps_page->ps_page[j],
3235 PCI_DMA_FROMDEVICE);
3237 /* Refresh the desc even if buffer_addrs didn't
3238 * change because each write-back erases this info.
3240 rx_desc->read.buffer_addr[j+1] =
3241 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3244 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3249 /* Make buffer alignment 2 beyond a 16 byte boundary
3250 * this will result in a 16 byte aligned IP header after
3251 * the 14 byte MAC header is removed
3253 skb_reserve(skb, NET_IP_ALIGN);
3257 buffer_info->skb = skb;
3258 buffer_info->length = adapter->rx_ps_bsize0;
3259 buffer_info->dma = pci_map_single(pdev, skb->data,
3260 adapter->rx_ps_bsize0,
3261 PCI_DMA_FROMDEVICE);
3263 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3265 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3266 /* Force memory writes to complete before letting h/w
3267 * know there are new descriptors to fetch. (Only
3268 * applicable for weak-ordered memory model archs,
3269 * such as IA-64). */
3271 /* Hardware increments by 16 bytes, but packet split
3272 * descriptors are 32 bytes...so we increment tail
3275 E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
3278 if(unlikely(++i == rx_ring->count)) i = 0;
3279 buffer_info = &rx_ring->buffer_info[i];
3280 ps_page = &rx_ring->ps_page[i];
3281 ps_page_dma = &rx_ring->ps_page_dma[i];
3285 rx_ring->next_to_use = i;
3289 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3294 e1000_smartspeed(struct e1000_adapter *adapter)
3296 uint16_t phy_status;
3299 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3300 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3303 if(adapter->smartspeed == 0) {
3304 /* If Master/Slave config fault is asserted twice,
3305 * we assume back-to-back */
3306 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3307 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3308 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3309 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3310 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3311 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3312 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3313 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3315 adapter->smartspeed++;
3316 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3317 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3319 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3320 MII_CR_RESTART_AUTO_NEG);
3321 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3326 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3327 /* If still no link, perhaps using 2/3 pair cable */
3328 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3329 phy_ctrl |= CR_1000T_MS_ENABLE;
3330 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3331 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3332 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3333 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3334 MII_CR_RESTART_AUTO_NEG);
3335 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3338 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3339 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3340 adapter->smartspeed = 0;
3351 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3357 return e1000_mii_ioctl(netdev, ifr, cmd);
3371 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3373 struct e1000_adapter *adapter = netdev->priv;
3374 struct mii_ioctl_data *data = if_mii(ifr);
3379 if(adapter->hw.media_type != e1000_media_type_copper)
3384 data->phy_id = adapter->hw.phy_addr;
3387 if (!capable(CAP_NET_ADMIN))
3389 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3394 if (!capable(CAP_NET_ADMIN))
3396 if (data->reg_num & ~(0x1F))
3398 mii_reg = data->val_in;
3399 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
3402 if (adapter->hw.phy_type == e1000_phy_m88) {
3403 switch (data->reg_num) {
3405 if(mii_reg & MII_CR_POWER_DOWN)
3407 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3408 adapter->hw.autoneg = 1;
3409 adapter->hw.autoneg_advertised = 0x2F;
3412 spddplx = SPEED_1000;
3413 else if (mii_reg & 0x2000)
3414 spddplx = SPEED_100;
3417 spddplx += (mii_reg & 0x100)
3420 retval = e1000_set_spd_dplx(adapter,
3425 if(netif_running(adapter->netdev)) {
3426 e1000_down(adapter);
3429 e1000_reset(adapter);
3431 case M88E1000_PHY_SPEC_CTRL:
3432 case M88E1000_EXT_PHY_SPEC_CTRL:
3433 if (e1000_phy_reset(&adapter->hw))
3438 switch (data->reg_num) {
3440 if(mii_reg & MII_CR_POWER_DOWN)
3442 if(netif_running(adapter->netdev)) {
3443 e1000_down(adapter);
3446 e1000_reset(adapter);
3454 return E1000_SUCCESS;
3458 e1000_pci_set_mwi(struct e1000_hw *hw)
3460 struct e1000_adapter *adapter = hw->back;
3461 int ret_val = pci_set_mwi(adapter->pdev);
3464 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
3468 e1000_pci_clear_mwi(struct e1000_hw *hw)
3470 struct e1000_adapter *adapter = hw->back;
3472 pci_clear_mwi(adapter->pdev);
3476 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3478 struct e1000_adapter *adapter = hw->back;
3480 pci_read_config_word(adapter->pdev, reg, value);
3484 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3486 struct e1000_adapter *adapter = hw->back;
3488 pci_write_config_word(adapter->pdev, reg, *value);
3492 e1000_io_read(struct e1000_hw *hw, unsigned long port)
3498 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3504 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3506 struct e1000_adapter *adapter = netdev->priv;
3507 uint32_t ctrl, rctl;
3509 e1000_irq_disable(adapter);
3510 adapter->vlgrp = grp;
3513 /* enable VLAN tag insert/strip */
3514 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3515 ctrl |= E1000_CTRL_VME;
3516 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3518 /* enable VLAN receive filtering */
3519 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3520 rctl |= E1000_RCTL_VFE;
3521 rctl &= ~E1000_RCTL_CFIEN;
3522 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3523 e1000_update_mng_vlan(adapter);
3525 /* disable VLAN tag insert/strip */
3526 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3527 ctrl &= ~E1000_CTRL_VME;
3528 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3530 /* disable VLAN filtering */
3531 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3532 rctl &= ~E1000_RCTL_VFE;
3533 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3534 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
3535 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3536 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3540 e1000_irq_enable(adapter);
3544 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3546 struct e1000_adapter *adapter = netdev->priv;
3547 uint32_t vfta, index;
3548 if((adapter->hw.mng_cookie.status &
3549 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3550 (vid == adapter->mng_vlan_id))
3552 /* add VID to filter table */
3553 index = (vid >> 5) & 0x7F;
3554 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3555 vfta |= (1 << (vid & 0x1F));
3556 e1000_write_vfta(&adapter->hw, index, vfta);
3560 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3562 struct e1000_adapter *adapter = netdev->priv;
3563 uint32_t vfta, index;
3565 e1000_irq_disable(adapter);
3568 adapter->vlgrp->vlan_devices[vid] = NULL;
3570 e1000_irq_enable(adapter);
3572 if((adapter->hw.mng_cookie.status &
3573 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3574 (vid == adapter->mng_vlan_id))
3576 /* remove VID from filter table */
3577 index = (vid >> 5) & 0x7F;
3578 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3579 vfta &= ~(1 << (vid & 0x1F));
3580 e1000_write_vfta(&adapter->hw, index, vfta);
3584 e1000_restore_vlan(struct e1000_adapter *adapter)
3586 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
3588 if(adapter->vlgrp) {
3590 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
3591 if(!adapter->vlgrp->vlan_devices[vid])
3593 e1000_vlan_rx_add_vid(adapter->netdev, vid);
3599 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3601 adapter->hw.autoneg = 0;
3604 case SPEED_10 + DUPLEX_HALF:
3605 adapter->hw.forced_speed_duplex = e1000_10_half;
3607 case SPEED_10 + DUPLEX_FULL:
3608 adapter->hw.forced_speed_duplex = e1000_10_full;
3610 case SPEED_100 + DUPLEX_HALF:
3611 adapter->hw.forced_speed_duplex = e1000_100_half;
3613 case SPEED_100 + DUPLEX_FULL:
3614 adapter->hw.forced_speed_duplex = e1000_100_full;
3616 case SPEED_1000 + DUPLEX_FULL:
3617 adapter->hw.autoneg = 1;
3618 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
3620 case SPEED_1000 + DUPLEX_HALF: /* not supported */
3622 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3629 e1000_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3631 struct pci_dev *pdev = NULL;
3637 while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
3638 if(pci_dev_driver(pdev) == &e1000_driver)
3639 e1000_suspend(pdev, 3);
3646 e1000_suspend(struct pci_dev *pdev, uint32_t state)
3648 struct net_device *netdev = pci_get_drvdata(pdev);
3649 struct e1000_adapter *adapter = netdev->priv;
3650 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
3651 uint32_t wufc = adapter->wol;
3653 netif_device_detach(netdev);
3655 if(netif_running(netdev))
3656 e1000_down(adapter);
3658 status = E1000_READ_REG(&adapter->hw, STATUS);
3659 if(status & E1000_STATUS_LU)
3660 wufc &= ~E1000_WUFC_LNKC;
3663 e1000_setup_rctl(adapter);
3664 e1000_set_multi(netdev);
3666 /* turn on all-multi mode if wake on multicast is enabled */
3667 if(adapter->wol & E1000_WUFC_MC) {
3668 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3669 rctl |= E1000_RCTL_MPE;
3670 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3673 if(adapter->hw.mac_type >= e1000_82540) {
3674 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3675 /* advertise wake from D3Cold */
3676 #define E1000_CTRL_ADVD3WUC 0x00100000
3677 /* phy power management enable */
3678 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3679 ctrl |= E1000_CTRL_ADVD3WUC |
3680 E1000_CTRL_EN_PHY_PWR_MGMT;
3681 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3684 if(adapter->hw.media_type == e1000_media_type_fiber ||
3685 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3686 /* keep the laser running in D3 */
3687 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
3688 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3689 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
3692 /* Allow time for pending master requests to run */
3693 e1000_disable_pciex_master(&adapter->hw);
3695 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
3696 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
3697 pci_enable_wake(pdev, 3, 1);
3698 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3700 E1000_WRITE_REG(&adapter->hw, WUC, 0);
3701 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
3702 pci_enable_wake(pdev, 3, 0);
3703 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3706 pci_save_state(pdev);
3708 if(adapter->hw.mac_type >= e1000_82540 &&
3709 adapter->hw.media_type == e1000_media_type_copper) {
3710 manc = E1000_READ_REG(&adapter->hw, MANC);
3711 if(manc & E1000_MANC_SMBUS_EN) {
3712 manc |= E1000_MANC_ARP_EN;
3713 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3714 pci_enable_wake(pdev, 3, 1);
3715 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3719 switch(adapter->hw.mac_type) {
3721 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3722 E1000_WRITE_REG(&adapter->hw, SWSM,
3723 swsm & ~E1000_SWSM_DRV_LOAD);
3729 pci_disable_device(pdev);
3731 state = (state > 0) ? 3 : 0;
3732 pci_set_power_state(pdev, state);
3739 e1000_resume(struct pci_dev *pdev)
3741 struct net_device *netdev = pci_get_drvdata(pdev);
3742 struct e1000_adapter *adapter = netdev->priv;
3743 uint32_t manc, ret, swsm;
3745 pci_set_power_state(pdev, 0);
3746 pci_restore_state(pdev);
3747 ret = pci_enable_device(pdev);
3748 pci_set_master(pdev);
3750 pci_enable_wake(pdev, 3, 0);
3751 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3753 e1000_reset(adapter);
3754 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
3756 if(netif_running(netdev))
3759 netif_device_attach(netdev);
3761 if(adapter->hw.mac_type >= e1000_82540 &&
3762 adapter->hw.media_type == e1000_media_type_copper) {
3763 manc = E1000_READ_REG(&adapter->hw, MANC);
3764 manc &= ~(E1000_MANC_ARP_EN);
3765 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3768 switch(adapter->hw.mac_type) {
3770 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3771 E1000_WRITE_REG(&adapter->hw, SWSM,
3772 swsm | E1000_SWSM_DRV_LOAD);
3781 #ifdef CONFIG_NET_POLL_CONTROLLER
3783 * Polling 'interrupt' - used by things like netconsole to send skbs
3784 * without having to re-enable interrupts. It's not called while
3785 * the interrupt routine is executing.
3788 e1000_netpoll(struct net_device *netdev)
3790 struct e1000_adapter *adapter = netdev->priv;
3791 disable_irq(adapter->pdev->irq);
3792 e1000_intr(adapter->pdev->irq, netdev, NULL);
3793 enable_irq(adapter->pdev->irq);