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 Accepted ethtool cleanup patch from Stephen Hemminger
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
39 char e1000_driver_name[] = "e1000";
40 char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.0.60-k2"DRIVERNAPI
47 char e1000_driver_version[] = DRV_VERSION;
48 char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
50 /* e1000_pci_tbl - PCI Device ID Table
52 * Last entry must be all 0s
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
57 static struct pci_device_id e1000_pci_tbl[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
77 INTEL_E1000_ETHERNET_DEVICE(0x101A),
78 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x1075),
84 INTEL_E1000_ETHERNET_DEVICE(0x1076),
85 INTEL_E1000_ETHERNET_DEVICE(0x1077),
86 INTEL_E1000_ETHERNET_DEVICE(0x1078),
87 INTEL_E1000_ETHERNET_DEVICE(0x1079),
88 INTEL_E1000_ETHERNET_DEVICE(0x107A),
89 INTEL_E1000_ETHERNET_DEVICE(0x107B),
90 INTEL_E1000_ETHERNET_DEVICE(0x107C),
91 INTEL_E1000_ETHERNET_DEVICE(0x108A),
92 INTEL_E1000_ETHERNET_DEVICE(0x108B),
93 INTEL_E1000_ETHERNET_DEVICE(0x108C),
94 INTEL_E1000_ETHERNET_DEVICE(0x1099),
95 /* required last entry */
99 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
101 int e1000_up(struct e1000_adapter *adapter);
102 void e1000_down(struct e1000_adapter *adapter);
103 void e1000_reset(struct e1000_adapter *adapter);
104 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
105 int e1000_setup_tx_resources(struct e1000_adapter *adapter);
106 int e1000_setup_rx_resources(struct e1000_adapter *adapter);
107 void e1000_free_tx_resources(struct e1000_adapter *adapter);
108 void e1000_free_rx_resources(struct e1000_adapter *adapter);
109 void e1000_update_stats(struct e1000_adapter *adapter);
111 /* Local Function Prototypes */
113 static int e1000_init_module(void);
114 static void e1000_exit_module(void);
115 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
116 static void __devexit e1000_remove(struct pci_dev *pdev);
117 static int e1000_sw_init(struct e1000_adapter *adapter);
118 static int e1000_open(struct net_device *netdev);
119 static int e1000_close(struct net_device *netdev);
120 static void e1000_configure_tx(struct e1000_adapter *adapter);
121 static void e1000_configure_rx(struct e1000_adapter *adapter);
122 static void e1000_setup_rctl(struct e1000_adapter *adapter);
123 static void e1000_clean_tx_ring(struct e1000_adapter *adapter);
124 static void e1000_clean_rx_ring(struct e1000_adapter *adapter);
125 static void e1000_set_multi(struct net_device *netdev);
126 static void e1000_update_phy_info(unsigned long data);
127 static void e1000_watchdog(unsigned long data);
128 static void e1000_watchdog_task(struct e1000_adapter *adapter);
129 static void e1000_82547_tx_fifo_stall(unsigned long data);
130 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
131 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
132 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
133 static int e1000_set_mac(struct net_device *netdev, void *p);
134 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
135 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter);
136 #ifdef CONFIG_E1000_NAPI
137 static int e1000_clean(struct net_device *netdev, int *budget);
138 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
139 int *work_done, int work_to_do);
140 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
141 int *work_done, int work_to_do);
143 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter);
144 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter);
146 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);
147 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter);
148 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
149 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
151 void e1000_set_ethtool_ops(struct net_device *netdev);
152 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
153 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
154 static void e1000_tx_timeout(struct net_device *dev);
155 static void e1000_tx_timeout_task(struct net_device *dev);
156 static void e1000_smartspeed(struct e1000_adapter *adapter);
157 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
158 struct sk_buff *skb);
160 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
161 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
162 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
163 static void e1000_restore_vlan(struct e1000_adapter *adapter);
165 static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
166 static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
168 static int e1000_resume(struct pci_dev *pdev);
171 #ifdef CONFIG_NET_POLL_CONTROLLER
172 /* for netdump / net console */
173 static void e1000_netpoll (struct net_device *netdev);
176 struct notifier_block e1000_notifier_reboot = {
177 .notifier_call = e1000_notify_reboot,
182 /* Exported from other modules */
184 extern void e1000_check_options(struct e1000_adapter *adapter);
186 static struct pci_driver e1000_driver = {
187 .name = e1000_driver_name,
188 .id_table = e1000_pci_tbl,
189 .probe = e1000_probe,
190 .remove = __devexit_p(e1000_remove),
191 /* Power Managment Hooks */
193 .suspend = e1000_suspend,
194 .resume = e1000_resume
198 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
199 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
200 MODULE_LICENSE("GPL");
201 MODULE_VERSION(DRV_VERSION);
203 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
204 module_param(debug, int, 0);
205 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
208 * e1000_init_module - Driver Registration Routine
210 * e1000_init_module is the first routine called when the driver is
211 * loaded. All it does is register with the PCI subsystem.
215 e1000_init_module(void)
218 printk(KERN_INFO "%s - version %s\n",
219 e1000_driver_string, e1000_driver_version);
221 printk(KERN_INFO "%s\n", e1000_copyright);
223 ret = pci_module_init(&e1000_driver);
225 register_reboot_notifier(&e1000_notifier_reboot);
230 module_init(e1000_init_module);
233 * e1000_exit_module - Driver Exit Cleanup Routine
235 * e1000_exit_module is called just before the driver is removed
240 e1000_exit_module(void)
242 unregister_reboot_notifier(&e1000_notifier_reboot);
243 pci_unregister_driver(&e1000_driver);
246 module_exit(e1000_exit_module);
249 * e1000_irq_disable - Mask off interrupt generation on the NIC
250 * @adapter: board private structure
254 e1000_irq_disable(struct e1000_adapter *adapter)
256 atomic_inc(&adapter->irq_sem);
257 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
258 E1000_WRITE_FLUSH(&adapter->hw);
259 synchronize_irq(adapter->pdev->irq);
263 * e1000_irq_enable - Enable default interrupt generation settings
264 * @adapter: board private structure
268 e1000_irq_enable(struct e1000_adapter *adapter)
270 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
271 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
272 E1000_WRITE_FLUSH(&adapter->hw);
276 e1000_update_mng_vlan(struct e1000_adapter *adapter)
278 struct net_device *netdev = adapter->netdev;
279 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
280 uint16_t old_vid = adapter->mng_vlan_id;
282 if(!adapter->vlgrp->vlan_devices[vid]) {
283 if(adapter->hw.mng_cookie.status &
284 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
285 e1000_vlan_rx_add_vid(netdev, vid);
286 adapter->mng_vlan_id = vid;
288 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
290 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
292 !adapter->vlgrp->vlan_devices[old_vid])
293 e1000_vlan_rx_kill_vid(netdev, old_vid);
299 e1000_up(struct e1000_adapter *adapter)
301 struct net_device *netdev = adapter->netdev;
304 /* hardware has been reset, we need to reload some things */
306 /* Reset the PHY if it was previously powered down */
307 if(adapter->hw.media_type == e1000_media_type_copper) {
309 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
310 if(mii_reg & MII_CR_POWER_DOWN)
311 e1000_phy_reset(&adapter->hw);
314 e1000_set_multi(netdev);
316 e1000_restore_vlan(adapter);
318 e1000_configure_tx(adapter);
319 e1000_setup_rctl(adapter);
320 e1000_configure_rx(adapter);
321 adapter->alloc_rx_buf(adapter);
323 #ifdef CONFIG_PCI_MSI
324 if(adapter->hw.mac_type > e1000_82547_rev_2) {
325 adapter->have_msi = TRUE;
326 if((err = pci_enable_msi(adapter->pdev))) {
328 "Unable to allocate MSI interrupt Error: %d\n", err);
329 adapter->have_msi = FALSE;
333 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
334 SA_SHIRQ | SA_SAMPLE_RANDOM,
335 netdev->name, netdev))) {
337 "Unable to allocate interrupt Error: %d\n", err);
341 mod_timer(&adapter->watchdog_timer, jiffies);
343 #ifdef CONFIG_E1000_NAPI
344 netif_poll_enable(netdev);
346 e1000_irq_enable(adapter);
352 e1000_down(struct e1000_adapter *adapter)
354 struct net_device *netdev = adapter->netdev;
356 e1000_irq_disable(adapter);
357 free_irq(adapter->pdev->irq, netdev);
358 #ifdef CONFIG_PCI_MSI
359 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
360 adapter->have_msi == TRUE)
361 pci_disable_msi(adapter->pdev);
363 del_timer_sync(&adapter->tx_fifo_stall_timer);
364 del_timer_sync(&adapter->watchdog_timer);
365 del_timer_sync(&adapter->phy_info_timer);
367 #ifdef CONFIG_E1000_NAPI
368 netif_poll_disable(netdev);
370 adapter->link_speed = 0;
371 adapter->link_duplex = 0;
372 netif_carrier_off(netdev);
373 netif_stop_queue(netdev);
375 e1000_reset(adapter);
376 e1000_clean_tx_ring(adapter);
377 e1000_clean_rx_ring(adapter);
379 /* If WoL is not enabled
380 * and management mode is not IAMT
381 * Power down the PHY so no link is implied when interface is down */
382 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
383 adapter->hw.media_type == e1000_media_type_copper &&
384 !e1000_check_mng_mode(&adapter->hw) &&
385 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
387 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
388 mii_reg |= MII_CR_POWER_DOWN;
389 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
395 e1000_reset(struct e1000_adapter *adapter)
397 struct net_device *netdev = adapter->netdev;
399 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
400 uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
402 /* Repartition Pba for greater than 9k mtu
403 * To take effect CTRL.RST is required.
406 switch (adapter->hw.mac_type) {
408 case e1000_82547_rev_2:
419 if((adapter->hw.mac_type != e1000_82573) &&
420 (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {
421 pba -= 8; /* allocate more FIFO for Tx */
422 /* send an XOFF when there is enough space in the
423 * Rx FIFO to hold one extra full size Rx packet
425 fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE +
426 ETHERNET_FCS_SIZE + 1;
427 fc_low_water_mark = fc_high_water_mark + 8;
431 if(adapter->hw.mac_type == e1000_82547) {
432 adapter->tx_fifo_head = 0;
433 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
434 adapter->tx_fifo_size =
435 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
436 atomic_set(&adapter->tx_fifo_stall, 0);
439 E1000_WRITE_REG(&adapter->hw, PBA, pba);
441 /* flow control settings */
442 adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
444 adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
446 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
447 adapter->hw.fc_send_xon = 1;
448 adapter->hw.fc = adapter->hw.original_fc;
450 /* Allow time for pending master requests to run */
451 e1000_reset_hw(&adapter->hw);
452 if(adapter->hw.mac_type >= e1000_82544)
453 E1000_WRITE_REG(&adapter->hw, WUC, 0);
454 if(e1000_init_hw(&adapter->hw))
455 DPRINTK(PROBE, ERR, "Hardware Error\n");
456 e1000_update_mng_vlan(adapter);
457 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
458 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
460 e1000_reset_adaptive(&adapter->hw);
461 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
462 if (adapter->en_mng_pt) {
463 manc = E1000_READ_REG(&adapter->hw, MANC);
464 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
465 E1000_WRITE_REG(&adapter->hw, MANC, manc);
470 * e1000_probe - Device Initialization Routine
471 * @pdev: PCI device information struct
472 * @ent: entry in e1000_pci_tbl
474 * Returns 0 on success, negative on failure
476 * e1000_probe initializes an adapter identified by a pci_dev structure.
477 * The OS initialization, configuring of the adapter private structure,
478 * and a hardware reset occur.
482 e1000_probe(struct pci_dev *pdev,
483 const struct pci_device_id *ent)
485 struct net_device *netdev;
486 struct e1000_adapter *adapter;
487 unsigned long mmio_start, mmio_len;
490 static int cards_found = 0;
491 int i, err, pci_using_dac;
492 uint16_t eeprom_data;
493 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
494 if((err = pci_enable_device(pdev)))
497 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
500 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
501 E1000_ERR("No usable DMA configuration, aborting\n");
507 if((err = pci_request_regions(pdev, e1000_driver_name)))
510 pci_set_master(pdev);
512 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
515 goto err_alloc_etherdev;
518 SET_MODULE_OWNER(netdev);
519 SET_NETDEV_DEV(netdev, &pdev->dev);
521 pci_set_drvdata(pdev, netdev);
522 adapter = netdev_priv(netdev);
523 adapter->netdev = netdev;
524 adapter->pdev = pdev;
525 adapter->hw.back = adapter;
526 adapter->msg_enable = (1 << debug) - 1;
528 mmio_start = pci_resource_start(pdev, BAR_0);
529 mmio_len = pci_resource_len(pdev, BAR_0);
531 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
532 if(!adapter->hw.hw_addr) {
537 for(i = BAR_1; i <= BAR_5; i++) {
538 if(pci_resource_len(pdev, i) == 0)
540 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
541 adapter->hw.io_base = pci_resource_start(pdev, i);
546 netdev->open = &e1000_open;
547 netdev->stop = &e1000_close;
548 netdev->hard_start_xmit = &e1000_xmit_frame;
549 netdev->get_stats = &e1000_get_stats;
550 netdev->set_multicast_list = &e1000_set_multi;
551 netdev->set_mac_address = &e1000_set_mac;
552 netdev->change_mtu = &e1000_change_mtu;
553 netdev->do_ioctl = &e1000_ioctl;
554 e1000_set_ethtool_ops(netdev);
555 netdev->tx_timeout = &e1000_tx_timeout;
556 netdev->watchdog_timeo = 5 * HZ;
557 #ifdef CONFIG_E1000_NAPI
558 netdev->poll = &e1000_clean;
561 netdev->vlan_rx_register = e1000_vlan_rx_register;
562 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
563 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
564 #ifdef CONFIG_NET_POLL_CONTROLLER
565 netdev->poll_controller = e1000_netpoll;
567 strcpy(netdev->name, pci_name(pdev));
569 netdev->mem_start = mmio_start;
570 netdev->mem_end = mmio_start + mmio_len;
571 netdev->base_addr = adapter->hw.io_base;
573 adapter->bd_number = cards_found;
575 /* setup the private structure */
577 if((err = e1000_sw_init(adapter)))
580 if((err = e1000_check_phy_reset_block(&adapter->hw)))
581 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
583 if(adapter->hw.mac_type >= e1000_82543) {
584 netdev->features = NETIF_F_SG |
588 NETIF_F_HW_VLAN_FILTER;
592 if((adapter->hw.mac_type >= e1000_82544) &&
593 (adapter->hw.mac_type != e1000_82547))
594 netdev->features |= NETIF_F_TSO;
596 #ifdef NETIF_F_TSO_IPV6
597 if(adapter->hw.mac_type > e1000_82547_rev_2)
598 netdev->features |= NETIF_F_TSO_IPV6;
602 netdev->features |= NETIF_F_HIGHDMA;
604 /* hard_start_xmit is safe against parallel locking */
605 netdev->features |= NETIF_F_LLTX;
607 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
609 /* before reading the EEPROM, reset the controller to
610 * put the device in a known good starting state */
612 e1000_reset_hw(&adapter->hw);
614 /* make sure the EEPROM is good */
616 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
617 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
622 /* copy the MAC address out of the EEPROM */
624 if(e1000_read_mac_addr(&adapter->hw))
625 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
626 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
628 if(!is_valid_ether_addr(netdev->dev_addr)) {
629 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
634 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
636 e1000_get_bus_info(&adapter->hw);
638 init_timer(&adapter->tx_fifo_stall_timer);
639 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
640 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
642 init_timer(&adapter->watchdog_timer);
643 adapter->watchdog_timer.function = &e1000_watchdog;
644 adapter->watchdog_timer.data = (unsigned long) adapter;
646 INIT_WORK(&adapter->watchdog_task,
647 (void (*)(void *))e1000_watchdog_task, adapter);
649 init_timer(&adapter->phy_info_timer);
650 adapter->phy_info_timer.function = &e1000_update_phy_info;
651 adapter->phy_info_timer.data = (unsigned long) adapter;
653 INIT_WORK(&adapter->tx_timeout_task,
654 (void (*)(void *))e1000_tx_timeout_task, netdev);
656 /* we're going to reset, so assume we have no link for now */
658 netif_carrier_off(netdev);
659 netif_stop_queue(netdev);
661 e1000_check_options(adapter);
663 /* Initial Wake on LAN setting
664 * If APM wake is enabled in the EEPROM,
665 * enable the ACPI Magic Packet filter
668 switch(adapter->hw.mac_type) {
669 case e1000_82542_rev2_0:
670 case e1000_82542_rev2_1:
674 e1000_read_eeprom(&adapter->hw,
675 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
676 eeprom_apme_mask = E1000_EEPROM_82544_APM;
679 case e1000_82546_rev_3:
680 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
681 && (adapter->hw.media_type == e1000_media_type_copper)) {
682 e1000_read_eeprom(&adapter->hw,
683 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
688 e1000_read_eeprom(&adapter->hw,
689 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
692 if(eeprom_data & eeprom_apme_mask)
693 adapter->wol |= E1000_WUFC_MAG;
695 /* reset the hardware with the new settings */
696 e1000_reset(adapter);
698 /* Let firmware know the driver has taken over */
699 switch(adapter->hw.mac_type) {
701 swsm = E1000_READ_REG(&adapter->hw, SWSM);
702 E1000_WRITE_REG(&adapter->hw, SWSM,
703 swsm | E1000_SWSM_DRV_LOAD);
709 strcpy(netdev->name, "eth%d");
710 if((err = register_netdev(netdev)))
713 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
721 iounmap(adapter->hw.hw_addr);
725 pci_release_regions(pdev);
730 * e1000_remove - Device Removal Routine
731 * @pdev: PCI device information struct
733 * e1000_remove is called by the PCI subsystem to alert the driver
734 * that it should release a PCI device. The could be caused by a
735 * Hot-Plug event, or because the driver is going to be removed from
739 static void __devexit
740 e1000_remove(struct pci_dev *pdev)
742 struct net_device *netdev = pci_get_drvdata(pdev);
743 struct e1000_adapter *adapter = netdev_priv(netdev);
746 flush_scheduled_work();
748 if(adapter->hw.mac_type >= e1000_82540 &&
749 adapter->hw.media_type == e1000_media_type_copper) {
750 manc = E1000_READ_REG(&adapter->hw, MANC);
751 if(manc & E1000_MANC_SMBUS_EN) {
752 manc |= E1000_MANC_ARP_EN;
753 E1000_WRITE_REG(&adapter->hw, MANC, manc);
757 switch(adapter->hw.mac_type) {
759 swsm = E1000_READ_REG(&adapter->hw, SWSM);
760 E1000_WRITE_REG(&adapter->hw, SWSM,
761 swsm & ~E1000_SWSM_DRV_LOAD);
768 unregister_netdev(netdev);
770 if(!e1000_check_phy_reset_block(&adapter->hw))
771 e1000_phy_hw_reset(&adapter->hw);
773 iounmap(adapter->hw.hw_addr);
774 pci_release_regions(pdev);
778 pci_disable_device(pdev);
782 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
783 * @adapter: board private structure to initialize
785 * e1000_sw_init initializes the Adapter private data structure.
786 * Fields are initialized based on PCI device information and
787 * OS network device settings (MTU size).
791 e1000_sw_init(struct e1000_adapter *adapter)
793 struct e1000_hw *hw = &adapter->hw;
794 struct net_device *netdev = adapter->netdev;
795 struct pci_dev *pdev = adapter->pdev;
797 /* PCI config space info */
799 hw->vendor_id = pdev->vendor;
800 hw->device_id = pdev->device;
801 hw->subsystem_vendor_id = pdev->subsystem_vendor;
802 hw->subsystem_id = pdev->subsystem_device;
804 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
806 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
808 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
809 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
810 hw->max_frame_size = netdev->mtu +
811 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
812 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
814 /* identify the MAC */
816 if(e1000_set_mac_type(hw)) {
817 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
821 /* initialize eeprom parameters */
823 if(e1000_init_eeprom_params(hw)) {
824 E1000_ERR("EEPROM initialization failed\n");
828 switch(hw->mac_type) {
833 case e1000_82541_rev_2:
834 case e1000_82547_rev_2:
835 hw->phy_init_script = 1;
839 e1000_set_media_type(hw);
841 hw->wait_autoneg_complete = FALSE;
842 hw->tbi_compatibility_en = TRUE;
843 hw->adaptive_ifs = TRUE;
847 if(hw->media_type == e1000_media_type_copper) {
848 hw->mdix = AUTO_ALL_MODES;
849 hw->disable_polarity_correction = FALSE;
850 hw->master_slave = E1000_MASTER_SLAVE;
853 atomic_set(&adapter->irq_sem, 1);
854 spin_lock_init(&adapter->stats_lock);
855 spin_lock_init(&adapter->tx_lock);
861 * e1000_open - Called when a network interface is made active
862 * @netdev: network interface device structure
864 * Returns 0 on success, negative value on failure
866 * The open entry point is called when a network interface is made
867 * active by the system (IFF_UP). At this point all resources needed
868 * for transmit and receive operations are allocated, the interrupt
869 * handler is registered with the OS, the watchdog timer is started,
870 * and the stack is notified that the interface is ready.
874 e1000_open(struct net_device *netdev)
876 struct e1000_adapter *adapter = netdev_priv(netdev);
879 /* allocate transmit descriptors */
881 if((err = e1000_setup_tx_resources(adapter)))
884 /* allocate receive descriptors */
886 if((err = e1000_setup_rx_resources(adapter)))
889 if((err = e1000_up(adapter)))
891 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
892 if((adapter->hw.mng_cookie.status &
893 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
894 e1000_update_mng_vlan(adapter);
897 return E1000_SUCCESS;
900 e1000_free_rx_resources(adapter);
902 e1000_free_tx_resources(adapter);
904 e1000_reset(adapter);
910 * e1000_close - Disables a network interface
911 * @netdev: network interface device structure
913 * Returns 0, this is not allowed to fail
915 * The close entry point is called when an interface is de-activated
916 * by the OS. The hardware is still under the drivers control, but
917 * needs to be disabled. A global MAC reset is issued to stop the
918 * hardware, and all transmit and receive resources are freed.
922 e1000_close(struct net_device *netdev)
924 struct e1000_adapter *adapter = netdev_priv(netdev);
928 e1000_free_tx_resources(adapter);
929 e1000_free_rx_resources(adapter);
931 if((adapter->hw.mng_cookie.status &
932 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
933 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
939 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
940 * @adapter: address of board private structure
941 * @start: address of beginning of memory
942 * @len: length of memory
944 static inline boolean_t
945 e1000_check_64k_bound(struct e1000_adapter *adapter,
946 void *start, unsigned long len)
948 unsigned long begin = (unsigned long) start;
949 unsigned long end = begin + len;
951 /* First rev 82545 and 82546 need to not allow any memory
952 * write location to cross 64k boundary due to errata 23 */
953 if (adapter->hw.mac_type == e1000_82545 ||
954 adapter->hw.mac_type == e1000_82546) {
955 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
962 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
963 * @adapter: board private structure
965 * Return 0 on success, negative on failure
969 e1000_setup_tx_resources(struct e1000_adapter *adapter)
971 struct e1000_desc_ring *txdr = &adapter->tx_ring;
972 struct pci_dev *pdev = adapter->pdev;
975 size = sizeof(struct e1000_buffer) * txdr->count;
976 txdr->buffer_info = vmalloc(size);
977 if(!txdr->buffer_info) {
979 "Unable to allocate memory for the transmit descriptor ring\n");
982 memset(txdr->buffer_info, 0, size);
984 /* round up to nearest 4K */
986 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
987 E1000_ROUNDUP(txdr->size, 4096);
989 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
992 vfree(txdr->buffer_info);
994 "Unable to allocate memory for the transmit descriptor ring\n");
998 /* Fix for errata 23, can't cross 64kB boundary */
999 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1000 void *olddesc = txdr->desc;
1001 dma_addr_t olddma = txdr->dma;
1002 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1003 "at %p\n", txdr->size, txdr->desc);
1004 /* Try again, without freeing the previous */
1005 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1007 /* Failed allocation, critical failure */
1008 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1009 goto setup_tx_desc_die;
1012 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1014 pci_free_consistent(pdev, txdr->size, txdr->desc,
1016 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1018 "Unable to allocate aligned memory "
1019 "for the transmit descriptor ring\n");
1020 vfree(txdr->buffer_info);
1023 /* Free old allocation, new allocation was successful */
1024 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1027 memset(txdr->desc, 0, txdr->size);
1029 txdr->next_to_use = 0;
1030 txdr->next_to_clean = 0;
1036 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1037 * @adapter: board private structure
1039 * Configure the Tx unit of the MAC after a reset.
1043 e1000_configure_tx(struct e1000_adapter *adapter)
1045 uint64_t tdba = adapter->tx_ring.dma;
1046 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc);
1047 uint32_t tctl, tipg;
1049 E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1050 E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1052 E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
1054 /* Setup the HW Tx Head and Tail descriptor pointers */
1056 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1057 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1059 /* Set the default values for the Tx Inter Packet Gap timer */
1061 switch (adapter->hw.mac_type) {
1062 case e1000_82542_rev2_0:
1063 case e1000_82542_rev2_1:
1064 tipg = DEFAULT_82542_TIPG_IPGT;
1065 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1066 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1069 if(adapter->hw.media_type == e1000_media_type_fiber ||
1070 adapter->hw.media_type == e1000_media_type_internal_serdes)
1071 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1073 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1074 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1075 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1077 E1000_WRITE_REG(&adapter->hw, TIPG, tipg);
1079 /* Set the Tx Interrupt Delay register */
1081 E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
1082 if(adapter->hw.mac_type >= e1000_82540)
1083 E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay);
1085 /* Program the Transmit Control Register */
1087 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1089 tctl &= ~E1000_TCTL_CT;
1090 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
1091 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1093 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1095 e1000_config_collision_dist(&adapter->hw);
1097 /* Setup Transmit Descriptor Settings for eop descriptor */
1098 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1101 if(adapter->hw.mac_type < e1000_82543)
1102 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1104 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1106 /* Cache if we're 82544 running in PCI-X because we'll
1107 * need this to apply a workaround later in the send path. */
1108 if(adapter->hw.mac_type == e1000_82544 &&
1109 adapter->hw.bus_type == e1000_bus_type_pcix)
1110 adapter->pcix_82544 = 1;
1114 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1115 * @adapter: board private structure
1117 * Returns 0 on success, negative on failure
1121 e1000_setup_rx_resources(struct e1000_adapter *adapter)
1123 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
1124 struct pci_dev *pdev = adapter->pdev;
1127 size = sizeof(struct e1000_buffer) * rxdr->count;
1128 rxdr->buffer_info = vmalloc(size);
1129 if(!rxdr->buffer_info) {
1131 "Unable to allocate memory for the receive descriptor ring\n");
1134 memset(rxdr->buffer_info, 0, size);
1136 size = sizeof(struct e1000_ps_page) * rxdr->count;
1137 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1138 if(!rxdr->ps_page) {
1139 vfree(rxdr->buffer_info);
1141 "Unable to allocate memory for the receive descriptor ring\n");
1144 memset(rxdr->ps_page, 0, size);
1146 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1147 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1148 if(!rxdr->ps_page_dma) {
1149 vfree(rxdr->buffer_info);
1150 kfree(rxdr->ps_page);
1152 "Unable to allocate memory for the receive descriptor ring\n");
1155 memset(rxdr->ps_page_dma, 0, size);
1157 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1158 desc_len = sizeof(struct e1000_rx_desc);
1160 desc_len = sizeof(union e1000_rx_desc_packet_split);
1162 /* Round up to nearest 4K */
1164 rxdr->size = rxdr->count * desc_len;
1165 E1000_ROUNDUP(rxdr->size, 4096);
1167 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1171 vfree(rxdr->buffer_info);
1172 kfree(rxdr->ps_page);
1173 kfree(rxdr->ps_page_dma);
1175 "Unable to allocate memory for the receive descriptor ring\n");
1179 /* Fix for errata 23, can't cross 64kB boundary */
1180 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1181 void *olddesc = rxdr->desc;
1182 dma_addr_t olddma = rxdr->dma;
1183 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1184 "at %p\n", rxdr->size, rxdr->desc);
1185 /* Try again, without freeing the previous */
1186 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1188 /* Failed allocation, critical failure */
1189 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1190 goto setup_rx_desc_die;
1193 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1195 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1197 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1199 "Unable to allocate aligned memory "
1200 "for the receive descriptor ring\n");
1201 vfree(rxdr->buffer_info);
1202 kfree(rxdr->ps_page);
1203 kfree(rxdr->ps_page_dma);
1206 /* Free old allocation, new allocation was successful */
1207 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1210 memset(rxdr->desc, 0, rxdr->size);
1212 rxdr->next_to_clean = 0;
1213 rxdr->next_to_use = 0;
1219 * e1000_setup_rctl - configure the receive control registers
1220 * @adapter: Board private structure
1224 e1000_setup_rctl(struct e1000_adapter *adapter)
1226 uint32_t rctl, rfctl;
1227 uint32_t psrctl = 0;
1229 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1231 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1233 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1234 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1235 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1237 if(adapter->hw.tbi_compatibility_on == 1)
1238 rctl |= E1000_RCTL_SBP;
1240 rctl &= ~E1000_RCTL_SBP;
1242 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1243 rctl &= ~E1000_RCTL_LPE;
1245 rctl |= E1000_RCTL_LPE;
1247 /* Setup buffer sizes */
1248 if(adapter->hw.mac_type == e1000_82573) {
1249 /* We can now specify buffers in 1K increments.
1250 * BSIZE and BSEX are ignored in this case. */
1251 rctl |= adapter->rx_buffer_len << 0x11;
1253 rctl &= ~E1000_RCTL_SZ_4096;
1254 rctl |= E1000_RCTL_BSEX;
1255 switch (adapter->rx_buffer_len) {
1256 case E1000_RXBUFFER_2048:
1258 rctl |= E1000_RCTL_SZ_2048;
1259 rctl &= ~E1000_RCTL_BSEX;
1261 case E1000_RXBUFFER_4096:
1262 rctl |= E1000_RCTL_SZ_4096;
1264 case E1000_RXBUFFER_8192:
1265 rctl |= E1000_RCTL_SZ_8192;
1267 case E1000_RXBUFFER_16384:
1268 rctl |= E1000_RCTL_SZ_16384;
1273 #ifdef CONFIG_E1000_PACKET_SPLIT
1274 /* 82571 and greater support packet-split where the protocol
1275 * header is placed in skb->data and the packet data is
1276 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1277 * In the case of a non-split, skb->data is linearly filled,
1278 * followed by the page buffers. Therefore, skb->data is
1279 * sized to hold the largest protocol header.
1281 adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2)
1282 && (adapter->netdev->mtu
1283 < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0));
1285 if(adapter->rx_ps) {
1286 /* Configure extra packet-split registers */
1287 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1288 rfctl |= E1000_RFCTL_EXTEN;
1289 /* disable IPv6 packet split support */
1290 rfctl |= E1000_RFCTL_IPV6_DIS;
1291 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1293 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1295 psrctl |= adapter->rx_ps_bsize0 >>
1296 E1000_PSRCTL_BSIZE0_SHIFT;
1297 psrctl |= PAGE_SIZE >>
1298 E1000_PSRCTL_BSIZE1_SHIFT;
1299 psrctl |= PAGE_SIZE <<
1300 E1000_PSRCTL_BSIZE2_SHIFT;
1301 psrctl |= PAGE_SIZE <<
1302 E1000_PSRCTL_BSIZE3_SHIFT;
1304 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1307 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1311 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1312 * @adapter: board private structure
1314 * Configure the Rx unit of the MAC after a reset.
1318 e1000_configure_rx(struct e1000_adapter *adapter)
1320 uint64_t rdba = adapter->rx_ring.dma;
1321 uint32_t rdlen, rctl, rxcsum;
1323 if(adapter->rx_ps) {
1324 rdlen = adapter->rx_ring.count *
1325 sizeof(union e1000_rx_desc_packet_split);
1326 adapter->clean_rx = e1000_clean_rx_irq_ps;
1327 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1329 rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc);
1330 adapter->clean_rx = e1000_clean_rx_irq;
1331 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1334 /* disable receives while setting up the descriptors */
1335 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1336 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1338 /* set the Receive Delay Timer Register */
1339 E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay);
1341 if(adapter->hw.mac_type >= e1000_82540) {
1342 E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay);
1343 if(adapter->itr > 1)
1344 E1000_WRITE_REG(&adapter->hw, ITR,
1345 1000000000 / (adapter->itr * 256));
1348 /* Setup the Base and Length of the Rx Descriptor Ring */
1349 E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1350 E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
1352 E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen);
1354 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1355 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1356 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1358 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1359 if(adapter->hw.mac_type >= e1000_82543) {
1360 rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
1361 if(adapter->rx_csum == TRUE) {
1362 rxcsum |= E1000_RXCSUM_TUOFL;
1364 /* Enable 82573 IPv4 payload checksum for UDP fragments
1365 * Must be used in conjunction with packet-split. */
1366 if((adapter->hw.mac_type > e1000_82547_rev_2) &&
1368 rxcsum |= E1000_RXCSUM_IPPCSE;
1371 rxcsum &= ~E1000_RXCSUM_TUOFL;
1372 /* don't need to clear IPPCSE as it defaults to 0 */
1374 E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum);
1377 if (adapter->hw.mac_type == e1000_82573)
1378 E1000_WRITE_REG(&adapter->hw, ERT, 0x0100);
1380 /* Enable Receives */
1381 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1385 * e1000_free_tx_resources - Free Tx Resources
1386 * @adapter: board private structure
1388 * Free all transmit software resources
1392 e1000_free_tx_resources(struct e1000_adapter *adapter)
1394 struct pci_dev *pdev = adapter->pdev;
1396 e1000_clean_tx_ring(adapter);
1398 vfree(adapter->tx_ring.buffer_info);
1399 adapter->tx_ring.buffer_info = NULL;
1401 pci_free_consistent(pdev, adapter->tx_ring.size,
1402 adapter->tx_ring.desc, adapter->tx_ring.dma);
1404 adapter->tx_ring.desc = NULL;
1408 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1409 struct e1000_buffer *buffer_info)
1411 if(buffer_info->dma) {
1412 pci_unmap_page(adapter->pdev,
1414 buffer_info->length,
1416 buffer_info->dma = 0;
1418 if(buffer_info->skb) {
1419 dev_kfree_skb_any(buffer_info->skb);
1420 buffer_info->skb = NULL;
1425 * e1000_clean_tx_ring - Free Tx Buffers
1426 * @adapter: board private structure
1430 e1000_clean_tx_ring(struct e1000_adapter *adapter)
1432 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1433 struct e1000_buffer *buffer_info;
1437 /* Free all the Tx ring sk_buffs */
1439 if (likely(adapter->previous_buffer_info.skb != NULL)) {
1440 e1000_unmap_and_free_tx_resource(adapter,
1441 &adapter->previous_buffer_info);
1444 for(i = 0; i < tx_ring->count; i++) {
1445 buffer_info = &tx_ring->buffer_info[i];
1446 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1449 size = sizeof(struct e1000_buffer) * tx_ring->count;
1450 memset(tx_ring->buffer_info, 0, size);
1452 /* Zero out the descriptor ring */
1454 memset(tx_ring->desc, 0, tx_ring->size);
1456 tx_ring->next_to_use = 0;
1457 tx_ring->next_to_clean = 0;
1459 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1460 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1464 * e1000_free_rx_resources - Free Rx Resources
1465 * @adapter: board private structure
1467 * Free all receive software resources
1471 e1000_free_rx_resources(struct e1000_adapter *adapter)
1473 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1474 struct pci_dev *pdev = adapter->pdev;
1476 e1000_clean_rx_ring(adapter);
1478 vfree(rx_ring->buffer_info);
1479 rx_ring->buffer_info = NULL;
1480 kfree(rx_ring->ps_page);
1481 rx_ring->ps_page = NULL;
1482 kfree(rx_ring->ps_page_dma);
1483 rx_ring->ps_page_dma = NULL;
1485 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1487 rx_ring->desc = NULL;
1491 * e1000_clean_rx_ring - Free Rx Buffers
1492 * @adapter: board private structure
1496 e1000_clean_rx_ring(struct e1000_adapter *adapter)
1498 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1499 struct e1000_buffer *buffer_info;
1500 struct e1000_ps_page *ps_page;
1501 struct e1000_ps_page_dma *ps_page_dma;
1502 struct pci_dev *pdev = adapter->pdev;
1506 /* Free all the Rx ring sk_buffs */
1508 for(i = 0; i < rx_ring->count; i++) {
1509 buffer_info = &rx_ring->buffer_info[i];
1510 if(buffer_info->skb) {
1511 ps_page = &rx_ring->ps_page[i];
1512 ps_page_dma = &rx_ring->ps_page_dma[i];
1513 pci_unmap_single(pdev,
1515 buffer_info->length,
1516 PCI_DMA_FROMDEVICE);
1518 dev_kfree_skb(buffer_info->skb);
1519 buffer_info->skb = NULL;
1521 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
1522 if(!ps_page->ps_page[j]) break;
1523 pci_unmap_single(pdev,
1524 ps_page_dma->ps_page_dma[j],
1525 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1526 ps_page_dma->ps_page_dma[j] = 0;
1527 put_page(ps_page->ps_page[j]);
1528 ps_page->ps_page[j] = NULL;
1533 size = sizeof(struct e1000_buffer) * rx_ring->count;
1534 memset(rx_ring->buffer_info, 0, size);
1535 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1536 memset(rx_ring->ps_page, 0, size);
1537 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1538 memset(rx_ring->ps_page_dma, 0, size);
1540 /* Zero out the descriptor ring */
1542 memset(rx_ring->desc, 0, rx_ring->size);
1544 rx_ring->next_to_clean = 0;
1545 rx_ring->next_to_use = 0;
1547 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1548 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1551 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1552 * and memory write and invalidate disabled for certain operations
1555 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1557 struct net_device *netdev = adapter->netdev;
1560 e1000_pci_clear_mwi(&adapter->hw);
1562 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1563 rctl |= E1000_RCTL_RST;
1564 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1565 E1000_WRITE_FLUSH(&adapter->hw);
1568 if(netif_running(netdev))
1569 e1000_clean_rx_ring(adapter);
1573 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1575 struct net_device *netdev = adapter->netdev;
1578 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1579 rctl &= ~E1000_RCTL_RST;
1580 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1581 E1000_WRITE_FLUSH(&adapter->hw);
1584 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
1585 e1000_pci_set_mwi(&adapter->hw);
1587 if(netif_running(netdev)) {
1588 e1000_configure_rx(adapter);
1589 e1000_alloc_rx_buffers(adapter);
1594 * e1000_set_mac - Change the Ethernet Address of the NIC
1595 * @netdev: network interface device structure
1596 * @p: pointer to an address structure
1598 * Returns 0 on success, negative on failure
1602 e1000_set_mac(struct net_device *netdev, void *p)
1604 struct e1000_adapter *adapter = netdev_priv(netdev);
1605 struct sockaddr *addr = p;
1607 if(!is_valid_ether_addr(addr->sa_data))
1608 return -EADDRNOTAVAIL;
1610 /* 82542 2.0 needs to be in reset to write receive address registers */
1612 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1613 e1000_enter_82542_rst(adapter);
1615 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1616 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
1618 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
1620 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1621 e1000_leave_82542_rst(adapter);
1627 * e1000_set_multi - Multicast and Promiscuous mode set
1628 * @netdev: network interface device structure
1630 * The set_multi entry point is called whenever the multicast address
1631 * list or the network interface flags are updated. This routine is
1632 * responsible for configuring the hardware for proper multicast,
1633 * promiscuous mode, and all-multi behavior.
1637 e1000_set_multi(struct net_device *netdev)
1639 struct e1000_adapter *adapter = netdev_priv(netdev);
1640 struct e1000_hw *hw = &adapter->hw;
1641 struct dev_mc_list *mc_ptr;
1642 unsigned long flags;
1644 uint32_t hash_value;
1647 spin_lock_irqsave(&adapter->tx_lock, flags);
1649 /* Check for Promiscuous and All Multicast modes */
1651 rctl = E1000_READ_REG(hw, RCTL);
1653 if(netdev->flags & IFF_PROMISC) {
1654 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1655 } else if(netdev->flags & IFF_ALLMULTI) {
1656 rctl |= E1000_RCTL_MPE;
1657 rctl &= ~E1000_RCTL_UPE;
1659 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
1662 E1000_WRITE_REG(hw, RCTL, rctl);
1664 /* 82542 2.0 needs to be in reset to write receive address registers */
1666 if(hw->mac_type == e1000_82542_rev2_0)
1667 e1000_enter_82542_rst(adapter);
1669 /* load the first 14 multicast address into the exact filters 1-14
1670 * RAR 0 is used for the station MAC adddress
1671 * if there are not 14 addresses, go ahead and clear the filters
1673 mc_ptr = netdev->mc_list;
1675 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
1677 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
1678 mc_ptr = mc_ptr->next;
1680 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
1681 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
1685 /* clear the old settings from the multicast hash table */
1687 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
1688 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1690 /* load any remaining addresses into the hash table */
1692 for(; mc_ptr; mc_ptr = mc_ptr->next) {
1693 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
1694 e1000_mta_set(hw, hash_value);
1697 if(hw->mac_type == e1000_82542_rev2_0)
1698 e1000_leave_82542_rst(adapter);
1700 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1703 /* Need to wait a few seconds after link up to get diagnostic information from
1707 e1000_update_phy_info(unsigned long data)
1709 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1710 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
1714 * e1000_82547_tx_fifo_stall - Timer Call-back
1715 * @data: pointer to adapter cast into an unsigned long
1719 e1000_82547_tx_fifo_stall(unsigned long data)
1721 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1722 struct net_device *netdev = adapter->netdev;
1725 if(atomic_read(&adapter->tx_fifo_stall)) {
1726 if((E1000_READ_REG(&adapter->hw, TDT) ==
1727 E1000_READ_REG(&adapter->hw, TDH)) &&
1728 (E1000_READ_REG(&adapter->hw, TDFT) ==
1729 E1000_READ_REG(&adapter->hw, TDFH)) &&
1730 (E1000_READ_REG(&adapter->hw, TDFTS) ==
1731 E1000_READ_REG(&adapter->hw, TDFHS))) {
1732 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1733 E1000_WRITE_REG(&adapter->hw, TCTL,
1734 tctl & ~E1000_TCTL_EN);
1735 E1000_WRITE_REG(&adapter->hw, TDFT,
1736 adapter->tx_head_addr);
1737 E1000_WRITE_REG(&adapter->hw, TDFH,
1738 adapter->tx_head_addr);
1739 E1000_WRITE_REG(&adapter->hw, TDFTS,
1740 adapter->tx_head_addr);
1741 E1000_WRITE_REG(&adapter->hw, TDFHS,
1742 adapter->tx_head_addr);
1743 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1744 E1000_WRITE_FLUSH(&adapter->hw);
1746 adapter->tx_fifo_head = 0;
1747 atomic_set(&adapter->tx_fifo_stall, 0);
1748 netif_wake_queue(netdev);
1750 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
1756 * e1000_watchdog - Timer Call-back
1757 * @data: pointer to adapter cast into an unsigned long
1760 e1000_watchdog(unsigned long data)
1762 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1764 /* Do the rest outside of interrupt context */
1765 schedule_work(&adapter->watchdog_task);
1769 e1000_watchdog_task(struct e1000_adapter *adapter)
1771 struct net_device *netdev = adapter->netdev;
1772 struct e1000_desc_ring *txdr = &adapter->tx_ring;
1775 e1000_check_for_link(&adapter->hw);
1776 if (adapter->hw.mac_type == e1000_82573) {
1777 e1000_enable_tx_pkt_filtering(&adapter->hw);
1778 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
1779 e1000_update_mng_vlan(adapter);
1782 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
1783 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
1784 link = !adapter->hw.serdes_link_down;
1786 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
1789 if(!netif_carrier_ok(netdev)) {
1790 e1000_get_speed_and_duplex(&adapter->hw,
1791 &adapter->link_speed,
1792 &adapter->link_duplex);
1794 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
1795 adapter->link_speed,
1796 adapter->link_duplex == FULL_DUPLEX ?
1797 "Full Duplex" : "Half Duplex");
1799 netif_carrier_on(netdev);
1800 netif_wake_queue(netdev);
1801 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1802 adapter->smartspeed = 0;
1805 if(netif_carrier_ok(netdev)) {
1806 adapter->link_speed = 0;
1807 adapter->link_duplex = 0;
1808 DPRINTK(LINK, INFO, "NIC Link is Down\n");
1809 netif_carrier_off(netdev);
1810 netif_stop_queue(netdev);
1811 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1814 e1000_smartspeed(adapter);
1817 e1000_update_stats(adapter);
1819 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
1820 adapter->tpt_old = adapter->stats.tpt;
1821 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
1822 adapter->colc_old = adapter->stats.colc;
1824 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
1825 adapter->gorcl_old = adapter->stats.gorcl;
1826 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
1827 adapter->gotcl_old = adapter->stats.gotcl;
1829 e1000_update_adaptive(&adapter->hw);
1831 if(!netif_carrier_ok(netdev)) {
1832 if(E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
1833 /* We've lost link, so the controller stops DMA,
1834 * but we've got queued Tx work that's never going
1835 * to get done, so reset controller to flush Tx.
1836 * (Do the reset outside of interrupt context). */
1837 schedule_work(&adapter->tx_timeout_task);
1841 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
1842 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
1843 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
1844 * asymmetrical Tx or Rx gets ITR=8000; everyone
1845 * else is between 2000-8000. */
1846 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
1847 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
1848 adapter->gotcl - adapter->gorcl :
1849 adapter->gorcl - adapter->gotcl) / 10000;
1850 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
1851 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
1854 /* Cause software interrupt to ensure rx ring is cleaned */
1855 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
1857 /* Force detection of hung controller every watchdog period */
1858 adapter->detect_tx_hung = TRUE;
1860 /* Reset the timer */
1861 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1864 #define E1000_TX_FLAGS_CSUM 0x00000001
1865 #define E1000_TX_FLAGS_VLAN 0x00000002
1866 #define E1000_TX_FLAGS_TSO 0x00000004
1867 #define E1000_TX_FLAGS_IPV4 0x00000008
1868 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
1869 #define E1000_TX_FLAGS_VLAN_SHIFT 16
1872 e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1875 struct e1000_context_desc *context_desc;
1877 uint32_t cmd_length = 0;
1878 uint16_t ipcse = 0, tucse, mss;
1879 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1882 if(skb_shinfo(skb)->tso_size) {
1883 if (skb_header_cloned(skb)) {
1884 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1889 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1890 mss = skb_shinfo(skb)->tso_size;
1891 if(skb->protocol == ntohs(ETH_P_IP)) {
1892 skb->nh.iph->tot_len = 0;
1893 skb->nh.iph->check = 0;
1895 ~csum_tcpudp_magic(skb->nh.iph->saddr,
1900 cmd_length = E1000_TXD_CMD_IP;
1901 ipcse = skb->h.raw - skb->data - 1;
1902 #ifdef NETIF_F_TSO_IPV6
1903 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
1904 skb->nh.ipv6h->payload_len = 0;
1906 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
1907 &skb->nh.ipv6h->daddr,
1914 ipcss = skb->nh.raw - skb->data;
1915 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1916 tucss = skb->h.raw - skb->data;
1917 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1920 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
1921 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
1923 i = adapter->tx_ring.next_to_use;
1924 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1926 context_desc->lower_setup.ip_fields.ipcss = ipcss;
1927 context_desc->lower_setup.ip_fields.ipcso = ipcso;
1928 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
1929 context_desc->upper_setup.tcp_fields.tucss = tucss;
1930 context_desc->upper_setup.tcp_fields.tucso = tucso;
1931 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
1932 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
1933 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
1934 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
1936 if(++i == adapter->tx_ring.count) i = 0;
1937 adapter->tx_ring.next_to_use = i;
1946 static inline boolean_t
1947 e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1949 struct e1000_context_desc *context_desc;
1953 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1954 css = skb->h.raw - skb->data;
1956 i = adapter->tx_ring.next_to_use;
1957 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1959 context_desc->upper_setup.tcp_fields.tucss = css;
1960 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
1961 context_desc->upper_setup.tcp_fields.tucse = 0;
1962 context_desc->tcp_seg_setup.data = 0;
1963 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
1965 if(unlikely(++i == adapter->tx_ring.count)) i = 0;
1966 adapter->tx_ring.next_to_use = i;
1974 #define E1000_MAX_TXD_PWR 12
1975 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
1978 e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb,
1979 unsigned int first, unsigned int max_per_txd,
1980 unsigned int nr_frags, unsigned int mss)
1982 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1983 struct e1000_buffer *buffer_info;
1984 unsigned int len = skb->len;
1985 unsigned int offset = 0, size, count = 0, i;
1987 len -= skb->data_len;
1989 i = tx_ring->next_to_use;
1992 buffer_info = &tx_ring->buffer_info[i];
1993 size = min(len, max_per_txd);
1995 /* Workaround for premature desc write-backs
1996 * in TSO mode. Append 4-byte sentinel desc */
1997 if(unlikely(mss && !nr_frags && size == len && size > 8))
2000 /* work-around for errata 10 and it applies
2001 * to all controllers in PCI-X mode
2002 * The fix is to make sure that the first descriptor of a
2003 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2005 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2006 (size > 2015) && count == 0))
2009 /* Workaround for potential 82544 hang in PCI-X. Avoid
2010 * terminating buffers within evenly-aligned dwords. */
2011 if(unlikely(adapter->pcix_82544 &&
2012 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2016 buffer_info->length = size;
2018 pci_map_single(adapter->pdev,
2022 buffer_info->time_stamp = jiffies;
2027 if(unlikely(++i == tx_ring->count)) i = 0;
2030 for(f = 0; f < nr_frags; f++) {
2031 struct skb_frag_struct *frag;
2033 frag = &skb_shinfo(skb)->frags[f];
2035 offset = frag->page_offset;
2038 buffer_info = &tx_ring->buffer_info[i];
2039 size = min(len, max_per_txd);
2041 /* Workaround for premature desc write-backs
2042 * in TSO mode. Append 4-byte sentinel desc */
2043 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2046 /* Workaround for potential 82544 hang in PCI-X.
2047 * Avoid terminating buffers within evenly-aligned
2049 if(unlikely(adapter->pcix_82544 &&
2050 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2054 buffer_info->length = size;
2056 pci_map_page(adapter->pdev,
2061 buffer_info->time_stamp = jiffies;
2066 if(unlikely(++i == tx_ring->count)) i = 0;
2070 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2071 tx_ring->buffer_info[i].skb = skb;
2072 tx_ring->buffer_info[first].next_to_watch = i;
2078 e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
2080 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2081 struct e1000_tx_desc *tx_desc = NULL;
2082 struct e1000_buffer *buffer_info;
2083 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2086 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2087 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2089 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2091 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2092 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2095 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2096 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2097 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2100 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2101 txd_lower |= E1000_TXD_CMD_VLE;
2102 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2105 i = tx_ring->next_to_use;
2108 buffer_info = &tx_ring->buffer_info[i];
2109 tx_desc = E1000_TX_DESC(*tx_ring, i);
2110 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2111 tx_desc->lower.data =
2112 cpu_to_le32(txd_lower | buffer_info->length);
2113 tx_desc->upper.data = cpu_to_le32(txd_upper);
2114 if(unlikely(++i == tx_ring->count)) i = 0;
2117 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2119 /* Force memory writes to complete before letting h/w
2120 * know there are new descriptors to fetch. (Only
2121 * applicable for weak-ordered memory model archs,
2122 * such as IA-64). */
2125 tx_ring->next_to_use = i;
2126 E1000_WRITE_REG(&adapter->hw, TDT, i);
2130 * 82547 workaround to avoid controller hang in half-duplex environment.
2131 * The workaround is to avoid queuing a large packet that would span
2132 * the internal Tx FIFO ring boundary by notifying the stack to resend
2133 * the packet at a later time. This gives the Tx FIFO an opportunity to
2134 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2135 * to the beginning of the Tx FIFO.
2138 #define E1000_FIFO_HDR 0x10
2139 #define E1000_82547_PAD_LEN 0x3E0
2142 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2144 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2145 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2147 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2149 if(adapter->link_duplex != HALF_DUPLEX)
2150 goto no_fifo_stall_required;
2152 if(atomic_read(&adapter->tx_fifo_stall))
2155 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2156 atomic_set(&adapter->tx_fifo_stall, 1);
2160 no_fifo_stall_required:
2161 adapter->tx_fifo_head += skb_fifo_len;
2162 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2163 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2167 #define MINIMUM_DHCP_PACKET_SIZE 282
2169 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2171 struct e1000_hw *hw = &adapter->hw;
2172 uint16_t length, offset;
2173 if(vlan_tx_tag_present(skb)) {
2174 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2175 ( adapter->hw.mng_cookie.status &
2176 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2179 if(htons(ETH_P_IP) == skb->protocol) {
2180 const struct iphdr *ip = skb->nh.iph;
2181 if(IPPROTO_UDP == ip->protocol) {
2182 struct udphdr *udp = (struct udphdr *)(skb->h.uh);
2183 if(ntohs(udp->dest) == 67) {
2184 offset = (uint8_t *)udp + 8 - skb->data;
2185 length = skb->len - offset;
2187 return e1000_mng_write_dhcp_info(hw,
2188 (uint8_t *)udp + 8, length);
2191 } else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2192 struct ethhdr *eth = (struct ethhdr *) skb->data;
2193 if((htons(ETH_P_IP) == eth->h_proto)) {
2194 const struct iphdr *ip =
2195 (struct iphdr *)((uint8_t *)skb->data+14);
2196 if(IPPROTO_UDP == ip->protocol) {
2197 struct udphdr *udp =
2198 (struct udphdr *)((uint8_t *)ip +
2200 if(ntohs(udp->dest) == 67) {
2201 offset = (uint8_t *)udp + 8 - skb->data;
2202 length = skb->len - offset;
2204 return e1000_mng_write_dhcp_info(hw,
2214 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2216 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2218 struct e1000_adapter *adapter = netdev_priv(netdev);
2219 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2220 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2221 unsigned int tx_flags = 0;
2222 unsigned int len = skb->len;
2223 unsigned long flags;
2224 unsigned int nr_frags = 0;
2225 unsigned int mss = 0;
2229 len -= skb->data_len;
2231 if(unlikely(skb->len <= 0)) {
2232 dev_kfree_skb_any(skb);
2233 return NETDEV_TX_OK;
2237 mss = skb_shinfo(skb)->tso_size;
2238 /* The controller does a simple calculation to
2239 * make sure there is enough room in the FIFO before
2240 * initiating the DMA for each buffer. The calc is:
2241 * 4 = ceil(buffer len/mss). To make sure we don't
2242 * overrun the FIFO, adjust the max buffer len if mss
2245 max_per_txd = min(mss << 2, max_per_txd);
2246 max_txd_pwr = fls(max_per_txd) - 1;
2249 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2253 if(skb->ip_summed == CHECKSUM_HW)
2256 count += TXD_USE_COUNT(len, max_txd_pwr);
2258 if(adapter->pcix_82544)
2261 /* work-around for errata 10 and it applies to all controllers
2262 * in PCI-X mode, so add one more descriptor to the count
2264 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2268 nr_frags = skb_shinfo(skb)->nr_frags;
2269 for(f = 0; f < nr_frags; f++)
2270 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2272 if(adapter->pcix_82544)
2275 local_irq_save(flags);
2276 if (!spin_trylock(&adapter->tx_lock)) {
2277 /* Collision - tell upper layer to requeue */
2278 local_irq_restore(flags);
2279 return NETDEV_TX_LOCKED;
2281 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2282 e1000_transfer_dhcp_info(adapter, skb);
2285 /* need: count + 2 desc gap to keep tail from touching
2286 * head, otherwise try next time */
2287 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < count + 2)) {
2288 netif_stop_queue(netdev);
2289 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2290 return NETDEV_TX_BUSY;
2293 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2294 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2295 netif_stop_queue(netdev);
2296 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2297 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2298 return NETDEV_TX_BUSY;
2302 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2303 tx_flags |= E1000_TX_FLAGS_VLAN;
2304 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2307 first = adapter->tx_ring.next_to_use;
2309 tso = e1000_tso(adapter, skb);
2311 dev_kfree_skb_any(skb);
2312 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2313 return NETDEV_TX_OK;
2317 tx_flags |= E1000_TX_FLAGS_TSO;
2318 else if(likely(e1000_tx_csum(adapter, skb)))
2319 tx_flags |= E1000_TX_FLAGS_CSUM;
2321 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2322 * 82573 hardware supports TSO capabilities for IPv6 as well...
2323 * no longer assume, we must. */
2324 if(likely(skb->protocol == ntohs(ETH_P_IP)))
2325 tx_flags |= E1000_TX_FLAGS_IPV4;
2327 e1000_tx_queue(adapter,
2328 e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss),
2331 netdev->trans_start = jiffies;
2333 /* Make sure there is space in the ring for the next send. */
2334 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2))
2335 netif_stop_queue(netdev);
2337 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2338 return NETDEV_TX_OK;
2342 * e1000_tx_timeout - Respond to a Tx Hang
2343 * @netdev: network interface device structure
2347 e1000_tx_timeout(struct net_device *netdev)
2349 struct e1000_adapter *adapter = netdev_priv(netdev);
2351 /* Do the reset outside of interrupt context */
2352 schedule_work(&adapter->tx_timeout_task);
2356 e1000_tx_timeout_task(struct net_device *netdev)
2358 struct e1000_adapter *adapter = netdev_priv(netdev);
2360 e1000_down(adapter);
2365 * e1000_get_stats - Get System Network Statistics
2366 * @netdev: network interface device structure
2368 * Returns the address of the device statistics structure.
2369 * The statistics are actually updated from the timer callback.
2372 static struct net_device_stats *
2373 e1000_get_stats(struct net_device *netdev)
2375 struct e1000_adapter *adapter = netdev_priv(netdev);
2377 e1000_update_stats(adapter);
2378 return &adapter->net_stats;
2382 * e1000_change_mtu - Change the Maximum Transfer Unit
2383 * @netdev: network interface device structure
2384 * @new_mtu: new value for maximum frame size
2386 * Returns 0 on success, negative on failure
2390 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2392 struct e1000_adapter *adapter = netdev_priv(netdev);
2393 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2395 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2396 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2397 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2401 #define MAX_STD_JUMBO_FRAME_SIZE 9216
2402 /* might want this to be bigger enum check... */
2403 if (adapter->hw.mac_type == e1000_82573 &&
2404 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2405 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2410 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2411 adapter->rx_buffer_len = max_frame;
2412 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2414 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2415 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2416 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2421 if(max_frame <= E1000_RXBUFFER_2048) {
2422 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2423 } else if(max_frame <= E1000_RXBUFFER_4096) {
2424 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2425 } else if(max_frame <= E1000_RXBUFFER_8192) {
2426 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2427 } else if(max_frame <= E1000_RXBUFFER_16384) {
2428 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2433 netdev->mtu = new_mtu;
2435 if(netif_running(netdev)) {
2436 e1000_down(adapter);
2440 adapter->hw.max_frame_size = max_frame;
2446 * e1000_update_stats - Update the board statistics counters
2447 * @adapter: board private structure
2451 e1000_update_stats(struct e1000_adapter *adapter)
2453 struct e1000_hw *hw = &adapter->hw;
2454 unsigned long flags;
2457 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2459 spin_lock_irqsave(&adapter->stats_lock, flags);
2461 /* these counters are modified from e1000_adjust_tbi_stats,
2462 * called from the interrupt context, so they must only
2463 * be written while holding adapter->stats_lock
2466 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2467 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2468 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2469 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2470 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2471 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2472 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2473 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2474 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2475 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2476 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2477 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2478 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2480 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2481 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2482 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2483 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2484 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2485 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2486 adapter->stats.dc += E1000_READ_REG(hw, DC);
2487 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2488 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2489 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2490 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2491 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2492 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2493 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2494 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2495 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2496 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2497 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2498 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2499 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2500 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2501 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2502 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2503 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2504 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2505 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2506 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2507 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2508 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2509 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2510 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2511 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2512 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2513 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2515 /* used for adaptive IFS */
2517 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2518 adapter->stats.tpt += hw->tx_packet_delta;
2519 hw->collision_delta = E1000_READ_REG(hw, COLC);
2520 adapter->stats.colc += hw->collision_delta;
2522 if(hw->mac_type >= e1000_82543) {
2523 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2524 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
2525 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
2526 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
2527 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
2528 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
2530 if(hw->mac_type > e1000_82547_rev_2) {
2531 adapter->stats.iac += E1000_READ_REG(hw, IAC);
2532 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
2533 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
2534 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
2535 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
2536 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
2537 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
2538 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
2539 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
2542 /* Fill out the OS statistics structure */
2544 adapter->net_stats.rx_packets = adapter->stats.gprc;
2545 adapter->net_stats.tx_packets = adapter->stats.gptc;
2546 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2547 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2548 adapter->net_stats.multicast = adapter->stats.mprc;
2549 adapter->net_stats.collisions = adapter->stats.colc;
2553 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2554 adapter->stats.crcerrs + adapter->stats.algnerrc +
2555 adapter->stats.rlec + adapter->stats.mpc +
2556 adapter->stats.cexterr;
2557 adapter->net_stats.rx_dropped = adapter->stats.mpc;
2558 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2559 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2560 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2561 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
2562 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2566 adapter->net_stats.tx_errors = adapter->stats.ecol +
2567 adapter->stats.latecol;
2568 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2569 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2570 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2572 /* Tx Dropped needs to be maintained elsewhere */
2576 if(hw->media_type == e1000_media_type_copper) {
2577 if((adapter->link_speed == SPEED_1000) &&
2578 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
2579 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2580 adapter->phy_stats.idle_errors += phy_tmp;
2583 if((hw->mac_type <= e1000_82546) &&
2584 (hw->phy_type == e1000_phy_m88) &&
2585 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
2586 adapter->phy_stats.receive_errors += phy_tmp;
2589 spin_unlock_irqrestore(&adapter->stats_lock, flags);
2593 * e1000_intr - Interrupt Handler
2594 * @irq: interrupt number
2595 * @data: pointer to a network interface device structure
2596 * @pt_regs: CPU registers structure
2600 e1000_intr(int irq, void *data, struct pt_regs *regs)
2602 struct net_device *netdev = data;
2603 struct e1000_adapter *adapter = netdev_priv(netdev);
2604 struct e1000_hw *hw = &adapter->hw;
2605 uint32_t icr = E1000_READ_REG(hw, ICR);
2606 #ifndef CONFIG_E1000_NAPI
2611 return IRQ_NONE; /* Not our interrupt */
2613 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
2614 hw->get_link_status = 1;
2615 mod_timer(&adapter->watchdog_timer, jiffies);
2618 #ifdef CONFIG_E1000_NAPI
2619 if(likely(netif_rx_schedule_prep(netdev))) {
2621 /* Disable interrupts and register for poll. The flush
2622 of the posted write is intentionally left out.
2625 atomic_inc(&adapter->irq_sem);
2626 E1000_WRITE_REG(hw, IMC, ~0);
2627 __netif_rx_schedule(netdev);
2630 /* Writing IMC and IMS is needed for 82547.
2631 Due to Hub Link bus being occupied, an interrupt
2632 de-assertion message is not able to be sent.
2633 When an interrupt assertion message is generated later,
2634 two messages are re-ordered and sent out.
2635 That causes APIC to think 82547 is in de-assertion
2636 state, while 82547 is in assertion state, resulting
2637 in dead lock. Writing IMC forces 82547 into
2640 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
2641 atomic_inc(&adapter->irq_sem);
2642 E1000_WRITE_REG(hw, IMC, ~0);
2645 for(i = 0; i < E1000_MAX_INTR; i++)
2646 if(unlikely(!adapter->clean_rx(adapter) &
2647 !e1000_clean_tx_irq(adapter)))
2650 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
2651 e1000_irq_enable(adapter);
2657 #ifdef CONFIG_E1000_NAPI
2659 * e1000_clean - NAPI Rx polling callback
2660 * @adapter: board private structure
2664 e1000_clean(struct net_device *netdev, int *budget)
2666 struct e1000_adapter *adapter = netdev_priv(netdev);
2667 int work_to_do = min(*budget, netdev->quota);
2671 tx_cleaned = e1000_clean_tx_irq(adapter);
2672 adapter->clean_rx(adapter, &work_done, work_to_do);
2674 *budget -= work_done;
2675 netdev->quota -= work_done;
2677 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2678 /* If no Tx and not enough Rx work done, exit the polling mode */
2679 netif_rx_complete(netdev);
2680 e1000_irq_enable(adapter);
2689 * e1000_clean_tx_irq - Reclaim resources after transmit completes
2690 * @adapter: board private structure
2694 e1000_clean_tx_irq(struct e1000_adapter *adapter)
2696 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2697 struct net_device *netdev = adapter->netdev;
2698 struct e1000_tx_desc *tx_desc, *eop_desc;
2699 struct e1000_buffer *buffer_info;
2700 unsigned int i, eop;
2701 boolean_t cleaned = FALSE;
2703 i = tx_ring->next_to_clean;
2704 eop = tx_ring->buffer_info[i].next_to_watch;
2705 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2707 while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
2708 /* Premature writeback of Tx descriptors clear (free buffers
2709 * and unmap pci_mapping) previous_buffer_info */
2710 if (likely(adapter->previous_buffer_info.skb != NULL)) {
2711 e1000_unmap_and_free_tx_resource(adapter,
2712 &adapter->previous_buffer_info);
2715 for(cleaned = FALSE; !cleaned; ) {
2716 tx_desc = E1000_TX_DESC(*tx_ring, i);
2717 buffer_info = &tx_ring->buffer_info[i];
2718 cleaned = (i == eop);
2721 if (!(netdev->features & NETIF_F_TSO)) {
2723 e1000_unmap_and_free_tx_resource(adapter,
2728 memcpy(&adapter->previous_buffer_info,
2730 sizeof(struct e1000_buffer));
2731 memset(buffer_info, 0,
2732 sizeof(struct e1000_buffer));
2734 e1000_unmap_and_free_tx_resource(
2735 adapter, buffer_info);
2740 tx_desc->buffer_addr = 0;
2741 tx_desc->lower.data = 0;
2742 tx_desc->upper.data = 0;
2744 if(unlikely(++i == tx_ring->count)) i = 0;
2747 eop = tx_ring->buffer_info[i].next_to_watch;
2748 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2751 tx_ring->next_to_clean = i;
2753 spin_lock(&adapter->tx_lock);
2755 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
2756 netif_carrier_ok(netdev)))
2757 netif_wake_queue(netdev);
2759 spin_unlock(&adapter->tx_lock);
2760 if(adapter->detect_tx_hung) {
2762 /* Detect a transmit hang in hardware, this serializes the
2763 * check with the clearing of time_stamp and movement of i */
2764 adapter->detect_tx_hung = FALSE;
2765 if (tx_ring->buffer_info[i].dma &&
2766 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
2767 && !(E1000_READ_REG(&adapter->hw, STATUS) &
2768 E1000_STATUS_TXOFF)) {
2770 /* detected Tx unit hang */
2771 i = tx_ring->next_to_clean;
2772 eop = tx_ring->buffer_info[i].next_to_watch;
2773 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2774 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
2777 " next_to_use <%x>\n"
2778 " next_to_clean <%x>\n"
2779 "buffer_info[next_to_clean]\n"
2781 " time_stamp <%lx>\n"
2782 " next_to_watch <%x>\n"
2784 " next_to_watch.status <%x>\n",
2785 E1000_READ_REG(&adapter->hw, TDH),
2786 E1000_READ_REG(&adapter->hw, TDT),
2787 tx_ring->next_to_use,
2789 tx_ring->buffer_info[i].dma,
2790 tx_ring->buffer_info[i].time_stamp,
2793 eop_desc->upper.fields.status);
2794 netif_stop_queue(netdev);
2799 if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
2800 time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
2801 e1000_unmap_and_free_tx_resource(
2802 adapter, &adapter->previous_buffer_info);
2809 * e1000_rx_checksum - Receive Checksum Offload for 82543
2810 * @adapter: board private structure
2811 * @status_err: receive descriptor status and error fields
2812 * @csum: receive descriptor csum field
2813 * @sk_buff: socket buffer with received data
2817 e1000_rx_checksum(struct e1000_adapter *adapter,
2818 uint32_t status_err, uint32_t csum,
2819 struct sk_buff *skb)
2821 uint16_t status = (uint16_t)status_err;
2822 uint8_t errors = (uint8_t)(status_err >> 24);
2823 skb->ip_summed = CHECKSUM_NONE;
2825 /* 82543 or newer only */
2826 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
2827 /* Ignore Checksum bit is set */
2828 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
2829 /* TCP/UDP checksum error bit is set */
2830 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
2831 /* let the stack verify checksum errors */
2832 adapter->hw_csum_err++;
2835 /* TCP/UDP Checksum has not been calculated */
2836 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
2837 if(!(status & E1000_RXD_STAT_TCPCS))
2840 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
2843 /* It must be a TCP or UDP packet with a valid checksum */
2844 if (likely(status & E1000_RXD_STAT_TCPCS)) {
2845 /* TCP checksum is good */
2846 skb->ip_summed = CHECKSUM_UNNECESSARY;
2847 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
2848 /* IP fragment with UDP payload */
2849 /* Hardware complements the payload checksum, so we undo it
2850 * and then put the value in host order for further stack use.
2852 csum = ntohl(csum ^ 0xFFFF);
2854 skb->ip_summed = CHECKSUM_HW;
2856 adapter->hw_csum_good++;
2860 * e1000_clean_rx_irq - Send received data up the network stack; legacy
2861 * @adapter: board private structure
2865 #ifdef CONFIG_E1000_NAPI
2866 e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done,
2869 e1000_clean_rx_irq(struct e1000_adapter *adapter)
2872 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2873 struct net_device *netdev = adapter->netdev;
2874 struct pci_dev *pdev = adapter->pdev;
2875 struct e1000_rx_desc *rx_desc;
2876 struct e1000_buffer *buffer_info;
2877 struct sk_buff *skb;
2878 unsigned long flags;
2882 boolean_t cleaned = FALSE;
2884 i = rx_ring->next_to_clean;
2885 rx_desc = E1000_RX_DESC(*rx_ring, i);
2887 while(rx_desc->status & E1000_RXD_STAT_DD) {
2888 buffer_info = &rx_ring->buffer_info[i];
2889 #ifdef CONFIG_E1000_NAPI
2890 if(*work_done >= work_to_do)
2896 pci_unmap_single(pdev,
2898 buffer_info->length,
2899 PCI_DMA_FROMDEVICE);
2901 skb = buffer_info->skb;
2902 length = le16_to_cpu(rx_desc->length);
2904 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
2905 /* All receives must fit into a single buffer */
2906 E1000_DBG("%s: Receive packet consumed multiple"
2907 " buffers\n", netdev->name);
2908 dev_kfree_skb_irq(skb);
2912 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
2913 last_byte = *(skb->data + length - 1);
2914 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
2915 rx_desc->errors, length, last_byte)) {
2916 spin_lock_irqsave(&adapter->stats_lock, flags);
2917 e1000_tbi_adjust_stats(&adapter->hw,
2920 spin_unlock_irqrestore(&adapter->stats_lock,
2924 dev_kfree_skb_irq(skb);
2930 skb_put(skb, length - ETHERNET_FCS_SIZE);
2932 /* Receive Checksum Offload */
2933 e1000_rx_checksum(adapter,
2934 (uint32_t)(rx_desc->status) |
2935 ((uint32_t)(rx_desc->errors) << 24),
2936 rx_desc->csum, skb);
2937 skb->protocol = eth_type_trans(skb, netdev);
2938 #ifdef CONFIG_E1000_NAPI
2939 if(unlikely(adapter->vlgrp &&
2940 (rx_desc->status & E1000_RXD_STAT_VP))) {
2941 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
2942 le16_to_cpu(rx_desc->special) &
2943 E1000_RXD_SPC_VLAN_MASK);
2945 netif_receive_skb(skb);
2947 #else /* CONFIG_E1000_NAPI */
2948 if(unlikely(adapter->vlgrp &&
2949 (rx_desc->status & E1000_RXD_STAT_VP))) {
2950 vlan_hwaccel_rx(skb, adapter->vlgrp,
2951 le16_to_cpu(rx_desc->special) &
2952 E1000_RXD_SPC_VLAN_MASK);
2956 #endif /* CONFIG_E1000_NAPI */
2957 netdev->last_rx = jiffies;
2960 rx_desc->status = 0;
2961 buffer_info->skb = NULL;
2962 if(unlikely(++i == rx_ring->count)) i = 0;
2964 rx_desc = E1000_RX_DESC(*rx_ring, i);
2966 rx_ring->next_to_clean = i;
2967 adapter->alloc_rx_buf(adapter);
2973 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
2974 * @adapter: board private structure
2978 #ifdef CONFIG_E1000_NAPI
2979 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done,
2982 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
2985 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2986 union e1000_rx_desc_packet_split *rx_desc;
2987 struct net_device *netdev = adapter->netdev;
2988 struct pci_dev *pdev = adapter->pdev;
2989 struct e1000_buffer *buffer_info;
2990 struct e1000_ps_page *ps_page;
2991 struct e1000_ps_page_dma *ps_page_dma;
2992 struct sk_buff *skb;
2994 uint32_t length, staterr;
2995 boolean_t cleaned = FALSE;
2997 i = rx_ring->next_to_clean;
2998 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
2999 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3001 while(staterr & E1000_RXD_STAT_DD) {
3002 buffer_info = &rx_ring->buffer_info[i];
3003 ps_page = &rx_ring->ps_page[i];
3004 ps_page_dma = &rx_ring->ps_page_dma[i];
3005 #ifdef CONFIG_E1000_NAPI
3006 if(unlikely(*work_done >= work_to_do))
3011 pci_unmap_single(pdev, buffer_info->dma,
3012 buffer_info->length,
3013 PCI_DMA_FROMDEVICE);
3015 skb = buffer_info->skb;
3017 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3018 E1000_DBG("%s: Packet Split buffers didn't pick up"
3019 " the full packet\n", netdev->name);
3020 dev_kfree_skb_irq(skb);
3024 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3025 dev_kfree_skb_irq(skb);
3029 length = le16_to_cpu(rx_desc->wb.middle.length0);
3031 if(unlikely(!length)) {
3032 E1000_DBG("%s: Last part of the packet spanning"
3033 " multiple descriptors\n", netdev->name);
3034 dev_kfree_skb_irq(skb);
3039 skb_put(skb, length);
3041 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3042 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3045 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3046 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3047 ps_page_dma->ps_page_dma[j] = 0;
3048 skb_shinfo(skb)->frags[j].page =
3049 ps_page->ps_page[j];
3050 ps_page->ps_page[j] = NULL;
3051 skb_shinfo(skb)->frags[j].page_offset = 0;
3052 skb_shinfo(skb)->frags[j].size = length;
3053 skb_shinfo(skb)->nr_frags++;
3055 skb->data_len += length;
3058 e1000_rx_checksum(adapter, staterr,
3059 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3060 skb->protocol = eth_type_trans(skb, netdev);
3062 #ifdef HAVE_RX_ZERO_COPY
3063 if(likely(rx_desc->wb.upper.header_status &
3064 E1000_RXDPS_HDRSTAT_HDRSP))
3065 skb_shinfo(skb)->zero_copy = TRUE;
3067 #ifdef CONFIG_E1000_NAPI
3068 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3069 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3070 le16_to_cpu(rx_desc->wb.middle.vlan) &
3071 E1000_RXD_SPC_VLAN_MASK);
3073 netif_receive_skb(skb);
3075 #else /* CONFIG_E1000_NAPI */
3076 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3077 vlan_hwaccel_rx(skb, adapter->vlgrp,
3078 le16_to_cpu(rx_desc->wb.middle.vlan) &
3079 E1000_RXD_SPC_VLAN_MASK);
3083 #endif /* CONFIG_E1000_NAPI */
3084 netdev->last_rx = jiffies;
3087 rx_desc->wb.middle.status_error &= ~0xFF;
3088 buffer_info->skb = NULL;
3089 if(unlikely(++i == rx_ring->count)) i = 0;
3091 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3092 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3094 rx_ring->next_to_clean = i;
3095 adapter->alloc_rx_buf(adapter);
3101 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3102 * @adapter: address of board private structure
3106 e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3108 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3109 struct net_device *netdev = adapter->netdev;
3110 struct pci_dev *pdev = adapter->pdev;
3111 struct e1000_rx_desc *rx_desc;
3112 struct e1000_buffer *buffer_info;
3113 struct sk_buff *skb;
3115 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3117 i = rx_ring->next_to_use;
3118 buffer_info = &rx_ring->buffer_info[i];
3120 while(!buffer_info->skb) {
3121 skb = dev_alloc_skb(bufsz);
3123 if(unlikely(!skb)) {
3124 /* Better luck next round */
3128 /* Fix for errata 23, can't cross 64kB boundary */
3129 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3130 struct sk_buff *oldskb = skb;
3131 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3132 "at %p\n", bufsz, skb->data);
3133 /* Try again, without freeing the previous */
3134 skb = dev_alloc_skb(bufsz);
3135 /* Failed allocation, critical failure */
3137 dev_kfree_skb(oldskb);
3141 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3144 dev_kfree_skb(oldskb);
3145 break; /* while !buffer_info->skb */
3147 /* Use new allocation */
3148 dev_kfree_skb(oldskb);
3151 /* Make buffer alignment 2 beyond a 16 byte boundary
3152 * this will result in a 16 byte aligned IP header after
3153 * the 14 byte MAC header is removed
3155 skb_reserve(skb, NET_IP_ALIGN);
3159 buffer_info->skb = skb;
3160 buffer_info->length = adapter->rx_buffer_len;
3161 buffer_info->dma = pci_map_single(pdev,
3163 adapter->rx_buffer_len,
3164 PCI_DMA_FROMDEVICE);
3166 /* Fix for errata 23, can't cross 64kB boundary */
3167 if (!e1000_check_64k_bound(adapter,
3168 (void *)(unsigned long)buffer_info->dma,
3169 adapter->rx_buffer_len)) {
3170 DPRINTK(RX_ERR, ERR,
3171 "dma align check failed: %u bytes at %p\n",
3172 adapter->rx_buffer_len,
3173 (void *)(unsigned long)buffer_info->dma);
3175 buffer_info->skb = NULL;
3177 pci_unmap_single(pdev, buffer_info->dma,
3178 adapter->rx_buffer_len,
3179 PCI_DMA_FROMDEVICE);
3181 break; /* while !buffer_info->skb */
3183 rx_desc = E1000_RX_DESC(*rx_ring, i);
3184 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3186 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3187 /* Force memory writes to complete before letting h/w
3188 * know there are new descriptors to fetch. (Only
3189 * applicable for weak-ordered memory model archs,
3190 * such as IA-64). */
3192 E1000_WRITE_REG(&adapter->hw, RDT, i);
3195 if(unlikely(++i == rx_ring->count)) i = 0;
3196 buffer_info = &rx_ring->buffer_info[i];
3199 rx_ring->next_to_use = i;
3203 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3204 * @adapter: address of board private structure
3208 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3210 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3211 struct net_device *netdev = adapter->netdev;
3212 struct pci_dev *pdev = adapter->pdev;
3213 union e1000_rx_desc_packet_split *rx_desc;
3214 struct e1000_buffer *buffer_info;
3215 struct e1000_ps_page *ps_page;
3216 struct e1000_ps_page_dma *ps_page_dma;
3217 struct sk_buff *skb;
3220 i = rx_ring->next_to_use;
3221 buffer_info = &rx_ring->buffer_info[i];
3222 ps_page = &rx_ring->ps_page[i];
3223 ps_page_dma = &rx_ring->ps_page_dma[i];
3225 while(!buffer_info->skb) {
3226 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3228 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3229 if(unlikely(!ps_page->ps_page[j])) {
3230 ps_page->ps_page[j] =
3231 alloc_page(GFP_ATOMIC);
3232 if(unlikely(!ps_page->ps_page[j]))
3234 ps_page_dma->ps_page_dma[j] =
3236 ps_page->ps_page[j],
3238 PCI_DMA_FROMDEVICE);
3240 /* Refresh the desc even if buffer_addrs didn't
3241 * change because each write-back erases this info.
3243 rx_desc->read.buffer_addr[j+1] =
3244 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3247 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3252 /* Make buffer alignment 2 beyond a 16 byte boundary
3253 * this will result in a 16 byte aligned IP header after
3254 * the 14 byte MAC header is removed
3256 skb_reserve(skb, NET_IP_ALIGN);
3260 buffer_info->skb = skb;
3261 buffer_info->length = adapter->rx_ps_bsize0;
3262 buffer_info->dma = pci_map_single(pdev, skb->data,
3263 adapter->rx_ps_bsize0,
3264 PCI_DMA_FROMDEVICE);
3266 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3268 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3269 /* Force memory writes to complete before letting h/w
3270 * know there are new descriptors to fetch. (Only
3271 * applicable for weak-ordered memory model archs,
3272 * such as IA-64). */
3274 /* Hardware increments by 16 bytes, but packet split
3275 * descriptors are 32 bytes...so we increment tail
3278 E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
3281 if(unlikely(++i == rx_ring->count)) i = 0;
3282 buffer_info = &rx_ring->buffer_info[i];
3283 ps_page = &rx_ring->ps_page[i];
3284 ps_page_dma = &rx_ring->ps_page_dma[i];
3288 rx_ring->next_to_use = i;
3292 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3297 e1000_smartspeed(struct e1000_adapter *adapter)
3299 uint16_t phy_status;
3302 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3303 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3306 if(adapter->smartspeed == 0) {
3307 /* If Master/Slave config fault is asserted twice,
3308 * we assume back-to-back */
3309 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3310 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3311 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3312 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3313 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3314 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3315 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3316 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3318 adapter->smartspeed++;
3319 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3320 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3322 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3323 MII_CR_RESTART_AUTO_NEG);
3324 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3329 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3330 /* If still no link, perhaps using 2/3 pair cable */
3331 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3332 phy_ctrl |= CR_1000T_MS_ENABLE;
3333 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3334 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3335 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3336 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3337 MII_CR_RESTART_AUTO_NEG);
3338 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3341 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3342 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3343 adapter->smartspeed = 0;
3354 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3360 return e1000_mii_ioctl(netdev, ifr, cmd);
3374 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3376 struct e1000_adapter *adapter = netdev_priv(netdev);
3377 struct mii_ioctl_data *data = if_mii(ifr);
3381 unsigned long flags;
3383 if(adapter->hw.media_type != e1000_media_type_copper)
3388 data->phy_id = adapter->hw.phy_addr;
3391 if(!capable(CAP_NET_ADMIN))
3393 spin_lock_irqsave(&adapter->stats_lock, flags);
3394 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3396 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3399 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3402 if(!capable(CAP_NET_ADMIN))
3404 if(data->reg_num & ~(0x1F))
3406 mii_reg = data->val_in;
3407 spin_lock_irqsave(&adapter->stats_lock, flags);
3408 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3410 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3413 if(adapter->hw.phy_type == e1000_phy_m88) {
3414 switch (data->reg_num) {
3416 if(mii_reg & MII_CR_POWER_DOWN)
3418 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3419 adapter->hw.autoneg = 1;
3420 adapter->hw.autoneg_advertised = 0x2F;
3423 spddplx = SPEED_1000;
3424 else if (mii_reg & 0x2000)
3425 spddplx = SPEED_100;
3428 spddplx += (mii_reg & 0x100)
3431 retval = e1000_set_spd_dplx(adapter,
3434 spin_unlock_irqrestore(
3435 &adapter->stats_lock,
3440 if(netif_running(adapter->netdev)) {
3441 e1000_down(adapter);
3444 e1000_reset(adapter);
3446 case M88E1000_PHY_SPEC_CTRL:
3447 case M88E1000_EXT_PHY_SPEC_CTRL:
3448 if(e1000_phy_reset(&adapter->hw)) {
3449 spin_unlock_irqrestore(
3450 &adapter->stats_lock, flags);
3456 switch (data->reg_num) {
3458 if(mii_reg & MII_CR_POWER_DOWN)
3460 if(netif_running(adapter->netdev)) {
3461 e1000_down(adapter);
3464 e1000_reset(adapter);
3468 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3473 return E1000_SUCCESS;
3477 e1000_pci_set_mwi(struct e1000_hw *hw)
3479 struct e1000_adapter *adapter = hw->back;
3480 int ret_val = pci_set_mwi(adapter->pdev);
3483 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
3487 e1000_pci_clear_mwi(struct e1000_hw *hw)
3489 struct e1000_adapter *adapter = hw->back;
3491 pci_clear_mwi(adapter->pdev);
3495 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3497 struct e1000_adapter *adapter = hw->back;
3499 pci_read_config_word(adapter->pdev, reg, value);
3503 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3505 struct e1000_adapter *adapter = hw->back;
3507 pci_write_config_word(adapter->pdev, reg, *value);
3511 e1000_io_read(struct e1000_hw *hw, unsigned long port)
3517 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3523 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3525 struct e1000_adapter *adapter = netdev_priv(netdev);
3526 uint32_t ctrl, rctl;
3528 e1000_irq_disable(adapter);
3529 adapter->vlgrp = grp;
3532 /* enable VLAN tag insert/strip */
3533 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3534 ctrl |= E1000_CTRL_VME;
3535 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3537 /* enable VLAN receive filtering */
3538 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3539 rctl |= E1000_RCTL_VFE;
3540 rctl &= ~E1000_RCTL_CFIEN;
3541 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3542 e1000_update_mng_vlan(adapter);
3544 /* disable VLAN tag insert/strip */
3545 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3546 ctrl &= ~E1000_CTRL_VME;
3547 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3549 /* disable VLAN filtering */
3550 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3551 rctl &= ~E1000_RCTL_VFE;
3552 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3553 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
3554 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3555 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3559 e1000_irq_enable(adapter);
3563 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3565 struct e1000_adapter *adapter = netdev_priv(netdev);
3566 uint32_t vfta, index;
3567 if((adapter->hw.mng_cookie.status &
3568 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3569 (vid == adapter->mng_vlan_id))
3571 /* add VID to filter table */
3572 index = (vid >> 5) & 0x7F;
3573 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3574 vfta |= (1 << (vid & 0x1F));
3575 e1000_write_vfta(&adapter->hw, index, vfta);
3579 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3581 struct e1000_adapter *adapter = netdev_priv(netdev);
3582 uint32_t vfta, index;
3584 e1000_irq_disable(adapter);
3587 adapter->vlgrp->vlan_devices[vid] = NULL;
3589 e1000_irq_enable(adapter);
3591 if((adapter->hw.mng_cookie.status &
3592 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3593 (vid == adapter->mng_vlan_id))
3595 /* remove VID from filter table */
3596 index = (vid >> 5) & 0x7F;
3597 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3598 vfta &= ~(1 << (vid & 0x1F));
3599 e1000_write_vfta(&adapter->hw, index, vfta);
3603 e1000_restore_vlan(struct e1000_adapter *adapter)
3605 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
3607 if(adapter->vlgrp) {
3609 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
3610 if(!adapter->vlgrp->vlan_devices[vid])
3612 e1000_vlan_rx_add_vid(adapter->netdev, vid);
3618 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3620 adapter->hw.autoneg = 0;
3622 /* Fiber NICs only allow 1000 gbps Full duplex */
3623 if((adapter->hw.media_type == e1000_media_type_fiber) &&
3624 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
3625 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3630 case SPEED_10 + DUPLEX_HALF:
3631 adapter->hw.forced_speed_duplex = e1000_10_half;
3633 case SPEED_10 + DUPLEX_FULL:
3634 adapter->hw.forced_speed_duplex = e1000_10_full;
3636 case SPEED_100 + DUPLEX_HALF:
3637 adapter->hw.forced_speed_duplex = e1000_100_half;
3639 case SPEED_100 + DUPLEX_FULL:
3640 adapter->hw.forced_speed_duplex = e1000_100_full;
3642 case SPEED_1000 + DUPLEX_FULL:
3643 adapter->hw.autoneg = 1;
3644 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
3646 case SPEED_1000 + DUPLEX_HALF: /* not supported */
3648 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3655 e1000_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3657 struct pci_dev *pdev = NULL;
3663 while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
3664 if(pci_dev_driver(pdev) == &e1000_driver)
3665 e1000_suspend(pdev, 3);
3672 e1000_suspend(struct pci_dev *pdev, uint32_t state)
3674 struct net_device *netdev = pci_get_drvdata(pdev);
3675 struct e1000_adapter *adapter = netdev_priv(netdev);
3676 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
3677 uint32_t wufc = adapter->wol;
3679 netif_device_detach(netdev);
3681 if(netif_running(netdev))
3682 e1000_down(adapter);
3684 status = E1000_READ_REG(&adapter->hw, STATUS);
3685 if(status & E1000_STATUS_LU)
3686 wufc &= ~E1000_WUFC_LNKC;
3689 e1000_setup_rctl(adapter);
3690 e1000_set_multi(netdev);
3692 /* turn on all-multi mode if wake on multicast is enabled */
3693 if(adapter->wol & E1000_WUFC_MC) {
3694 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3695 rctl |= E1000_RCTL_MPE;
3696 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3699 if(adapter->hw.mac_type >= e1000_82540) {
3700 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3701 /* advertise wake from D3Cold */
3702 #define E1000_CTRL_ADVD3WUC 0x00100000
3703 /* phy power management enable */
3704 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3705 ctrl |= E1000_CTRL_ADVD3WUC |
3706 E1000_CTRL_EN_PHY_PWR_MGMT;
3707 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3710 if(adapter->hw.media_type == e1000_media_type_fiber ||
3711 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3712 /* keep the laser running in D3 */
3713 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
3714 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3715 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
3718 /* Allow time for pending master requests to run */
3719 e1000_disable_pciex_master(&adapter->hw);
3721 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
3722 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
3723 pci_enable_wake(pdev, 3, 1);
3724 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3726 E1000_WRITE_REG(&adapter->hw, WUC, 0);
3727 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
3728 pci_enable_wake(pdev, 3, 0);
3729 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3732 pci_save_state(pdev);
3734 if(adapter->hw.mac_type >= e1000_82540 &&
3735 adapter->hw.media_type == e1000_media_type_copper) {
3736 manc = E1000_READ_REG(&adapter->hw, MANC);
3737 if(manc & E1000_MANC_SMBUS_EN) {
3738 manc |= E1000_MANC_ARP_EN;
3739 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3740 pci_enable_wake(pdev, 3, 1);
3741 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3745 switch(adapter->hw.mac_type) {
3747 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3748 E1000_WRITE_REG(&adapter->hw, SWSM,
3749 swsm & ~E1000_SWSM_DRV_LOAD);
3755 pci_disable_device(pdev);
3757 state = (state > 0) ? 3 : 0;
3758 pci_set_power_state(pdev, state);
3765 e1000_resume(struct pci_dev *pdev)
3767 struct net_device *netdev = pci_get_drvdata(pdev);
3768 struct e1000_adapter *adapter = netdev_priv(netdev);
3769 uint32_t manc, ret_val, swsm;
3771 pci_set_power_state(pdev, 0);
3772 pci_restore_state(pdev);
3773 ret_val = pci_enable_device(pdev);
3774 pci_set_master(pdev);
3776 pci_enable_wake(pdev, 3, 0);
3777 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3779 e1000_reset(adapter);
3780 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
3782 if(netif_running(netdev))
3785 netif_device_attach(netdev);
3787 if(adapter->hw.mac_type >= e1000_82540 &&
3788 adapter->hw.media_type == e1000_media_type_copper) {
3789 manc = E1000_READ_REG(&adapter->hw, MANC);
3790 manc &= ~(E1000_MANC_ARP_EN);
3791 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3794 switch(adapter->hw.mac_type) {
3796 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3797 E1000_WRITE_REG(&adapter->hw, SWSM,
3798 swsm | E1000_SWSM_DRV_LOAD);
3807 #ifdef CONFIG_NET_POLL_CONTROLLER
3809 * Polling 'interrupt' - used by things like netconsole to send skbs
3810 * without having to re-enable interrupts. It's not called while
3811 * the interrupt routine is executing.
3814 e1000_netpoll(struct net_device *netdev)
3816 struct e1000_adapter *adapter = netdev_priv(netdev);
3817 disable_irq(adapter->pdev->irq);
3818 e1000_intr(adapter->pdev->irq, netdev, NULL);
3819 enable_irq(adapter->pdev->irq);